@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Load the $modSettings array. |
@@ -25,13 +26,14 @@ discard block |
||
25 | 26 | global $cache_enable, $sourcedir, $context; |
26 | 27 | |
27 | 28 | // Most database systems have not set UTF-8 as their default input charset. |
28 | - if (!empty($db_character_set)) |
|
29 | - $smcFunc['db_query']('', ' |
|
29 | + if (!empty($db_character_set)) { |
|
30 | + $smcFunc['db_query']('', ' |
|
30 | 31 | SET NAMES {string:db_character_set}', |
31 | 32 | array( |
32 | 33 | 'db_character_set' => $db_character_set, |
33 | 34 | ) |
34 | 35 | ); |
36 | + } |
|
35 | 37 | |
36 | 38 | // We need some caching support, maybe. |
37 | 39 | loadCacheAccelerator(); |
@@ -46,27 +48,35 @@ discard block |
||
46 | 48 | ) |
47 | 49 | ); |
48 | 50 | $modSettings = array(); |
49 | - if (!$request) |
|
50 | - display_db_error(); |
|
51 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
52 | - $modSettings[$row[0]] = $row[1]; |
|
51 | + if (!$request) { |
|
52 | + display_db_error(); |
|
53 | + } |
|
54 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
55 | + $modSettings[$row[0]] = $row[1]; |
|
56 | + } |
|
53 | 57 | $smcFunc['db_free_result']($request); |
54 | 58 | |
55 | 59 | // Do a few things to protect against missing settings or settings with invalid values... |
56 | - if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) |
|
57 | - $modSettings['defaultMaxTopics'] = 20; |
|
58 | - if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) |
|
59 | - $modSettings['defaultMaxMessages'] = 15; |
|
60 | - if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) |
|
61 | - $modSettings['defaultMaxMembers'] = 30; |
|
62 | - if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) |
|
63 | - $modSettings['defaultMaxListItems'] = 15; |
|
60 | + if (empty($modSettings['defaultMaxTopics']) || $modSettings['defaultMaxTopics'] <= 0 || $modSettings['defaultMaxTopics'] > 999) { |
|
61 | + $modSettings['defaultMaxTopics'] = 20; |
|
62 | + } |
|
63 | + if (empty($modSettings['defaultMaxMessages']) || $modSettings['defaultMaxMessages'] <= 0 || $modSettings['defaultMaxMessages'] > 999) { |
|
64 | + $modSettings['defaultMaxMessages'] = 15; |
|
65 | + } |
|
66 | + if (empty($modSettings['defaultMaxMembers']) || $modSettings['defaultMaxMembers'] <= 0 || $modSettings['defaultMaxMembers'] > 999) { |
|
67 | + $modSettings['defaultMaxMembers'] = 30; |
|
68 | + } |
|
69 | + if (empty($modSettings['defaultMaxListItems']) || $modSettings['defaultMaxListItems'] <= 0 || $modSettings['defaultMaxListItems'] > 999) { |
|
70 | + $modSettings['defaultMaxListItems'] = 15; |
|
71 | + } |
|
64 | 72 | |
65 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
66 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
73 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
74 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
75 | + } |
|
67 | 76 | |
68 | - if (!empty($cache_enable)) |
|
69 | - cache_put_data('modSettings', $modSettings, 90); |
|
77 | + if (!empty($cache_enable)) { |
|
78 | + cache_put_data('modSettings', $modSettings, 90); |
|
79 | + } |
|
70 | 80 | } |
71 | 81 | |
72 | 82 | $modSettings['cache_enable'] = $cache_enable; |
@@ -86,8 +96,9 @@ discard block |
||
86 | 96 | }; |
87 | 97 | $fix_utf8mb4 = function($string) use ($utf8, $smcFunc) |
88 | 98 | { |
89 | - if (!$utf8 || $smcFunc['db_mb4']) |
|
90 | - return $string; |
|
99 | + if (!$utf8 || $smcFunc['db_mb4']) { |
|
100 | + return $string; |
|
101 | + } |
|
91 | 102 | |
92 | 103 | $i = 0; |
93 | 104 | $len = strlen($string); |
@@ -99,18 +110,15 @@ discard block |
||
99 | 110 | { |
100 | 111 | $new_string .= $string[$i]; |
101 | 112 | $i++; |
102 | - } |
|
103 | - elseif ($ord < 224) |
|
113 | + } elseif ($ord < 224) |
|
104 | 114 | { |
105 | 115 | $new_string .= $string[$i] . $string[$i + 1]; |
106 | 116 | $i += 2; |
107 | - } |
|
108 | - elseif ($ord < 240) |
|
117 | + } elseif ($ord < 240) |
|
109 | 118 | { |
110 | 119 | $new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2]; |
111 | 120 | $i += 3; |
112 | - } |
|
113 | - elseif ($ord < 248) |
|
121 | + } elseif ($ord < 248) |
|
114 | 122 | { |
115 | 123 | // Magic happens. |
116 | 124 | $val = (ord($string[$i]) & 0x07) << 18; |
@@ -154,8 +162,7 @@ discard block |
||
154 | 162 | { |
155 | 163 | $result = array_search($needle, array_slice($haystack_arr, $offset)); |
156 | 164 | return is_int($result) ? $result + $offset : false; |
157 | - } |
|
158 | - else |
|
165 | + } else |
|
159 | 166 | { |
160 | 167 | $needle_arr = preg_split('~(&#' . (empty($modSettings['disableEntityCheck']) ? '\d{1,7}' : '021') . ';|"|&|<|>| |.)~' . ($utf8 ? 'u' : '') . '', $ent_check($needle), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); |
161 | 168 | $needle_size = count($needle_arr); |
@@ -164,8 +171,9 @@ discard block |
||
164 | 171 | while ((int) $result === $result) |
165 | 172 | { |
166 | 173 | $offset += $result; |
167 | - if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) |
|
168 | - return $offset; |
|
174 | + if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) { |
|
175 | + return $offset; |
|
176 | + } |
|
169 | 177 | $result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset)); |
170 | 178 | } |
171 | 179 | return false; |
@@ -203,8 +211,9 @@ discard block |
||
203 | 211 | $string = $ent_check($string); |
204 | 212 | preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches); |
205 | 213 | $string = $matches[0]; |
206 | - while (strlen($string) > $length) |
|
207 | - $string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string); |
|
214 | + while (strlen($string) > $length) { |
|
215 | + $string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string); |
|
216 | + } |
|
208 | 217 | return $string; |
209 | 218 | }, |
210 | 219 | 'ucfirst' => $utf8 ? function($string) use (&$smcFunc) |
@@ -214,23 +223,25 @@ discard block |
||
214 | 223 | 'ucwords' => $utf8 ? function($string) use (&$smcFunc) |
215 | 224 | { |
216 | 225 | $words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE); |
217 | - for ($i = 0, $n = count($words); $i < $n; $i += 2) |
|
218 | - $words[$i] = $smcFunc['ucfirst']($words[$i]); |
|
226 | + for ($i = 0, $n = count($words); $i < $n; $i += 2) { |
|
227 | + $words[$i] = $smcFunc['ucfirst']($words[$i]); |
|
228 | + } |
|
219 | 229 | return implode('', $words); |
220 | 230 | } : 'ucwords', |
221 | 231 | ); |
222 | 232 | |
223 | 233 | // Setting the timezone is a requirement for some functions. |
224 | - if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) |
|
225 | - date_default_timezone_set($modSettings['default_timezone']); |
|
226 | - else |
|
234 | + if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) { |
|
235 | + date_default_timezone_set($modSettings['default_timezone']); |
|
236 | + } else |
|
227 | 237 | { |
228 | 238 | // Get PHP's default timezone, if set |
229 | 239 | $ini_tz = ini_get('date.timezone'); |
230 | - if (!empty($ini_tz)) |
|
231 | - $modSettings['default_timezone'] = $ini_tz; |
|
232 | - else |
|
233 | - $modSettings['default_timezone'] = ''; |
|
240 | + if (!empty($ini_tz)) { |
|
241 | + $modSettings['default_timezone'] = $ini_tz; |
|
242 | + } else { |
|
243 | + $modSettings['default_timezone'] = ''; |
|
244 | + } |
|
234 | 245 | |
235 | 246 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
236 | 247 | if (!in_array($modSettings['default_timezone'], timezone_identifiers_list())) |
@@ -248,22 +259,26 @@ discard block |
||
248 | 259 | if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null) |
249 | 260 | { |
250 | 261 | $modSettings['load_average'] = @file_get_contents('/proc/loadavg'); |
251 | - if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) |
|
252 | - $modSettings['load_average'] = (float) $matches[1]; |
|
253 | - elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) |
|
254 | - $modSettings['load_average'] = (float) $matches[1]; |
|
255 | - else |
|
256 | - unset($modSettings['load_average']); |
|
262 | + if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) { |
|
263 | + $modSettings['load_average'] = (float) $matches[1]; |
|
264 | + } elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) { |
|
265 | + $modSettings['load_average'] = (float) $matches[1]; |
|
266 | + } else { |
|
267 | + unset($modSettings['load_average']); |
|
268 | + } |
|
257 | 269 | |
258 | - if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
|
259 | - cache_put_data('loadavg', $modSettings['load_average'], 90); |
|
270 | + if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) { |
|
271 | + cache_put_data('loadavg', $modSettings['load_average'], 90); |
|
272 | + } |
|
260 | 273 | } |
261 | 274 | |
262 | - if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
|
263 | - call_integration_hook('integrate_load_average', array($modSettings['load_average'])); |
|
275 | + if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) { |
|
276 | + call_integration_hook('integrate_load_average', array($modSettings['load_average'])); |
|
277 | + } |
|
264 | 278 | |
265 | - if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) |
|
266 | - display_loadavg_error(); |
|
279 | + if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) { |
|
280 | + display_loadavg_error(); |
|
281 | + } |
|
267 | 282 | } |
268 | 283 | |
269 | 284 | // Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is. |
@@ -284,8 +299,9 @@ discard block |
||
284 | 299 | if (defined('SMF_INTEGRATION_SETTINGS')) |
285 | 300 | { |
286 | 301 | $integration_settings = smf_json_decode(SMF_INTEGRATION_SETTINGS, true); |
287 | - foreach ($integration_settings as $hook => $function) |
|
288 | - add_integration_function($hook, $function, '', false); |
|
302 | + foreach ($integration_settings as $hook => $function) { |
|
303 | + add_integration_function($hook, $function, '', false); |
|
304 | + } |
|
289 | 305 | } |
290 | 306 | |
291 | 307 | // Any files to pre include? |
@@ -295,8 +311,9 @@ discard block |
||
295 | 311 | foreach ($pre_includes as $include) |
296 | 312 | { |
297 | 313 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
298 | - if (file_exists($include)) |
|
299 | - require_once($include); |
|
314 | + if (file_exists($include)) { |
|
315 | + require_once($include); |
|
316 | + } |
|
300 | 317 | } |
301 | 318 | } |
302 | 319 | |
@@ -400,27 +417,28 @@ discard block |
||
400 | 417 | break; |
401 | 418 | } |
402 | 419 | } |
420 | + } else { |
|
421 | + $id_member = 0; |
|
403 | 422 | } |
404 | - else |
|
405 | - $id_member = 0; |
|
406 | 423 | |
407 | 424 | if (empty($id_member) && isset($_COOKIE[$cookiename])) |
408 | 425 | { |
409 | 426 | $cookie_data = smf_json_decode($_COOKIE[$cookiename], true, false); |
410 | 427 | |
411 | - if (empty($cookie_data)) |
|
412 | - $cookie_data = safe_unserialize($_COOKIE[$cookiename]); |
|
428 | + if (empty($cookie_data)) { |
|
429 | + $cookie_data = safe_unserialize($_COOKIE[$cookiename]); |
|
430 | + } |
|
413 | 431 | |
414 | 432 | list ($id_member, $password) = $cookie_data; |
415 | 433 | $id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0; |
416 | - } |
|
417 | - elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA']))) |
|
434 | + } elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA']))) |
|
418 | 435 | { |
419 | 436 | // @todo Perhaps we can do some more checking on this, such as on the first octet of the IP? |
420 | 437 | $cookie_data = smf_json_decode($_SESSION['login_' . $cookiename]); |
421 | 438 | |
422 | - if (empty($cookie_data)) |
|
423 | - $cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
439 | + if (empty($cookie_data)) { |
|
440 | + $cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
441 | + } |
|
424 | 442 | |
425 | 443 | list ($id_member, $password, $login_span) = $cookie_data; |
426 | 444 | $id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0; |
@@ -445,30 +463,34 @@ discard block |
||
445 | 463 | $user_settings = $smcFunc['db_fetch_assoc']($request); |
446 | 464 | $smcFunc['db_free_result']($request); |
447 | 465 | |
448 | - if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) |
|
449 | - $user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret); |
|
466 | + if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) { |
|
467 | + $user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret); |
|
468 | + } |
|
450 | 469 | |
451 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
452 | - cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
470 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
471 | + cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
472 | + } |
|
453 | 473 | } |
454 | 474 | |
455 | 475 | // Did we find 'im? If not, junk it. |
456 | 476 | if (!empty($user_settings)) |
457 | 477 | { |
458 | 478 | // As much as the password should be right, we can assume the integration set things up. |
459 | - if (!empty($already_verified) && $already_verified === true) |
|
460 | - $check = true; |
|
479 | + if (!empty($already_verified) && $already_verified === true) { |
|
480 | + $check = true; |
|
481 | + } |
|
461 | 482 | // SHA-512 hash should be 128 characters long. |
462 | - elseif (strlen($password) == 128) |
|
463 | - $check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password; |
|
464 | - else |
|
465 | - $check = false; |
|
483 | + elseif (strlen($password) == 128) { |
|
484 | + $check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password; |
|
485 | + } else { |
|
486 | + $check = false; |
|
487 | + } |
|
466 | 488 | |
467 | 489 | // Wrong password or not activated - either way, you're going nowhere. |
468 | 490 | $id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0; |
491 | + } else { |
|
492 | + $id_member = 0; |
|
469 | 493 | } |
470 | - else |
|
471 | - $id_member = 0; |
|
472 | 494 | |
473 | 495 | // If we no longer have the member maybe they're being all hackey, stop brute force! |
474 | 496 | if (!$id_member) |
@@ -490,13 +512,15 @@ discard block |
||
490 | 512 | { |
491 | 513 | $tfa_data = smf_json_decode($_COOKIE[$tfacookie]); |
492 | 514 | |
493 | - if (is_null($tfa_data)) |
|
494 | - $tfa_data = safe_unserialize($_COOKIE[$tfacookie]); |
|
515 | + if (is_null($tfa_data)) { |
|
516 | + $tfa_data = safe_unserialize($_COOKIE[$tfacookie]); |
|
517 | + } |
|
495 | 518 | |
496 | 519 | list ($tfamember, $tfasecret) = $tfa_data; |
497 | 520 | |
498 | - if ((int) $tfamember != $id_member) |
|
499 | - $tfasecret = null; |
|
521 | + if ((int) $tfamember != $id_member) { |
|
522 | + $tfasecret = null; |
|
523 | + } |
|
500 | 524 | } |
501 | 525 | |
502 | 526 | if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret) |
@@ -516,10 +540,12 @@ discard block |
||
516 | 540 | // Are we forcing 2FA? Need to check if the user groups actually require 2FA |
517 | 541 | elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret'])) |
518 | 542 | { |
519 | - if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups |
|
543 | + if ($modSettings['tfa_mode'] == 2) { |
|
544 | + //only do this if we are just forcing SOME membergroups |
|
520 | 545 | { |
521 | 546 | //Build an array of ALL user membergroups. |
522 | 547 | $full_groups = array($user_settings['id_group']); |
548 | + } |
|
523 | 549 | if (!empty($user_settings['additional_groups'])) |
524 | 550 | { |
525 | 551 | $full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups'])); |
@@ -539,15 +565,17 @@ discard block |
||
539 | 565 | ); |
540 | 566 | $row = $smcFunc['db_fetch_assoc']($request); |
541 | 567 | $smcFunc['db_free_result']($request); |
568 | + } else { |
|
569 | + $row['total'] = 1; |
|
542 | 570 | } |
543 | - else |
|
544 | - $row['total'] = 1; //simplifies logics in the next "if" |
|
571 | + //simplifies logics in the next "if" |
|
545 | 572 | |
546 | 573 | $area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : ''; |
547 | 574 | $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : ''; |
548 | 575 | |
549 | - if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) |
|
550 | - redirectexit('action=profile;area=tfasetup;forced'); |
|
576 | + if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) { |
|
577 | + redirectexit('action=profile;area=tfasetup;forced'); |
|
578 | + } |
|
551 | 579 | } |
552 | 580 | } |
553 | 581 | |
@@ -584,33 +612,37 @@ discard block |
||
584 | 612 | updateMemberData($id_member, array('id_msg_last_visit' => (int) $modSettings['maxMsgID'], 'last_login' => time(), 'member_ip' => $_SERVER['REMOTE_ADDR'], 'member_ip2' => $_SERVER['BAN_CHECK_IP'])); |
585 | 613 | $user_settings['last_login'] = time(); |
586 | 614 | |
587 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
588 | - cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
615 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
616 | + cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
617 | + } |
|
589 | 618 | |
590 | - if (!empty($modSettings['cache_enable'])) |
|
591 | - cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600); |
|
619 | + if (!empty($modSettings['cache_enable'])) { |
|
620 | + cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600); |
|
621 | + } |
|
592 | 622 | } |
623 | + } elseif (empty($_SESSION['id_msg_last_visit'])) { |
|
624 | + $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit']; |
|
593 | 625 | } |
594 | - elseif (empty($_SESSION['id_msg_last_visit'])) |
|
595 | - $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit']; |
|
596 | 626 | |
597 | 627 | $username = $user_settings['member_name']; |
598 | 628 | |
599 | - if (empty($user_settings['additional_groups'])) |
|
600 | - $user_info = array( |
|
629 | + if (empty($user_settings['additional_groups'])) { |
|
630 | + $user_info = array( |
|
601 | 631 | 'groups' => array($user_settings['id_group'], $user_settings['id_post_group']) |
602 | 632 | ); |
603 | - else |
|
604 | - $user_info = array( |
|
633 | + } else { |
|
634 | + $user_info = array( |
|
605 | 635 | 'groups' => array_merge( |
606 | 636 | array($user_settings['id_group'], $user_settings['id_post_group']), |
607 | 637 | explode(',', $user_settings['additional_groups']) |
608 | 638 | ) |
609 | 639 | ); |
640 | + } |
|
610 | 641 | |
611 | 642 | // Because history has proven that it is possible for groups to go bad - clean up in case. |
612 | - foreach ($user_info['groups'] as $k => $v) |
|
613 | - $user_info['groups'][$k] = (int) $v; |
|
643 | + foreach ($user_info['groups'] as $k => $v) { |
|
644 | + $user_info['groups'][$k] = (int) $v; |
|
645 | + } |
|
614 | 646 | |
615 | 647 | // This is a logged in user, so definitely not a spider. |
616 | 648 | $user_info['possibly_robot'] = false; |
@@ -624,8 +656,7 @@ discard block |
||
624 | 656 | $time_system = new DateTime('now', $tz_system); |
625 | 657 | $time_user = new DateTime('now', $tz_user); |
626 | 658 | $user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600; |
627 | - } |
|
628 | - else |
|
659 | + } else |
|
629 | 660 | { |
630 | 661 | // !!! Compatibility. |
631 | 662 | $user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset']; |
@@ -639,16 +670,18 @@ discard block |
||
639 | 670 | $user_info = array('groups' => array(-1)); |
640 | 671 | $user_settings = array(); |
641 | 672 | |
642 | - if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) |
|
643 | - $_COOKIE[$cookiename] = ''; |
|
673 | + if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) { |
|
674 | + $_COOKIE[$cookiename] = ''; |
|
675 | + } |
|
644 | 676 | |
645 | 677 | // Expire the 2FA cookie |
646 | 678 | if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member'])) |
647 | 679 | { |
648 | 680 | $tfa_data = smf_json_decode($_COOKIE[$cookiename . '_tfa'], true); |
649 | 681 | |
650 | - if (is_null($tfa_data)) |
|
651 | - $tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']); |
|
682 | + if (is_null($tfa_data)) { |
|
683 | + $tfa_data = safe_unserialize($_COOKIE[$cookiename . '_tfa']); |
|
684 | + } |
|
652 | 685 | |
653 | 686 | list ($id, $user, $exp, $state, $preserve) = $tfa_data; |
654 | 687 | |
@@ -660,19 +693,20 @@ discard block |
||
660 | 693 | } |
661 | 694 | |
662 | 695 | // Create a login token if it doesn't exist yet. |
663 | - if (!isset($_SESSION['token']['post-login'])) |
|
664 | - createToken('login'); |
|
665 | - else |
|
666 | - list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login']; |
|
696 | + if (!isset($_SESSION['token']['post-login'])) { |
|
697 | + createToken('login'); |
|
698 | + } else { |
|
699 | + list ($context['login_token_var'],,, $context['login_token']) = $_SESSION['token']['post-login']; |
|
700 | + } |
|
667 | 701 | |
668 | 702 | // Do we perhaps think this is a search robot? Check every five minutes just in case... |
669 | 703 | if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300)) |
670 | 704 | { |
671 | 705 | require_once($sourcedir . '/ManageSearchEngines.php'); |
672 | 706 | $user_info['possibly_robot'] = SpiderCheck(); |
707 | + } elseif (!empty($modSettings['spider_mode'])) { |
|
708 | + $user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0; |
|
673 | 709 | } |
674 | - elseif (!empty($modSettings['spider_mode'])) |
|
675 | - $user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0; |
|
676 | 710 | // If we haven't turned on proper spider hunts then have a guess! |
677 | 711 | else |
678 | 712 | { |
@@ -720,8 +754,9 @@ discard block |
||
720 | 754 | $user_info['groups'] = array_unique($user_info['groups']); |
721 | 755 | |
722 | 756 | // Make sure that the last item in the ignore boards array is valid. If the list was too long it could have an ending comma that could cause problems. |
723 | - if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) |
|
724 | - unset($user_info['ignoreboards'][$tmp]); |
|
757 | + if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) { |
|
758 | + unset($user_info['ignoreboards'][$tmp]); |
|
759 | + } |
|
725 | 760 | |
726 | 761 | // Allow the user to change their language. |
727 | 762 | if (!empty($modSettings['userLanguage'])) |
@@ -734,31 +769,36 @@ discard block |
||
734 | 769 | $user_info['language'] = strtr($_GET['language'], './\\:', '____'); |
735 | 770 | |
736 | 771 | // Make it permanent for members. |
737 | - if (!empty($user_info['id'])) |
|
738 | - updateMemberData($user_info['id'], array('lngfile' => $user_info['language'])); |
|
739 | - else |
|
740 | - $_SESSION['language'] = $user_info['language']; |
|
772 | + if (!empty($user_info['id'])) { |
|
773 | + updateMemberData($user_info['id'], array('lngfile' => $user_info['language'])); |
|
774 | + } else { |
|
775 | + $_SESSION['language'] = $user_info['language']; |
|
776 | + } |
|
777 | + } elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) { |
|
778 | + $user_info['language'] = strtr($_SESSION['language'], './\\:', '____'); |
|
741 | 779 | } |
742 | - elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) |
|
743 | - $user_info['language'] = strtr($_SESSION['language'], './\\:', '____'); |
|
744 | 780 | } |
745 | 781 | |
746 | 782 | // Just build this here, it makes it easier to change/use - administrators can see all boards. |
747 | - if ($user_info['is_admin']) |
|
748 | - $user_info['query_see_board'] = '1=1'; |
|
783 | + if ($user_info['is_admin']) { |
|
784 | + $user_info['query_see_board'] = '1=1'; |
|
785 | + } |
|
749 | 786 | // Otherwise just the groups in $user_info['groups']. |
750 | - else |
|
751 | - $user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')'; |
|
787 | + else { |
|
788 | + $user_info['query_see_board'] = '((FIND_IN_SET(' . implode(', b.member_groups) != 0 OR FIND_IN_SET(', $user_info['groups']) . ', b.member_groups) != 0)' . (!empty($modSettings['deny_boards_access']) ? ' AND (FIND_IN_SET(' . implode(', b.deny_member_groups) = 0 AND FIND_IN_SET(', $user_info['groups']) . ', b.deny_member_groups) = 0)' : '') . (isset($user_info['mod_cache']) ? ' OR ' . $user_info['mod_cache']['mq'] : '') . ')'; |
|
789 | + } |
|
752 | 790 | |
753 | 791 | // Build the list of boards they WANT to see. |
754 | 792 | // This will take the place of query_see_boards in certain spots, so it better include the boards they can see also |
755 | 793 | |
756 | 794 | // If they aren't ignoring any boards then they want to see all the boards they can see |
757 | - if (empty($user_info['ignoreboards'])) |
|
758 | - $user_info['query_wanna_see_board'] = $user_info['query_see_board']; |
|
795 | + if (empty($user_info['ignoreboards'])) { |
|
796 | + $user_info['query_wanna_see_board'] = $user_info['query_see_board']; |
|
797 | + } |
|
759 | 798 | // Ok I guess they don't want to see all the boards |
760 | - else |
|
761 | - $user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))'; |
|
799 | + else { |
|
800 | + $user_info['query_wanna_see_board'] = '(' . $user_info['query_see_board'] . ' AND b.id_board NOT IN (' . implode(',', $user_info['ignoreboards']) . '))'; |
|
801 | + } |
|
762 | 802 | |
763 | 803 | call_integration_hook('integrate_user_info'); |
764 | 804 | } |
@@ -816,9 +856,9 @@ discard block |
||
816 | 856 | } |
817 | 857 | |
818 | 858 | // Remember redirection is the key to avoiding fallout from your bosses. |
819 | - if (!empty($topic)) |
|
820 | - redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']); |
|
821 | - else |
|
859 | + if (!empty($topic)) { |
|
860 | + redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']); |
|
861 | + } else |
|
822 | 862 | { |
823 | 863 | loadPermissions(); |
824 | 864 | loadTheme(); |
@@ -836,10 +876,11 @@ discard block |
||
836 | 876 | if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3)) |
837 | 877 | { |
838 | 878 | // @todo SLOW? |
839 | - if (!empty($topic)) |
|
840 | - $temp = cache_get_data('topic_board-' . $topic, 120); |
|
841 | - else |
|
842 | - $temp = cache_get_data('board-' . $board, 120); |
|
879 | + if (!empty($topic)) { |
|
880 | + $temp = cache_get_data('topic_board-' . $topic, 120); |
|
881 | + } else { |
|
882 | + $temp = cache_get_data('board-' . $board, 120); |
|
883 | + } |
|
843 | 884 | |
844 | 885 | if (!empty($temp)) |
845 | 886 | { |
@@ -877,8 +918,9 @@ discard block |
||
877 | 918 | $row = $smcFunc['db_fetch_assoc']($request); |
878 | 919 | |
879 | 920 | // Set the current board. |
880 | - if (!empty($row['id_board'])) |
|
881 | - $board = $row['id_board']; |
|
921 | + if (!empty($row['id_board'])) { |
|
922 | + $board = $row['id_board']; |
|
923 | + } |
|
882 | 924 | |
883 | 925 | // Basic operating information. (globals... :/) |
884 | 926 | $board_info = array( |
@@ -914,21 +956,23 @@ discard block |
||
914 | 956 | |
915 | 957 | do |
916 | 958 | { |
917 | - if (!empty($row['id_moderator'])) |
|
918 | - $board_info['moderators'][$row['id_moderator']] = array( |
|
959 | + if (!empty($row['id_moderator'])) { |
|
960 | + $board_info['moderators'][$row['id_moderator']] = array( |
|
919 | 961 | 'id' => $row['id_moderator'], |
920 | 962 | 'name' => $row['real_name'], |
921 | 963 | 'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'], |
922 | 964 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>' |
923 | 965 | ); |
966 | + } |
|
924 | 967 | |
925 | - if (!empty($row['id_moderator_group'])) |
|
926 | - $board_info['moderator_groups'][$row['id_moderator_group']] = array( |
|
968 | + if (!empty($row['id_moderator_group'])) { |
|
969 | + $board_info['moderator_groups'][$row['id_moderator_group']] = array( |
|
927 | 970 | 'id' => $row['id_moderator_group'], |
928 | 971 | 'name' => $row['group_name'], |
929 | 972 | 'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'], |
930 | 973 | 'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>' |
931 | 974 | ); |
975 | + } |
|
932 | 976 | } |
933 | 977 | while ($row = $smcFunc['db_fetch_assoc']($request)); |
934 | 978 | |
@@ -960,12 +1004,12 @@ discard block |
||
960 | 1004 | if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3)) |
961 | 1005 | { |
962 | 1006 | // @todo SLOW? |
963 | - if (!empty($topic)) |
|
964 | - cache_put_data('topic_board-' . $topic, $board_info, 120); |
|
1007 | + if (!empty($topic)) { |
|
1008 | + cache_put_data('topic_board-' . $topic, $board_info, 120); |
|
1009 | + } |
|
965 | 1010 | cache_put_data('board-' . $board, $board_info, 120); |
966 | 1011 | } |
967 | - } |
|
968 | - else |
|
1012 | + } else |
|
969 | 1013 | { |
970 | 1014 | // Otherwise the topic is invalid, there are no moderators, etc. |
971 | 1015 | $board_info = array( |
@@ -979,8 +1023,9 @@ discard block |
||
979 | 1023 | $smcFunc['db_free_result']($request); |
980 | 1024 | } |
981 | 1025 | |
982 | - if (!empty($topic)) |
|
983 | - $_GET['board'] = (int) $board; |
|
1026 | + if (!empty($topic)) { |
|
1027 | + $_GET['board'] = (int) $board; |
|
1028 | + } |
|
984 | 1029 | |
985 | 1030 | if (!empty($board)) |
986 | 1031 | { |
@@ -990,10 +1035,12 @@ discard block |
||
990 | 1035 | // Now check if the user is a moderator. |
991 | 1036 | $user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0; |
992 | 1037 | |
993 | - if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) |
|
994 | - $board_info['error'] = 'access'; |
|
995 | - if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) |
|
996 | - $board_info['error'] = 'access'; |
|
1038 | + if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) { |
|
1039 | + $board_info['error'] = 'access'; |
|
1040 | + } |
|
1041 | + if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) { |
|
1042 | + $board_info['error'] = 'access'; |
|
1043 | + } |
|
997 | 1044 | |
998 | 1045 | // Build up the linktree. |
999 | 1046 | $context['linktree'] = array_merge( |
@@ -1016,8 +1063,9 @@ discard block |
||
1016 | 1063 | $context['current_board'] = $board; |
1017 | 1064 | |
1018 | 1065 | // No posting in redirection boards! |
1019 | - if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) |
|
1020 | - $board_info['error'] == 'post_in_redirect'; |
|
1066 | + if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) { |
|
1067 | + $board_info['error'] == 'post_in_redirect'; |
|
1068 | + } |
|
1021 | 1069 | |
1022 | 1070 | // Hacker... you can't see this topic, I'll tell you that. (but moderators can!) |
1023 | 1071 | if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod'])) |
@@ -1043,24 +1091,23 @@ discard block |
||
1043 | 1091 | ob_end_clean(); |
1044 | 1092 | header('HTTP/1.1 403 Forbidden'); |
1045 | 1093 | die; |
1046 | - } |
|
1047 | - elseif ($board_info['error'] == 'post_in_redirect') |
|
1094 | + } elseif ($board_info['error'] == 'post_in_redirect') |
|
1048 | 1095 | { |
1049 | 1096 | // Slightly different error message here... |
1050 | 1097 | fatal_lang_error('cannot_post_redirect', false); |
1051 | - } |
|
1052 | - elseif ($user_info['is_guest']) |
|
1098 | + } elseif ($user_info['is_guest']) |
|
1053 | 1099 | { |
1054 | 1100 | loadLanguage('Errors'); |
1055 | 1101 | is_not_guest($txt['topic_gone']); |
1102 | + } else { |
|
1103 | + fatal_lang_error('topic_gone', false); |
|
1056 | 1104 | } |
1057 | - else |
|
1058 | - fatal_lang_error('topic_gone', false); |
|
1059 | 1105 | } |
1060 | 1106 | |
1061 | - if ($user_info['is_mod']) |
|
1062 | - $user_info['groups'][] = 3; |
|
1063 | -} |
|
1107 | + if ($user_info['is_mod']) { |
|
1108 | + $user_info['groups'][] = 3; |
|
1109 | + } |
|
1110 | + } |
|
1064 | 1111 | |
1065 | 1112 | /** |
1066 | 1113 | * Load this user's permissions. |
@@ -1081,8 +1128,9 @@ discard block |
||
1081 | 1128 | asort($cache_groups); |
1082 | 1129 | $cache_groups = implode(',', $cache_groups); |
1083 | 1130 | // If it's a spider then cache it different. |
1084 | - if ($user_info['possibly_robot']) |
|
1085 | - $cache_groups .= '-spider'; |
|
1131 | + if ($user_info['possibly_robot']) { |
|
1132 | + $cache_groups .= '-spider'; |
|
1133 | + } |
|
1086 | 1134 | |
1087 | 1135 | if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated']) |
1088 | 1136 | { |
@@ -1090,9 +1138,9 @@ discard block |
||
1090 | 1138 | banPermissions(); |
1091 | 1139 | |
1092 | 1140 | return; |
1141 | + } elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) { |
|
1142 | + list ($user_info['permissions'], $removals) = $temp; |
|
1093 | 1143 | } |
1094 | - elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) |
|
1095 | - list ($user_info['permissions'], $removals) = $temp; |
|
1096 | 1144 | } |
1097 | 1145 | |
1098 | 1146 | // If it is detected as a robot, and we are restricting permissions as a special group - then implement this. |
@@ -1114,23 +1162,26 @@ discard block |
||
1114 | 1162 | $removals = array(); |
1115 | 1163 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1116 | 1164 | { |
1117 | - if (empty($row['add_deny'])) |
|
1118 | - $removals[] = $row['permission']; |
|
1119 | - else |
|
1120 | - $user_info['permissions'][] = $row['permission']; |
|
1165 | + if (empty($row['add_deny'])) { |
|
1166 | + $removals[] = $row['permission']; |
|
1167 | + } else { |
|
1168 | + $user_info['permissions'][] = $row['permission']; |
|
1169 | + } |
|
1121 | 1170 | } |
1122 | 1171 | $smcFunc['db_free_result']($request); |
1123 | 1172 | |
1124 | - if (isset($cache_groups)) |
|
1125 | - cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240); |
|
1173 | + if (isset($cache_groups)) { |
|
1174 | + cache_put_data('permissions:' . $cache_groups, array($user_info['permissions'], $removals), 240); |
|
1175 | + } |
|
1126 | 1176 | } |
1127 | 1177 | |
1128 | 1178 | // Get the board permissions. |
1129 | 1179 | if (!empty($board)) |
1130 | 1180 | { |
1131 | 1181 | // Make sure the board (if any) has been loaded by loadBoard(). |
1132 | - if (!isset($board_info['profile'])) |
|
1133 | - fatal_lang_error('no_board'); |
|
1182 | + if (!isset($board_info['profile'])) { |
|
1183 | + fatal_lang_error('no_board'); |
|
1184 | + } |
|
1134 | 1185 | |
1135 | 1186 | $request = $smcFunc['db_query']('', ' |
1136 | 1187 | SELECT permission, add_deny |
@@ -1146,20 +1197,23 @@ discard block |
||
1146 | 1197 | ); |
1147 | 1198 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1148 | 1199 | { |
1149 | - if (empty($row['add_deny'])) |
|
1150 | - $removals[] = $row['permission']; |
|
1151 | - else |
|
1152 | - $user_info['permissions'][] = $row['permission']; |
|
1200 | + if (empty($row['add_deny'])) { |
|
1201 | + $removals[] = $row['permission']; |
|
1202 | + } else { |
|
1203 | + $user_info['permissions'][] = $row['permission']; |
|
1204 | + } |
|
1153 | 1205 | } |
1154 | 1206 | $smcFunc['db_free_result']($request); |
1155 | 1207 | } |
1156 | 1208 | |
1157 | 1209 | // Remove all the permissions they shouldn't have ;). |
1158 | - if (!empty($modSettings['permission_enable_deny'])) |
|
1159 | - $user_info['permissions'] = array_diff($user_info['permissions'], $removals); |
|
1210 | + if (!empty($modSettings['permission_enable_deny'])) { |
|
1211 | + $user_info['permissions'] = array_diff($user_info['permissions'], $removals); |
|
1212 | + } |
|
1160 | 1213 | |
1161 | - if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) |
|
1162 | - cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240); |
|
1214 | + if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) { |
|
1215 | + cache_put_data('permissions:' . $cache_groups . ':' . $board, array($user_info['permissions'], null), 240); |
|
1216 | + } |
|
1163 | 1217 | |
1164 | 1218 | // Banned? Watch, don't touch.. |
1165 | 1219 | banPermissions(); |
@@ -1171,17 +1225,18 @@ discard block |
||
1171 | 1225 | { |
1172 | 1226 | require_once($sourcedir . '/Subs-Auth.php'); |
1173 | 1227 | rebuildModCache(); |
1228 | + } else { |
|
1229 | + $user_info['mod_cache'] = $_SESSION['mc']; |
|
1174 | 1230 | } |
1175 | - else |
|
1176 | - $user_info['mod_cache'] = $_SESSION['mc']; |
|
1177 | 1231 | |
1178 | 1232 | // This is a useful phantom permission added to the current user, and only the current user while they are logged in. |
1179 | 1233 | // For example this drastically simplifies certain changes to the profile area. |
1180 | 1234 | $user_info['permissions'][] = 'is_not_guest'; |
1181 | 1235 | // And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions. |
1182 | 1236 | $user_info['permissions'][] = 'profile_view_own'; |
1183 | - if (in_array('profile_view', $user_info['permissions'])) |
|
1184 | - $user_info['permissions'][] = 'profile_view_any'; |
|
1237 | + if (in_array('profile_view', $user_info['permissions'])) { |
|
1238 | + $user_info['permissions'][] = 'profile_view_any'; |
|
1239 | + } |
|
1185 | 1240 | } |
1186 | 1241 | } |
1187 | 1242 | |
@@ -1199,8 +1254,9 @@ discard block |
||
1199 | 1254 | global $image_proxy_enabled, $image_proxy_secret, $boardurl; |
1200 | 1255 | |
1201 | 1256 | // Can't just look for no users :P. |
1202 | - if (empty($users)) |
|
1203 | - return array(); |
|
1257 | + if (empty($users)) { |
|
1258 | + return array(); |
|
1259 | + } |
|
1204 | 1260 | |
1205 | 1261 | // Pass the set value |
1206 | 1262 | $context['loadMemberContext_set'] = $set; |
@@ -1215,8 +1271,9 @@ discard block |
||
1215 | 1271 | for ($i = 0, $n = count($users); $i < $n; $i++) |
1216 | 1272 | { |
1217 | 1273 | $data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240); |
1218 | - if ($data == null) |
|
1219 | - continue; |
|
1274 | + if ($data == null) { |
|
1275 | + continue; |
|
1276 | + } |
|
1220 | 1277 | |
1221 | 1278 | $loaded_ids[] = $data['id_member']; |
1222 | 1279 | $user_profile[$data['id_member']] = $data; |
@@ -1283,13 +1340,16 @@ discard block |
||
1283 | 1340 | $row['avatar_original'] = $row['avatar']; |
1284 | 1341 | |
1285 | 1342 | // Take care of proxying avatar if required, do this here for maximum reach |
1286 | - if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) |
|
1287 | - $row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret); |
|
1343 | + if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) { |
|
1344 | + $row['avatar'] = $boardurl . '/proxy.php?request=' . urlencode($row['avatar']) . '&hash=' . md5($row['avatar'] . $image_proxy_secret); |
|
1345 | + } |
|
1288 | 1346 | |
1289 | - if (isset($row['member_ip'])) |
|
1290 | - $row['member_ip'] = inet_dtop($row['member_ip']); |
|
1291 | - if (isset($row['member_ip2'])) |
|
1292 | - $row['member_ip2'] = inet_dtop($row['member_ip2']); |
|
1347 | + if (isset($row['member_ip'])) { |
|
1348 | + $row['member_ip'] = inet_dtop($row['member_ip']); |
|
1349 | + } |
|
1350 | + if (isset($row['member_ip2'])) { |
|
1351 | + $row['member_ip2'] = inet_dtop($row['member_ip2']); |
|
1352 | + } |
|
1293 | 1353 | $new_loaded_ids[] = $row['id_member']; |
1294 | 1354 | $loaded_ids[] = $row['id_member']; |
1295 | 1355 | $row['options'] = array(); |
@@ -1308,8 +1368,9 @@ discard block |
||
1308 | 1368 | 'loaded_ids' => $new_loaded_ids, |
1309 | 1369 | ) |
1310 | 1370 | ); |
1311 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1312 | - $user_profile[$row['id_member']]['options'][$row['variable']] = $row['value']; |
|
1371 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1372 | + $user_profile[$row['id_member']]['options'][$row['variable']] = $row['value']; |
|
1373 | + } |
|
1313 | 1374 | $smcFunc['db_free_result']($request); |
1314 | 1375 | } |
1315 | 1376 | |
@@ -1320,10 +1381,11 @@ discard block |
||
1320 | 1381 | { |
1321 | 1382 | foreach ($loaded_ids as $a_member) |
1322 | 1383 | { |
1323 | - if (!empty($user_profile[$a_member]['additional_groups'])) |
|
1324 | - $groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups'])); |
|
1325 | - else |
|
1326 | - $groups = array($user_profile[$a_member]['id_group']); |
|
1384 | + if (!empty($user_profile[$a_member]['additional_groups'])) { |
|
1385 | + $groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups'])); |
|
1386 | + } else { |
|
1387 | + $groups = array($user_profile[$a_member]['id_group']); |
|
1388 | + } |
|
1327 | 1389 | |
1328 | 1390 | $temp = array_intersect($groups, array_keys($board_info['moderator_groups'])); |
1329 | 1391 | |
@@ -1336,8 +1398,9 @@ discard block |
||
1336 | 1398 | |
1337 | 1399 | if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) |
1338 | 1400 | { |
1339 | - for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) |
|
1340 | - cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240); |
|
1401 | + for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) { |
|
1402 | + cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240); |
|
1403 | + } |
|
1341 | 1404 | } |
1342 | 1405 | |
1343 | 1406 | // Are we loading any moderators? If so, fix their group data... |
@@ -1363,14 +1426,17 @@ discard block |
||
1363 | 1426 | foreach ($temp_mods as $id) |
1364 | 1427 | { |
1365 | 1428 | // By popular demand, don't show admins or global moderators as moderators. |
1366 | - if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) |
|
1367 | - $user_profile[$id]['member_group'] = $row['member_group']; |
|
1429 | + if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) { |
|
1430 | + $user_profile[$id]['member_group'] = $row['member_group']; |
|
1431 | + } |
|
1368 | 1432 | |
1369 | 1433 | // If the Moderator group has no color or icons, but their group does... don't overwrite. |
1370 | - if (!empty($row['icons'])) |
|
1371 | - $user_profile[$id]['icons'] = $row['icons']; |
|
1372 | - if (!empty($row['member_group_color'])) |
|
1373 | - $user_profile[$id]['member_group_color'] = $row['member_group_color']; |
|
1434 | + if (!empty($row['icons'])) { |
|
1435 | + $user_profile[$id]['icons'] = $row['icons']; |
|
1436 | + } |
|
1437 | + if (!empty($row['member_group_color'])) { |
|
1438 | + $user_profile[$id]['member_group_color'] = $row['member_group_color']; |
|
1439 | + } |
|
1374 | 1440 | } |
1375 | 1441 | } |
1376 | 1442 | |
@@ -1392,12 +1458,14 @@ discard block |
||
1392 | 1458 | static $loadedLanguages = array(); |
1393 | 1459 | |
1394 | 1460 | // If this person's data is already loaded, skip it. |
1395 | - if (isset($dataLoaded[$user])) |
|
1396 | - return true; |
|
1461 | + if (isset($dataLoaded[$user])) { |
|
1462 | + return true; |
|
1463 | + } |
|
1397 | 1464 | |
1398 | 1465 | // We can't load guests or members not loaded by loadMemberData()! |
1399 | - if ($user == 0) |
|
1400 | - return false; |
|
1466 | + if ($user == 0) { |
|
1467 | + return false; |
|
1468 | + } |
|
1401 | 1469 | if (!isset($user_profile[$user])) |
1402 | 1470 | { |
1403 | 1471 | trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING); |
@@ -1423,12 +1491,16 @@ discard block |
||
1423 | 1491 | $buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array(); |
1424 | 1492 | |
1425 | 1493 | //We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme |
1426 | - if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists |
|
1494 | + if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) { |
|
1495 | + //icon is set and exists |
|
1427 | 1496 | $group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1]; |
1428 | - elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default |
|
1497 | + } elseif (isset($profile['icons'][1])) { |
|
1498 | + //icon is set and doesn't exist, fallback to default |
|
1429 | 1499 | $group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1]; |
1430 | - else //not set, bye bye |
|
1500 | + } else { |
|
1501 | + //not set, bye bye |
|
1431 | 1502 | $group_icon_url = ''; |
1503 | + } |
|
1432 | 1504 | |
1433 | 1505 | // These minimal values are always loaded |
1434 | 1506 | $memberContext[$user] = array( |
@@ -1447,8 +1519,9 @@ discard block |
||
1447 | 1519 | if ($context['loadMemberContext_set'] != 'minimal') |
1448 | 1520 | { |
1449 | 1521 | // Go the extra mile and load the user's native language name. |
1450 | - if (empty($loadedLanguages)) |
|
1451 | - $loadedLanguages = getLanguages(); |
|
1522 | + if (empty($loadedLanguages)) { |
|
1523 | + $loadedLanguages = getLanguages(); |
|
1524 | + } |
|
1452 | 1525 | |
1453 | 1526 | $memberContext[$user] += array( |
1454 | 1527 | 'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>', |
@@ -1502,31 +1575,33 @@ discard block |
||
1502 | 1575 | { |
1503 | 1576 | if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://'))) |
1504 | 1577 | { |
1505 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) |
|
1506 | - $image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11)); |
|
1507 | - else |
|
1508 | - $image = get_gravatar_url($profile['email_address']); |
|
1509 | - } |
|
1510 | - else |
|
1578 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) { |
|
1579 | + $image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11)); |
|
1580 | + } else { |
|
1581 | + $image = get_gravatar_url($profile['email_address']); |
|
1582 | + } |
|
1583 | + } else |
|
1511 | 1584 | { |
1512 | 1585 | // So it's stored in the member table? |
1513 | 1586 | if (!empty($profile['avatar'])) |
1514 | 1587 | { |
1515 | 1588 | $image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar']; |
1589 | + } elseif (!empty($profile['filename'])) { |
|
1590 | + $image = $modSettings['custom_avatar_url'] . '/' . $profile['filename']; |
|
1516 | 1591 | } |
1517 | - elseif (!empty($profile['filename'])) |
|
1518 | - $image = $modSettings['custom_avatar_url'] . '/' . $profile['filename']; |
|
1519 | 1592 | // Right... no avatar...use the default one |
1520 | - else |
|
1521 | - $image = $modSettings['avatar_url'] . '/default.png'; |
|
1593 | + else { |
|
1594 | + $image = $modSettings['avatar_url'] . '/default.png'; |
|
1595 | + } |
|
1522 | 1596 | } |
1523 | - if (!empty($image)) |
|
1524 | - $memberContext[$user]['avatar'] = array( |
|
1597 | + if (!empty($image)) { |
|
1598 | + $memberContext[$user]['avatar'] = array( |
|
1525 | 1599 | 'name' => $profile['avatar'], |
1526 | 1600 | 'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">', |
1527 | 1601 | 'href' => $image, |
1528 | 1602 | 'url' => $image, |
1529 | 1603 | ); |
1604 | + } |
|
1530 | 1605 | } |
1531 | 1606 | |
1532 | 1607 | // Are we also loading the members custom fields into context? |
@@ -1534,35 +1609,41 @@ discard block |
||
1534 | 1609 | { |
1535 | 1610 | $memberContext[$user]['custom_fields'] = array(); |
1536 | 1611 | |
1537 | - if (!isset($context['display_fields'])) |
|
1538 | - $context['display_fields'] = smf_json_decode($modSettings['displayFields'], true); |
|
1612 | + if (!isset($context['display_fields'])) { |
|
1613 | + $context['display_fields'] = smf_json_decode($modSettings['displayFields'], true); |
|
1614 | + } |
|
1539 | 1615 | |
1540 | 1616 | foreach ($context['display_fields'] as $custom) |
1541 | 1617 | { |
1542 | - if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) |
|
1543 | - continue; |
|
1618 | + if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) { |
|
1619 | + continue; |
|
1620 | + } |
|
1544 | 1621 | |
1545 | 1622 | $value = $profile['options'][$custom['col_name']]; |
1546 | 1623 | |
1547 | 1624 | // Don't show the "disabled" option for the "gender" field. |
1548 | - if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') |
|
1549 | - continue; |
|
1625 | + if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') { |
|
1626 | + continue; |
|
1627 | + } |
|
1550 | 1628 | |
1551 | 1629 | // BBC? |
1552 | - if ($custom['bbc']) |
|
1553 | - $value = parse_bbc($value); |
|
1630 | + if ($custom['bbc']) { |
|
1631 | + $value = parse_bbc($value); |
|
1632 | + } |
|
1554 | 1633 | // ... or checkbox? |
1555 | - elseif (isset($custom['type']) && $custom['type'] == 'check') |
|
1556 | - $value = $value ? $txt['yes'] : $txt['no']; |
|
1634 | + elseif (isset($custom['type']) && $custom['type'] == 'check') { |
|
1635 | + $value = $value ? $txt['yes'] : $txt['no']; |
|
1636 | + } |
|
1557 | 1637 | |
1558 | 1638 | // Enclosing the user input within some other text? |
1559 | - if (!empty($custom['enclose'])) |
|
1560 | - $value = strtr($custom['enclose'], array( |
|
1639 | + if (!empty($custom['enclose'])) { |
|
1640 | + $value = strtr($custom['enclose'], array( |
|
1561 | 1641 | '{SCRIPTURL}' => $scripturl, |
1562 | 1642 | '{IMAGES_URL}' => $settings['images_url'], |
1563 | 1643 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
1564 | 1644 | '{INPUT}' => $value, |
1565 | 1645 | )); |
1646 | + } |
|
1566 | 1647 | |
1567 | 1648 | $memberContext[$user]['custom_fields'][] = array( |
1568 | 1649 | 'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'], |
@@ -1589,8 +1670,9 @@ discard block |
||
1589 | 1670 | global $smcFunc, $txt, $scripturl, $settings; |
1590 | 1671 | |
1591 | 1672 | // Do not waste my time... |
1592 | - if (empty($users) || empty($params)) |
|
1593 | - return false; |
|
1673 | + if (empty($users) || empty($params)) { |
|
1674 | + return false; |
|
1675 | + } |
|
1594 | 1676 | |
1595 | 1677 | // Make sure it's an array. |
1596 | 1678 | $users = !is_array($users) ? array($users) : array_unique($users); |
@@ -1614,31 +1696,36 @@ discard block |
||
1614 | 1696 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1615 | 1697 | { |
1616 | 1698 | // BBC? |
1617 | - if (!empty($row['bbc'])) |
|
1618 | - $row['value'] = parse_bbc($row['value']); |
|
1699 | + if (!empty($row['bbc'])) { |
|
1700 | + $row['value'] = parse_bbc($row['value']); |
|
1701 | + } |
|
1619 | 1702 | |
1620 | 1703 | // ... or checkbox? |
1621 | - elseif (isset($row['type']) && $row['type'] == 'check') |
|
1622 | - $row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no']; |
|
1704 | + elseif (isset($row['type']) && $row['type'] == 'check') { |
|
1705 | + $row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no']; |
|
1706 | + } |
|
1623 | 1707 | |
1624 | 1708 | // Enclosing the user input within some other text? |
1625 | - if (!empty($row['enclose'])) |
|
1626 | - $row['value'] = strtr($row['enclose'], array( |
|
1709 | + if (!empty($row['enclose'])) { |
|
1710 | + $row['value'] = strtr($row['enclose'], array( |
|
1627 | 1711 | '{SCRIPTURL}' => $scripturl, |
1628 | 1712 | '{IMAGES_URL}' => $settings['images_url'], |
1629 | 1713 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
1630 | 1714 | '{INPUT}' => un_htmlspecialchars($row['value']), |
1631 | 1715 | )); |
1716 | + } |
|
1632 | 1717 | |
1633 | 1718 | // Send a simple array if there is just 1 param |
1634 | - if (count($params) == 1) |
|
1635 | - $return[$row['id_member']] = $row; |
|
1719 | + if (count($params) == 1) { |
|
1720 | + $return[$row['id_member']] = $row; |
|
1721 | + } |
|
1636 | 1722 | |
1637 | 1723 | // More than 1? knock yourself out... |
1638 | 1724 | else |
1639 | 1725 | { |
1640 | - if (!isset($return[$row['id_member']])) |
|
1641 | - $return[$row['id_member']] = array(); |
|
1726 | + if (!isset($return[$row['id_member']])) { |
|
1727 | + $return[$row['id_member']] = array(); |
|
1728 | + } |
|
1642 | 1729 | |
1643 | 1730 | $return[$row['id_member']][$row['variable']] = $row; |
1644 | 1731 | } |
@@ -1672,8 +1759,9 @@ discard block |
||
1672 | 1759 | global $context; |
1673 | 1760 | |
1674 | 1761 | // Don't know any browser! |
1675 | - if (empty($context['browser'])) |
|
1676 | - detectBrowser(); |
|
1762 | + if (empty($context['browser'])) { |
|
1763 | + detectBrowser(); |
|
1764 | + } |
|
1677 | 1765 | |
1678 | 1766 | return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false; |
1679 | 1767 | } |
@@ -1691,8 +1779,9 @@ discard block |
||
1691 | 1779 | global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled; |
1692 | 1780 | |
1693 | 1781 | // The theme was specified by parameter. |
1694 | - if (!empty($id_theme)) |
|
1695 | - $id_theme = (int) $id_theme; |
|
1782 | + if (!empty($id_theme)) { |
|
1783 | + $id_theme = (int) $id_theme; |
|
1784 | + } |
|
1696 | 1785 | // The theme was specified by REQUEST. |
1697 | 1786 | elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) |
1698 | 1787 | { |
@@ -1700,51 +1789,58 @@ discard block |
||
1700 | 1789 | $_SESSION['id_theme'] = $id_theme; |
1701 | 1790 | } |
1702 | 1791 | // The theme was specified by REQUEST... previously. |
1703 | - elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) |
|
1704 | - $id_theme = (int) $_SESSION['id_theme']; |
|
1792 | + elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) { |
|
1793 | + $id_theme = (int) $_SESSION['id_theme']; |
|
1794 | + } |
|
1705 | 1795 | // The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.) |
1706 | - elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) |
|
1707 | - $id_theme = $user_info['theme']; |
|
1796 | + elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) { |
|
1797 | + $id_theme = $user_info['theme']; |
|
1798 | + } |
|
1708 | 1799 | // The theme was specified by the board. |
1709 | - elseif (!empty($board_info['theme'])) |
|
1710 | - $id_theme = $board_info['theme']; |
|
1800 | + elseif (!empty($board_info['theme'])) { |
|
1801 | + $id_theme = $board_info['theme']; |
|
1802 | + } |
|
1711 | 1803 | // The theme is the forum's default. |
1712 | - else |
|
1713 | - $id_theme = $modSettings['theme_guests']; |
|
1804 | + else { |
|
1805 | + $id_theme = $modSettings['theme_guests']; |
|
1806 | + } |
|
1714 | 1807 | |
1715 | 1808 | // Verify the id_theme... no foul play. |
1716 | 1809 | // Always allow the board specific theme, if they are overriding. |
1717 | - if (!empty($board_info['theme']) && $board_info['override_theme']) |
|
1718 | - $id_theme = $board_info['theme']; |
|
1810 | + if (!empty($board_info['theme']) && $board_info['override_theme']) { |
|
1811 | + $id_theme = $board_info['theme']; |
|
1812 | + } |
|
1719 | 1813 | // If they have specified a particular theme to use with SSI allow it to be used. |
1720 | - elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) |
|
1721 | - $id_theme = (int) $id_theme; |
|
1722 | - elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum')) |
|
1814 | + elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) { |
|
1815 | + $id_theme = (int) $id_theme; |
|
1816 | + } elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum')) |
|
1723 | 1817 | { |
1724 | 1818 | $themes = explode(',', $modSettings['enableThemes']); |
1725 | - if (!in_array($id_theme, $themes)) |
|
1726 | - $id_theme = $modSettings['theme_guests']; |
|
1727 | - else |
|
1819 | + if (!in_array($id_theme, $themes)) { |
|
1820 | + $id_theme = $modSettings['theme_guests']; |
|
1821 | + } else { |
|
1822 | + $id_theme = (int) $id_theme; |
|
1823 | + } |
|
1824 | + } else { |
|
1728 | 1825 | $id_theme = (int) $id_theme; |
1729 | 1826 | } |
1730 | - else |
|
1731 | - $id_theme = (int) $id_theme; |
|
1732 | 1827 | |
1733 | 1828 | $member = empty($user_info['id']) ? -1 : $user_info['id']; |
1734 | 1829 | |
1735 | 1830 | // Disable image proxy if we don't have SSL enabled |
1736 | - if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) |
|
1737 | - $image_proxy_enabled = false; |
|
1831 | + if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) { |
|
1832 | + $image_proxy_enabled = false; |
|
1833 | + } |
|
1738 | 1834 | |
1739 | 1835 | if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2 && ($temp = cache_get_data('theme_settings-' . $id_theme . ':' . $member, 60)) != null && time() - 60 > $modSettings['settings_updated']) |
1740 | 1836 | { |
1741 | 1837 | $themeData = $temp; |
1742 | 1838 | $flag = true; |
1839 | + } elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) { |
|
1840 | + $themeData = $temp + array($member => array()); |
|
1841 | + } else { |
|
1842 | + $themeData = array(-1 => array(), 0 => array(), $member => array()); |
|
1743 | 1843 | } |
1744 | - elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) |
|
1745 | - $themeData = $temp + array($member => array()); |
|
1746 | - else |
|
1747 | - $themeData = array(-1 => array(), 0 => array(), $member => array()); |
|
1748 | 1844 | |
1749 | 1845 | if (empty($flag)) |
1750 | 1846 | { |
@@ -1763,31 +1859,37 @@ discard block |
||
1763 | 1859 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
1764 | 1860 | { |
1765 | 1861 | // There are just things we shouldn't be able to change as members. |
1766 | - if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) |
|
1767 | - continue; |
|
1862 | + if ($row['id_member'] != 0 && in_array($row['variable'], array('actual_theme_url', 'actual_images_url', 'base_theme_dir', 'base_theme_url', 'default_images_url', 'default_theme_dir', 'default_theme_url', 'default_template', 'images_url', 'number_recent_posts', 'smiley_sets_default', 'theme_dir', 'theme_id', 'theme_layers', 'theme_templates', 'theme_url'))) { |
|
1863 | + continue; |
|
1864 | + } |
|
1768 | 1865 | |
1769 | 1866 | // If this is the theme_dir of the default theme, store it. |
1770 | - if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) |
|
1771 | - $themeData[0]['default_' . $row['variable']] = $row['value']; |
|
1867 | + if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) { |
|
1868 | + $themeData[0]['default_' . $row['variable']] = $row['value']; |
|
1869 | + } |
|
1772 | 1870 | |
1773 | 1871 | // If this isn't set yet, is a theme option, or is not the default theme.. |
1774 | - if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') |
|
1775 | - $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value']; |
|
1872 | + if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') { |
|
1873 | + $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value']; |
|
1874 | + } |
|
1776 | 1875 | } |
1777 | 1876 | $smcFunc['db_free_result']($result); |
1778 | 1877 | |
1779 | - if (!empty($themeData[-1])) |
|
1780 | - foreach ($themeData[-1] as $k => $v) |
|
1878 | + if (!empty($themeData[-1])) { |
|
1879 | + foreach ($themeData[-1] as $k => $v) |
|
1781 | 1880 | { |
1782 | 1881 | if (!isset($themeData[$member][$k])) |
1783 | 1882 | $themeData[$member][$k] = $v; |
1883 | + } |
|
1784 | 1884 | } |
1785 | 1885 | |
1786 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
1787 | - cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60); |
|
1886 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
1887 | + cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60); |
|
1888 | + } |
|
1788 | 1889 | // Only if we didn't already load that part of the cache... |
1789 | - elseif (!isset($temp)) |
|
1790 | - cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90); |
|
1890 | + elseif (!isset($temp)) { |
|
1891 | + cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90); |
|
1892 | + } |
|
1791 | 1893 | } |
1792 | 1894 | |
1793 | 1895 | $settings = $themeData[0]; |
@@ -1804,20 +1906,24 @@ discard block |
||
1804 | 1906 | $settings['template_dirs'][] = $settings['theme_dir']; |
1805 | 1907 | |
1806 | 1908 | // Based on theme (if there is one). |
1807 | - if (!empty($settings['base_theme_dir'])) |
|
1808 | - $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
1909 | + if (!empty($settings['base_theme_dir'])) { |
|
1910 | + $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
1911 | + } |
|
1809 | 1912 | |
1810 | 1913 | // Lastly the default theme. |
1811 | - if ($settings['theme_dir'] != $settings['default_theme_dir']) |
|
1812 | - $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
1914 | + if ($settings['theme_dir'] != $settings['default_theme_dir']) { |
|
1915 | + $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
1916 | + } |
|
1813 | 1917 | |
1814 | - if (!$initialize) |
|
1815 | - return; |
|
1918 | + if (!$initialize) { |
|
1919 | + return; |
|
1920 | + } |
|
1816 | 1921 | |
1817 | 1922 | // Check to see if we're forcing SSL |
1818 | 1923 | if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) && |
1819 | - (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') |
|
1820 | - redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://'))); |
|
1924 | + (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') { |
|
1925 | + redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://'))); |
|
1926 | + } |
|
1821 | 1927 | |
1822 | 1928 | // Check to see if they're accessing it from the wrong place. |
1823 | 1929 | if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME'])) |
@@ -1825,8 +1931,9 @@ discard block |
||
1825 | 1931 | $detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://'; |
1826 | 1932 | $detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST']; |
1827 | 1933 | $temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/')); |
1828 | - if ($temp != '/') |
|
1829 | - $detected_url .= $temp; |
|
1934 | + if ($temp != '/') { |
|
1935 | + $detected_url .= $temp; |
|
1936 | + } |
|
1830 | 1937 | } |
1831 | 1938 | if (isset($detected_url) && $detected_url != $boardurl) |
1832 | 1939 | { |
@@ -1838,8 +1945,9 @@ discard block |
||
1838 | 1945 | foreach ($aliases as $alias) |
1839 | 1946 | { |
1840 | 1947 | // Rip off all the boring parts, spaces, etc. |
1841 | - if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) |
|
1842 | - $do_fix = true; |
|
1948 | + if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) { |
|
1949 | + $do_fix = true; |
|
1950 | + } |
|
1843 | 1951 | } |
1844 | 1952 | } |
1845 | 1953 | |
@@ -1847,20 +1955,22 @@ discard block |
||
1847 | 1955 | if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI') |
1848 | 1956 | { |
1849 | 1957 | // Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;). |
1850 | - if (empty($_GET)) |
|
1851 | - redirectexit('wwwRedirect'); |
|
1852 | - else |
|
1958 | + if (empty($_GET)) { |
|
1959 | + redirectexit('wwwRedirect'); |
|
1960 | + } else |
|
1853 | 1961 | { |
1854 | 1962 | list ($k, $v) = each($_GET); |
1855 | 1963 | |
1856 | - if ($k != 'wwwRedirect') |
|
1857 | - redirectexit('wwwRedirect;' . $k . '=' . $v); |
|
1964 | + if ($k != 'wwwRedirect') { |
|
1965 | + redirectexit('wwwRedirect;' . $k . '=' . $v); |
|
1966 | + } |
|
1858 | 1967 | } |
1859 | 1968 | } |
1860 | 1969 | |
1861 | 1970 | // #3 is just a check for SSL... |
1862 | - if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) |
|
1863 | - $do_fix = true; |
|
1971 | + if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) { |
|
1972 | + $do_fix = true; |
|
1973 | + } |
|
1864 | 1974 | |
1865 | 1975 | // Okay, #4 - perhaps it's an IP address? We're gonna want to use that one, then. (assuming it's the IP or something...) |
1866 | 1976 | if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1) |
@@ -1894,8 +2004,9 @@ discard block |
||
1894 | 2004 | $board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl)); |
1895 | 2005 | } |
1896 | 2006 | } |
1897 | - foreach ($context['linktree'] as $k => $dummy) |
|
1898 | - $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl)); |
|
2007 | + foreach ($context['linktree'] as $k => $dummy) { |
|
2008 | + $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl)); |
|
2009 | + } |
|
1899 | 2010 | } |
1900 | 2011 | } |
1901 | 2012 | // Set up the contextual user array. |
@@ -1914,16 +2025,16 @@ discard block |
||
1914 | 2025 | 'email' => $user_info['email'], |
1915 | 2026 | 'ignoreusers' => $user_info['ignoreusers'], |
1916 | 2027 | ); |
1917 | - if (!$context['user']['is_guest']) |
|
1918 | - $context['user']['name'] = $user_info['name']; |
|
1919 | - elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) |
|
1920 | - $context['user']['name'] = $txt['guest_title']; |
|
2028 | + if (!$context['user']['is_guest']) { |
|
2029 | + $context['user']['name'] = $user_info['name']; |
|
2030 | + } elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) { |
|
2031 | + $context['user']['name'] = $txt['guest_title']; |
|
2032 | + } |
|
1921 | 2033 | |
1922 | 2034 | // Determine the current smiley set. |
1923 | 2035 | $user_info['smiley_set'] = (!in_array($user_info['smiley_set'], explode(',', $modSettings['smiley_sets_known'])) && $user_info['smiley_set'] != 'none') || empty($modSettings['smiley_sets_enable']) ? (!empty($settings['smiley_sets_default']) ? $settings['smiley_sets_default'] : $modSettings['smiley_sets_default']) : $user_info['smiley_set']; |
1924 | 2036 | $context['user']['smiley_set'] = $user_info['smiley_set']; |
1925 | - } |
|
1926 | - else |
|
2037 | + } else |
|
1927 | 2038 | { |
1928 | 2039 | $context['user'] = array( |
1929 | 2040 | 'id' => -1, |
@@ -1939,18 +2050,24 @@ discard block |
||
1939 | 2050 | } |
1940 | 2051 | |
1941 | 2052 | // Some basic information... |
1942 | - if (!isset($context['html_headers'])) |
|
1943 | - $context['html_headers'] = ''; |
|
1944 | - if (!isset($context['javascript_files'])) |
|
1945 | - $context['javascript_files'] = array(); |
|
1946 | - if (!isset($context['css_files'])) |
|
1947 | - $context['css_files'] = array(); |
|
1948 | - if (!isset($context['css_header'])) |
|
1949 | - $context['css_header'] = array(); |
|
1950 | - if (!isset($context['javascript_inline'])) |
|
1951 | - $context['javascript_inline'] = array('standard' => array(), 'defer' => array()); |
|
1952 | - if (!isset($context['javascript_vars'])) |
|
1953 | - $context['javascript_vars'] = array(); |
|
2053 | + if (!isset($context['html_headers'])) { |
|
2054 | + $context['html_headers'] = ''; |
|
2055 | + } |
|
2056 | + if (!isset($context['javascript_files'])) { |
|
2057 | + $context['javascript_files'] = array(); |
|
2058 | + } |
|
2059 | + if (!isset($context['css_files'])) { |
|
2060 | + $context['css_files'] = array(); |
|
2061 | + } |
|
2062 | + if (!isset($context['css_header'])) { |
|
2063 | + $context['css_header'] = array(); |
|
2064 | + } |
|
2065 | + if (!isset($context['javascript_inline'])) { |
|
2066 | + $context['javascript_inline'] = array('standard' => array(), 'defer' => array()); |
|
2067 | + } |
|
2068 | + if (!isset($context['javascript_vars'])) { |
|
2069 | + $context['javascript_vars'] = array(); |
|
2070 | + } |
|
1954 | 2071 | |
1955 | 2072 | $context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2'; |
1956 | 2073 | $context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | '; |
@@ -1962,8 +2079,9 @@ discard block |
||
1962 | 2079 | $context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null; |
1963 | 2080 | $context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null; |
1964 | 2081 | $context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3; |
1965 | - if (isset($modSettings['load_average'])) |
|
1966 | - $context['load_average'] = $modSettings['load_average']; |
|
2082 | + if (isset($modSettings['load_average'])) { |
|
2083 | + $context['load_average'] = $modSettings['load_average']; |
|
2084 | + } |
|
1967 | 2085 | |
1968 | 2086 | // Detect the browser. This is separated out because it's also used in attachment downloads |
1969 | 2087 | detectBrowser(); |
@@ -1977,8 +2095,9 @@ discard block |
||
1977 | 2095 | // This allows sticking some HTML on the page output - useful for controls. |
1978 | 2096 | $context['insert_after_template'] = ''; |
1979 | 2097 | |
1980 | - if (!isset($txt)) |
|
1981 | - $txt = array(); |
|
2098 | + if (!isset($txt)) { |
|
2099 | + $txt = array(); |
|
2100 | + } |
|
1982 | 2101 | |
1983 | 2102 | $simpleActions = array( |
1984 | 2103 | 'findmember', |
@@ -2024,9 +2143,10 @@ discard block |
||
2024 | 2143 | |
2025 | 2144 | // See if theres any extra param to check. |
2026 | 2145 | $requiresXML = false; |
2027 | - foreach ($extraParams as $key => $extra) |
|
2028 | - if (isset($_REQUEST[$extra])) |
|
2146 | + foreach ($extraParams as $key => $extra) { |
|
2147 | + if (isset($_REQUEST[$extra])) |
|
2029 | 2148 | $requiresXML = true; |
2149 | + } |
|
2030 | 2150 | |
2031 | 2151 | // Output is fully XML, so no need for the index template. |
2032 | 2152 | if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML)) |
@@ -2041,37 +2161,39 @@ discard block |
||
2041 | 2161 | { |
2042 | 2162 | loadLanguage('index+Modifications'); |
2043 | 2163 | $context['template_layers'] = array(); |
2044 | - } |
|
2045 | - |
|
2046 | - else |
|
2164 | + } else |
|
2047 | 2165 | { |
2048 | 2166 | // Custom templates to load, or just default? |
2049 | - if (isset($settings['theme_templates'])) |
|
2050 | - $templates = explode(',', $settings['theme_templates']); |
|
2051 | - else |
|
2052 | - $templates = array('index'); |
|
2167 | + if (isset($settings['theme_templates'])) { |
|
2168 | + $templates = explode(',', $settings['theme_templates']); |
|
2169 | + } else { |
|
2170 | + $templates = array('index'); |
|
2171 | + } |
|
2053 | 2172 | |
2054 | 2173 | // Load each template... |
2055 | - foreach ($templates as $template) |
|
2056 | - loadTemplate($template); |
|
2174 | + foreach ($templates as $template) { |
|
2175 | + loadTemplate($template); |
|
2176 | + } |
|
2057 | 2177 | |
2058 | 2178 | // ...and attempt to load their associated language files. |
2059 | 2179 | $required_files = implode('+', array_merge($templates, array('Modifications'))); |
2060 | 2180 | loadLanguage($required_files, '', false); |
2061 | 2181 | |
2062 | 2182 | // Custom template layers? |
2063 | - if (isset($settings['theme_layers'])) |
|
2064 | - $context['template_layers'] = explode(',', $settings['theme_layers']); |
|
2065 | - else |
|
2066 | - $context['template_layers'] = array('html', 'body'); |
|
2183 | + if (isset($settings['theme_layers'])) { |
|
2184 | + $context['template_layers'] = explode(',', $settings['theme_layers']); |
|
2185 | + } else { |
|
2186 | + $context['template_layers'] = array('html', 'body'); |
|
2187 | + } |
|
2067 | 2188 | } |
2068 | 2189 | |
2069 | 2190 | // Initialize the theme. |
2070 | 2191 | loadSubTemplate('init', 'ignore'); |
2071 | 2192 | |
2072 | 2193 | // Allow overriding the board wide time/number formats. |
2073 | - if (empty($user_settings['time_format']) && !empty($txt['time_format'])) |
|
2074 | - $user_info['time_format'] = $txt['time_format']; |
|
2194 | + if (empty($user_settings['time_format']) && !empty($txt['time_format'])) { |
|
2195 | + $user_info['time_format'] = $txt['time_format']; |
|
2196 | + } |
|
2075 | 2197 | |
2076 | 2198 | // Set the character set from the template. |
2077 | 2199 | $context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']; |
@@ -2079,12 +2201,14 @@ discard block |
||
2079 | 2201 | $context['right_to_left'] = !empty($txt['lang_rtl']); |
2080 | 2202 | |
2081 | 2203 | // Guests may still need a name. |
2082 | - if ($context['user']['is_guest'] && empty($context['user']['name'])) |
|
2083 | - $context['user']['name'] = $txt['guest_title']; |
|
2204 | + if ($context['user']['is_guest'] && empty($context['user']['name'])) { |
|
2205 | + $context['user']['name'] = $txt['guest_title']; |
|
2206 | + } |
|
2084 | 2207 | |
2085 | 2208 | // Any theme-related strings that need to be loaded? |
2086 | - if (!empty($settings['require_theme_strings'])) |
|
2087 | - loadLanguage('ThemeStrings', '', false); |
|
2209 | + if (!empty($settings['require_theme_strings'])) { |
|
2210 | + loadLanguage('ThemeStrings', '', false); |
|
2211 | + } |
|
2088 | 2212 | |
2089 | 2213 | // Make a special URL for the language. |
2090 | 2214 | $settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']); |
@@ -2095,8 +2219,9 @@ discard block |
||
2095 | 2219 | // Here is my luvly Responsive CSS |
2096 | 2220 | loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive'); |
2097 | 2221 | |
2098 | - if ($context['right_to_left']) |
|
2099 | - loadCSSFile('rtl.css', array(), 'smf_rtl'); |
|
2222 | + if ($context['right_to_left']) { |
|
2223 | + loadCSSFile('rtl.css', array(), 'smf_rtl'); |
|
2224 | + } |
|
2100 | 2225 | |
2101 | 2226 | // We allow theme variants, because we're cool. |
2102 | 2227 | $context['theme_variant'] = ''; |
@@ -2104,14 +2229,17 @@ discard block |
||
2104 | 2229 | if (!empty($settings['theme_variants'])) |
2105 | 2230 | { |
2106 | 2231 | // Overriding - for previews and that ilk. |
2107 | - if (!empty($_REQUEST['variant'])) |
|
2108 | - $_SESSION['id_variant'] = $_REQUEST['variant']; |
|
2232 | + if (!empty($_REQUEST['variant'])) { |
|
2233 | + $_SESSION['id_variant'] = $_REQUEST['variant']; |
|
2234 | + } |
|
2109 | 2235 | // User selection? |
2110 | - if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) |
|
2111 | - $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : ''); |
|
2236 | + if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) { |
|
2237 | + $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : ''); |
|
2238 | + } |
|
2112 | 2239 | // If not a user variant, select the default. |
2113 | - if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) |
|
2114 | - $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0]; |
|
2240 | + if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) { |
|
2241 | + $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0]; |
|
2242 | + } |
|
2115 | 2243 | |
2116 | 2244 | // Do this to keep things easier in the templates. |
2117 | 2245 | $context['theme_variant'] = '_' . $context['theme_variant']; |
@@ -2120,20 +2248,23 @@ discard block |
||
2120 | 2248 | if (!empty($context['theme_variant'])) |
2121 | 2249 | { |
2122 | 2250 | loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']); |
2123 | - if ($context['right_to_left']) |
|
2124 | - loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']); |
|
2251 | + if ($context['right_to_left']) { |
|
2252 | + loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']); |
|
2253 | + } |
|
2125 | 2254 | } |
2126 | 2255 | } |
2127 | 2256 | |
2128 | 2257 | // Let's be compatible with old themes! |
2129 | - if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) |
|
2130 | - $context['template_layers'] = array('main'); |
|
2258 | + if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) { |
|
2259 | + $context['template_layers'] = array('main'); |
|
2260 | + } |
|
2131 | 2261 | |
2132 | 2262 | $context['tabindex'] = 1; |
2133 | 2263 | |
2134 | 2264 | // Compatibility. |
2135 | - if (!isset($settings['theme_version'])) |
|
2136 | - $modSettings['memberCount'] = $modSettings['totalMembers']; |
|
2265 | + if (!isset($settings['theme_version'])) { |
|
2266 | + $modSettings['memberCount'] = $modSettings['totalMembers']; |
|
2267 | + } |
|
2137 | 2268 | |
2138 | 2269 | // Default JS variables for use in every theme |
2139 | 2270 | $context['javascript_vars'] = array( |
@@ -2152,18 +2283,18 @@ discard block |
||
2152 | 2283 | ); |
2153 | 2284 | |
2154 | 2285 | // Add the JQuery library to the list of files to load. |
2155 | - if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') |
|
2156 | - loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2157 | - |
|
2158 | - elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') |
|
2159 | - loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery'); |
|
2160 | - |
|
2161 | - elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') |
|
2162 | - loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery'); |
|
2286 | + if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') { |
|
2287 | + loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2288 | + } elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') { |
|
2289 | + loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery'); |
|
2290 | + } elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') { |
|
2291 | + loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery'); |
|
2292 | + } |
|
2163 | 2293 | |
2164 | 2294 | // Auto loading? template_javascript() will take care of the local half of this. |
2165 | - else |
|
2166 | - loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2295 | + else { |
|
2296 | + loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2297 | + } |
|
2167 | 2298 | |
2168 | 2299 | // Queue our JQuery plugins! |
2169 | 2300 | loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins'); |
@@ -2186,12 +2317,12 @@ discard block |
||
2186 | 2317 | require_once($sourcedir . '/ScheduledTasks.php'); |
2187 | 2318 | |
2188 | 2319 | // What to do, what to do?! |
2189 | - if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) |
|
2190 | - AutoTask(); |
|
2191 | - else |
|
2192 | - ReduceMailQueue(); |
|
2193 | - } |
|
2194 | - else |
|
2320 | + if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) { |
|
2321 | + AutoTask(); |
|
2322 | + } else { |
|
2323 | + ReduceMailQueue(); |
|
2324 | + } |
|
2325 | + } else |
|
2195 | 2326 | { |
2196 | 2327 | $type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq'; |
2197 | 2328 | $ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time']; |
@@ -2242,8 +2373,9 @@ discard block |
||
2242 | 2373 | foreach ($theme_includes as $include) |
2243 | 2374 | { |
2244 | 2375 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
2245 | - if (file_exists($include)) |
|
2246 | - require_once($include); |
|
2376 | + if (file_exists($include)) { |
|
2377 | + require_once($include); |
|
2378 | + } |
|
2247 | 2379 | } |
2248 | 2380 | } |
2249 | 2381 | |
@@ -2273,16 +2405,19 @@ discard block |
||
2273 | 2405 | // Do any style sheets first, cause we're easy with those. |
2274 | 2406 | if (!empty($style_sheets)) |
2275 | 2407 | { |
2276 | - if (!is_array($style_sheets)) |
|
2277 | - $style_sheets = array($style_sheets); |
|
2408 | + if (!is_array($style_sheets)) { |
|
2409 | + $style_sheets = array($style_sheets); |
|
2410 | + } |
|
2278 | 2411 | |
2279 | - foreach ($style_sheets as $sheet) |
|
2280 | - loadCSSFile($sheet . '.css', array(), $sheet); |
|
2412 | + foreach ($style_sheets as $sheet) { |
|
2413 | + loadCSSFile($sheet . '.css', array(), $sheet); |
|
2414 | + } |
|
2281 | 2415 | } |
2282 | 2416 | |
2283 | 2417 | // No template to load? |
2284 | - if ($template_name === false) |
|
2285 | - return true; |
|
2418 | + if ($template_name === false) { |
|
2419 | + return true; |
|
2420 | + } |
|
2286 | 2421 | |
2287 | 2422 | $loaded = false; |
2288 | 2423 | foreach ($settings['template_dirs'] as $template_dir) |
@@ -2297,12 +2432,14 @@ discard block |
||
2297 | 2432 | |
2298 | 2433 | if ($loaded) |
2299 | 2434 | { |
2300 | - if ($db_show_debug === true) |
|
2301 | - $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; |
|
2435 | + if ($db_show_debug === true) { |
|
2436 | + $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; |
|
2437 | + } |
|
2302 | 2438 | |
2303 | 2439 | // If they have specified an initialization function for this template, go ahead and call it now. |
2304 | - if (function_exists('template_' . $template_name . '_init')) |
|
2305 | - call_user_func('template_' . $template_name . '_init'); |
|
2440 | + if (function_exists('template_' . $template_name . '_init')) { |
|
2441 | + call_user_func('template_' . $template_name . '_init'); |
|
2442 | + } |
|
2306 | 2443 | } |
2307 | 2444 | // Hmmm... doesn't exist?! I don't suppose the directory is wrong, is it? |
2308 | 2445 | elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default')) |
@@ -2322,13 +2459,14 @@ discard block |
||
2322 | 2459 | loadTemplate($template_name); |
2323 | 2460 | } |
2324 | 2461 | // Cause an error otherwise. |
2325 | - elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) |
|
2326 | - fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); |
|
2327 | - elseif ($fatal) |
|
2328 | - die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template')); |
|
2329 | - else |
|
2330 | - return false; |
|
2331 | -} |
|
2462 | + elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) { |
|
2463 | + fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); |
|
2464 | + } elseif ($fatal) { |
|
2465 | + die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load Themes/default/%s.template.php!', (string) $template_name), 'template')); |
|
2466 | + } else { |
|
2467 | + return false; |
|
2468 | + } |
|
2469 | + } |
|
2332 | 2470 | |
2333 | 2471 | /** |
2334 | 2472 | * Load a sub-template. |
@@ -2346,17 +2484,19 @@ discard block |
||
2346 | 2484 | { |
2347 | 2485 | global $context, $txt, $db_show_debug; |
2348 | 2486 | |
2349 | - if ($db_show_debug === true) |
|
2350 | - $context['debug']['sub_templates'][] = $sub_template_name; |
|
2487 | + if ($db_show_debug === true) { |
|
2488 | + $context['debug']['sub_templates'][] = $sub_template_name; |
|
2489 | + } |
|
2351 | 2490 | |
2352 | 2491 | // Figure out what the template function is named. |
2353 | 2492 | $theme_function = 'template_' . $sub_template_name; |
2354 | - if (function_exists($theme_function)) |
|
2355 | - $theme_function(); |
|
2356 | - elseif ($fatal === false) |
|
2357 | - fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name)); |
|
2358 | - elseif ($fatal !== 'ignore') |
|
2359 | - die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template')); |
|
2493 | + if (function_exists($theme_function)) { |
|
2494 | + $theme_function(); |
|
2495 | + } elseif ($fatal === false) { |
|
2496 | + fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name)); |
|
2497 | + } elseif ($fatal !== 'ignore') { |
|
2498 | + die(log_error(sprintf(isset($txt['theme_template_error']) ? $txt['theme_template_error'] : 'Unable to load the %s sub template!', (string) $sub_template_name), 'template')); |
|
2499 | + } |
|
2360 | 2500 | |
2361 | 2501 | // Are we showing debugging for templates? Just make sure not to do it before the doctype... |
2362 | 2502 | if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml'])) |
@@ -2393,8 +2533,9 @@ discard block |
||
2393 | 2533 | $params['validate'] = isset($params['validate']) ? $params['validate'] : true; |
2394 | 2534 | |
2395 | 2535 | // If this is an external file, automatically set this to false. |
2396 | - if (!empty($params['external'])) |
|
2397 | - $params['minimize'] = false; |
|
2536 | + if (!empty($params['external'])) { |
|
2537 | + $params['minimize'] = false; |
|
2538 | + } |
|
2398 | 2539 | |
2399 | 2540 | // Account for shorthand like admin.css?alp21 filenames |
2400 | 2541 | $has_seed = strpos($fileName, '.css?'); |
@@ -2411,13 +2552,10 @@ discard block |
||
2411 | 2552 | { |
2412 | 2553 | $fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
2413 | 2554 | $filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
2555 | + } else { |
|
2556 | + $fileUrl = false; |
|
2414 | 2557 | } |
2415 | - |
|
2416 | - else |
|
2417 | - $fileUrl = false; |
|
2418 | - } |
|
2419 | - |
|
2420 | - else |
|
2558 | + } else |
|
2421 | 2559 | { |
2422 | 2560 | $fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
2423 | 2561 | $filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
@@ -2432,12 +2570,14 @@ discard block |
||
2432 | 2570 | } |
2433 | 2571 | |
2434 | 2572 | // Add it to the array for use in the template |
2435 | - if (!empty($fileName)) |
|
2436 | - $context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
2573 | + if (!empty($fileName)) { |
|
2574 | + $context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
2575 | + } |
|
2437 | 2576 | |
2438 | - if (!empty($context['right_to_left']) && !empty($params['rtl'])) |
|
2439 | - loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0))); |
|
2440 | -} |
|
2577 | + if (!empty($context['right_to_left']) && !empty($params['rtl'])) { |
|
2578 | + loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0))); |
|
2579 | + } |
|
2580 | + } |
|
2441 | 2581 | |
2442 | 2582 | /** |
2443 | 2583 | * Add a block of inline css code to be executed later |
@@ -2454,8 +2594,9 @@ discard block |
||
2454 | 2594 | global $context; |
2455 | 2595 | |
2456 | 2596 | // Gotta add something... |
2457 | - if (empty($css)) |
|
2458 | - return false; |
|
2597 | + if (empty($css)) { |
|
2598 | + return false; |
|
2599 | + } |
|
2459 | 2600 | |
2460 | 2601 | $context['css_header'][] = $css; |
2461 | 2602 | } |
@@ -2490,8 +2631,9 @@ discard block |
||
2490 | 2631 | $params['validate'] = isset($params['validate']) ? $params['validate'] : true; |
2491 | 2632 | |
2492 | 2633 | // If this is an external file, automatically set this to false. |
2493 | - if (!empty($params['external'])) |
|
2494 | - $params['minimize'] = false; |
|
2634 | + if (!empty($params['external'])) { |
|
2635 | + $params['minimize'] = false; |
|
2636 | + } |
|
2495 | 2637 | |
2496 | 2638 | // Account for shorthand like admin.js?alp21 filenames |
2497 | 2639 | $has_seed = strpos($fileName, '.js?'); |
@@ -2508,16 +2650,12 @@ discard block |
||
2508 | 2650 | { |
2509 | 2651 | $fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
2510 | 2652 | $filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
2511 | - } |
|
2512 | - |
|
2513 | - else |
|
2653 | + } else |
|
2514 | 2654 | { |
2515 | 2655 | $fileUrl = false; |
2516 | 2656 | $filePath = false; |
2517 | 2657 | } |
2518 | - } |
|
2519 | - |
|
2520 | - else |
|
2658 | + } else |
|
2521 | 2659 | { |
2522 | 2660 | $fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
2523 | 2661 | $filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
@@ -2532,9 +2670,10 @@ discard block |
||
2532 | 2670 | } |
2533 | 2671 | |
2534 | 2672 | // Add it to the array for use in the template |
2535 | - if (!empty($fileName)) |
|
2536 | - $context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
2537 | -} |
|
2673 | + if (!empty($fileName)) { |
|
2674 | + $context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
2675 | + } |
|
2676 | + } |
|
2538 | 2677 | |
2539 | 2678 | /** |
2540 | 2679 | * Add a Javascript variable for output later (for feeding text strings and similar to JS) |
@@ -2548,9 +2687,10 @@ discard block |
||
2548 | 2687 | { |
2549 | 2688 | global $context; |
2550 | 2689 | |
2551 | - if (!empty($key) && (!empty($value) || $value === '0')) |
|
2552 | - $context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value; |
|
2553 | -} |
|
2690 | + if (!empty($key) && (!empty($value) || $value === '0')) { |
|
2691 | + $context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value; |
|
2692 | + } |
|
2693 | + } |
|
2554 | 2694 | |
2555 | 2695 | /** |
2556 | 2696 | * Add a block of inline Javascript code to be executed later |
@@ -2567,8 +2707,9 @@ discard block |
||
2567 | 2707 | { |
2568 | 2708 | global $context; |
2569 | 2709 | |
2570 | - if (empty($javascript)) |
|
2571 | - return false; |
|
2710 | + if (empty($javascript)) { |
|
2711 | + return false; |
|
2712 | + } |
|
2572 | 2713 | |
2573 | 2714 | $context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript; |
2574 | 2715 | } |
@@ -2589,15 +2730,18 @@ discard block |
||
2589 | 2730 | static $already_loaded = array(); |
2590 | 2731 | |
2591 | 2732 | // Default to the user's language. |
2592 | - if ($lang == '') |
|
2593 | - $lang = isset($user_info['language']) ? $user_info['language'] : $language; |
|
2733 | + if ($lang == '') { |
|
2734 | + $lang = isset($user_info['language']) ? $user_info['language'] : $language; |
|
2735 | + } |
|
2594 | 2736 | |
2595 | 2737 | // Do we want the English version of language file as fallback? |
2596 | - if (empty($modSettings['disable_language_fallback']) && $lang != 'english') |
|
2597 | - loadLanguage($template_name, 'english', false); |
|
2738 | + if (empty($modSettings['disable_language_fallback']) && $lang != 'english') { |
|
2739 | + loadLanguage($template_name, 'english', false); |
|
2740 | + } |
|
2598 | 2741 | |
2599 | - if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) |
|
2600 | - return $lang; |
|
2742 | + if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) { |
|
2743 | + return $lang; |
|
2744 | + } |
|
2601 | 2745 | |
2602 | 2746 | // Make sure we have $settings - if not we're in trouble and need to find it! |
2603 | 2747 | if (empty($settings['default_theme_dir'])) |
@@ -2608,8 +2752,9 @@ discard block |
||
2608 | 2752 | |
2609 | 2753 | // What theme are we in? |
2610 | 2754 | $theme_name = basename($settings['theme_url']); |
2611 | - if (empty($theme_name)) |
|
2612 | - $theme_name = 'unknown'; |
|
2755 | + if (empty($theme_name)) { |
|
2756 | + $theme_name = 'unknown'; |
|
2757 | + } |
|
2613 | 2758 | |
2614 | 2759 | // For each file open it up and write it out! |
2615 | 2760 | foreach (explode('+', $template_name) as $template) |
@@ -2651,8 +2796,9 @@ discard block |
||
2651 | 2796 | $found = true; |
2652 | 2797 | |
2653 | 2798 | // setlocale is required for basename() & pathinfo() to work properly on the selected language |
2654 | - if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) |
|
2655 | - setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']); |
|
2799 | + if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) { |
|
2800 | + setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']); |
|
2801 | + } |
|
2656 | 2802 | |
2657 | 2803 | break; |
2658 | 2804 | } |
@@ -2692,8 +2838,9 @@ discard block |
||
2692 | 2838 | } |
2693 | 2839 | |
2694 | 2840 | // Keep track of what we're up to soldier. |
2695 | - if ($db_show_debug === true) |
|
2696 | - $context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')'; |
|
2841 | + if ($db_show_debug === true) { |
|
2842 | + $context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')'; |
|
2843 | + } |
|
2697 | 2844 | |
2698 | 2845 | // Remember what we have loaded, and in which language. |
2699 | 2846 | $already_loaded[$template_name] = $lang; |
@@ -2739,8 +2886,9 @@ discard block |
||
2739 | 2886 | ) |
2740 | 2887 | ); |
2741 | 2888 | // In the EXTREMELY unlikely event this happens, give an error message. |
2742 | - if ($smcFunc['db_num_rows']($result) == 0) |
|
2743 | - fatal_lang_error('parent_not_found', 'critical'); |
|
2889 | + if ($smcFunc['db_num_rows']($result) == 0) { |
|
2890 | + fatal_lang_error('parent_not_found', 'critical'); |
|
2891 | + } |
|
2744 | 2892 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
2745 | 2893 | { |
2746 | 2894 | if (!isset($boards[$row['id_board']])) |
@@ -2757,8 +2905,8 @@ discard block |
||
2757 | 2905 | ); |
2758 | 2906 | } |
2759 | 2907 | // If a moderator exists for this board, add that moderator for all children too. |
2760 | - if (!empty($row['id_moderator'])) |
|
2761 | - foreach ($boards as $id => $dummy) |
|
2908 | + if (!empty($row['id_moderator'])) { |
|
2909 | + foreach ($boards as $id => $dummy) |
|
2762 | 2910 | { |
2763 | 2911 | $boards[$id]['moderators'][$row['id_moderator']] = array( |
2764 | 2912 | 'id' => $row['id_moderator'], |
@@ -2766,11 +2914,12 @@ discard block |
||
2766 | 2914 | 'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'], |
2767 | 2915 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>' |
2768 | 2916 | ); |
2917 | + } |
|
2769 | 2918 | } |
2770 | 2919 | |
2771 | 2920 | // If a moderator group exists for this board, add that moderator group for all children too |
2772 | - if (!empty($row['id_moderator_group'])) |
|
2773 | - foreach ($boards as $id => $dummy) |
|
2921 | + if (!empty($row['id_moderator_group'])) { |
|
2922 | + foreach ($boards as $id => $dummy) |
|
2774 | 2923 | { |
2775 | 2924 | $boards[$id]['moderator_groups'][$row['id_moderator_group']] = array( |
2776 | 2925 | 'id' => $row['id_moderator_group'], |
@@ -2778,6 +2927,7 @@ discard block |
||
2778 | 2927 | 'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'], |
2779 | 2928 | 'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>' |
2780 | 2929 | ); |
2930 | + } |
|
2781 | 2931 | } |
2782 | 2932 | } |
2783 | 2933 | $smcFunc['db_free_result']($result); |
@@ -2804,23 +2954,27 @@ discard block |
||
2804 | 2954 | if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null) |
2805 | 2955 | { |
2806 | 2956 | // If we don't have our ucwords function defined yet, let's load the settings data. |
2807 | - if (empty($smcFunc['ucwords'])) |
|
2808 | - reloadSettings(); |
|
2957 | + if (empty($smcFunc['ucwords'])) { |
|
2958 | + reloadSettings(); |
|
2959 | + } |
|
2809 | 2960 | |
2810 | 2961 | // If we don't have our theme information yet, let's get it. |
2811 | - if (empty($settings['default_theme_dir'])) |
|
2812 | - loadTheme(0, false); |
|
2962 | + if (empty($settings['default_theme_dir'])) { |
|
2963 | + loadTheme(0, false); |
|
2964 | + } |
|
2813 | 2965 | |
2814 | 2966 | // Default language directories to try. |
2815 | 2967 | $language_directories = array( |
2816 | 2968 | $settings['default_theme_dir'] . '/languages', |
2817 | 2969 | ); |
2818 | - if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) |
|
2819 | - $language_directories[] = $settings['actual_theme_dir'] . '/languages'; |
|
2970 | + if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) { |
|
2971 | + $language_directories[] = $settings['actual_theme_dir'] . '/languages'; |
|
2972 | + } |
|
2820 | 2973 | |
2821 | 2974 | // We possibly have a base theme directory. |
2822 | - if (!empty($settings['base_theme_dir'])) |
|
2823 | - $language_directories[] = $settings['base_theme_dir'] . '/languages'; |
|
2975 | + if (!empty($settings['base_theme_dir'])) { |
|
2976 | + $language_directories[] = $settings['base_theme_dir'] . '/languages'; |
|
2977 | + } |
|
2824 | 2978 | |
2825 | 2979 | // Remove any duplicates. |
2826 | 2980 | $language_directories = array_unique($language_directories); |
@@ -2834,20 +2988,21 @@ discard block |
||
2834 | 2988 | foreach ($language_directories as $language_dir) |
2835 | 2989 | { |
2836 | 2990 | // Can't look in here... doesn't exist! |
2837 | - if (!file_exists($language_dir)) |
|
2838 | - continue; |
|
2991 | + if (!file_exists($language_dir)) { |
|
2992 | + continue; |
|
2993 | + } |
|
2839 | 2994 | |
2840 | 2995 | $dir = dir($language_dir); |
2841 | 2996 | while ($entry = $dir->read()) |
2842 | 2997 | { |
2843 | 2998 | // Look for the index language file... For good measure skip any "index.language-utf8.php" files |
2844 | - if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) |
|
2845 | - continue; |
|
2846 | - |
|
2847 | - if (!empty($langList) && !empty($langList[$matches[1]])) |
|
2848 | - $langName = $langList[$matches[1]]; |
|
2999 | + if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) { |
|
3000 | + continue; |
|
3001 | + } |
|
2849 | 3002 | |
2850 | - else |
|
3003 | + if (!empty($langList) && !empty($langList[$matches[1]])) { |
|
3004 | + $langName = $langList[$matches[1]]; |
|
3005 | + } else |
|
2851 | 3006 | { |
2852 | 3007 | $langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' '))); |
2853 | 3008 | |
@@ -2888,12 +3043,14 @@ discard block |
||
2888 | 3043 | } |
2889 | 3044 | |
2890 | 3045 | // Do we need to store the lang list? |
2891 | - if (empty($langList)) |
|
2892 | - updateSettings(array('langList' => json_encode($catchLang))); |
|
3046 | + if (empty($langList)) { |
|
3047 | + updateSettings(array('langList' => json_encode($catchLang))); |
|
3048 | + } |
|
2893 | 3049 | |
2894 | 3050 | // Let's cash in on this deal. |
2895 | - if (!empty($modSettings['cache_enable'])) |
|
2896 | - cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600); |
|
3051 | + if (!empty($modSettings['cache_enable'])) { |
|
3052 | + cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600); |
|
3053 | + } |
|
2897 | 3054 | } |
2898 | 3055 | |
2899 | 3056 | return $context['languages']; |
@@ -2916,8 +3073,9 @@ discard block |
||
2916 | 3073 | global $modSettings, $options, $txt; |
2917 | 3074 | static $censor_vulgar = null, $censor_proper; |
2918 | 3075 | |
2919 | - if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') |
|
2920 | - return $text; |
|
3076 | + if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') { |
|
3077 | + return $text; |
|
3078 | + } |
|
2921 | 3079 | |
2922 | 3080 | // If they haven't yet been loaded, load them. |
2923 | 3081 | if ($censor_vulgar == null) |
@@ -2945,9 +3103,9 @@ discard block |
||
2945 | 3103 | { |
2946 | 3104 | $func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace'; |
2947 | 3105 | $text = $func($censor_vulgar, $censor_proper, $text); |
3106 | + } else { |
|
3107 | + $text = preg_replace($censor_vulgar, $censor_proper, $text); |
|
2948 | 3108 | } |
2949 | - else |
|
2950 | - $text = preg_replace($censor_vulgar, $censor_proper, $text); |
|
2951 | 3109 | |
2952 | 3110 | return $text; |
2953 | 3111 | } |
@@ -2973,38 +3131,42 @@ discard block |
||
2973 | 3131 | @ini_set('track_errors', '1'); |
2974 | 3132 | |
2975 | 3133 | // Don't include the file more than once, if $once is true. |
2976 | - if ($once && in_array($filename, $templates)) |
|
2977 | - return; |
|
3134 | + if ($once && in_array($filename, $templates)) { |
|
3135 | + return; |
|
3136 | + } |
|
2978 | 3137 | // Add this file to the include list, whether $once is true or not. |
2979 | - else |
|
2980 | - $templates[] = $filename; |
|
3138 | + else { |
|
3139 | + $templates[] = $filename; |
|
3140 | + } |
|
2981 | 3141 | |
2982 | 3142 | // Are we going to use eval? |
2983 | 3143 | if (empty($modSettings['disableTemplateEval'])) |
2984 | 3144 | { |
2985 | 3145 | $file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false; |
2986 | 3146 | $settings['current_include_filename'] = $filename; |
2987 | - } |
|
2988 | - else |
|
3147 | + } else |
|
2989 | 3148 | { |
2990 | 3149 | $file_found = file_exists($filename); |
2991 | 3150 | |
2992 | - if ($once && $file_found) |
|
2993 | - require_once($filename); |
|
2994 | - elseif ($file_found) |
|
2995 | - require($filename); |
|
3151 | + if ($once && $file_found) { |
|
3152 | + require_once($filename); |
|
3153 | + } elseif ($file_found) { |
|
3154 | + require($filename); |
|
3155 | + } |
|
2996 | 3156 | } |
2997 | 3157 | |
2998 | 3158 | if ($file_found !== true) |
2999 | 3159 | { |
3000 | 3160 | ob_end_clean(); |
3001 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
3002 | - @ob_start('ob_gzhandler'); |
|
3003 | - else |
|
3004 | - ob_start(); |
|
3161 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
3162 | + @ob_start('ob_gzhandler'); |
|
3163 | + } else { |
|
3164 | + ob_start(); |
|
3165 | + } |
|
3005 | 3166 | |
3006 | - if (isset($_GET['debug'])) |
|
3007 | - header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3167 | + if (isset($_GET['debug'])) { |
|
3168 | + header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3169 | + } |
|
3008 | 3170 | |
3009 | 3171 | // Don't cache error pages!! |
3010 | 3172 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
@@ -3023,12 +3185,13 @@ discard block |
||
3023 | 3185 | echo '<!DOCTYPE html> |
3024 | 3186 | <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '> |
3025 | 3187 | <head>'; |
3026 | - if (isset($context['character_set'])) |
|
3027 | - echo ' |
|
3188 | + if (isset($context['character_set'])) { |
|
3189 | + echo ' |
|
3028 | 3190 | <meta charset="', $context['character_set'], '">'; |
3191 | + } |
|
3029 | 3192 | |
3030 | - if (!empty($maintenance) && !allowedTo('admin_forum')) |
|
3031 | - echo ' |
|
3193 | + if (!empty($maintenance) && !allowedTo('admin_forum')) { |
|
3194 | + echo ' |
|
3032 | 3195 | <title>', $mtitle, '</title> |
3033 | 3196 | </head> |
3034 | 3197 | <body> |
@@ -3036,8 +3199,8 @@ discard block |
||
3036 | 3199 | ', $mmessage, ' |
3037 | 3200 | </body> |
3038 | 3201 | </html>'; |
3039 | - elseif (!allowedTo('admin_forum')) |
|
3040 | - echo ' |
|
3202 | + } elseif (!allowedTo('admin_forum')) { |
|
3203 | + echo ' |
|
3041 | 3204 | <title>', $txt['template_parse_error'], '</title> |
3042 | 3205 | </head> |
3043 | 3206 | <body> |
@@ -3045,15 +3208,17 @@ discard block |
||
3045 | 3208 | ', $txt['template_parse_error_message'], ' |
3046 | 3209 | </body> |
3047 | 3210 | </html>'; |
3048 | - else |
|
3211 | + } else |
|
3049 | 3212 | { |
3050 | 3213 | require_once($sourcedir . '/Subs-Package.php'); |
3051 | 3214 | |
3052 | 3215 | $error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); |
3053 | - if (empty($error) && ini_get('track_errors') && !empty($php_errormsg)) |
|
3054 | - $error = $php_errormsg; |
|
3055 | - if (empty($error)) |
|
3056 | - $error = $txt['template_parse_errmsg']; |
|
3216 | + if (empty($error) && ini_get('track_errors') && !empty($php_errormsg)) { |
|
3217 | + $error = $php_errormsg; |
|
3218 | + } |
|
3219 | + if (empty($error)) { |
|
3220 | + $error = $txt['template_parse_errmsg']; |
|
3221 | + } |
|
3057 | 3222 | |
3058 | 3223 | $error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>')); |
3059 | 3224 | |
@@ -3064,11 +3229,12 @@ discard block |
||
3064 | 3229 | <h3>', $txt['template_parse_error'], '</h3> |
3065 | 3230 | ', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); |
3066 | 3231 | |
3067 | - if (!empty($error)) |
|
3068 | - echo ' |
|
3232 | + if (!empty($error)) { |
|
3233 | + echo ' |
|
3069 | 3234 | <hr> |
3070 | 3235 | |
3071 | 3236 | <div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>'; |
3237 | + } |
|
3072 | 3238 | |
3073 | 3239 | // I know, I know... this is VERY COMPLICATED. Still, it's good. |
3074 | 3240 | if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0) |
@@ -3078,10 +3244,11 @@ discard block |
||
3078 | 3244 | $data2 = preg_split('~\<br( /)?\>~', $data2); |
3079 | 3245 | |
3080 | 3246 | // Fix the PHP code stuff... |
3081 | - if (!isBrowser('gecko')) |
|
3082 | - $data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2); |
|
3083 | - else |
|
3084 | - $data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2); |
|
3247 | + if (!isBrowser('gecko')) { |
|
3248 | + $data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2); |
|
3249 | + } else { |
|
3250 | + $data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2); |
|
3251 | + } |
|
3085 | 3252 | |
3086 | 3253 | // Now we get to work around a bug in PHP where it doesn't escape <br>s! |
3087 | 3254 | $j = -1; |
@@ -3089,8 +3256,9 @@ discard block |
||
3089 | 3256 | { |
3090 | 3257 | $j++; |
3091 | 3258 | |
3092 | - if (substr_count($line, '<br>') == 0) |
|
3093 | - continue; |
|
3259 | + if (substr_count($line, '<br>') == 0) { |
|
3260 | + continue; |
|
3261 | + } |
|
3094 | 3262 | |
3095 | 3263 | $n = substr_count($line, '<br>'); |
3096 | 3264 | for ($i = 0; $i < $n; $i++) |
@@ -3109,38 +3277,42 @@ discard block |
||
3109 | 3277 | // Figure out what the color coding was before... |
3110 | 3278 | $line = max($match[1] - 9, 1); |
3111 | 3279 | $last_line = ''; |
3112 | - for ($line2 = $line - 1; $line2 > 1; $line2--) |
|
3113 | - if (strpos($data2[$line2], '<') !== false) |
|
3280 | + for ($line2 = $line - 1; $line2 > 1; $line2--) { |
|
3281 | + if (strpos($data2[$line2], '<') !== false) |
|
3114 | 3282 | { |
3115 | 3283 | if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0) |
3116 | 3284 | $last_line = $color_match[1]; |
3285 | + } |
|
3117 | 3286 | break; |
3118 | 3287 | } |
3119 | 3288 | |
3120 | 3289 | // Show the relevant lines... |
3121 | 3290 | for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++) |
3122 | 3291 | { |
3123 | - if ($line == $match[1]) |
|
3124 | - echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">'; |
|
3292 | + if ($line == $match[1]) { |
|
3293 | + echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">'; |
|
3294 | + } |
|
3125 | 3295 | |
3126 | 3296 | echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> '; |
3127 | - if (isset($data2[$line]) && $data2[$line] != '') |
|
3128 | - echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line]; |
|
3297 | + if (isset($data2[$line]) && $data2[$line] != '') { |
|
3298 | + echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line]; |
|
3299 | + } |
|
3129 | 3300 | |
3130 | 3301 | if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0) |
3131 | 3302 | { |
3132 | 3303 | $last_line = $color_match[1]; |
3133 | 3304 | echo '</', substr($last_line, 1, 4), '>'; |
3305 | + } elseif ($last_line != '' && strpos($data2[$line], '<') !== false) { |
|
3306 | + $last_line = ''; |
|
3307 | + } elseif ($last_line != '' && $data2[$line] != '') { |
|
3308 | + echo '</', substr($last_line, 1, 4), '>'; |
|
3134 | 3309 | } |
3135 | - elseif ($last_line != '' && strpos($data2[$line], '<') !== false) |
|
3136 | - $last_line = ''; |
|
3137 | - elseif ($last_line != '' && $data2[$line] != '') |
|
3138 | - echo '</', substr($last_line, 1, 4), '>'; |
|
3139 | 3310 | |
3140 | - if ($line == $match[1]) |
|
3141 | - echo '</pre></div><pre style="margin: 0;">'; |
|
3142 | - else |
|
3143 | - echo "\n"; |
|
3311 | + if ($line == $match[1]) { |
|
3312 | + echo '</pre></div><pre style="margin: 0;">'; |
|
3313 | + } else { |
|
3314 | + echo "\n"; |
|
3315 | + } |
|
3144 | 3316 | } |
3145 | 3317 | |
3146 | 3318 | echo '</pre></div>'; |
@@ -3164,8 +3336,9 @@ discard block |
||
3164 | 3336 | global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port; |
3165 | 3337 | |
3166 | 3338 | // Figure out what type of database we are using. |
3167 | - if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) |
|
3168 | - $db_type = 'mysql'; |
|
3339 | + if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) { |
|
3340 | + $db_type = 'mysql'; |
|
3341 | + } |
|
3169 | 3342 | |
3170 | 3343 | // Load the file for the database. |
3171 | 3344 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
@@ -3173,8 +3346,9 @@ discard block |
||
3173 | 3346 | $db_options = array(); |
3174 | 3347 | |
3175 | 3348 | // Add in the port if needed |
3176 | - if (!empty($db_port)) |
|
3177 | - $db_options['port'] = $db_port; |
|
3349 | + if (!empty($db_port)) { |
|
3350 | + $db_options['port'] = $db_port; |
|
3351 | + } |
|
3178 | 3352 | |
3179 | 3353 | // If we are in SSI try them first, but don't worry if it doesn't work, we have the normal username and password we can use. |
3180 | 3354 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
@@ -3193,13 +3367,15 @@ discard block |
||
3193 | 3367 | } |
3194 | 3368 | |
3195 | 3369 | // Safe guard here, if there isn't a valid connection lets put a stop to it. |
3196 | - if (!$db_connection) |
|
3197 | - display_db_error(); |
|
3370 | + if (!$db_connection) { |
|
3371 | + display_db_error(); |
|
3372 | + } |
|
3198 | 3373 | |
3199 | 3374 | // If in SSI mode fix up the prefix. |
3200 | - if (SMF == 'SSI') |
|
3201 | - db_fix_prefix($db_prefix, $db_name); |
|
3202 | -} |
|
3375 | + if (SMF == 'SSI') { |
|
3376 | + db_fix_prefix($db_prefix, $db_name); |
|
3377 | + } |
|
3378 | + } |
|
3203 | 3379 | |
3204 | 3380 | /** |
3205 | 3381 | * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it. |
@@ -3213,10 +3389,11 @@ discard block |
||
3213 | 3389 | global $sourcedir, $cacheAPI, $cache_accelerator; |
3214 | 3390 | |
3215 | 3391 | // Not overriding this and we have a cacheAPI, send it back. |
3216 | - if (empty($overrideCache) && is_object($cacheAPI)) |
|
3217 | - return $cacheAPI; |
|
3218 | - elseif (is_null($cacheAPI)) |
|
3219 | - $cacheAPI = false; |
|
3392 | + if (empty($overrideCache) && is_object($cacheAPI)) { |
|
3393 | + return $cacheAPI; |
|
3394 | + } elseif (is_null($cacheAPI)) { |
|
3395 | + $cacheAPI = false; |
|
3396 | + } |
|
3220 | 3397 | |
3221 | 3398 | // Make sure our class is in session. |
3222 | 3399 | require_once($sourcedir . '/Class-CacheAPI.php'); |
@@ -3237,8 +3414,9 @@ discard block |
||
3237 | 3414 | if (!$testAPI->isSupported()) |
3238 | 3415 | { |
3239 | 3416 | // Can we save ourselves? |
3240 | - if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') |
|
3241 | - return loadCacheAccelerator(null, false); |
|
3417 | + if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') { |
|
3418 | + return loadCacheAccelerator(null, false); |
|
3419 | + } |
|
3242 | 3420 | return false; |
3243 | 3421 | } |
3244 | 3422 | |
@@ -3250,9 +3428,9 @@ discard block |
||
3250 | 3428 | { |
3251 | 3429 | $cacheAPI = $testAPI; |
3252 | 3430 | return $cacheAPI; |
3431 | + } else { |
|
3432 | + return $testAPI; |
|
3253 | 3433 | } |
3254 | - else |
|
3255 | - return $testAPI; |
|
3256 | 3434 | } |
3257 | 3435 | } |
3258 | 3436 | |
@@ -3272,8 +3450,9 @@ discard block |
||
3272 | 3450 | |
3273 | 3451 | // @todo Why are we doing this if caching is disabled? |
3274 | 3452 | |
3275 | - if (function_exists('call_integration_hook')) |
|
3276 | - call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level)); |
|
3453 | + if (function_exists('call_integration_hook')) { |
|
3454 | + call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level)); |
|
3455 | + } |
|
3277 | 3456 | |
3278 | 3457 | /* Refresh the cache if either: |
3279 | 3458 | 1. Caching is disabled. |
@@ -3287,16 +3466,19 @@ discard block |
||
3287 | 3466 | require_once($sourcedir . '/' . $file); |
3288 | 3467 | $cache_block = call_user_func_array($function, $params); |
3289 | 3468 | |
3290 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) |
|
3291 | - cache_put_data($key, $cache_block, $cache_block['expires'] - time()); |
|
3469 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) { |
|
3470 | + cache_put_data($key, $cache_block, $cache_block['expires'] - time()); |
|
3471 | + } |
|
3292 | 3472 | } |
3293 | 3473 | |
3294 | 3474 | // Some cached data may need a freshening up after retrieval. |
3295 | - if (!empty($cache_block['post_retri_eval'])) |
|
3296 | - eval($cache_block['post_retri_eval']); |
|
3475 | + if (!empty($cache_block['post_retri_eval'])) { |
|
3476 | + eval($cache_block['post_retri_eval']); |
|
3477 | + } |
|
3297 | 3478 | |
3298 | - if (function_exists('call_integration_hook')) |
|
3299 | - call_integration_hook('post_cache_quick_get', array(&$cache_block)); |
|
3479 | + if (function_exists('call_integration_hook')) { |
|
3480 | + call_integration_hook('post_cache_quick_get', array(&$cache_block)); |
|
3481 | + } |
|
3300 | 3482 | |
3301 | 3483 | return $cache_block['data']; |
3302 | 3484 | } |
@@ -3323,8 +3505,9 @@ discard block |
||
3323 | 3505 | global $cache_enable, $cacheAPI; |
3324 | 3506 | global $cache_hits, $cache_count, $db_show_debug; |
3325 | 3507 | |
3326 | - if (empty($cache_enable) || empty($cacheAPI)) |
|
3327 | - return; |
|
3508 | + if (empty($cache_enable) || empty($cacheAPI)) { |
|
3509 | + return; |
|
3510 | + } |
|
3328 | 3511 | |
3329 | 3512 | $cache_count = isset($cache_count) ? $cache_count + 1 : 1; |
3330 | 3513 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -3337,12 +3520,14 @@ discard block |
||
3337 | 3520 | $value = $value === null ? null : json_encode($value); |
3338 | 3521 | $cacheAPI->putData($key, $value, $ttl); |
3339 | 3522 | |
3340 | - if (function_exists('call_integration_hook')) |
|
3341 | - call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl)); |
|
3523 | + if (function_exists('call_integration_hook')) { |
|
3524 | + call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl)); |
|
3525 | + } |
|
3342 | 3526 | |
3343 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
3344 | - $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
3345 | -} |
|
3527 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
3528 | + $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
3529 | + } |
|
3530 | + } |
|
3346 | 3531 | |
3347 | 3532 | /** |
3348 | 3533 | * Gets the value from the cache specified by key, so long as it is not older than ttl seconds. |
@@ -3358,8 +3543,9 @@ discard block |
||
3358 | 3543 | global $cache_enable, $cacheAPI; |
3359 | 3544 | global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug; |
3360 | 3545 | |
3361 | - if (empty($cache_enable) || empty($cacheAPI)) |
|
3362 | - return; |
|
3546 | + if (empty($cache_enable) || empty($cacheAPI)) { |
|
3547 | + return; |
|
3548 | + } |
|
3363 | 3549 | |
3364 | 3550 | $cache_count = isset($cache_count) ? $cache_count + 1 : 1; |
3365 | 3551 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -3379,16 +3565,18 @@ discard block |
||
3379 | 3565 | |
3380 | 3566 | if (empty($value)) |
3381 | 3567 | { |
3382 | - if (!is_array($cache_misses)) |
|
3383 | - $cache_misses = array(); |
|
3568 | + if (!is_array($cache_misses)) { |
|
3569 | + $cache_misses = array(); |
|
3570 | + } |
|
3384 | 3571 | |
3385 | 3572 | $cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1; |
3386 | 3573 | $cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get'); |
3387 | 3574 | } |
3388 | 3575 | } |
3389 | 3576 | |
3390 | - if (function_exists('call_integration_hook') && isset($value)) |
|
3391 | - call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value)); |
|
3577 | + if (function_exists('call_integration_hook') && isset($value)) { |
|
3578 | + call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value)); |
|
3579 | + } |
|
3392 | 3580 | |
3393 | 3581 | return empty($value) ? null : smf_json_decode($value, true); |
3394 | 3582 | } |
@@ -3410,8 +3598,9 @@ discard block |
||
3410 | 3598 | global $cacheAPI; |
3411 | 3599 | |
3412 | 3600 | // If we can't get to the API, can't do this. |
3413 | - if (empty($cacheAPI)) |
|
3414 | - return; |
|
3601 | + if (empty($cacheAPI)) { |
|
3602 | + return; |
|
3603 | + } |
|
3415 | 3604 | |
3416 | 3605 | // Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure. |
3417 | 3606 | $cacheAPI->cleanCache($type); |
@@ -3436,8 +3625,9 @@ discard block |
||
3436 | 3625 | global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret; |
3437 | 3626 | |
3438 | 3627 | // Come on! |
3439 | - if (empty($data)) |
|
3440 | - return array(); |
|
3628 | + if (empty($data)) { |
|
3629 | + return array(); |
|
3630 | + } |
|
3441 | 3631 | |
3442 | 3632 | // Set a nice default var. |
3443 | 3633 | $image = ''; |
@@ -3445,11 +3635,11 @@ discard block |
||
3445 | 3635 | // Gravatar has been set as mandatory! |
3446 | 3636 | if (!empty($modSettings['gravatarOverride'])) |
3447 | 3637 | { |
3448 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) |
|
3449 | - $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3450 | - |
|
3451 | - else if (!empty($data['email'])) |
|
3452 | - $image = get_gravatar_url($data['email']); |
|
3638 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) { |
|
3639 | + $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3640 | + } else if (!empty($data['email'])) { |
|
3641 | + $image = get_gravatar_url($data['email']); |
|
3642 | + } |
|
3453 | 3643 | } |
3454 | 3644 | |
3455 | 3645 | // Look if the user has a gravatar field or has set an external url as avatar. |
@@ -3461,54 +3651,60 @@ discard block |
||
3461 | 3651 | // Gravatar. |
3462 | 3652 | if (stristr($data['avatar'], 'gravatar://')) |
3463 | 3653 | { |
3464 | - if ($data['avatar'] == 'gravatar://') |
|
3465 | - $image = get_gravatar_url($data['email']); |
|
3466 | - |
|
3467 | - elseif (!empty($modSettings['gravatarAllowExtraEmail'])) |
|
3468 | - $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3654 | + if ($data['avatar'] == 'gravatar://') { |
|
3655 | + $image = get_gravatar_url($data['email']); |
|
3656 | + } elseif (!empty($modSettings['gravatarAllowExtraEmail'])) { |
|
3657 | + $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3658 | + } |
|
3469 | 3659 | } |
3470 | 3660 | |
3471 | 3661 | // External url. |
3472 | 3662 | else |
3473 | 3663 | { |
3474 | 3664 | // Using ssl? |
3475 | - if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) |
|
3476 | - $image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret); |
|
3665 | + if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) { |
|
3666 | + $image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret); |
|
3667 | + } |
|
3477 | 3668 | |
3478 | 3669 | // Just a plain external url. |
3479 | - else |
|
3480 | - $image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar']; |
|
3670 | + else { |
|
3671 | + $image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar']; |
|
3672 | + } |
|
3481 | 3673 | } |
3482 | 3674 | } |
3483 | 3675 | |
3484 | 3676 | // Perhaps this user has an attachment as avatar... |
3485 | - else if (!empty($data['filename'])) |
|
3486 | - $image = $modSettings['custom_avatar_url'] . '/' . $data['filename']; |
|
3677 | + else if (!empty($data['filename'])) { |
|
3678 | + $image = $modSettings['custom_avatar_url'] . '/' . $data['filename']; |
|
3679 | + } |
|
3487 | 3680 | |
3488 | 3681 | // Right... no avatar... use our default image. |
3489 | - else |
|
3490 | - $image = $modSettings['avatar_url'] . '/default.png'; |
|
3682 | + else { |
|
3683 | + $image = $modSettings['avatar_url'] . '/default.png'; |
|
3684 | + } |
|
3491 | 3685 | } |
3492 | 3686 | |
3493 | 3687 | call_integration_hook('integrate_set_avatar_data', array(&$image, &$data)); |
3494 | 3688 | |
3495 | 3689 | // At this point in time $image has to be filled unless you chose to force gravatar and the user doesn't have the needed data to retrieve it... thus a check for !empty() is still needed. |
3496 | - if (!empty($image)) |
|
3497 | - return array( |
|
3690 | + if (!empty($image)) { |
|
3691 | + return array( |
|
3498 | 3692 | 'name' => !empty($data['avatar']) ? $data['avatar'] : '', |
3499 | 3693 | 'image' => '<img class="avatar" src="' . $image . '" />', |
3500 | 3694 | 'href' => $image, |
3501 | 3695 | 'url' => $image, |
3502 | 3696 | ); |
3697 | + } |
|
3503 | 3698 | |
3504 | 3699 | // Fallback to make life easier for everyone... |
3505 | - else |
|
3506 | - return array( |
|
3700 | + else { |
|
3701 | + return array( |
|
3507 | 3702 | 'name' => '', |
3508 | 3703 | 'image' => '', |
3509 | 3704 | 'href' => '', |
3510 | 3705 | 'url' => '', |
3511 | 3706 | ); |
3512 | -} |
|
3707 | + } |
|
3708 | + } |
|
3513 | 3709 | |
3514 | 3710 | ?> |
3515 | 3711 | \ No newline at end of file |
@@ -11,8 +11,9 @@ discard block |
||
11 | 11 | * @version 2.1 Beta 3 |
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 |
@@ -27,8 +28,9 @@ discard block |
||
27 | 28 | { |
28 | 29 | $supported = function_exists('apcu_fetch') && function_exists('apcu_store'); |
29 | 30 | |
30 | - if ($test) |
|
31 | - return $supported; |
|
31 | + if ($test) { |
|
32 | + return $supported; |
|
33 | + } |
|
32 | 34 | return parent::isSupported() && $supported; |
33 | 35 | } |
34 | 36 | |
@@ -50,10 +52,11 @@ discard block |
||
50 | 52 | $key = $this->prefix . strtr($key, ':/', '-_'); |
51 | 53 | |
52 | 54 | // An extended key is needed to counteract a bug in APC. |
53 | - if ($value === null) |
|
54 | - return apcu_delete($key . 'smf'); |
|
55 | - else |
|
56 | - return apcu_store($key . 'smf', $value, $ttl); |
|
55 | + if ($value === null) { |
|
56 | + return apcu_delete($key . 'smf'); |
|
57 | + } else { |
|
58 | + return apcu_store($key . 'smf', $value, $ttl); |
|
59 | + } |
|
57 | 60 | } |
58 | 61 | |
59 | 62 | /** |
@@ -18,10 +18,10 @@ |
||
18 | 18 | */ |
19 | 19 | class Birthday_Notify_Background extends SMF_BackgroundTask |
20 | 20 | { |
21 | - /** |
|
22 | - * This executes the task. It loads up the birthdays, figures out the greeting, etc. |
|
23 | - * @return bool Always returns true |
|
24 | - */ |
|
21 | + /** |
|
22 | + * This executes the task. It loads up the birthdays, figures out the greeting, etc. |
|
23 | + * @return bool Always returns true |
|
24 | + */ |
|
25 | 25 | public function execute() |
26 | 26 | { |
27 | 27 | global $txt, $smcFunc, $txtBirthdayEmails, $modSettings, $sourcedir; |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 3 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | /** |
21 | 22 | * This function allows to move a topic, making sure to ask the moderator |
@@ -32,8 +33,9 @@ discard block |
||
32 | 33 | { |
33 | 34 | global $txt, $board, $topic, $user_info, $context, $language, $scripturl, $smcFunc, $modSettings, $sourcedir; |
34 | 35 | |
35 | - if (empty($topic)) |
|
36 | - fatal_lang_error('no_access', false); |
|
36 | + if (empty($topic)) { |
|
37 | + fatal_lang_error('no_access', false); |
|
38 | + } |
|
37 | 39 | |
38 | 40 | $request = $smcFunc['db_query']('', ' |
39 | 41 | SELECT t.id_member_started, ms.subject, t.approved |
@@ -49,8 +51,9 @@ discard block |
||
49 | 51 | $smcFunc['db_free_result']($request); |
50 | 52 | |
51 | 53 | // Can they see it - if not approved? |
52 | - if ($modSettings['postmod_active'] && !$context['is_approved']) |
|
53 | - isAllowedTo('approve_posts'); |
|
54 | + if ($modSettings['postmod_active'] && !$context['is_approved']) { |
|
55 | + isAllowedTo('approve_posts'); |
|
56 | + } |
|
54 | 57 | |
55 | 58 | // Permission check! |
56 | 59 | // @todo |
@@ -59,9 +62,9 @@ discard block |
||
59 | 62 | if ($id_member_started == $user_info['id']) |
60 | 63 | { |
61 | 64 | isAllowedTo('move_own'); |
65 | + } else { |
|
66 | + isAllowedTo('move_any'); |
|
62 | 67 | } |
63 | - else |
|
64 | - isAllowedTo('move_any'); |
|
65 | 68 | } |
66 | 69 | |
67 | 70 | $context['move_any'] = $user_info['is_admin'] || $modSettings['topic_move_any']; |
@@ -83,11 +86,13 @@ discard block |
||
83 | 86 | 'not_redirection' => true, |
84 | 87 | ); |
85 | 88 | |
86 | - if (!empty($_SESSION['move_to_topic']) && $_SESSION['move_to_topic'] != $board) |
|
87 | - $options['selected_board'] = $_SESSION['move_to_topic']; |
|
89 | + if (!empty($_SESSION['move_to_topic']) && $_SESSION['move_to_topic'] != $board) { |
|
90 | + $options['selected_board'] = $_SESSION['move_to_topic']; |
|
91 | + } |
|
88 | 92 | |
89 | - if (!$context['move_any']) |
|
90 | - $options['included_boards'] = $boards; |
|
93 | + if (!$context['move_any']) { |
|
94 | + $options['included_boards'] = $boards; |
|
95 | + } |
|
91 | 96 | |
92 | 97 | require_once($sourcedir . '/Subs-MessageIndex.php'); |
93 | 98 | $context['categories'] = getBoardList($options); |
@@ -138,12 +143,14 @@ discard block |
||
138 | 143 | global $txt, $topic, $scripturl, $sourcedir, $context; |
139 | 144 | global $board, $language, $user_info, $smcFunc; |
140 | 145 | |
141 | - if (empty($topic)) |
|
142 | - fatal_lang_error('no_access', false); |
|
146 | + if (empty($topic)) { |
|
147 | + fatal_lang_error('no_access', false); |
|
148 | + } |
|
143 | 149 | |
144 | 150 | // You can't choose to have a redirection topic and use an empty reason. |
145 | - if (isset($_POST['postRedirect']) && (!isset($_POST['reason']) || trim($_POST['reason']) == '')) |
|
146 | - fatal_lang_error('movetopic_no_reason', false); |
|
151 | + if (isset($_POST['postRedirect']) && (!isset($_POST['reason']) || trim($_POST['reason']) == '')) { |
|
152 | + fatal_lang_error('movetopic_no_reason', false); |
|
153 | + } |
|
147 | 154 | |
148 | 155 | moveTopicConcurrence(); |
149 | 156 | |
@@ -163,16 +170,18 @@ discard block |
||
163 | 170 | $smcFunc['db_free_result']($request); |
164 | 171 | |
165 | 172 | // Can they see it? |
166 | - if (!$context['is_approved']) |
|
167 | - isAllowedTo('approve_posts'); |
|
173 | + if (!$context['is_approved']) { |
|
174 | + isAllowedTo('approve_posts'); |
|
175 | + } |
|
168 | 176 | |
169 | 177 | // Can they move topics on this board? |
170 | 178 | if (!allowedTo('move_any')) |
171 | 179 | { |
172 | - if ($id_member_started == $user_info['id']) |
|
173 | - isAllowedTo('move_own'); |
|
174 | - else |
|
175 | - isAllowedTo('move_any'); |
|
180 | + if ($id_member_started == $user_info['id']) { |
|
181 | + isAllowedTo('move_own'); |
|
182 | + } else { |
|
183 | + isAllowedTo('move_any'); |
|
184 | + } |
|
176 | 185 | } |
177 | 186 | |
178 | 187 | checkSession(); |
@@ -197,8 +206,9 @@ discard block |
||
197 | 206 | 'blank_redirect' => '', |
198 | 207 | ) |
199 | 208 | ); |
200 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
201 | - fatal_lang_error('no_board'); |
|
209 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
210 | + fatal_lang_error('no_board'); |
|
211 | + } |
|
202 | 212 | list ($pcounter, $board_name, $subject) = $smcFunc['db_fetch_row']($request); |
203 | 213 | $smcFunc['db_free_result']($request); |
204 | 214 | |
@@ -210,8 +220,9 @@ discard block |
||
210 | 220 | { |
211 | 221 | $_POST['custom_subject'] = strtr($smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['custom_subject'])), array("\r" => '', "\n" => '', "\t" => '')); |
212 | 222 | // Keep checking the length. |
213 | - if ($smcFunc['strlen']($_POST['custom_subject']) > 100) |
|
214 | - $_POST['custom_subject'] = $smcFunc['substr']($_POST['custom_subject'], 0, 100); |
|
223 | + if ($smcFunc['strlen']($_POST['custom_subject']) > 100) { |
|
224 | + $_POST['custom_subject'] = $smcFunc['substr']($_POST['custom_subject'], 0, 100); |
|
225 | + } |
|
215 | 226 | |
216 | 227 | // If it's still valid move onwards and upwards. |
217 | 228 | if ($_POST['custom_subject'] != '') |
@@ -221,9 +232,9 @@ discard block |
||
221 | 232 | // Get a response prefix, but in the forum's default language. |
222 | 233 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) |
223 | 234 | { |
224 | - if ($language === $user_info['language']) |
|
225 | - $context['response_prefix'] = $txt['response_prefix']; |
|
226 | - else |
|
235 | + if ($language === $user_info['language']) { |
|
236 | + $context['response_prefix'] = $txt['response_prefix']; |
|
237 | + } else |
|
227 | 238 | { |
228 | 239 | loadLanguage('index', $language, false); |
229 | 240 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -263,8 +274,9 @@ discard block |
||
263 | 274 | if (isset($_POST['postRedirect'])) |
264 | 275 | { |
265 | 276 | // Should be in the boardwide language. |
266 | - if ($user_info['language'] != $language) |
|
267 | - loadLanguage('index', $language); |
|
277 | + if ($user_info['language'] != $language) { |
|
278 | + loadLanguage('index', $language); |
|
279 | + } |
|
268 | 280 | |
269 | 281 | $_POST['reason'] = $smcFunc['htmlspecialchars']($_POST['reason'], ENT_QUOTES); |
270 | 282 | preparsecode($_POST['reason']); |
@@ -328,8 +340,9 @@ discard block |
||
328 | 340 | $posters = array(); |
329 | 341 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
330 | 342 | { |
331 | - if (!isset($posters[$row['id_member']])) |
|
332 | - $posters[$row['id_member']] = 0; |
|
343 | + if (!isset($posters[$row['id_member']])) { |
|
344 | + $posters[$row['id_member']] = 0; |
|
345 | + } |
|
333 | 346 | |
334 | 347 | $posters[$row['id_member']]++; |
335 | 348 | } |
@@ -338,11 +351,13 @@ discard block |
||
338 | 351 | foreach ($posters as $id_member => $posts) |
339 | 352 | { |
340 | 353 | // The board we're moving from counted posts, but not to. |
341 | - if (empty($pcounter_from)) |
|
342 | - updateMemberData($id_member, array('posts' => 'posts - ' . $posts)); |
|
354 | + if (empty($pcounter_from)) { |
|
355 | + updateMemberData($id_member, array('posts' => 'posts - ' . $posts)); |
|
356 | + } |
|
343 | 357 | // The reverse: from didn't, to did. |
344 | - else |
|
345 | - updateMemberData($id_member, array('posts' => 'posts + ' . $posts)); |
|
358 | + else { |
|
359 | + updateMemberData($id_member, array('posts' => 'posts + ' . $posts)); |
|
360 | + } |
|
346 | 361 | } |
347 | 362 | } |
348 | 363 | |
@@ -350,17 +365,19 @@ discard block |
||
350 | 365 | moveTopics($topic, $_POST['toboard']); |
351 | 366 | |
352 | 367 | // Log that they moved this topic. |
353 | - if (!allowedTo('move_own') || $id_member_started != $user_info['id']) |
|
354 | - logAction('move', array('topic' => $topic, 'board_from' => $board, 'board_to' => $_POST['toboard'])); |
|
368 | + if (!allowedTo('move_own') || $id_member_started != $user_info['id']) { |
|
369 | + logAction('move', array('topic' => $topic, 'board_from' => $board, 'board_to' => $_POST['toboard'])); |
|
370 | + } |
|
355 | 371 | // Notify people that this topic has been moved? |
356 | 372 | sendNotifications($topic, 'move'); |
357 | 373 | |
358 | 374 | // Why not go back to the original board in case they want to keep moving? |
359 | - if (!isset($_REQUEST['goback'])) |
|
360 | - redirectexit('board=' . $board . '.0'); |
|
361 | - else |
|
362 | - redirectexit('topic=' . $topic . '.0'); |
|
363 | -} |
|
375 | + if (!isset($_REQUEST['goback'])) { |
|
376 | + redirectexit('board=' . $board . '.0'); |
|
377 | + } else { |
|
378 | + redirectexit('topic=' . $topic . '.0'); |
|
379 | + } |
|
380 | + } |
|
364 | 381 | |
365 | 382 | /** |
366 | 383 | * Moves one or more topics to a specific board. (doesn't check permissions.) |
@@ -376,18 +393,21 @@ discard block |
||
376 | 393 | global $sourcedir, $user_info, $modSettings, $smcFunc; |
377 | 394 | |
378 | 395 | // Empty array? |
379 | - if (empty($topics)) |
|
380 | - return; |
|
396 | + if (empty($topics)) { |
|
397 | + return; |
|
398 | + } |
|
381 | 399 | |
382 | 400 | // Only a single topic. |
383 | - if (is_numeric($topics)) |
|
384 | - $topics = array($topics); |
|
401 | + if (is_numeric($topics)) { |
|
402 | + $topics = array($topics); |
|
403 | + } |
|
385 | 404 | |
386 | 405 | $fromBoards = array(); |
387 | 406 | |
388 | 407 | // Destination board empty or equal to 0? |
389 | - if (empty($toBoard)) |
|
390 | - return; |
|
408 | + if (empty($toBoard)) { |
|
409 | + return; |
|
410 | + } |
|
391 | 411 | |
392 | 412 | // Are we moving to the recycle board? |
393 | 413 | $isRecycleDest = !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $toBoard; |
@@ -395,8 +415,9 @@ discard block |
||
395 | 415 | // Callback for search APIs to do their thing |
396 | 416 | require_once($sourcedir . '/Search.php'); |
397 | 417 | $searchAPI = findSearchAPI(); |
398 | - if ($searchAPI->supportsMethod('topicsMoved')) |
|
399 | - $searchAPI->topicsMoved($topics, $toBoard); |
|
418 | + if ($searchAPI->supportsMethod('topicsMoved')) { |
|
419 | + $searchAPI->topicsMoved($topics, $toBoard); |
|
420 | + } |
|
400 | 421 | |
401 | 422 | // Determine the source boards... |
402 | 423 | $request = $smcFunc['db_query']('', ' |
@@ -410,8 +431,9 @@ discard block |
||
410 | 431 | ) |
411 | 432 | ); |
412 | 433 | // Num of rows = 0 -> no topics found. Num of rows > 1 -> topics are on multiple boards. |
413 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
414 | - return; |
|
434 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
435 | + return; |
|
436 | + } |
|
415 | 437 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
416 | 438 | { |
417 | 439 | if (!isset($fromBoards[$row['id_board']]['num_posts'])) |
@@ -429,10 +451,11 @@ discard block |
||
429 | 451 | $fromBoards[$row['id_board']]['unapproved_posts'] += $row['unapproved_posts']; |
430 | 452 | |
431 | 453 | // Add the topics to the right type. |
432 | - if ($row['approved']) |
|
433 | - $fromBoards[$row['id_board']]['num_topics'] += $row['num_topics']; |
|
434 | - else |
|
435 | - $fromBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics']; |
|
454 | + if ($row['approved']) { |
|
455 | + $fromBoards[$row['id_board']]['num_topics'] += $row['num_topics']; |
|
456 | + } else { |
|
457 | + $fromBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics']; |
|
458 | + } |
|
436 | 459 | } |
437 | 460 | $smcFunc['db_free_result']($request); |
438 | 461 | |
@@ -558,13 +581,14 @@ discard block |
||
558 | 581 | ) |
559 | 582 | ); |
560 | 583 | $approval_msgs = array(); |
561 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
562 | - $approval_msgs[] = $row['id_msg']; |
|
584 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
585 | + $approval_msgs[] = $row['id_msg']; |
|
586 | + } |
|
563 | 587 | $smcFunc['db_free_result']($request); |
564 | 588 | |
565 | 589 | // Empty the approval queue for these, as we're going to approve them next. |
566 | - if (!empty($approval_msgs)) |
|
567 | - $smcFunc['db_query']('', ' |
|
590 | + if (!empty($approval_msgs)) { |
|
591 | + $smcFunc['db_query']('', ' |
|
568 | 592 | DELETE FROM {db_prefix}approval_queue |
569 | 593 | WHERE id_msg IN ({array_int:message_list}) |
570 | 594 | AND id_attach = {int:id_attach}', |
@@ -573,6 +597,7 @@ discard block |
||
573 | 597 | 'id_attach' => 0, |
574 | 598 | ) |
575 | 599 | ); |
600 | + } |
|
576 | 601 | |
577 | 602 | // Get all the current max and mins. |
578 | 603 | $request = $smcFunc['db_query']('', ' |
@@ -606,8 +631,8 @@ discard block |
||
606 | 631 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
607 | 632 | { |
608 | 633 | // If not, update. |
609 | - if ($row['first_msg'] != $topicMaxMin[$row['id_topic']]['min'] || $row['last_msg'] != $topicMaxMin[$row['id_topic']]['max']) |
|
610 | - $smcFunc['db_query']('', ' |
|
634 | + if ($row['first_msg'] != $topicMaxMin[$row['id_topic']]['min'] || $row['last_msg'] != $topicMaxMin[$row['id_topic']]['max']) { |
|
635 | + $smcFunc['db_query']('', ' |
|
611 | 636 | UPDATE {db_prefix}topics |
612 | 637 | SET id_first_msg = {int:first_msg}, id_last_msg = {int:last_msg} |
613 | 638 | WHERE id_topic = {int:selected_topic}', |
@@ -617,6 +642,7 @@ discard block |
||
617 | 642 | 'selected_topic' => $row['id_topic'], |
618 | 643 | ) |
619 | 644 | ); |
645 | + } |
|
620 | 646 | } |
621 | 647 | $smcFunc['db_free_result']($request); |
622 | 648 | } |
@@ -675,9 +701,10 @@ discard block |
||
675 | 701 | } |
676 | 702 | |
677 | 703 | // Update the cache? |
678 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) |
|
679 | - foreach ($topics as $topic_id) |
|
704 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) { |
|
705 | + foreach ($topics as $topic_id) |
|
680 | 706 | cache_put_data('topic_board-' . $topic_id, null, 120); |
707 | + } |
|
681 | 708 | |
682 | 709 | require_once($sourcedir . '/Subs-Post.php'); |
683 | 710 | |
@@ -701,15 +728,17 @@ discard block |
||
701 | 728 | { |
702 | 729 | global $board, $topic, $smcFunc, $scripturl; |
703 | 730 | |
704 | - if (isset($_GET['current_board'])) |
|
705 | - $move_from = (int) $_GET['current_board']; |
|
731 | + if (isset($_GET['current_board'])) { |
|
732 | + $move_from = (int) $_GET['current_board']; |
|
733 | + } |
|
706 | 734 | |
707 | - if (empty($move_from) || empty($board) || empty($topic)) |
|
708 | - return true; |
|
735 | + if (empty($move_from) || empty($board) || empty($topic)) { |
|
736 | + return true; |
|
737 | + } |
|
709 | 738 | |
710 | - if ($move_from == $board) |
|
711 | - return true; |
|
712 | - else |
|
739 | + if ($move_from == $board) { |
|
740 | + return true; |
|
741 | + } else |
|
713 | 742 | { |
714 | 743 | $request = $smcFunc['db_query']('', ' |
715 | 744 | SELECT m.subject, b.name |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 3 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * This is the dispatcher of smileys administration. |
@@ -91,8 +92,9 @@ discard block |
||
91 | 92 | ); |
92 | 93 | |
93 | 94 | // Some settings may not be enabled, disallow these from the tabs as appropriate. |
94 | - if (empty($modSettings['messageIcons_enable'])) |
|
95 | - $context[$context['admin_menu_name']]['tab_data']['tabs']['editicons']['disabled'] = true; |
|
95 | + if (empty($modSettings['messageIcons_enable'])) { |
|
96 | + $context[$context['admin_menu_name']]['tab_data']['tabs']['editicons']['disabled'] = true; |
|
97 | + } |
|
96 | 98 | if (empty($modSettings['smiley_enable'])) |
97 | 99 | { |
98 | 100 | $context[$context['admin_menu_name']]['tab_data']['tabs']['addsmiley']['disabled'] = true; |
@@ -125,8 +127,9 @@ discard block |
||
125 | 127 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
126 | 128 | |
127 | 129 | $smiley_context = array(); |
128 | - foreach ($smiley_sets as $i => $set) |
|
129 | - $smiley_context[$set] = $set_names[$i]; |
|
130 | + foreach ($smiley_sets as $i => $set) { |
|
131 | + $smiley_context[$set] = $set_names[$i]; |
|
132 | + } |
|
130 | 133 | |
131 | 134 | // All the settings for the page... |
132 | 135 | $config_vars = array( |
@@ -147,8 +150,9 @@ discard block |
||
147 | 150 | |
148 | 151 | call_integration_hook('integrate_modify_smiley_settings', array(&$config_vars)); |
149 | 152 | |
150 | - if ($return_config) |
|
151 | - return $config_vars; |
|
153 | + if ($return_config) { |
|
154 | + return $config_vars; |
|
155 | + } |
|
152 | 156 | |
153 | 157 | // Setup the basics of the settings template. |
154 | 158 | require_once($sourcedir . '/ManageServer.php'); |
@@ -207,8 +211,9 @@ discard block |
||
207 | 211 | foreach ($_POST['smiley_set'] as $id => $val) |
208 | 212 | { |
209 | 213 | // If this is the set you've marked as default, or the only one remaining, you can't delete it |
210 | - if ($modSettings['smiley_sets_default'] != $set_paths[$id] && count($set_paths) != 1 && isset($set_paths[$id], $set_names[$id])) |
|
211 | - unset($set_paths[$id], $set_names[$id]); |
|
214 | + if ($modSettings['smiley_sets_default'] != $set_paths[$id] && count($set_paths) != 1 && isset($set_paths[$id], $set_names[$id])) { |
|
215 | + unset($set_paths[$id], $set_names[$id]); |
|
216 | + } |
|
212 | 217 | } |
213 | 218 | |
214 | 219 | // Shortcut... array_merge() on a single array resets the numeric keys |
@@ -222,8 +227,9 @@ discard block |
||
222 | 227 | )); |
223 | 228 | } |
224 | 229 | // Add a new smiley set. |
225 | - elseif (!empty($_POST['add'])) |
|
226 | - $context['sub_action'] = 'modifyset'; |
|
230 | + elseif (!empty($_POST['add'])) { |
|
231 | + $context['sub_action'] = 'modifyset'; |
|
232 | + } |
|
227 | 233 | // Create or modify a smiley set. |
228 | 234 | elseif (isset($_POST['set'])) |
229 | 235 | { |
@@ -233,8 +239,9 @@ discard block |
||
233 | 239 | // Create a new smiley set. |
234 | 240 | if ($_POST['set'] == -1 && isset($_POST['smiley_sets_path'])) |
235 | 241 | { |
236 | - if (in_array($_POST['smiley_sets_path'], $set_paths)) |
|
237 | - fatal_lang_error('smiley_set_already_exists'); |
|
242 | + if (in_array($_POST['smiley_sets_path'], $set_paths)) { |
|
243 | + fatal_lang_error('smiley_set_already_exists'); |
|
244 | + } |
|
238 | 245 | |
239 | 246 | updateSettings(array( |
240 | 247 | 'smiley_sets_known' => $modSettings['smiley_sets_known'] . ',' . $_POST['smiley_sets_path'], |
@@ -246,12 +253,14 @@ discard block |
||
246 | 253 | else |
247 | 254 | { |
248 | 255 | // Make sure the smiley set exists. |
249 | - if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']])) |
|
250 | - fatal_lang_error('smiley_set_not_found'); |
|
256 | + if (!isset($set_paths[$_POST['set']]) || !isset($set_names[$_POST['set']])) { |
|
257 | + fatal_lang_error('smiley_set_not_found'); |
|
258 | + } |
|
251 | 259 | |
252 | 260 | // Make sure the path is not yet used by another smileyset. |
253 | - if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']]) |
|
254 | - fatal_lang_error('smiley_set_path_already_used'); |
|
261 | + if (in_array($_POST['smiley_sets_path'], $set_paths) && $_POST['smiley_sets_path'] != $set_paths[$_POST['set']]) { |
|
262 | + fatal_lang_error('smiley_set_path_already_used'); |
|
263 | + } |
|
255 | 264 | |
256 | 265 | $set_paths[$_POST['set']] = $_POST['smiley_sets_path']; |
257 | 266 | $set_names[$_POST['set']] = $_POST['smiley_sets_name']; |
@@ -263,8 +272,9 @@ discard block |
||
263 | 272 | } |
264 | 273 | |
265 | 274 | // The user might have checked to also import smileys. |
266 | - if (!empty($_POST['smiley_sets_import'])) |
|
267 | - ImportSmileys($_POST['smiley_sets_path']); |
|
275 | + if (!empty($_POST['smiley_sets_import'])) { |
|
276 | + ImportSmileys($_POST['smiley_sets_path']); |
|
277 | + } |
|
268 | 278 | } |
269 | 279 | cache_put_data('parsing_smileys', null, 480); |
270 | 280 | cache_put_data('posting_smileys', null, 480); |
@@ -273,13 +283,14 @@ discard block |
||
273 | 283 | // Load all available smileysets... |
274 | 284 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
275 | 285 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
276 | - foreach ($context['smiley_sets'] as $i => $set) |
|
277 | - $context['smiley_sets'][$i] = array( |
|
286 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
287 | + $context['smiley_sets'][$i] = array( |
|
278 | 288 | 'id' => $i, |
279 | 289 | 'path' => $smcFunc['htmlspecialchars']($set), |
280 | 290 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
281 | 291 | 'selected' => $set == $modSettings['smiley_sets_default'] |
282 | 292 | ); |
293 | + } |
|
283 | 294 | |
284 | 295 | // Importing any smileys from an existing set? |
285 | 296 | if ($context['sub_action'] == 'import') |
@@ -290,8 +301,9 @@ discard block |
||
290 | 301 | $_GET['set'] = (int) $_GET['set']; |
291 | 302 | |
292 | 303 | // Sanity check - then import. |
293 | - if (isset($context['smiley_sets'][$_GET['set']])) |
|
294 | - ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path'])); |
|
304 | + if (isset($context['smiley_sets'][$_GET['set']])) { |
|
305 | + ImportSmileys(un_htmlspecialchars($context['smiley_sets'][$_GET['set']]['path'])); |
|
306 | + } |
|
295 | 307 | |
296 | 308 | // Force the process to continue. |
297 | 309 | $context['sub_action'] = 'modifyset'; |
@@ -301,15 +313,15 @@ discard block |
||
301 | 313 | if ($context['sub_action'] == 'modifyset') |
302 | 314 | { |
303 | 315 | $_GET['set'] = !isset($_GET['set']) ? -1 : (int) $_GET['set']; |
304 | - if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']])) |
|
305 | - $context['current_set'] = array( |
|
316 | + if ($_GET['set'] == -1 || !isset($context['smiley_sets'][$_GET['set']])) { |
|
317 | + $context['current_set'] = array( |
|
306 | 318 | 'id' => '-1', |
307 | 319 | 'path' => '', |
308 | 320 | 'name' => '', |
309 | 321 | 'selected' => false, |
310 | 322 | 'is_new' => true, |
311 | 323 | ); |
312 | - else |
|
324 | + } else |
|
313 | 325 | { |
314 | 326 | $context['current_set'] = &$context['smiley_sets'][$_GET['set']]; |
315 | 327 | $context['current_set']['is_new'] = false; |
@@ -321,13 +333,15 @@ discard block |
||
321 | 333 | $dir = dir($modSettings['smileys_dir'] . '/' . $context['current_set']['path']); |
322 | 334 | while ($entry = $dir->read()) |
323 | 335 | { |
324 | - if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
325 | - $smileys[strtolower($entry)] = $entry; |
|
336 | + if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
337 | + $smileys[strtolower($entry)] = $entry; |
|
338 | + } |
|
326 | 339 | } |
327 | 340 | $dir->close(); |
328 | 341 | |
329 | - if (empty($smileys)) |
|
330 | - fatal_lang_error('smiley_set_dir_not_found', false, array($context['current_set']['name'])); |
|
342 | + if (empty($smileys)) { |
|
343 | + fatal_lang_error('smiley_set_dir_not_found', false, array($context['current_set']['name'])); |
|
344 | + } |
|
331 | 345 | |
332 | 346 | // Exclude the smileys that are already in the database. |
333 | 347 | $request = $smcFunc['db_query']('', ' |
@@ -338,9 +352,10 @@ discard block |
||
338 | 352 | 'smiley_list' => $smileys, |
339 | 353 | ) |
340 | 354 | ); |
341 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
342 | - if (isset($smileys[strtolower($row['filename'])])) |
|
355 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
356 | + if (isset($smileys[strtolower($row['filename'])])) |
|
343 | 357 | unset($smileys[strtolower($row['filename'])]); |
358 | + } |
|
344 | 359 | $smcFunc['db_free_result']($request); |
345 | 360 | |
346 | 361 | $context['current_set']['can_import'] = count($smileys); |
@@ -355,13 +370,14 @@ discard block |
||
355 | 370 | $dir = dir($modSettings['smileys_dir']); |
356 | 371 | while ($entry = $dir->read()) |
357 | 372 | { |
358 | - if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry)) |
|
359 | - $context['smiley_set_dirs'][] = array( |
|
373 | + if (!in_array($entry, array('.', '..')) && is_dir($modSettings['smileys_dir'] . '/' . $entry)) { |
|
374 | + $context['smiley_set_dirs'][] = array( |
|
360 | 375 | 'id' => $entry, |
361 | 376 | 'path' => $modSettings['smileys_dir'] . '/' . $entry, |
362 | 377 | 'selectable' => $entry == $context['current_set']['path'] || !in_array($entry, explode(',', $modSettings['smiley_sets_known'])), |
363 | 378 | 'current' => $entry == $context['current_set']['path'], |
364 | 379 | ); |
380 | + } |
|
365 | 381 | } |
366 | 382 | $dir->close(); |
367 | 383 | } |
@@ -371,8 +387,9 @@ discard block |
||
371 | 387 | createToken('admin-mss', 'request'); |
372 | 388 | |
373 | 389 | // In case we need to import smileys, we need to add the token in now. |
374 | - if (isset($context['current_set']['import_url'])) |
|
375 | - $context['current_set']['import_url'] .= ';' . $context['admin-mss_token_var'] . '=' . $context['admin-mss_token']; |
|
390 | + if (isset($context['current_set']['import_url'])) { |
|
391 | + $context['current_set']['import_url'] .= ';' . $context['admin-mss_token_var'] . '=' . $context['admin-mss_token']; |
|
392 | + } |
|
376 | 393 | |
377 | 394 | $listOptions = array( |
378 | 395 | 'id' => 'smiley_set_list', |
@@ -510,21 +527,23 @@ discard block |
||
510 | 527 | $cols['name'][] = $set_names[$i]; |
511 | 528 | } |
512 | 529 | $sort_flag = strpos($sort, 'DESC') === false ? SORT_ASC : SORT_DESC; |
513 | - if (substr($sort, 0, 4) === 'name') |
|
514 | - array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id']); |
|
515 | - elseif (substr($sort, 0, 4) === 'path') |
|
516 | - array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id']); |
|
517 | - else |
|
518 | - array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id']); |
|
530 | + if (substr($sort, 0, 4) === 'name') { |
|
531 | + array_multisort($cols['name'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['selected'], $cols['id']); |
|
532 | + } elseif (substr($sort, 0, 4) === 'path') { |
|
533 | + array_multisort($cols['path'], $sort_flag, SORT_REGULAR, $cols['name'], $cols['selected'], $cols['id']); |
|
534 | + } else { |
|
535 | + array_multisort($cols['selected'], $sort_flag, SORT_REGULAR, $cols['path'], $cols['name'], $cols['id']); |
|
536 | + } |
|
519 | 537 | |
520 | 538 | $smiley_sets = array(); |
521 | - foreach ($cols['id'] as $i => $id) |
|
522 | - $smiley_sets[] = array( |
|
539 | + foreach ($cols['id'] as $i => $id) { |
|
540 | + $smiley_sets[] = array( |
|
523 | 541 | 'id' => $id, |
524 | 542 | 'path' => $cols['path'][$i], |
525 | 543 | 'name' => $cols['name'][$i], |
526 | 544 | 'selected' => $cols['path'][$i] == $modSettings['smiley_sets_default'] |
527 | 545 | ); |
546 | + } |
|
528 | 547 | |
529 | 548 | return $smiley_sets; |
530 | 549 | } |
@@ -553,13 +572,14 @@ discard block |
||
553 | 572 | $context['smileys_dir_found'] = is_dir($context['smileys_dir']); |
554 | 573 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
555 | 574 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
556 | - foreach ($context['smiley_sets'] as $i => $set) |
|
557 | - $context['smiley_sets'][$i] = array( |
|
575 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
576 | + $context['smiley_sets'][$i] = array( |
|
558 | 577 | 'id' => $i, |
559 | 578 | 'path' => $smcFunc['htmlspecialchars']($set), |
560 | 579 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
561 | 580 | 'selected' => $set == $modSettings['smiley_sets_default'] |
562 | 581 | ); |
582 | + } |
|
563 | 583 | |
564 | 584 | // Submitting a form? |
565 | 585 | if (isset($_POST[$context['session_var']], $_POST['smiley_code'])) |
@@ -575,8 +595,9 @@ discard block |
||
575 | 595 | $_POST['smiley_filename'] = htmltrim__recursive($_POST['smiley_filename']); |
576 | 596 | |
577 | 597 | // Make sure some code was entered. |
578 | - if (empty($_POST['smiley_code'])) |
|
579 | - fatal_lang_error('smiley_has_no_code'); |
|
598 | + if (empty($_POST['smiley_code'])) { |
|
599 | + fatal_lang_error('smiley_has_no_code'); |
|
600 | + } |
|
580 | 601 | |
581 | 602 | // Check whether the new code has duplicates. It should be unique. |
582 | 603 | $request = $smcFunc['db_query']('', ' |
@@ -588,8 +609,9 @@ discard block |
||
588 | 609 | 'smiley_code' => $_POST['smiley_code'], |
589 | 610 | ) |
590 | 611 | ); |
591 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
592 | - fatal_lang_error('smiley_not_unique'); |
|
612 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
613 | + fatal_lang_error('smiley_not_unique'); |
|
614 | + } |
|
593 | 615 | $smcFunc['db_free_result']($request); |
594 | 616 | |
595 | 617 | // If we are uploading - check all the smiley sets are writable! |
@@ -598,38 +620,44 @@ discard block |
||
598 | 620 | $writeErrors = array(); |
599 | 621 | foreach ($context['smiley_sets'] as $set) |
600 | 622 | { |
601 | - if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path']))) |
|
602 | - $writeErrors[] = $set['path']; |
|
623 | + if (!is_writable($context['smileys_dir'] . '/' . un_htmlspecialchars($set['path']))) { |
|
624 | + $writeErrors[] = $set['path']; |
|
625 | + } |
|
626 | + } |
|
627 | + if (!empty($writeErrors)) { |
|
628 | + fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors))); |
|
603 | 629 | } |
604 | - if (!empty($writeErrors)) |
|
605 | - fatal_lang_error('smileys_upload_error_notwritable', true, array(implode(', ', $writeErrors))); |
|
606 | 630 | } |
607 | 631 | |
608 | 632 | // Uploading just one smiley for all of them? |
609 | 633 | if (isset($_POST['sameall']) && isset($_FILES['uploadSmiley']['name']) && $_FILES['uploadSmiley']['name'] != '') |
610 | 634 | { |
611 | - if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name']))) |
|
612 | - fatal_lang_error('smileys_upload_error'); |
|
635 | + if (!is_uploaded_file($_FILES['uploadSmiley']['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['uploadSmiley']['tmp_name']))) { |
|
636 | + fatal_lang_error('smileys_upload_error'); |
|
637 | + } |
|
613 | 638 | |
614 | 639 | // Sorry, no spaces, dots, or anything else but letters allowed. |
615 | 640 | $_FILES['uploadSmiley']['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['uploadSmiley']['name']); |
616 | 641 | |
617 | 642 | // We only allow image files - it's THAT simple - no messing around here... |
618 | - if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes)) |
|
619 | - fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
643 | + if (!in_array(strtolower(substr(strrchr($_FILES['uploadSmiley']['name'], '.'), 1)), $allowedTypes)) { |
|
644 | + fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
645 | + } |
|
620 | 646 | |
621 | 647 | // We only need the filename... |
622 | 648 | $destName = basename($_FILES['uploadSmiley']['name']); |
623 | 649 | |
624 | 650 | // Make sure they aren't trying to upload a nasty file - for their own good here! |
625 | - if (in_array(strtolower($destName), $disabledFiles)) |
|
626 | - fatal_lang_error('smileys_upload_error_illegal'); |
|
651 | + if (in_array(strtolower($destName), $disabledFiles)) { |
|
652 | + fatal_lang_error('smileys_upload_error_illegal'); |
|
653 | + } |
|
627 | 654 | |
628 | 655 | // Check if the file already exists... and if not move it to EVERY smiley set directory. |
629 | 656 | $i = 0; |
630 | 657 | // Keep going until we find a set the file doesn't exist in. (or maybe it exists in all of them?) |
631 | - while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName)) |
|
632 | - $i++; |
|
658 | + while (isset($context['smiley_sets'][$i]) && file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName)) { |
|
659 | + $i++; |
|
660 | + } |
|
633 | 661 | |
634 | 662 | // Okay, we're going to put the smiley right here, since it's not there yet! |
635 | 663 | if (isset($context['smiley_sets'][$i]['path'])) |
@@ -644,8 +672,9 @@ discard block |
||
644 | 672 | $currentPath = $context['smileys_dir'] . '/' . un_htmlspecialchars($context['smiley_sets'][$i]['path']) . '/' . $destName; |
645 | 673 | |
646 | 674 | // The file is already there! Don't overwrite it! |
647 | - if (file_exists($currentPath)) |
|
648 | - continue; |
|
675 | + if (file_exists($currentPath)) { |
|
676 | + continue; |
|
677 | + } |
|
649 | 678 | |
650 | 679 | // Okay, so copy the first one we made to here. |
651 | 680 | copy($smileyLocation, $currentPath); |
@@ -662,13 +691,15 @@ discard block |
||
662 | 691 | $newName = ''; |
663 | 692 | foreach ($_FILES as $name => $data) |
664 | 693 | { |
665 | - if ($_FILES[$name]['name'] == '') |
|
666 | - fatal_lang_error('smileys_upload_error_blank'); |
|
694 | + if ($_FILES[$name]['name'] == '') { |
|
695 | + fatal_lang_error('smileys_upload_error_blank'); |
|
696 | + } |
|
667 | 697 | |
668 | - if (empty($newName)) |
|
669 | - $newName = basename($_FILES[$name]['name']); |
|
670 | - elseif (basename($_FILES[$name]['name']) != $newName) |
|
671 | - fatal_lang_error('smileys_upload_error_name'); |
|
698 | + if (empty($newName)) { |
|
699 | + $newName = basename($_FILES[$name]['name']); |
|
700 | + } elseif (basename($_FILES[$name]['name']) != $newName) { |
|
701 | + fatal_lang_error('smileys_upload_error_name'); |
|
702 | + } |
|
672 | 703 | } |
673 | 704 | |
674 | 705 | foreach ($context['smiley_sets'] as $i => $set) |
@@ -676,31 +707,36 @@ discard block |
||
676 | 707 | $set['name'] = un_htmlspecialchars($set['name']); |
677 | 708 | $set['path'] = un_htmlspecialchars($set['path']); |
678 | 709 | |
679 | - if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '') |
|
680 | - continue; |
|
710 | + if (!isset($_FILES['individual_' . $set['name']]['name']) || $_FILES['individual_' . $set['name']]['name'] == '') { |
|
711 | + continue; |
|
712 | + } |
|
681 | 713 | |
682 | 714 | // Got one... |
683 | - if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name']))) |
|
684 | - fatal_lang_error('smileys_upload_error'); |
|
715 | + if (!is_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name']) || (ini_get('open_basedir') == '' && !file_exists($_FILES['individual_' . $set['name']]['tmp_name']))) { |
|
716 | + fatal_lang_error('smileys_upload_error'); |
|
717 | + } |
|
685 | 718 | |
686 | 719 | // Sorry, no spaces, dots, or anything else but letters allowed. |
687 | 720 | $_FILES['individual_' . $set['name']]['name'] = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $_FILES['individual_' . $set['name']]['name']); |
688 | 721 | |
689 | 722 | // We only allow image files - it's THAT simple - no messing around here... |
690 | - if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes)) |
|
691 | - fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
723 | + if (!in_array(strtolower(substr(strrchr($_FILES['individual_' . $set['name']]['name'], '.'), 1)), $allowedTypes)) { |
|
724 | + fatal_lang_error('smileys_upload_error_types', false, array(implode(', ', $allowedTypes))); |
|
725 | + } |
|
692 | 726 | |
693 | 727 | // We only need the filename... |
694 | 728 | $destName = basename($_FILES['individual_' . $set['name']]['name']); |
695 | 729 | |
696 | 730 | // Make sure they aren't trying to upload a nasty file - for their own good here! |
697 | - if (in_array(strtolower($destName), $disabledFiles)) |
|
698 | - fatal_lang_error('smileys_upload_error_illegal'); |
|
731 | + if (in_array(strtolower($destName), $disabledFiles)) { |
|
732 | + fatal_lang_error('smileys_upload_error_illegal'); |
|
733 | + } |
|
699 | 734 | |
700 | 735 | // If the file exists - ignore it. |
701 | 736 | $smileyLocation = $context['smileys_dir'] . '/' . $set['path'] . '/' . $destName; |
702 | - if (file_exists($smileyLocation)) |
|
703 | - continue; |
|
737 | + if (file_exists($smileyLocation)) { |
|
738 | + continue; |
|
739 | + } |
|
704 | 740 | |
705 | 741 | // Finally - move the image! |
706 | 742 | move_uploaded_file($_FILES['individual_' . $set['name']]['tmp_name'], $smileyLocation); |
@@ -712,8 +748,9 @@ discard block |
||
712 | 748 | } |
713 | 749 | |
714 | 750 | // Also make sure a filename was given. |
715 | - if (empty($_POST['smiley_filename'])) |
|
716 | - fatal_lang_error('smiley_has_no_filename'); |
|
751 | + if (empty($_POST['smiley_filename'])) { |
|
752 | + fatal_lang_error('smiley_has_no_filename'); |
|
753 | + } |
|
717 | 754 | |
718 | 755 | // Find the position on the right. |
719 | 756 | $smiley_order = '0'; |
@@ -732,8 +769,9 @@ discard block |
||
732 | 769 | list ($smiley_order) = $smcFunc['db_fetch_row']($request); |
733 | 770 | $smcFunc['db_free_result']($request); |
734 | 771 | |
735 | - if (empty($smiley_order)) |
|
736 | - $smiley_order = '0'; |
|
772 | + if (empty($smiley_order)) { |
|
773 | + $smiley_order = '0'; |
|
774 | + } |
|
737 | 775 | } |
738 | 776 | $smcFunc['db_insert']('', |
739 | 777 | '{db_prefix}smileys', |
@@ -761,17 +799,19 @@ discard block |
||
761 | 799 | { |
762 | 800 | foreach ($context['smiley_sets'] as $smiley_set) |
763 | 801 | { |
764 | - if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) |
|
765 | - continue; |
|
802 | + if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) { |
|
803 | + continue; |
|
804 | + } |
|
766 | 805 | |
767 | 806 | $dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])); |
768 | 807 | while ($entry = $dir->read()) |
769 | 808 | { |
770 | - if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
771 | - $context['filenames'][strtolower($entry)] = array( |
|
809 | + if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
810 | + $context['filenames'][strtolower($entry)] = array( |
|
772 | 811 | 'id' => $smcFunc['htmlspecialchars']($entry), |
773 | 812 | 'selected' => false, |
774 | 813 | ); |
814 | + } |
|
775 | 815 | } |
776 | 816 | $dir->close(); |
777 | 817 | } |
@@ -809,17 +849,19 @@ discard block |
||
809 | 849 | // Changing the selected smileys? |
810 | 850 | if (isset($_POST['smiley_action']) && !empty($_POST['checked_smileys'])) |
811 | 851 | { |
812 | - foreach ($_POST['checked_smileys'] as $id => $smiley_id) |
|
813 | - $_POST['checked_smileys'][$id] = (int) $smiley_id; |
|
852 | + foreach ($_POST['checked_smileys'] as $id => $smiley_id) { |
|
853 | + $_POST['checked_smileys'][$id] = (int) $smiley_id; |
|
854 | + } |
|
814 | 855 | |
815 | - if ($_POST['smiley_action'] == 'delete') |
|
816 | - $smcFunc['db_query']('', ' |
|
856 | + if ($_POST['smiley_action'] == 'delete') { |
|
857 | + $smcFunc['db_query']('', ' |
|
817 | 858 | DELETE FROM {db_prefix}smileys |
818 | 859 | WHERE id_smiley IN ({array_int:checked_smileys})', |
819 | 860 | array( |
820 | 861 | 'checked_smileys' => $_POST['checked_smileys'], |
821 | 862 | ) |
822 | 863 | ); |
864 | + } |
|
823 | 865 | // Changing the status of the smiley? |
824 | 866 | else |
825 | 867 | { |
@@ -829,8 +871,8 @@ discard block |
||
829 | 871 | 'hidden' => 1, |
830 | 872 | 'popup' => 2 |
831 | 873 | ); |
832 | - if (isset($displayTypes[$_POST['smiley_action']])) |
|
833 | - $smcFunc['db_query']('', ' |
|
874 | + if (isset($displayTypes[$_POST['smiley_action']])) { |
|
875 | + $smcFunc['db_query']('', ' |
|
834 | 876 | UPDATE {db_prefix}smileys |
835 | 877 | SET hidden = {int:display_type} |
836 | 878 | WHERE id_smiley IN ({array_int:checked_smileys})', |
@@ -839,6 +881,7 @@ discard block |
||
839 | 881 | 'display_type' => $displayTypes[$_POST['smiley_action']], |
840 | 882 | ) |
841 | 883 | ); |
884 | + } |
|
842 | 885 | } |
843 | 886 | } |
844 | 887 | // Create/modify a smiley. |
@@ -864,12 +907,14 @@ discard block |
||
864 | 907 | $_POST['smiley_location'] = empty($_POST['smiley_location']) || $_POST['smiley_location'] > 2 || $_POST['smiley_location'] < 0 ? 0 : (int) $_POST['smiley_location']; |
865 | 908 | |
866 | 909 | // Make sure some code was entered. |
867 | - if (empty($_POST['smiley_code'])) |
|
868 | - fatal_lang_error('smiley_has_no_code'); |
|
910 | + if (empty($_POST['smiley_code'])) { |
|
911 | + fatal_lang_error('smiley_has_no_code'); |
|
912 | + } |
|
869 | 913 | |
870 | 914 | // Also make sure a filename was given. |
871 | - if (empty($_POST['smiley_filename'])) |
|
872 | - fatal_lang_error('smiley_has_no_filename'); |
|
915 | + if (empty($_POST['smiley_filename'])) { |
|
916 | + fatal_lang_error('smiley_has_no_filename'); |
|
917 | + } |
|
873 | 918 | |
874 | 919 | // Check whether the new code has duplicates. It should be unique. |
875 | 920 | $request = $smcFunc['db_query']('', ' |
@@ -883,8 +928,9 @@ discard block |
||
883 | 928 | 'smiley_code' => $_POST['smiley_code'], |
884 | 929 | ) |
885 | 930 | ); |
886 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
887 | - fatal_lang_error('smiley_not_unique'); |
|
931 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
932 | + fatal_lang_error('smiley_not_unique'); |
|
933 | + } |
|
888 | 934 | $smcFunc['db_free_result']($request); |
889 | 935 | |
890 | 936 | $smcFunc['db_query']('', ' |
@@ -913,13 +959,14 @@ discard block |
||
913 | 959 | // Load all known smiley sets. |
914 | 960 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
915 | 961 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
916 | - foreach ($context['smiley_sets'] as $i => $set) |
|
917 | - $context['smiley_sets'][$i] = array( |
|
962 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
963 | + $context['smiley_sets'][$i] = array( |
|
918 | 964 | 'id' => $i, |
919 | 965 | 'path' => $smcFunc['htmlspecialchars']($set), |
920 | 966 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
921 | 967 | 'selected' => $set == $modSettings['smiley_sets_default'] |
922 | 968 | ); |
969 | + } |
|
923 | 970 | |
924 | 971 | // Prepare overview of all (custom) smileys. |
925 | 972 | if ($context['sub_action'] == 'editsmileys') |
@@ -935,9 +982,10 @@ discard block |
||
935 | 982 | // Create a list of options for selecting smiley sets. |
936 | 983 | $smileyset_option_list = ' |
937 | 984 | <select name="set" onchange="changeSet(this.options[this.selectedIndex].value);">'; |
938 | - foreach ($context['smiley_sets'] as $smiley_set) |
|
939 | - $smileyset_option_list .= ' |
|
985 | + foreach ($context['smiley_sets'] as $smiley_set) { |
|
986 | + $smileyset_option_list .= ' |
|
940 | 987 | <option value="' . $smiley_set['path'] . '"' . ($modSettings['smiley_sets_default'] == $smiley_set['path'] ? ' selected' : '') . '>' . $smiley_set['name'] . '</option>'; |
988 | + } |
|
941 | 989 | $smileyset_option_list .= ' |
942 | 990 | </select>'; |
943 | 991 | |
@@ -999,12 +1047,13 @@ discard block |
||
999 | 1047 | 'data' => array( |
1000 | 1048 | 'function' => function ($rowData) use ($txt) |
1001 | 1049 | { |
1002 | - if (empty($rowData['hidden'])) |
|
1003 | - return $txt['smileys_location_form']; |
|
1004 | - elseif ($rowData['hidden'] == 1) |
|
1005 | - return $txt['smileys_location_hidden']; |
|
1006 | - else |
|
1007 | - return $txt['smileys_location_popup']; |
|
1050 | + if (empty($rowData['hidden'])) { |
|
1051 | + return $txt['smileys_location_form']; |
|
1052 | + } elseif ($rowData['hidden'] == 1) { |
|
1053 | + return $txt['smileys_location_hidden']; |
|
1054 | + } else { |
|
1055 | + return $txt['smileys_location_popup']; |
|
1056 | + } |
|
1008 | 1057 | }, |
1009 | 1058 | ), |
1010 | 1059 | 'sort' => array( |
@@ -1019,19 +1068,22 @@ discard block |
||
1019 | 1068 | 'data' => array( |
1020 | 1069 | 'function' => function ($rowData) use ($context, $txt, $modSettings, $smcFunc) |
1021 | 1070 | { |
1022 | - if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'])) |
|
1023 | - return $smcFunc['htmlspecialchars']($rowData['description']); |
|
1071 | + if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'])) { |
|
1072 | + return $smcFunc['htmlspecialchars']($rowData['description']); |
|
1073 | + } |
|
1024 | 1074 | |
1025 | 1075 | // Check if there are smileys missing in some sets. |
1026 | 1076 | $missing_sets = array(); |
1027 | - foreach ($context['smiley_sets'] as $smiley_set) |
|
1028 | - if (!file_exists(sprintf('%1$s/%2$s/%3$s', $modSettings['smileys_dir'], $smiley_set['path'], $rowData['filename']))) |
|
1077 | + foreach ($context['smiley_sets'] as $smiley_set) { |
|
1078 | + if (!file_exists(sprintf('%1$s/%2$s/%3$s', $modSettings['smileys_dir'], $smiley_set['path'], $rowData['filename']))) |
|
1029 | 1079 | $missing_sets[] = $smiley_set['path']; |
1080 | + } |
|
1030 | 1081 | |
1031 | 1082 | $description = $smcFunc['htmlspecialchars']($rowData['description']); |
1032 | 1083 | |
1033 | - if (!empty($missing_sets)) |
|
1034 | - $description .= sprintf('<br><span class="smalltext"><strong>%1$s:</strong> %2$s</span>', $txt['smileys_not_found_in_set'], implode(', ', $missing_sets)); |
|
1084 | + if (!empty($missing_sets)) { |
|
1085 | + $description .= sprintf('<br><span class="smalltext"><strong>%1$s:</strong> %2$s</span>', $txt['smileys_not_found_in_set'], implode(', ', $missing_sets)); |
|
1086 | + } |
|
1035 | 1087 | |
1036 | 1088 | return $description; |
1037 | 1089 | }, |
@@ -1147,13 +1199,14 @@ discard block |
||
1147 | 1199 | $context['smileys_dir_found'] = is_dir($context['smileys_dir']); |
1148 | 1200 | $context['smiley_sets'] = explode(',', $modSettings['smiley_sets_known']); |
1149 | 1201 | $set_names = explode("\n", $modSettings['smiley_sets_names']); |
1150 | - foreach ($context['smiley_sets'] as $i => $set) |
|
1151 | - $context['smiley_sets'][$i] = array( |
|
1202 | + foreach ($context['smiley_sets'] as $i => $set) { |
|
1203 | + $context['smiley_sets'][$i] = array( |
|
1152 | 1204 | 'id' => $i, |
1153 | 1205 | 'path' => $smcFunc['htmlspecialchars']($set), |
1154 | 1206 | 'name' => $smcFunc['htmlspecialchars']($set_names[$i]), |
1155 | 1207 | 'selected' => $set == $modSettings['smiley_sets_default'] |
1156 | 1208 | ); |
1209 | + } |
|
1157 | 1210 | |
1158 | 1211 | $context['selected_set'] = $modSettings['smiley_sets_default']; |
1159 | 1212 | |
@@ -1163,17 +1216,19 @@ discard block |
||
1163 | 1216 | { |
1164 | 1217 | foreach ($context['smiley_sets'] as $smiley_set) |
1165 | 1218 | { |
1166 | - if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) |
|
1167 | - continue; |
|
1219 | + if (!file_exists($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path']))) { |
|
1220 | + continue; |
|
1221 | + } |
|
1168 | 1222 | |
1169 | 1223 | $dir = dir($context['smileys_dir'] . '/' . un_htmlspecialchars($smiley_set['path'])); |
1170 | 1224 | while ($entry = $dir->read()) |
1171 | 1225 | { |
1172 | - if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
1173 | - $context['filenames'][strtolower($entry)] = array( |
|
1226 | + if (!in_array($entry, $context['filenames']) && in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
1227 | + $context['filenames'][strtolower($entry)] = array( |
|
1174 | 1228 | 'id' => $smcFunc['htmlspecialchars']($entry), |
1175 | 1229 | 'selected' => false, |
1176 | 1230 | ); |
1231 | + } |
|
1177 | 1232 | } |
1178 | 1233 | $dir->close(); |
1179 | 1234 | } |
@@ -1188,8 +1243,9 @@ discard block |
||
1188 | 1243 | 'current_smiley' => (int) $_REQUEST['smiley'], |
1189 | 1244 | ) |
1190 | 1245 | ); |
1191 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
1192 | - fatal_lang_error('smiley_not_found'); |
|
1246 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
1247 | + fatal_lang_error('smiley_not_found'); |
|
1248 | + } |
|
1193 | 1249 | $context['current_smiley'] = $smcFunc['db_fetch_assoc']($request); |
1194 | 1250 | $smcFunc['db_free_result']($request); |
1195 | 1251 | |
@@ -1197,8 +1253,9 @@ discard block |
||
1197 | 1253 | $context['current_smiley']['filename'] = $smcFunc['htmlspecialchars']($context['current_smiley']['filename']); |
1198 | 1254 | $context['current_smiley']['description'] = $smcFunc['htmlspecialchars']($context['current_smiley']['description']); |
1199 | 1255 | |
1200 | - if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])])) |
|
1201 | - $context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true; |
|
1256 | + if (isset($context['filenames'][strtolower($context['current_smiley']['filename'])])) { |
|
1257 | + $context['filenames'][strtolower($context['current_smiley']['filename'])]['selected'] = true; |
|
1258 | + } |
|
1202 | 1259 | } |
1203 | 1260 | } |
1204 | 1261 | |
@@ -1223,8 +1280,9 @@ discard block |
||
1223 | 1280 | ) |
1224 | 1281 | ); |
1225 | 1282 | $smileys = array(); |
1226 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1227 | - $smileys[] = $row; |
|
1283 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1284 | + $smileys[] = $row; |
|
1285 | + } |
|
1228 | 1286 | $smcFunc['db_free_result']($request); |
1229 | 1287 | |
1230 | 1288 | return $smileys; |
@@ -1264,8 +1322,9 @@ discard block |
||
1264 | 1322 | $_GET['location'] = empty($_GET['location']) || $_GET['location'] != 'popup' ? 0 : 2; |
1265 | 1323 | $_GET['source'] = empty($_GET['source']) ? 0 : (int) $_GET['source']; |
1266 | 1324 | |
1267 | - if (empty($_GET['source'])) |
|
1268 | - fatal_lang_error('smiley_not_found'); |
|
1325 | + if (empty($_GET['source'])) { |
|
1326 | + fatal_lang_error('smiley_not_found'); |
|
1327 | + } |
|
1269 | 1328 | |
1270 | 1329 | if (!empty($_GET['after'])) |
1271 | 1330 | { |
@@ -1281,12 +1340,12 @@ discard block |
||
1281 | 1340 | 'after_smiley' => $_GET['after'], |
1282 | 1341 | ) |
1283 | 1342 | ); |
1284 | - if ($smcFunc['db_num_rows']($request) != 1) |
|
1285 | - fatal_lang_error('smiley_not_found'); |
|
1343 | + if ($smcFunc['db_num_rows']($request) != 1) { |
|
1344 | + fatal_lang_error('smiley_not_found'); |
|
1345 | + } |
|
1286 | 1346 | list ($smiley_row, $smiley_order, $smileyLocation) = $smcFunc['db_fetch_row']($request); |
1287 | 1347 | $smcFunc['db_free_result']($request); |
1288 | - } |
|
1289 | - else |
|
1348 | + } else |
|
1290 | 1349 | { |
1291 | 1350 | $smiley_row = (int) $_GET['row']; |
1292 | 1351 | $smiley_order = -1; |
@@ -1360,14 +1419,15 @@ discard block |
||
1360 | 1419 | $context['move_smiley'] = empty($_REQUEST['move']) ? 0 : (int) $_REQUEST['move']; |
1361 | 1420 | |
1362 | 1421 | // Make sure all rows are sequential. |
1363 | - foreach (array_keys($context['smileys']) as $location) |
|
1364 | - $context['smileys'][$location] = array( |
|
1422 | + foreach (array_keys($context['smileys']) as $location) { |
|
1423 | + $context['smileys'][$location] = array( |
|
1365 | 1424 | 'id' => $location, |
1366 | 1425 | 'title' => $location == 'postform' ? $txt['smileys_location_form'] : $txt['smileys_location_popup'], |
1367 | 1426 | 'description' => $location == 'postform' ? $txt['smileys_location_form_description'] : $txt['smileys_location_popup_description'], |
1368 | 1427 | 'last_row' => count($context['smileys'][$location]['rows']), |
1369 | 1428 | 'rows' => array_values($context['smileys'][$location]['rows']), |
1370 | 1429 | ); |
1430 | + } |
|
1371 | 1431 | |
1372 | 1432 | // Check & fix smileys that are not ordered properly in the database. |
1373 | 1433 | foreach (array_keys($context['smileys']) as $location) |
@@ -1392,8 +1452,8 @@ discard block |
||
1392 | 1452 | $context['smileys'][$location]['rows'][$id][0]['row'] = $id; |
1393 | 1453 | } |
1394 | 1454 | // Make sure the smiley order is always sequential. |
1395 | - foreach ($smiley_row as $order_id => $smiley) |
|
1396 | - if ($order_id != $smiley['order']) |
|
1455 | + foreach ($smiley_row as $order_id => $smiley) { |
|
1456 | + if ($order_id != $smiley['order']) |
|
1397 | 1457 | $smcFunc['db_query']('', ' |
1398 | 1458 | UPDATE {db_prefix}smileys |
1399 | 1459 | SET smiley_order = {int:new_order} |
@@ -1403,6 +1463,7 @@ discard block |
||
1403 | 1463 | 'current_smiley' => $smiley['id'], |
1404 | 1464 | ) |
1405 | 1465 | ); |
1466 | + } |
|
1406 | 1467 | } |
1407 | 1468 | } |
1408 | 1469 | |
@@ -1436,19 +1497,20 @@ discard block |
||
1436 | 1497 | |
1437 | 1498 | // Check that the smiley is from simplemachines.org, for now... maybe add mirroring later. |
1438 | 1499 | // @ TODO: Our current xml files serve http links. Allowing both for now until we serve https. |
1439 | - if (preg_match('~^https?://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false) |
|
1440 | - fatal_lang_error('not_on_simplemachines'); |
|
1500 | + if (preg_match('~^https?://[\w_\-]+\.simplemachines\.org/~', $_REQUEST['set_gz']) == 0 || strpos($_REQUEST['set_gz'], 'dlattach') !== false) { |
|
1501 | + fatal_lang_error('not_on_simplemachines'); |
|
1502 | + } |
|
1441 | 1503 | |
1442 | 1504 | $destination = $packagesdir . '/' . $base_name; |
1443 | 1505 | |
1444 | - if (file_exists($destination)) |
|
1445 | - fatal_lang_error('package_upload_error_exists'); |
|
1506 | + if (file_exists($destination)) { |
|
1507 | + fatal_lang_error('package_upload_error_exists'); |
|
1508 | + } |
|
1446 | 1509 | |
1447 | 1510 | // Let's copy it to the Packages directory |
1448 | 1511 | file_put_contents($destination, fetch_web_data($_REQUEST['set_gz'])); |
1449 | 1512 | $testing = true; |
1450 | - } |
|
1451 | - elseif (isset($_REQUEST['package'])) |
|
1513 | + } elseif (isset($_REQUEST['package'])) |
|
1452 | 1514 | { |
1453 | 1515 | $base_name = basename($_REQUEST['package']); |
1454 | 1516 | $name = $smcFunc['htmlspecialchars'](strtok(basename($_REQUEST['package']), '.')); |
@@ -1457,12 +1519,14 @@ discard block |
||
1457 | 1519 | $destination = $packagesdir . '/' . basename($_REQUEST['package']); |
1458 | 1520 | } |
1459 | 1521 | |
1460 | - if (empty($destination) || !file_exists($destination)) |
|
1461 | - fatal_lang_error('package_no_file', false); |
|
1522 | + if (empty($destination) || !file_exists($destination)) { |
|
1523 | + fatal_lang_error('package_no_file', false); |
|
1524 | + } |
|
1462 | 1525 | |
1463 | 1526 | // Make sure temp directory exists and is empty. |
1464 | - if (file_exists($packagesdir . '/temp')) |
|
1465 | - deltree($packagesdir . '/temp', false); |
|
1527 | + if (file_exists($packagesdir . '/temp')) { |
|
1528 | + deltree($packagesdir . '/temp', false); |
|
1529 | + } |
|
1466 | 1530 | |
1467 | 1531 | if (!mktree($packagesdir . '/temp', 0755)) |
1468 | 1532 | { |
@@ -1474,31 +1538,37 @@ discard block |
||
1474 | 1538 | create_chmod_control(array($packagesdir . '/temp/delme.tmp'), array('destination_url' => $scripturl . '?action=admin;area=smileys;sa=install;set_gz=' . $_REQUEST['set_gz'], 'crash_on_error' => true)); |
1475 | 1539 | |
1476 | 1540 | deltree($packagesdir . '/temp', false); |
1477 | - if (!mktree($packagesdir . '/temp', 0777)) |
|
1478 | - fatal_lang_error('package_cant_download', false); |
|
1541 | + if (!mktree($packagesdir . '/temp', 0777)) { |
|
1542 | + fatal_lang_error('package_cant_download', false); |
|
1543 | + } |
|
1479 | 1544 | } |
1480 | 1545 | } |
1481 | 1546 | |
1482 | 1547 | $extracted = read_tgz_file($destination, $packagesdir . '/temp'); |
1483 | - if (!$extracted) |
|
1484 | - fatal_lang_error('packageget_unable', false, array('https://custom.simplemachines.org/mods/index.php?action=search;type=12;basic_search=' . $name)); |
|
1485 | - if ($extracted && !file_exists($packagesdir . '/temp/package-info.xml')) |
|
1486 | - foreach ($extracted as $file) |
|
1548 | + if (!$extracted) { |
|
1549 | + fatal_lang_error('packageget_unable', false, array('https://custom.simplemachines.org/mods/index.php?action=search;type=12;basic_search=' . $name)); |
|
1550 | + } |
|
1551 | + if ($extracted && !file_exists($packagesdir . '/temp/package-info.xml')) { |
|
1552 | + foreach ($extracted as $file) |
|
1487 | 1553 | if (basename($file['filename']) == 'package-info.xml') |
1488 | 1554 | { |
1489 | 1555 | $base_path = dirname($file['filename']) . '/'; |
1556 | + } |
|
1490 | 1557 | break; |
1491 | 1558 | } |
1492 | 1559 | |
1493 | - if (!isset($base_path)) |
|
1494 | - $base_path = ''; |
|
1560 | + if (!isset($base_path)) { |
|
1561 | + $base_path = ''; |
|
1562 | + } |
|
1495 | 1563 | |
1496 | - if (!file_exists($packagesdir . '/temp/' . $base_path . 'package-info.xml')) |
|
1497 | - fatal_lang_error('package_get_error_missing_xml', false); |
|
1564 | + if (!file_exists($packagesdir . '/temp/' . $base_path . 'package-info.xml')) { |
|
1565 | + fatal_lang_error('package_get_error_missing_xml', false); |
|
1566 | + } |
|
1498 | 1567 | |
1499 | 1568 | $smileyInfo = getPackageInfo($context['filename']); |
1500 | - if (!is_array($smileyInfo)) |
|
1501 | - fatal_lang_error($smileyInfo); |
|
1569 | + if (!is_array($smileyInfo)) { |
|
1570 | + fatal_lang_error($smileyInfo); |
|
1571 | + } |
|
1502 | 1572 | |
1503 | 1573 | // See if it is installed? |
1504 | 1574 | $request = $smcFunc['db_query']('', ' |
@@ -1514,8 +1584,9 @@ discard block |
||
1514 | 1584 | ) |
1515 | 1585 | ); |
1516 | 1586 | |
1517 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
1518 | - fatal_lang_error('package_installed_warning1'); |
|
1587 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
1588 | + fatal_lang_error('package_installed_warning1'); |
|
1589 | + } |
|
1519 | 1590 | |
1520 | 1591 | // Everything is fine, now it's time to do something |
1521 | 1592 | $actions = parsePackageInfo($smileyInfo['xml'], true, 'install'); |
@@ -1530,23 +1601,23 @@ discard block |
||
1530 | 1601 | if ($action['type'] == 'readme' || $action['type'] == 'license') |
1531 | 1602 | { |
1532 | 1603 | $type = 'package_' . $action['type']; |
1533 | - if (file_exists($packagesdir . '/temp/' . $base_path . $action['filename'])) |
|
1534 | - $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $base_path . $action['filename']), "\n\r")); |
|
1535 | - elseif (file_exists($action['filename'])) |
|
1536 | - $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r")); |
|
1604 | + if (file_exists($packagesdir . '/temp/' . $base_path . $action['filename'])) { |
|
1605 | + $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($packagesdir . '/temp/' . $base_path . $action['filename']), "\n\r")); |
|
1606 | + } elseif (file_exists($action['filename'])) { |
|
1607 | + $context[$type] = $smcFunc['htmlspecialchars'](trim(file_get_contents($action['filename']), "\n\r")); |
|
1608 | + } |
|
1537 | 1609 | |
1538 | 1610 | if (!empty($action['parse_bbc'])) |
1539 | 1611 | { |
1540 | 1612 | require_once($sourcedir . '/Subs-Post.php'); |
1541 | 1613 | preparsecode($context[$type]); |
1542 | 1614 | $context[$type] = parse_bbc($context[$type]); |
1615 | + } else { |
|
1616 | + $context[$type] = nl2br($context[$type]); |
|
1543 | 1617 | } |
1544 | - else |
|
1545 | - $context[$type] = nl2br($context[$type]); |
|
1546 | 1618 | |
1547 | 1619 | continue; |
1548 | - } |
|
1549 | - elseif ($action['type'] == 'require-dir') |
|
1620 | + } elseif ($action['type'] == 'require-dir') |
|
1550 | 1621 | { |
1551 | 1622 | // Do this one... |
1552 | 1623 | $thisAction = array( |
@@ -1565,12 +1636,12 @@ discard block |
||
1565 | 1636 | ); |
1566 | 1637 | } |
1567 | 1638 | // @todo None given? |
1568 | - if (empty($thisAction['description'])) |
|
1569 | - $thisAction['description'] = isset($action['description']) ? $action['description'] : ''; |
|
1639 | + if (empty($thisAction['description'])) { |
|
1640 | + $thisAction['description'] = isset($action['description']) ? $action['description'] : ''; |
|
1641 | + } |
|
1570 | 1642 | |
1571 | 1643 | $context['actions'][] = $thisAction; |
1572 | - } |
|
1573 | - elseif ($action['type'] == 'credits') |
|
1644 | + } elseif ($action['type'] == 'credits') |
|
1574 | 1645 | { |
1575 | 1646 | // Time to build the billboard |
1576 | 1647 | $credits_tag = array( |
@@ -1630,12 +1701,14 @@ discard block |
||
1630 | 1701 | cache_put_data('posting_smileys', null, 480); |
1631 | 1702 | } |
1632 | 1703 | |
1633 | - if (file_exists($packagesdir . '/temp')) |
|
1634 | - deltree($packagesdir . '/temp'); |
|
1704 | + if (file_exists($packagesdir . '/temp')) { |
|
1705 | + deltree($packagesdir . '/temp'); |
|
1706 | + } |
|
1635 | 1707 | |
1636 | - if (!$testing) |
|
1637 | - redirectexit('action=admin;area=smileys'); |
|
1638 | -} |
|
1708 | + if (!$testing) { |
|
1709 | + redirectexit('action=admin;area=smileys'); |
|
1710 | + } |
|
1711 | + } |
|
1639 | 1712 | |
1640 | 1713 | /** |
1641 | 1714 | * A function to import new smileys from an existing directory into the database. |
@@ -1646,15 +1719,17 @@ discard block |
||
1646 | 1719 | { |
1647 | 1720 | global $modSettings, $smcFunc; |
1648 | 1721 | |
1649 | - if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath)) |
|
1650 | - fatal_lang_error('smiley_set_unable_to_import'); |
|
1722 | + if (empty($modSettings['smileys_dir']) || !is_dir($modSettings['smileys_dir'] . '/' . $smileyPath)) { |
|
1723 | + fatal_lang_error('smiley_set_unable_to_import'); |
|
1724 | + } |
|
1651 | 1725 | |
1652 | 1726 | $smileys = array(); |
1653 | 1727 | $dir = dir($modSettings['smileys_dir'] . '/' . $smileyPath); |
1654 | 1728 | while ($entry = $dir->read()) |
1655 | 1729 | { |
1656 | - if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) |
|
1657 | - $smileys[strtolower($entry)] = $entry; |
|
1730 | + if (in_array(strrchr($entry, '.'), array('.jpg', '.gif', '.jpeg', '.png'))) { |
|
1731 | + $smileys[strtolower($entry)] = $entry; |
|
1732 | + } |
|
1658 | 1733 | } |
1659 | 1734 | $dir->close(); |
1660 | 1735 | |
@@ -1667,9 +1742,10 @@ discard block |
||
1667 | 1742 | 'smiley_list' => $smileys, |
1668 | 1743 | ) |
1669 | 1744 | ); |
1670 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1671 | - if (isset($smileys[strtolower($row['filename'])])) |
|
1745 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1746 | + if (isset($smileys[strtolower($row['filename'])])) |
|
1672 | 1747 | unset($smileys[strtolower($row['filename'])]); |
1748 | + } |
|
1673 | 1749 | $smcFunc['db_free_result']($request); |
1674 | 1750 | |
1675 | 1751 | $request = $smcFunc['db_query']('', ' |
@@ -1686,9 +1762,10 @@ discard block |
||
1686 | 1762 | $smcFunc['db_free_result']($request); |
1687 | 1763 | |
1688 | 1764 | $new_smileys = array(); |
1689 | - foreach ($smileys as $smiley) |
|
1690 | - if (strlen($smiley) <= 48) |
|
1765 | + foreach ($smileys as $smiley) { |
|
1766 | + if (strlen($smiley) <= 48) |
|
1691 | 1767 | $new_smileys[] = array(':' . strtok($smiley, '.') . ':', $smiley, strtok($smiley, '.'), 0, ++$smiley_order); |
1768 | + } |
|
1692 | 1769 | |
1693 | 1770 | if (!empty($new_smileys)) |
1694 | 1771 | { |
@@ -1753,8 +1830,9 @@ discard block |
||
1753 | 1830 | if (isset($_POST['delete']) && !empty($_POST['checked_icons'])) |
1754 | 1831 | { |
1755 | 1832 | $deleteIcons = array(); |
1756 | - foreach ($_POST['checked_icons'] as $icon) |
|
1757 | - $deleteIcons[] = (int) $icon; |
|
1833 | + foreach ($_POST['checked_icons'] as $icon) { |
|
1834 | + $deleteIcons[] = (int) $icon; |
|
1835 | + } |
|
1758 | 1836 | |
1759 | 1837 | // Do the actual delete! |
1760 | 1838 | $smcFunc['db_query']('', ' |
@@ -1771,35 +1849,41 @@ discard block |
||
1771 | 1849 | $_GET['icon'] = (int) $_GET['icon']; |
1772 | 1850 | |
1773 | 1851 | // Do some preperation with the data... like check the icon exists *somewhere* |
1774 | - if (strpos($_POST['icon_filename'], '.png') !== false) |
|
1775 | - $_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4); |
|
1776 | - if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.png')) |
|
1777 | - fatal_lang_error('icon_not_found'); |
|
1852 | + if (strpos($_POST['icon_filename'], '.png') !== false) { |
|
1853 | + $_POST['icon_filename'] = substr($_POST['icon_filename'], 0, -4); |
|
1854 | + } |
|
1855 | + if (!file_exists($settings['default_theme_dir'] . '/images/post/' . $_POST['icon_filename'] . '.png')) { |
|
1856 | + fatal_lang_error('icon_not_found'); |
|
1857 | + } |
|
1778 | 1858 | // There is a 16 character limit on message icons... |
1779 | - elseif (strlen($_POST['icon_filename']) > 16) |
|
1780 | - fatal_lang_error('icon_name_too_long'); |
|
1781 | - elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon'])) |
|
1782 | - fatal_lang_error('icon_after_itself'); |
|
1859 | + elseif (strlen($_POST['icon_filename']) > 16) { |
|
1860 | + fatal_lang_error('icon_name_too_long'); |
|
1861 | + } elseif ($_POST['icon_location'] == $_GET['icon'] && !empty($_GET['icon'])) { |
|
1862 | + fatal_lang_error('icon_after_itself'); |
|
1863 | + } |
|
1783 | 1864 | |
1784 | 1865 | // First do the sorting... if this is an edit reduce the order of everything after it by one ;) |
1785 | 1866 | if ($_GET['icon'] != 0) |
1786 | 1867 | { |
1787 | 1868 | $oldOrder = $context['icons'][$_GET['icon']]['true_order']; |
1788 | - foreach ($context['icons'] as $id => $data) |
|
1789 | - if ($data['true_order'] > $oldOrder) |
|
1869 | + foreach ($context['icons'] as $id => $data) { |
|
1870 | + if ($data['true_order'] > $oldOrder) |
|
1790 | 1871 | $context['icons'][$id]['true_order']--; |
1872 | + } |
|
1791 | 1873 | } |
1792 | 1874 | |
1793 | 1875 | // If there are no existing icons and this is a new one, set the id to 1 (mainly for non-mysql) |
1794 | - if (empty($_GET['icon']) && empty($context['icons'])) |
|
1795 | - $_GET['icon'] = 1; |
|
1876 | + if (empty($_GET['icon']) && empty($context['icons'])) { |
|
1877 | + $_GET['icon'] = 1; |
|
1878 | + } |
|
1796 | 1879 | |
1797 | 1880 | // Get the new order. |
1798 | 1881 | $newOrder = $_POST['icon_location'] == 0 ? 0 : $context['icons'][$_POST['icon_location']]['true_order'] + 1; |
1799 | 1882 | // Do the same, but with the one that used to be after this icon, done to avoid conflict. |
1800 | - foreach ($context['icons'] as $id => $data) |
|
1801 | - if ($data['true_order'] >= $newOrder) |
|
1883 | + foreach ($context['icons'] as $id => $data) { |
|
1884 | + if ($data['true_order'] >= $newOrder) |
|
1802 | 1885 | $context['icons'][$id]['true_order']++; |
1886 | + } |
|
1803 | 1887 | |
1804 | 1888 | // Finally set the current icon's position! |
1805 | 1889 | $context['icons'][$_GET['icon']]['true_order'] = $newOrder; |
@@ -1817,8 +1901,7 @@ discard block |
||
1817 | 1901 | if ($id != 0) |
1818 | 1902 | { |
1819 | 1903 | $iconInsert[] = array($id, $icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']); |
1820 | - } |
|
1821 | - else |
|
1904 | + } else |
|
1822 | 1905 | { |
1823 | 1906 | $iconInsert_new[] = array($icon['board_id'], $icon['title'], $icon['filename'], $icon['true_order']); |
1824 | 1907 | } |
@@ -1843,8 +1926,9 @@ discard block |
||
1843 | 1926 | } |
1844 | 1927 | |
1845 | 1928 | // Unless we're adding a new thing, we'll escape |
1846 | - if (!isset($_POST['add'])) |
|
1847 | - redirectexit('action=admin;area=smileys;sa=editicons'); |
|
1929 | + if (!isset($_POST['add'])) { |
|
1930 | + redirectexit('action=admin;area=smileys;sa=editicons'); |
|
1931 | + } |
|
1848 | 1932 | } |
1849 | 1933 | |
1850 | 1934 | $context[$context['admin_menu_name']]['current_subsection'] = 'editicons'; |
@@ -1954,8 +2038,9 @@ discard block |
||
1954 | 2038 | $context['new_icon'] = !isset($_GET['icon']); |
1955 | 2039 | |
1956 | 2040 | // Get the properties of the current icon from the icon list. |
1957 | - if (!$context['new_icon']) |
|
1958 | - $context['icon'] = $context['icons'][$_GET['icon']]; |
|
2041 | + if (!$context['new_icon']) { |
|
2042 | + $context['icon'] = $context['icons'][$_GET['icon']]; |
|
2043 | + } |
|
1959 | 2044 | |
1960 | 2045 | // Get a list of boards needed for assigning this icon to a specific board. |
1961 | 2046 | $boardListOptions = array( |
@@ -1989,8 +2074,9 @@ discard block |
||
1989 | 2074 | ); |
1990 | 2075 | |
1991 | 2076 | $message_icons = array(); |
1992 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1993 | - $message_icons[] = $row; |
|
2077 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
2078 | + $message_icons[] = $row; |
|
2079 | + } |
|
1994 | 2080 | $smcFunc['db_free_result']($request); |
1995 | 2081 | |
1996 | 2082 | return $message_icons; |
@@ -40,16 +40,14 @@ discard block |
||
40 | 40 | ', template_show_upcoming_list('main'), ' |
41 | 41 | </div> |
42 | 42 | '; |
43 | - } |
|
44 | - elseif ($context['calendar_view'] == 'view_week') |
|
43 | + } elseif ($context['calendar_view'] == 'view_week') |
|
45 | 44 | { |
46 | 45 | echo ' |
47 | 46 | <div id="main_grid"> |
48 | 47 | ', template_show_week_grid('main'), ' |
49 | 48 | </div> |
50 | 49 | '; |
51 | - } |
|
52 | - else |
|
50 | + } else |
|
53 | 51 | { |
54 | 52 | echo ' |
55 | 53 | <div id="main_grid"> |
@@ -75,8 +73,9 @@ discard block |
||
75 | 73 | global $context, $scripturl, $txt; |
76 | 74 | |
77 | 75 | // Bail out if we have nothing to work with |
78 | - if (!isset($context['calendar_grid_' . $grid_name])) |
|
79 | - return false; |
|
76 | + if (!isset($context['calendar_grid_' . $grid_name])) { |
|
77 | + return false; |
|
78 | + } |
|
80 | 79 | |
81 | 80 | // Protect programmer sanity |
82 | 81 | $calendar_data = &$context['calendar_grid_' . $grid_name]; |
@@ -113,11 +112,13 @@ discard block |
||
113 | 112 | <li class="windowbg"> |
114 | 113 | <b class="event_title">', $event['link'], '</b>'; |
115 | 114 | |
116 | - if ($event['can_edit']) |
|
117 | - echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>'; |
|
115 | + if ($event['can_edit']) { |
|
116 | + echo ' <a href="' . $event['modify_href'] . '"><span class="generic_icons calendar_modify" title="', $txt['calendar_edit'], '"></span></a>'; |
|
117 | + } |
|
118 | 118 | |
119 | - if ($event['can_export']) |
|
120 | - echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>'; |
|
119 | + if ($event['can_export']) { |
|
120 | + echo ' <a href="' . $event['export_href'] . '"><span class="generic_icons calendar_export" title="', $txt['calendar_export'], '"></span></a>'; |
|
121 | + } |
|
121 | 122 | |
122 | 123 | echo ' |
123 | 124 | <br>'; |
@@ -125,14 +126,14 @@ discard block |
||
125 | 126 | if (!empty($event['allday'])) |
126 | 127 | { |
127 | 128 | echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), '</time>', ($event['start_date'] != $event['end_date']) ? ' – <time datetime="' . $event['end_iso_gmdate'] . '">' . trim($event['end_date_local']) . '</time>' : ''; |
128 | - } |
|
129 | - else |
|
129 | + } else |
|
130 | 130 | { |
131 | 131 | // Display event info relative to user's local timezone |
132 | 132 | echo '<time datetime="' . $event['start_iso_gmdate'] . '">', trim($event['start_date_local']), ', ', trim($event['start_time_local']), '</time> – <time datetime="' . $event['end_iso_gmdate'] . '">'; |
133 | 133 | |
134 | - if ($event['start_date_local'] != $event['end_date_local']) |
|
135 | - echo trim($event['end_date_local']) . ', '; |
|
134 | + if ($event['start_date_local'] != $event['end_date_local']) { |
|
135 | + echo trim($event['end_date_local']) . ', '; |
|
136 | + } |
|
136 | 137 | |
137 | 138 | echo trim($event['end_time_local']); |
138 | 139 | |
@@ -141,23 +142,27 @@ discard block |
||
141 | 142 | { |
142 | 143 | echo '</time> (<time datetime="' . $event['start_iso_gmdate'] . '">'; |
143 | 144 | |
144 | - if ($event['start_date_orig'] != $event['start_date_local'] || $event['end_date_orig'] != $event['end_date_local'] || $event['start_date_orig'] != $event['end_date_orig']) |
|
145 | - echo trim($event['start_date_orig']), ', '; |
|
145 | + if ($event['start_date_orig'] != $event['start_date_local'] || $event['end_date_orig'] != $event['end_date_local'] || $event['start_date_orig'] != $event['end_date_orig']) { |
|
146 | + echo trim($event['start_date_orig']), ', '; |
|
147 | + } |
|
146 | 148 | |
147 | 149 | echo trim($event['start_time_orig']), '</time> – <time datetime="' . $event['end_iso_gmdate'] . '">'; |
148 | 150 | |
149 | - if ($event['start_date_orig'] != $event['end_date_orig']) |
|
150 | - echo trim($event['end_date_orig']) . ', '; |
|
151 | + if ($event['start_date_orig'] != $event['end_date_orig']) { |
|
152 | + echo trim($event['end_date_orig']) . ', '; |
|
153 | + } |
|
151 | 154 | |
152 | 155 | echo trim($event['end_time_orig']), ' ', $event['tz_abbrev'], '</time>)'; |
153 | 156 | } |
154 | 157 | // Event is scheduled in the user's own timezone? Let 'em know, just to avoid confusion |
155 | - else |
|
156 | - echo ' ', $event['tz_abbrev'], '</time>'; |
|
158 | + else { |
|
159 | + echo ' ', $event['tz_abbrev'], '</time>'; |
|
160 | + } |
|
157 | 161 | } |
158 | 162 | |
159 | - if (!empty($event['location'])) |
|
160 | - echo '<br>', $event['location']; |
|
163 | + if (!empty($event['location'])) { |
|
164 | + echo '<br>', $event['location']; |
|
165 | + } |
|
161 | 166 | |
162 | 167 | echo ' |
163 | 168 | </li>'; |
@@ -189,8 +194,9 @@ discard block |
||
189 | 194 | |
190 | 195 | $birthdays = array(); |
191 | 196 | |
192 | - foreach ($date as $member) |
|
193 | - $birthdays[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '">' . $member['name'] . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>'; |
|
197 | + foreach ($date as $member) { |
|
198 | + $birthdays[] = '<a href="' . $scripturl . '?action=profile;u=' . $member['id'] . '">' . $member['name'] . (isset($member['age']) ? ' (' . $member['age'] . ')' : '') . '</a>'; |
|
199 | + } |
|
194 | 200 | |
195 | 201 | echo implode(', ', $birthdays); |
196 | 202 | |
@@ -221,8 +227,9 @@ discard block |
||
221 | 227 | $date_local = $date['date_local']; |
222 | 228 | unset($date['date_local']); |
223 | 229 | |
224 | - foreach ($date as $holiday) |
|
225 | - $holidays[] = $holiday . ' (' . $date_local . ')'; |
|
230 | + foreach ($date as $holiday) { |
|
231 | + $holidays[] = $holiday . ' (' . $date_local . ')'; |
|
232 | + } |
|
226 | 233 | } |
227 | 234 | |
228 | 235 | echo implode(', ', $holidays); |
@@ -245,17 +252,19 @@ discard block |
||
245 | 252 | global $context, $txt, $scripturl, $modSettings; |
246 | 253 | |
247 | 254 | // If the grid doesn't exist, no point in proceeding. |
248 | - if (!isset($context['calendar_grid_' . $grid_name])) |
|
249 | - return false; |
|
255 | + if (!isset($context['calendar_grid_' . $grid_name])) { |
|
256 | + return false; |
|
257 | + } |
|
250 | 258 | |
251 | 259 | // A handy little pointer variable. |
252 | 260 | $calendar_data = &$context['calendar_grid_' . $grid_name]; |
253 | 261 | |
254 | 262 | // Some conditions for whether or not we should show the week links *here*. |
255 | - if (isset($calendar_data['show_week_links']) && ($calendar_data['show_week_links'] == 3 || (($calendar_data['show_week_links'] == 1 && $is_mini === true) || $calendar_data['show_week_links'] == 2 && $is_mini === false))) |
|
256 | - $show_week_links = true; |
|
257 | - else |
|
258 | - $show_week_links = false; |
|
263 | + if (isset($calendar_data['show_week_links']) && ($calendar_data['show_week_links'] == 3 || (($calendar_data['show_week_links'] == 1 && $is_mini === true) || $calendar_data['show_week_links'] == 2 && $is_mini === false))) { |
|
264 | + $show_week_links = true; |
|
265 | + } else { |
|
266 | + $show_week_links = false; |
|
267 | + } |
|
259 | 268 | |
260 | 269 | // Assuming that we've not disabled it, show the title block! |
261 | 270 | if (empty($calendar_data['disable_title'])) |
@@ -294,8 +303,9 @@ discard block |
||
294 | 303 | } |
295 | 304 | |
296 | 305 | // Show the controls on main grids |
297 | - if ($is_mini === false) |
|
298 | - template_calendar_top($calendar_data); |
|
306 | + if ($is_mini === false) { |
|
307 | + template_calendar_top($calendar_data); |
|
308 | + } |
|
299 | 309 | |
300 | 310 | // Finally, the main calendar table. |
301 | 311 | echo '<table class="calendar_table">'; |
@@ -306,8 +316,9 @@ discard block |
||
306 | 316 | echo '<tr>'; |
307 | 317 | |
308 | 318 | // If we're showing week links, there's an extra column ahead of the week links, so let's think ahead and be prepared! |
309 | - if ($show_week_links === true) |
|
310 | - echo '<th> </th>'; |
|
319 | + if ($show_week_links === true) { |
|
320 | + echo '<th> </th>'; |
|
321 | + } |
|
311 | 322 | |
312 | 323 | // Now, loop through each actual day of the week. |
313 | 324 | foreach ($calendar_data['week_days'] as $day) |
@@ -354,27 +365,29 @@ discard block |
||
354 | 365 | // Additional classes are given for events, holidays, and birthdays. |
355 | 366 | if (!empty($day['events']) && !empty($calendar_data['highlight']['events'])) |
356 | 367 | { |
357 | - if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1, 3))) |
|
358 | - $classes[] = 'events'; |
|
359 | - elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2, 3))) |
|
360 | - $classes[] = 'events'; |
|
368 | + if ($is_mini === true && in_array($calendar_data['highlight']['events'], array(1, 3))) { |
|
369 | + $classes[] = 'events'; |
|
370 | + } elseif ($is_mini === false && in_array($calendar_data['highlight']['events'], array(2, 3))) { |
|
371 | + $classes[] = 'events'; |
|
372 | + } |
|
361 | 373 | } |
362 | 374 | if (!empty($day['holidays']) && !empty($calendar_data['highlight']['holidays'])) |
363 | 375 | { |
364 | - if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1, 3))) |
|
365 | - $classes[] = 'holidays'; |
|
366 | - elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2, 3))) |
|
367 | - $classes[] = 'holidays'; |
|
376 | + if ($is_mini === true && in_array($calendar_data['highlight']['holidays'], array(1, 3))) { |
|
377 | + $classes[] = 'holidays'; |
|
378 | + } elseif ($is_mini === false && in_array($calendar_data['highlight']['holidays'], array(2, 3))) { |
|
379 | + $classes[] = 'holidays'; |
|
380 | + } |
|
368 | 381 | } |
369 | 382 | if (!empty($day['birthdays']) && !empty($calendar_data['highlight']['birthdays'])) |
370 | 383 | { |
371 | - if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1, 3))) |
|
372 | - $classes[] = 'birthdays'; |
|
373 | - elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2, 3))) |
|
374 | - $classes[] = 'birthdays'; |
|
384 | + if ($is_mini === true && in_array($calendar_data['highlight']['birthdays'], array(1, 3))) { |
|
385 | + $classes[] = 'birthdays'; |
|
386 | + } elseif ($is_mini === false && in_array($calendar_data['highlight']['birthdays'], array(2, 3))) { |
|
387 | + $classes[] = 'birthdays'; |
|
388 | + } |
|
375 | 389 | } |
376 | - } |
|
377 | - else |
|
390 | + } else |
|
378 | 391 | { |
379 | 392 | // Default Classes (either compact or comfortable and disabled). |
380 | 393 | $classes[] = !empty($calendar_data['size']) && $calendar_data['size'] == 'small' ? 'compact' : 'comfortable'; |
@@ -392,17 +405,19 @@ discard block |
||
392 | 405 | $title_prefix = !empty($day['is_first_of_month']) && $context['current_month'] == $calendar_data['current_month'] && $is_mini === false ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$calendar_data['current_month']] . ' ' : $txt['months_titles'][$calendar_data['current_month']] . ' ') : ''; |
393 | 406 | |
394 | 407 | // The actual day number - be it a link, or just plain old text! |
395 | - if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) |
|
396 | - echo '<a href="', $scripturl, '?action=calendar;sa=post;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>'; |
|
397 | - else |
|
398 | - echo '<span class="day_text">', $title_prefix, $day['day'], '</span>'; |
|
408 | + if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) { |
|
409 | + echo '<a href="', $scripturl, '?action=calendar;sa=post;year=', $calendar_data['current_year'], ';month=', $calendar_data['current_month'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '"><span class="day_text">', $title_prefix, $day['day'], '</span></a>'; |
|
410 | + } else { |
|
411 | + echo '<span class="day_text">', $title_prefix, $day['day'], '</span>'; |
|
412 | + } |
|
399 | 413 | |
400 | 414 | // A lot of stuff, we're not showing on mini-calendars to conserve space. |
401 | 415 | if ($is_mini === false) |
402 | 416 | { |
403 | 417 | // Holidays are always fun, let's show them! |
404 | - if (!empty($day['holidays'])) |
|
405 | - echo '<div class="smalltext holiday"><span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '</div>'; |
|
418 | + if (!empty($day['holidays'])) { |
|
419 | + echo '<div class="smalltext holiday"><span>', $txt['calendar_prompt'], '</span> ', implode(', ', $day['holidays']), '</div>'; |
|
420 | + } |
|
406 | 421 | |
407 | 422 | // Happy Birthday Dear, Member! |
408 | 423 | if (!empty($day['birthdays'])) |
@@ -420,14 +435,16 @@ discard block |
||
420 | 435 | echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '"><span class="fix_rtl_names">', $member['name'], '</span>', isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', $member['is_last'] || ($count == 10 && $use_js_hide) ? '' : ', '; |
421 | 436 | |
422 | 437 | // 9...10! Let's stop there. |
423 | - if ($birthday_count == 10 && $use_js_hide) |
|
424 | - // !!TODO - Inline CSS and JavaScript should be moved. |
|
438 | + if ($birthday_count == 10 && $use_js_hide) { |
|
439 | + // !!TODO - Inline CSS and JavaScript should be moved. |
|
425 | 440 | echo '<span class="hidelink" id="bdhidelink_', $day['day'], '">...<br><a href="', $scripturl, '?action=calendar;month=', $calendar_data['current_month'], ';year=', $calendar_data['current_year'], ';showbd" onclick="document.getElementById(\'bdhide_', $day['day'], '\').style.display = \'\'; document.getElementById(\'bdhidelink_', $day['day'], '\').style.display = \'none\'; return false;">(', sprintf($txt['calendar_click_all'], count($day['birthdays'])), ')</a></span><span id="bdhide_', $day['day'], '" style="display: none;">, '; |
441 | + } |
|
426 | 442 | |
427 | 443 | ++$birthday_count; |
428 | 444 | } |
429 | - if ($use_js_hide) |
|
430 | - echo '</span>'; |
|
445 | + if ($use_js_hide) { |
|
446 | + echo '</span>'; |
|
447 | + } |
|
431 | 448 | |
432 | 449 | echo '</div>'; |
433 | 450 | } |
@@ -437,8 +454,9 @@ discard block |
||
437 | 454 | { |
438 | 455 | // Sort events by start time (all day events will be listed first) |
439 | 456 | uasort($day['events'], function($a, $b) { |
440 | - if ($a['start_timestamp'] == $b['start_timestamp']) |
|
441 | - return 0; |
|
457 | + if ($a['start_timestamp'] == $b['start_timestamp']) { |
|
458 | + return 0; |
|
459 | + } |
|
442 | 460 | return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1; |
443 | 461 | }); |
444 | 462 | |
@@ -454,17 +472,19 @@ discard block |
||
454 | 472 | |
455 | 473 | echo '<div class="event_wrapper', $event['starts_today'] == true ? ' event_starts_today' : '', $event['ends_today'] == true ? ' event_ends_today' : '', $event['allday'] == true ? ' allday' : '', $event['is_selected'] ? ' sel_event' : '', '">', $event['link'], '<br><span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">'; |
456 | 474 | |
457 | - if (!empty($event['start_time_local']) && $event['starts_today'] == true) |
|
458 | - echo trim(str_replace(':00 ', ' ', $event['start_time_local'])); |
|
459 | - elseif (!empty($event['end_time_local']) && $event['ends_today'] == true) |
|
460 | - echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local'])); |
|
461 | - elseif (!empty($event['allday'])) |
|
462 | - echo $txt['calendar_allday']; |
|
475 | + if (!empty($event['start_time_local']) && $event['starts_today'] == true) { |
|
476 | + echo trim(str_replace(':00 ', ' ', $event['start_time_local'])); |
|
477 | + } elseif (!empty($event['end_time_local']) && $event['ends_today'] == true) { |
|
478 | + echo strtolower($txt['ends']), ' ', trim(str_replace(':00 ', ' ', $event['end_time_local'])); |
|
479 | + } elseif (!empty($event['allday'])) { |
|
480 | + echo $txt['calendar_allday']; |
|
481 | + } |
|
463 | 482 | |
464 | 483 | echo '</span>'; |
465 | 484 | |
466 | - if (!empty($event['location'])) |
|
467 | - echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>'; |
|
485 | + if (!empty($event['location'])) { |
|
486 | + echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>'; |
|
487 | + } |
|
468 | 488 | |
469 | 489 | if ($event['can_edit'] || $event['can_export']) |
470 | 490 | { |
@@ -501,10 +521,11 @@ discard block |
||
501 | 521 | // Otherwise, assuming it's not a mini-calendar, we can show previous / next month days! |
502 | 522 | elseif ($is_mini === false) |
503 | 523 | { |
504 | - if (empty($current_month_started) && !empty($context['calendar_grid_prev'])) |
|
505 | - echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_prev']['current_year'], ';month=', $context['calendar_grid_prev']['current_month'], '">', $context['calendar_grid_prev']['last_of_month'] - $calendar_data['shift']-- +1, '</a>'; |
|
506 | - elseif (!empty($current_month_started) && !empty($context['calendar_grid_next'])) |
|
507 | - echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_next']['current_year'], ';month=', $context['calendar_grid_next']['current_month'], '">', $current_month_started + 1 == $count ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$context['calendar_grid_next']['current_month']] . ' ' : $txt['months_titles'][$context['calendar_grid_next']['current_month']] . ' ') : '', $final_count++, '</a>'; |
|
524 | + if (empty($current_month_started) && !empty($context['calendar_grid_prev'])) { |
|
525 | + echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_prev']['current_year'], ';month=', $context['calendar_grid_prev']['current_month'], '">', $context['calendar_grid_prev']['last_of_month'] - $calendar_data['shift']-- +1, '</a>'; |
|
526 | + } elseif (!empty($current_month_started) && !empty($context['calendar_grid_next'])) { |
|
527 | + echo '<a href="', $scripturl, '?action=calendar;year=', $context['calendar_grid_next']['current_year'], ';month=', $context['calendar_grid_next']['current_month'], '">', $current_month_started + 1 == $count ? (!empty($calendar_data['short_month_titles']) ? $txt['months_short'][$context['calendar_grid_next']['current_month']] . ' ' : $txt['months_titles'][$context['calendar_grid_next']['current_month']] . ' ') : '', $final_count++, '</a>'; |
|
528 | + } |
|
508 | 529 | } |
509 | 530 | |
510 | 531 | // Close this day and increase var count. |
@@ -530,8 +551,9 @@ discard block |
||
530 | 551 | global $context, $txt, $scripturl, $modSettings; |
531 | 552 | |
532 | 553 | // We might have no reason to proceed, if the variable isn't there. |
533 | - if (!isset($context['calendar_grid_' . $grid_name])) |
|
534 | - return false; |
|
554 | + if (!isset($context['calendar_grid_' . $grid_name])) { |
|
555 | + return false; |
|
556 | + } |
|
535 | 557 | |
536 | 558 | // Handy pointer. |
537 | 559 | $calendar_data = &$context['calendar_grid_' . $grid_name]; |
@@ -566,8 +588,9 @@ discard block |
||
566 | 588 | } |
567 | 589 | |
568 | 590 | // The Month Title + Week Number... |
569 | - if (!empty($calendar_data['week_title'])) |
|
570 | - echo $calendar_data['week_title']; |
|
591 | + if (!empty($calendar_data['week_title'])) { |
|
592 | + echo $calendar_data['week_title']; |
|
593 | + } |
|
571 | 594 | |
572 | 595 | echo ' |
573 | 596 | </h3> |
@@ -606,10 +629,11 @@ discard block |
||
606 | 629 | <tr class="days_wrapper"> |
607 | 630 | <td class="', implode(' ', $classes), ' act_day">'; |
608 | 631 | // Should the day number be a link? |
609 | - if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) |
|
610 | - echo '<a href="', $scripturl, '?action=calendar;sa=post;month=', $month_data['current_month'], ';year=', $month_data['current_year'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['days'][$day['day_of_week']], ' - ', $day['day'], '</a>'; |
|
611 | - else |
|
612 | - echo $txt['days'][$day['day_of_week']], ' - ', $day['day']; |
|
632 | + if (!empty($modSettings['cal_daysaslink']) && $context['can_post']) { |
|
633 | + echo '<a href="', $scripturl, '?action=calendar;sa=post;month=', $month_data['current_month'], ';year=', $month_data['current_year'], ';day=', $day['day'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['days'][$day['day_of_week']], ' - ', $day['day'], '</a>'; |
|
634 | + } else { |
|
635 | + echo $txt['days'][$day['day_of_week']], ' - ', $day['day']; |
|
636 | + } |
|
613 | 637 | |
614 | 638 | echo '</td> |
615 | 639 | <td class="', implode(' ', $classes), '', empty($day['events']) ? (' disabled' . ($context['can_post'] ? ' week_post' : '')) : ' events', ' event_col" data-css-prefix="' . $txt['events'] . ' ', (empty($day['events']) && empty($context['can_post'])) ? $txt['none'] : '', '">'; |
@@ -618,8 +642,9 @@ discard block |
||
618 | 642 | { |
619 | 643 | // Sort events by start time (all day events will be listed first) |
620 | 644 | uasort($day['events'], function($a, $b) { |
621 | - if ($a['start_timestamp'] == $b['start_timestamp']) |
|
622 | - return 0; |
|
645 | + if ($a['start_timestamp'] == $b['start_timestamp']) { |
|
646 | + return 0; |
|
647 | + } |
|
623 | 648 | return ($a['start_timestamp'] < $b['start_timestamp']) ? -1 : 1; |
624 | 649 | }); |
625 | 650 | |
@@ -631,15 +656,17 @@ discard block |
||
631 | 656 | |
632 | 657 | echo $event['link'], '<br><span class="event_time', empty($event_icons_needed) ? ' floatright' : '', '">'; |
633 | 658 | |
634 | - if (!empty($event['start_time_local'])) |
|
635 | - echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' – ' . trim($event['end_time_local']) : ''; |
|
636 | - else |
|
637 | - echo $txt['calendar_allday']; |
|
659 | + if (!empty($event['start_time_local'])) { |
|
660 | + echo trim($event['start_time_local']), !empty($event['end_time_local']) ? ' – ' . trim($event['end_time_local']) : ''; |
|
661 | + } else { |
|
662 | + echo $txt['calendar_allday']; |
|
663 | + } |
|
638 | 664 | |
639 | 665 | echo '</span>'; |
640 | 666 | |
641 | - if (!empty($event['location'])) |
|
642 | - echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>'; |
|
667 | + if (!empty($event['location'])) { |
|
668 | + echo '<br><span class="event_location', empty($event_icons_needed) ? ' floatright' : '', '">' . $event['location'] . '</span>'; |
|
669 | + } |
|
643 | 670 | |
644 | 671 | if (!empty($event_icons_needed)) |
645 | 672 | { |
@@ -676,8 +703,7 @@ discard block |
||
676 | 703 | </div> |
677 | 704 | <br class="clear">'; |
678 | 705 | } |
679 | - } |
|
680 | - else |
|
706 | + } else |
|
681 | 707 | { |
682 | 708 | if (!empty($context['can_post'])) |
683 | 709 | { |
@@ -690,8 +716,9 @@ discard block |
||
690 | 716 | echo '</td> |
691 | 717 | <td class="', implode(' ', $classes), !empty($day['holidays']) ? ' holidays' : ' disabled', ' holiday_col" data-css-prefix="' . $txt['calendar_prompt'] . ' ">'; |
692 | 718 | // Show any holidays! |
693 | - if (!empty($day['holidays'])) |
|
694 | - echo implode('<br>', $day['holidays']); |
|
719 | + if (!empty($day['holidays'])) { |
|
720 | + echo implode('<br>', $day['holidays']); |
|
721 | + } |
|
695 | 722 | |
696 | 723 | echo '</td> |
697 | 724 | <td class="', implode(' ', $classes), '', !empty($day['birthdays']) ? ' birthdays' : ' disabled', ' birthday_col" data-css-prefix="' . $txt['birthdays'] . ' ">'; |
@@ -749,8 +776,7 @@ discard block |
||
749 | 776 | <input type="text" name="end_date" id="end_date" maxlength="10" value="', $calendar_data['end_date'], '" tabindex="', $context['tabindex']++, '" class="input_text date_input end" data-type="date"> |
750 | 777 | <input type="submit" class="button_submit" style="float:none" id="view_button" value="', $txt['view'], '"> |
751 | 778 | </form>'; |
752 | - } |
|
753 | - else |
|
779 | + } else |
|
754 | 780 | { |
755 | 781 | echo' |
756 | 782 | <form action="', $scripturl, '?action=calendar" id="calendar_navigation" method="post" accept-charset="', $context['character_set'], '"> |
@@ -792,8 +818,9 @@ discard block |
||
792 | 818 | echo ' |
793 | 819 | <form action="', $scripturl, '?action=calendar;sa=post" method="post" name="postevent" accept-charset="', $context['character_set'], '" onsubmit="submitonce(this);smc_saveEntities(\'postevent\', [\'evtitle\']);" style="margin: 0;">'; |
794 | 820 | |
795 | - if (!empty($context['event']['new'])) |
|
796 | - echo '<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">'; |
|
821 | + if (!empty($context['event']['new'])) { |
|
822 | + echo '<input type="hidden" name="eventid" value="', $context['event']['eventid'], '">'; |
|
823 | + } |
|
797 | 824 | |
798 | 825 | // Start the main table. |
799 | 826 | echo ' |
@@ -843,9 +870,10 @@ discard block |
||
843 | 870 | { |
844 | 871 | echo ' |
845 | 872 | <optgroup label="', $category['name'], '">'; |
846 | - foreach ($category['boards'] as $board) |
|
847 | - echo ' |
|
873 | + foreach ($category['boards'] as $board) { |
|
874 | + echo ' |
|
848 | 875 | <option value="', $board['id'], '"', $board['selected'] ? ' selected' : '', '>', $board['child_level'] > 0 ? str_repeat('==', $board['child_level'] - 1) . '=>' : '', ' ', $board['name'], ' </option>'; |
876 | + } |
|
849 | 877 | echo ' |
850 | 878 | </optgroup>'; |
851 | 879 | } |
@@ -881,9 +909,10 @@ discard block |
||
881 | 909 | <span class="label">', $txt['calendar_timezone'], '</span> |
882 | 910 | <select name="tz" id="tz"', !empty($context['event']['allday']) ? ' disabled' : '', '>'; |
883 | 911 | |
884 | - foreach ($context['all_timezones'] as $tz => $tzname) |
|
885 | - echo ' |
|
912 | + foreach ($context['all_timezones'] as $tz => $tzname) { |
|
913 | + echo ' |
|
886 | 914 | <option value="', $tz, '"', $tz == $context['event']['tz'] ? ' selected' : '', '>', $tzname, '</option>'; |
915 | + } |
|
887 | 916 | |
888 | 917 | echo ' |
889 | 918 | </select> |
@@ -898,9 +927,10 @@ discard block |
||
898 | 927 | echo ' |
899 | 928 | <input type="submit" value="', empty($context['event']['new']) ? $txt['save'] : $txt['post'], '" class="button_submit">'; |
900 | 929 | // Delete button? |
901 | - if (empty($context['event']['new'])) |
|
902 | - echo ' |
|
930 | + if (empty($context['event']['new'])) { |
|
931 | + echo ' |
|
903 | 932 | <input type="submit" name="deleteevent" value="', $txt['event_delete'], '" data-confirm="', $txt['calendar_confirm_delete'], '" class="button_submit you_sure">'; |
933 | + } |
|
904 | 934 | |
905 | 935 | echo ' |
906 | 936 | <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '"> |
@@ -944,9 +974,10 @@ discard block |
||
944 | 974 | |
945 | 975 | foreach ($context['clockicons'] as $t => $v) |
946 | 976 | { |
947 | - foreach ($v as $i) |
|
948 | - echo ' |
|
977 | + foreach ($v as $i) { |
|
978 | + echo ' |
|
949 | 979 | icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');'; |
980 | + } |
|
950 | 981 | } |
951 | 982 | |
952 | 983 | echo ' |
@@ -971,13 +1002,14 @@ discard block |
||
971 | 1002 | |
972 | 1003 | foreach ($context['clockicons'] as $t => $v) |
973 | 1004 | { |
974 | - foreach ($v as $i) |
|
975 | - echo ' |
|
1005 | + foreach ($v as $i) { |
|
1006 | + echo ' |
|
976 | 1007 | if (', $t, ' >= ', $i, ') |
977 | 1008 | { |
978 | 1009 | turnon.push("', $t, '_', $i, '"); |
979 | 1010 | ', $t, ' -= ', $i, '; |
980 | 1011 | }'; |
1012 | + } |
|
981 | 1013 | } |
982 | 1014 | |
983 | 1015 | echo ' |
@@ -1041,9 +1073,10 @@ discard block |
||
1041 | 1073 | |
1042 | 1074 | foreach ($context['clockicons'] as $t => $v) |
1043 | 1075 | { |
1044 | - foreach ($v as $i) |
|
1045 | - echo ' |
|
1076 | + foreach ($v as $i) { |
|
1077 | + echo ' |
|
1046 | 1078 | icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');'; |
1079 | + } |
|
1047 | 1080 | } |
1048 | 1081 | |
1049 | 1082 | echo ' |
@@ -1060,13 +1093,14 @@ discard block |
||
1060 | 1093 | |
1061 | 1094 | foreach ($context['clockicons'] as $t => $v) |
1062 | 1095 | { |
1063 | - foreach ($v as $i) |
|
1064 | - echo ' |
|
1096 | + foreach ($v as $i) { |
|
1097 | + echo ' |
|
1065 | 1098 | if (', $t, ' >= ', $i, ') |
1066 | 1099 | { |
1067 | 1100 | turnon.push("', $t, '_', $i, '"); |
1068 | 1101 | ', $t, ' -= ', $i, '; |
1069 | 1102 | }'; |
1103 | + } |
|
1070 | 1104 | } |
1071 | 1105 | |
1072 | 1106 | echo ' |
@@ -1125,9 +1159,10 @@ discard block |
||
1125 | 1159 | |
1126 | 1160 | foreach ($context['clockicons'] as $t => $v) |
1127 | 1161 | { |
1128 | - foreach ($v as $i) |
|
1129 | - echo ' |
|
1162 | + foreach ($v as $i) { |
|
1163 | + echo ' |
|
1130 | 1164 | icons[\'', $t, '_', $i, '\'] = document.getElementById(\'', $t, '_', $i, '\');'; |
1165 | + } |
|
1131 | 1166 | } |
1132 | 1167 | |
1133 | 1168 | echo ' |
@@ -1148,13 +1183,14 @@ discard block |
||
1148 | 1183 | |
1149 | 1184 | foreach ($context['clockicons'] as $t => $v) |
1150 | 1185 | { |
1151 | - foreach ($v as $i) |
|
1152 | - echo ' |
|
1186 | + foreach ($v as $i) { |
|
1187 | + echo ' |
|
1153 | 1188 | if (', $t, ' >= ', $i, ') |
1154 | 1189 | { |
1155 | 1190 | turnon.push("', $t, '_', $i, '"); |
1156 | 1191 | ', $t, ' -= ', $i, '; |
1157 | 1192 | }'; |
1193 | + } |
|
1158 | 1194 | } |
1159 | 1195 | |
1160 | 1196 | echo ' |
@@ -64,9 +64,10 @@ discard block |
||
64 | 64 | <strong>', $txt['administrators'], ':</strong> |
65 | 65 | ', implode(', ', $context['administrators']); |
66 | 66 | // If we have lots of admins... don't show them all. |
67 | - if (!empty($context['more_admins_link'])) |
|
68 | - echo ' |
|
67 | + if (!empty($context['more_admins_link'])) { |
|
68 | + echo ' |
|
69 | 69 | (', $context['more_admins_link'], ')'; |
70 | + } |
|
70 | 71 | |
71 | 72 | echo ' |
72 | 73 | </div> |
@@ -83,16 +84,18 @@ discard block |
||
83 | 84 | foreach ($area['areas'] as $item_id => $item) |
84 | 85 | { |
85 | 86 | // No point showing the 'home' page here, we're already on it! |
86 | - if ($area_id == 'forum' && $item_id == 'index') |
|
87 | - continue; |
|
87 | + if ($area_id == 'forum' && $item_id == 'index') { |
|
88 | + continue; |
|
89 | + } |
|
88 | 90 | |
89 | 91 | $url = isset($item['url']) ? $item['url'] : $scripturl . '?action=admin;area=' . $item_id . (!empty($context[$context['admin_menu_name']]['extra_parameters']) ? $context[$context['admin_menu_name']]['extra_parameters'] : ''); |
90 | - if (!empty($item['icon_file'])) |
|
91 | - echo ' |
|
92 | + if (!empty($item['icon_file'])) { |
|
93 | + echo ' |
|
92 | 94 | <a href="', $url, '" class="admin_group', !empty($item['inactive']) ? ' inactive' : '', '"><img class="large_admin_menu_icon_file" src="', $item['icon_file'], '" alt="">', $item['label'], '</a>'; |
93 | - else |
|
94 | - echo ' |
|
95 | + } else { |
|
96 | + echo ' |
|
95 | 97 | <a href="', $url, '"><span class="large_', $item['icon_class'], !empty($item['inactive']) ? ' inactive' : '', '"></span>', $item['label'], '</a>'; |
98 | + } |
|
96 | 99 | } |
97 | 100 | |
98 | 101 | echo ' |
@@ -103,10 +106,11 @@ discard block |
||
103 | 106 | </div>'; |
104 | 107 | |
105 | 108 | // The below functions include all the scripts needed from the simplemachines.org site. The language and format are passed for internationalization. |
106 | - if (empty($modSettings['disable_smf_js'])) |
|
107 | - echo ' |
|
109 | + if (empty($modSettings['disable_smf_js'])) { |
|
110 | + echo ' |
|
108 | 111 | <script src="', $scripturl, '?action=viewsmfile;filename=current-version.js"></script> |
109 | 112 | <script src="', $scripturl, '?action=viewsmfile;filename=latest-news.js"></script>'; |
113 | + } |
|
110 | 114 | |
111 | 115 | // This sets the announcements and current versions themselves ;). |
112 | 116 | echo ' |
@@ -185,9 +189,10 @@ discard block |
||
185 | 189 | <em>', $version['version'], '</em>'; |
186 | 190 | |
187 | 191 | // more details for this item, show them a link |
188 | - if ($context['can_admin'] && isset($version['more'])) |
|
189 | - echo |
|
192 | + if ($context['can_admin'] && isset($version['more'])) { |
|
193 | + echo |
|
190 | 194 | ' <a href="', $scripturl, $version['more'], ';', $context['session_var'], '=', $context['session_id'], '">', $txt['version_check_more'], '</a>'; |
195 | + } |
|
191 | 196 | echo ' |
192 | 197 | <br>'; |
193 | 198 | } |
@@ -218,20 +223,22 @@ discard block |
||
218 | 223 | |
219 | 224 | foreach ($context['credits'] as $section) |
220 | 225 | { |
221 | - if (isset($section['pretext'])) |
|
222 | - echo ' |
|
226 | + if (isset($section['pretext'])) { |
|
227 | + echo ' |
|
223 | 228 | <p>', $section['pretext'], '</p><hr>'; |
229 | + } |
|
224 | 230 | |
225 | 231 | echo ' |
226 | 232 | <dl>'; |
227 | 233 | |
228 | 234 | foreach ($section['groups'] as $group) |
229 | 235 | { |
230 | - if (isset($group['title'])) |
|
231 | - echo ' |
|
236 | + if (isset($group['title'])) { |
|
237 | + echo ' |
|
232 | 238 | <dt> |
233 | 239 | <strong>', $group['title'], ':</strong> |
234 | 240 | </dt>'; |
241 | + } |
|
235 | 242 | |
236 | 243 | echo ' |
237 | 244 | <dd>', implode(', ', $group['members']), '</dd>'; |
@@ -240,10 +247,11 @@ discard block |
||
240 | 247 | echo ' |
241 | 248 | </dl>'; |
242 | 249 | |
243 | - if (isset($section['posttext'])) |
|
244 | - echo ' |
|
250 | + if (isset($section['posttext'])) { |
|
251 | + echo ' |
|
245 | 252 | <hr> |
246 | 253 | <p>', $section['posttext'], '</p>'; |
254 | + } |
|
247 | 255 | } |
248 | 256 | |
249 | 257 | echo ' |
@@ -259,9 +267,10 @@ discard block |
||
259 | 267 | smfSupportVersions.forum = "', $context['forum_version'], '";'; |
260 | 268 | |
261 | 269 | // Don't worry, none of this is logged, it's just used to give information that might be of use. |
262 | - foreach ($context['current_versions'] as $variable => $version) |
|
263 | - echo ' |
|
270 | + foreach ($context['current_versions'] as $variable => $version) { |
|
271 | + echo ' |
|
264 | 272 | smfSupportVersions.', $variable, ' = "', $version['version'], '";'; |
273 | + } |
|
265 | 274 | |
266 | 275 | // Now we just have to include the script and wait ;). |
267 | 276 | echo ' |
@@ -358,8 +367,8 @@ discard block |
||
358 | 367 | <tbody>'; |
359 | 368 | |
360 | 369 | // Loop through every source file displaying its version - using javascript. |
361 | - foreach ($context['file_versions'] as $filename => $version) |
|
362 | - echo ' |
|
370 | + foreach ($context['file_versions'] as $filename => $version) { |
|
371 | + echo ' |
|
363 | 372 | <tr class="windowbg"> |
364 | 373 | <td class="half_table"> |
365 | 374 | ', $filename, ' |
@@ -371,6 +380,7 @@ discard block |
||
371 | 380 | <em id="currentSources', $filename, '">??</em> |
372 | 381 | </td> |
373 | 382 | </tr>'; |
383 | + } |
|
374 | 384 | |
375 | 385 | // Default template files. |
376 | 386 | echo ' |
@@ -396,8 +406,8 @@ discard block |
||
396 | 406 | <table id="Default" class="table_grid"> |
397 | 407 | <tbody>'; |
398 | 408 | |
399 | - foreach ($context['default_template_versions'] as $filename => $version) |
|
400 | - echo ' |
|
409 | + foreach ($context['default_template_versions'] as $filename => $version) { |
|
410 | + echo ' |
|
401 | 411 | <tr class="windowbg"> |
402 | 412 | <td class="half_table"> |
403 | 413 | ', $filename, ' |
@@ -409,6 +419,7 @@ discard block |
||
409 | 419 | <em id="currentDefault', $filename, '">??</em> |
410 | 420 | </td> |
411 | 421 | </tr>'; |
422 | + } |
|
412 | 423 | |
413 | 424 | // Now the language files... |
414 | 425 | echo ' |
@@ -436,8 +447,8 @@ discard block |
||
436 | 447 | |
437 | 448 | foreach ($context['default_language_versions'] as $language => $files) |
438 | 449 | { |
439 | - foreach ($files as $filename => $version) |
|
440 | - echo ' |
|
450 | + foreach ($files as $filename => $version) { |
|
451 | + echo ' |
|
441 | 452 | <tr class="windowbg"> |
442 | 453 | <td class="half_table"> |
443 | 454 | ', $filename, '.<em>', $language, '</em>.php |
@@ -449,6 +460,7 @@ discard block |
||
449 | 460 | <em id="current', $filename, '.', $language, '">??</em> |
450 | 461 | </td> |
451 | 462 | </tr>'; |
463 | + } |
|
452 | 464 | } |
453 | 465 | |
454 | 466 | echo ' |
@@ -478,8 +490,8 @@ discard block |
||
478 | 490 | <table id="Templates" class="table_grid"> |
479 | 491 | <tbody>'; |
480 | 492 | |
481 | - foreach ($context['template_versions'] as $filename => $version) |
|
482 | - echo ' |
|
493 | + foreach ($context['template_versions'] as $filename => $version) { |
|
494 | + echo ' |
|
483 | 495 | <tr class="windowbg"> |
484 | 496 | <td class="half_table"> |
485 | 497 | ', $filename, ' |
@@ -491,6 +503,7 @@ discard block |
||
491 | 503 | <em id="currentTemplates', $filename, '">??</em> |
492 | 504 | </td> |
493 | 505 | </tr>'; |
506 | + } |
|
494 | 507 | |
495 | 508 | echo ' |
496 | 509 | </tbody> |
@@ -520,8 +533,8 @@ discard block |
||
520 | 533 | <table id="Tasks" class="table_grid"> |
521 | 534 | <tbody>'; |
522 | 535 | |
523 | - foreach ($context['tasks_versions'] as $filename => $version) |
|
524 | - echo ' |
|
536 | + foreach ($context['tasks_versions'] as $filename => $version) { |
|
537 | + echo ' |
|
525 | 538 | <tr class="windowbg"> |
526 | 539 | <td class="half_table"> |
527 | 540 | ', $filename, ' |
@@ -533,6 +546,7 @@ discard block |
||
533 | 546 | <em id="currentTasks', $filename, '">??</em> |
534 | 547 | </td> |
535 | 548 | </tr>'; |
549 | + } |
|
536 | 550 | |
537 | 551 | echo ' |
538 | 552 | </tbody> |
@@ -574,9 +588,10 @@ discard block |
||
574 | 588 | { |
575 | 589 | global $context, $scripturl, $txt, $modSettings; |
576 | 590 | |
577 | - if (!empty($context['saved_successful'])) |
|
578 | - echo ' |
|
591 | + if (!empty($context['saved_successful'])) { |
|
592 | + echo ' |
|
579 | 593 | <div class="infobox">', $txt['settings_saved'], '</div>'; |
594 | + } |
|
580 | 595 | |
581 | 596 | // First section is for adding/removing words from the censored list. |
582 | 597 | echo ' |
@@ -591,11 +606,12 @@ discard block |
||
591 | 606 | <p>', $txt['admin_censored_where'], '</p>'; |
592 | 607 | |
593 | 608 | // Show text boxes for censoring [bad ] => [good ]. |
594 | - foreach ($context['censored_words'] as $vulgar => $proper) |
|
595 | - echo ' |
|
609 | + foreach ($context['censored_words'] as $vulgar => $proper) { |
|
610 | + echo ' |
|
596 | 611 | <div class="block"> |
597 | 612 | <input type="text" name="censor_vulgar[]" value="', $vulgar, '" size="30"> => <input type="text" name="censor_proper[]" value="', $proper, '" size="30"> |
598 | 613 | </div>'; |
614 | + } |
|
599 | 615 | |
600 | 616 | // Now provide a way to censor more words. |
601 | 617 | echo ' |
@@ -669,19 +685,21 @@ discard block |
||
669 | 685 | <div class="windowbg2 noup"> |
670 | 686 | ', $txt['not_done_reason']; |
671 | 687 | |
672 | - if (!empty($context['continue_percent'])) |
|
673 | - echo ' |
|
688 | + if (!empty($context['continue_percent'])) { |
|
689 | + echo ' |
|
674 | 690 | <div class="progress_bar"> |
675 | 691 | <div class="full_bar">', $context['continue_percent'], '%</div> |
676 | 692 | <div class="green_percent" style="width: ', $context['continue_percent'], '%;"> </div> |
677 | 693 | </div>'; |
694 | + } |
|
678 | 695 | |
679 | - if (!empty($context['substep_enabled'])) |
|
680 | - echo ' |
|
696 | + if (!empty($context['substep_enabled'])) { |
|
697 | + echo ' |
|
681 | 698 | <div class="progress_bar"> |
682 | 699 | <div class="full_bar">', $context['substep_title'], ' (', $context['substep_continue_percent'], '%)</div> |
683 | 700 | <div class="blue_percent" style="width: ', $context['substep_continue_percent'], '%;"> </div> |
684 | 701 | </div>'; |
702 | + } |
|
685 | 703 | |
686 | 704 | echo ' |
687 | 705 | <form action="', $scripturl, $context['continue_get_data'], '" method="post" accept-charset="', $context['character_set'], '" name="autoSubmit" id="autoSubmit"> |
@@ -716,35 +734,40 @@ discard block |
||
716 | 734 | { |
717 | 735 | global $context, $txt, $scripturl; |
718 | 736 | |
719 | - if (!empty($context['saved_successful'])) |
|
720 | - echo ' |
|
737 | + if (!empty($context['saved_successful'])) { |
|
738 | + echo ' |
|
721 | 739 | <div class="infobox">', $txt['settings_saved'], '</div>'; |
722 | - elseif (!empty($context['saved_failed'])) |
|
723 | - echo ' |
|
740 | + } elseif (!empty($context['saved_failed'])) { |
|
741 | + echo ' |
|
724 | 742 | <div class="errorbox">', sprintf($txt['settings_not_saved'], $context['saved_failed']), '</div>'; |
743 | + } |
|
725 | 744 | |
726 | - if (!empty($context['settings_pre_javascript'])) |
|
727 | - echo ' |
|
745 | + if (!empty($context['settings_pre_javascript'])) { |
|
746 | + echo ' |
|
728 | 747 | <script>', $context['settings_pre_javascript'], '</script>'; |
748 | + } |
|
729 | 749 | |
730 | - if (!empty($context['settings_insert_above'])) |
|
731 | - echo $context['settings_insert_above']; |
|
750 | + if (!empty($context['settings_insert_above'])) { |
|
751 | + echo $context['settings_insert_above']; |
|
752 | + } |
|
732 | 753 | |
733 | 754 | echo ' |
734 | 755 | <div id="admincenter"> |
735 | 756 | <form id="admin_form_wrapper" action="', $context['post_url'], '" method="post" accept-charset="', $context['character_set'], '"', !empty($context['force_form_onsubmit']) ? ' onsubmit="' . $context['force_form_onsubmit'] . '"' : '', '>'; |
736 | 757 | |
737 | 758 | // Is there a custom title? |
738 | - if (isset($context['settings_title'])) |
|
739 | - echo ' |
|
759 | + if (isset($context['settings_title'])) { |
|
760 | + echo ' |
|
740 | 761 | <div class="cat_bar"> |
741 | 762 | <h3 class="catbg">', $context['settings_title'], '</h3> |
742 | 763 | </div>'; |
764 | + } |
|
743 | 765 | |
744 | 766 | // Have we got a message to display? |
745 | - if (!empty($context['settings_message'])) |
|
746 | - echo ' |
|
767 | + if (!empty($context['settings_message'])) { |
|
768 | + echo ' |
|
747 | 769 | <div class="information">', $context['settings_message'], '</div>'; |
770 | + } |
|
748 | 771 | |
749 | 772 | // Now actually loop through all the variables. |
750 | 773 | $is_open = false; |
@@ -797,8 +820,9 @@ discard block |
||
797 | 820 | // Hang about? Are you pulling my leg - a callback?! |
798 | 821 | if (is_array($config_var) && $config_var['type'] == 'callback') |
799 | 822 | { |
800 | - if (function_exists('template_callback_' . $config_var['name'])) |
|
801 | - call_user_func('template_callback_' . $config_var['name']); |
|
823 | + if (function_exists('template_callback_' . $config_var['name'])) { |
|
824 | + call_user_func('template_callback_' . $config_var['name']); |
|
825 | + } |
|
802 | 826 | |
803 | 827 | continue; |
804 | 828 | } |
@@ -828,9 +852,10 @@ discard block |
||
828 | 852 | $text_types = array('color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time'); |
829 | 853 | |
830 | 854 | // Show the [?] button. |
831 | - if ($config_var['help']) |
|
832 | - echo ' |
|
855 | + if ($config_var['help']) { |
|
856 | + echo ' |
|
833 | 857 | <a id="setting_', $config_var['name'], '_help" href="', $scripturl, '?action=helpadmin;help=', $config_var['help'], '" onclick="return reqOverlayDiv(this.href);"><span class="generic_icons help" title="', $txt['help'], '"></span></a> '; |
858 | + } |
|
834 | 859 | |
835 | 860 | echo ' |
836 | 861 | <a id="setting_', $config_var['name'], '"></a> <span', ($config_var['disabled'] ? ' style="color: #777777;"' : ($config_var['invalid'] ? ' class="error"' : '')), '><label for="', $config_var['name'], '">', $config_var['label'], '</label>', $subtext, ($config_var['type'] == 'password' ? '<br><em>' . $txt['admin_confirm_password'] . '</em>' : ''), '</span> |
@@ -839,22 +864,25 @@ discard block |
||
839 | 864 | $config_var['preinput']; |
840 | 865 | |
841 | 866 | // Show a check box. |
842 | - if ($config_var['type'] == 'check') |
|
843 | - echo ' |
|
867 | + if ($config_var['type'] == 'check') { |
|
868 | + echo ' |
|
844 | 869 | <input type="checkbox"', $javascript, $disabled, ' name="', $config_var['name'], '" id="', $config_var['name'], '"', ($config_var['value'] ? ' checked' : ''), ' value="1" class="input_check">'; |
870 | + } |
|
845 | 871 | // Escape (via htmlspecialchars.) the text box. |
846 | - elseif ($config_var['type'] == 'password') |
|
847 | - echo ' |
|
872 | + elseif ($config_var['type'] == 'password') { |
|
873 | + echo ' |
|
848 | 874 | <input type="password"', $disabled, $javascript, ' name="', $config_var['name'], '[0]"', ($config_var['size'] ? ' size="' . $config_var['size'] . '"' : ''), ' value="*#fakepass#*" onfocus="this.value = \'\'; this.form.', $config_var['name'], '.disabled = false;" class="input_password"><br> |
849 | 875 | <input type="password" disabled id="', $config_var['name'], '" name="', $config_var['name'], '[1]"', ($config_var['size'] ? ' size="' . $config_var['size'] . '"' : ''), ' class="input_password">'; |
876 | + } |
|
850 | 877 | // Show a selection box. |
851 | 878 | elseif ($config_var['type'] == 'select') |
852 | 879 | { |
853 | 880 | echo ' |
854 | 881 | <select name="', $config_var['name'], '" id="', $config_var['name'], '" ', $javascript, $disabled, (!empty($config_var['multiple']) ? ' multiple="multiple"' : ''), (!empty($config_var['multiple']) && !empty($config_var['size']) ? ' size="' . $config_var['size'] . '"' : ''), '>'; |
855 | - foreach ($config_var['data'] as $option) |
|
856 | - echo ' |
|
882 | + foreach ($config_var['data'] as $option) { |
|
883 | + echo ' |
|
857 | 884 | <option value="', $option[0], '"', (!empty($config_var['value']) && ($option[0] == $config_var['value'] || (!empty($config_var['multiple']) && in_array($option[0], $config_var['value']))) ? ' selected' : ''), '>', $option[1], '</option>'; |
885 | + } |
|
858 | 886 | echo ' |
859 | 887 | </select>'; |
860 | 888 | } |
@@ -868,15 +896,17 @@ discard block |
||
868 | 896 | <legend class="board_selector"><a href="#">', $txt['select_boards_from_list'], '</a></legend>'; |
869 | 897 | foreach ($context['board_list'] as $id_cat => $cat) |
870 | 898 | { |
871 | - if (!$first) |
|
872 | - echo ' |
|
899 | + if (!$first) { |
|
900 | + echo ' |
|
873 | 901 | <hr>'; |
902 | + } |
|
874 | 903 | echo ' |
875 | 904 | <strong>', $cat['name'], '</strong> |
876 | 905 | <ul>'; |
877 | - foreach ($cat['boards'] as $id_board => $brd) |
|
878 | - echo ' |
|
906 | + foreach ($cat['boards'] as $id_board => $brd) { |
|
907 | + echo ' |
|
879 | 908 | <li><label><input type="checkbox" name="', $config_var['name'], '[', $brd['id'], ']" value="1" class="input_check"', in_array($brd['id'], $config_var['value']) ? ' checked' : '', '> ', $brd['child_level'] > 0 ? str_repeat(' ', $brd['child_level']) : '', $brd['name'], '</label></li>'; |
909 | + } |
|
880 | 910 | |
881 | 911 | echo ' |
882 | 912 | </ul>'; |
@@ -886,12 +916,14 @@ discard block |
||
886 | 916 | </fieldset>'; |
887 | 917 | } |
888 | 918 | // Text area? |
889 | - elseif ($config_var['type'] == 'large_text') |
|
890 | - echo ' |
|
919 | + elseif ($config_var['type'] == 'large_text') { |
|
920 | + echo ' |
|
891 | 921 | <textarea rows="', (!empty($config_var['size']) ? $config_var['size'] : (!empty($config_var['rows']) ? $config_var['rows'] : 4)), '" cols="', (!empty($config_var['cols']) ? $config_var['cols'] : 30), '" ', $javascript, $disabled, ' name="', $config_var['name'], '" id="', $config_var['name'], '">', $config_var['value'], '</textarea>'; |
922 | + } |
|
892 | 923 | // Permission group? |
893 | - elseif ($config_var['type'] == 'permissions') |
|
894 | - theme_inline_permissions($config_var['name']); |
|
924 | + elseif ($config_var['type'] == 'permissions') { |
|
925 | + theme_inline_permissions($config_var['name']); |
|
926 | + } |
|
895 | 927 | // BBC selection? |
896 | 928 | elseif ($config_var['type'] == 'bbc') |
897 | 929 | { |
@@ -902,20 +934,22 @@ discard block |
||
902 | 934 | |
903 | 935 | foreach ($context['bbc_columns'] as $bbcColumn) |
904 | 936 | { |
905 | - foreach ($bbcColumn as $bbcTag) |
|
906 | - echo ' |
|
937 | + foreach ($bbcColumn as $bbcTag) { |
|
938 | + echo ' |
|
907 | 939 | <li class="list_bbc floatleft"> |
908 | 940 | <input type="checkbox" name="', $config_var['name'], '_enabledTags[]" id="tag_', $config_var['name'], '_', $bbcTag['tag'], '" value="', $bbcTag['tag'], '"', !in_array($bbcTag['tag'], $context['bbc_sections'][$config_var['name']]['disabled']) ? ' checked' : '', ' class="input_check"> <label for="tag_', $config_var['name'], '_', $bbcTag['tag'], '">', $bbcTag['tag'], '</label>', $bbcTag['show_help'] ? ' (<a href="' . $scripturl . '?action=helpadmin;help=tag_' . $bbcTag['tag'] . '" onclick="return reqOverlayDiv(this.href);">?</a>)' : '', ' |
909 | 941 | </li>'; |
942 | + } |
|
910 | 943 | } |
911 | 944 | echo ' </ul> |
912 | 945 | <input type="checkbox" id="bbc_', $config_var['name'], '_select_all" onclick="invertAll(this, this.form, \'', $config_var['name'], '_enabledTags\');"', $context['bbc_sections'][$config_var['name']]['all_selected'] ? ' checked' : '', ' class="input_check"> <label for="bbc_', $config_var['name'], '_select_all"><em>', $txt['bbcTagsToUse_select_all'], '</em></label> |
913 | 946 | </fieldset>'; |
914 | 947 | } |
915 | 948 | // A simple message? |
916 | - elseif ($config_var['type'] == 'var_message') |
|
917 | - echo ' |
|
949 | + elseif ($config_var['type'] == 'var_message') { |
|
950 | + echo ' |
|
918 | 951 | <div', !empty($config_var['name']) ? ' id="' . $config_var['name'] . '"' : '', '>', $config_var['var_message'], '</div>'; |
952 | + } |
|
919 | 953 | // Assume it must be a text box |
920 | 954 | else |
921 | 955 | { |
@@ -940,63 +974,70 @@ discard block |
||
940 | 974 | ' . $config_var['postinput'] : '', |
941 | 975 | '</dd>'; |
942 | 976 | } |
943 | - } |
|
944 | - |
|
945 | - else |
|
977 | + } else |
|
946 | 978 | { |
947 | 979 | // Just show a separator. |
948 | - if ($config_var == '') |
|
949 | - echo ' |
|
980 | + if ($config_var == '') { |
|
981 | + echo ' |
|
950 | 982 | </dl> |
951 | 983 | <hr> |
952 | 984 | <dl class="settings">'; |
953 | - else |
|
954 | - echo ' |
|
985 | + } else { |
|
986 | + echo ' |
|
955 | 987 | <dd> |
956 | 988 | <strong>' . $config_var . '</strong> |
957 | 989 | </dd>'; |
990 | + } |
|
958 | 991 | } |
959 | 992 | } |
960 | 993 | |
961 | - if ($is_open) |
|
962 | - echo ' |
|
994 | + if ($is_open) { |
|
995 | + echo ' |
|
963 | 996 | </dl>'; |
997 | + } |
|
964 | 998 | |
965 | - if (empty($context['settings_save_dont_show'])) |
|
966 | - echo ' |
|
999 | + if (empty($context['settings_save_dont_show'])) { |
|
1000 | + echo ' |
|
967 | 1001 | <input type="submit" value="', $txt['save'], '"', (!empty($context['save_disabled']) ? ' disabled' : ''), (!empty($context['settings_save_onclick']) ? ' onclick="' . $context['settings_save_onclick'] . '"' : ''), ' class="button_submit">'; |
1002 | + } |
|
968 | 1003 | |
969 | - if ($is_open) |
|
970 | - echo ' |
|
1004 | + if ($is_open) { |
|
1005 | + echo ' |
|
971 | 1006 | </div>'; |
1007 | + } |
|
972 | 1008 | |
973 | 1009 | |
974 | 1010 | // At least one token has to be used! |
975 | - if (isset($context['admin-ssc_token'])) |
|
976 | - echo ' |
|
1011 | + if (isset($context['admin-ssc_token'])) { |
|
1012 | + echo ' |
|
977 | 1013 | <input type="hidden" name="', $context['admin-ssc_token_var'], '" value="', $context['admin-ssc_token'], '">'; |
1014 | + } |
|
978 | 1015 | |
979 | - if (isset($context['admin-dbsc_token'])) |
|
980 | - echo ' |
|
1016 | + if (isset($context['admin-dbsc_token'])) { |
|
1017 | + echo ' |
|
981 | 1018 | <input type="hidden" name="', $context['admin-dbsc_token_var'], '" value="', $context['admin-dbsc_token'], '">'; |
1019 | + } |
|
982 | 1020 | |
983 | - if (isset($context['admin-mp_token'])) |
|
984 | - echo ' |
|
1021 | + if (isset($context['admin-mp_token'])) { |
|
1022 | + echo ' |
|
985 | 1023 | <input type="hidden" name="', $context['admin-mp_token_var'], '" value="', $context['admin-mp_token'], '">'; |
1024 | + } |
|
986 | 1025 | |
987 | 1026 | echo ' |
988 | 1027 | <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '"> |
989 | 1028 | </form> |
990 | 1029 | </div>'; |
991 | 1030 | |
992 | - if (!empty($context['settings_post_javascript'])) |
|
993 | - echo ' |
|
1031 | + if (!empty($context['settings_post_javascript'])) { |
|
1032 | + echo ' |
|
994 | 1033 | <script> |
995 | 1034 | ', $context['settings_post_javascript'], ' |
996 | 1035 | </script>'; |
1036 | + } |
|
997 | 1037 | |
998 | - if (!empty($context['settings_insert_below'])) |
|
999 | - echo $context['settings_insert_below']; |
|
1038 | + if (!empty($context['settings_insert_below'])) { |
|
1039 | + echo $context['settings_insert_below']; |
|
1040 | + } |
|
1000 | 1041 | |
1001 | 1042 | // We may have added a board listing. If we did, we need to make it work. |
1002 | 1043 | addInlineJavascript(' |
@@ -1019,9 +1060,10 @@ discard block |
||
1019 | 1060 | { |
1020 | 1061 | global $context, $txt; |
1021 | 1062 | |
1022 | - if (!empty($context['saved_successful'])) |
|
1023 | - echo ' |
|
1063 | + if (!empty($context['saved_successful'])) { |
|
1064 | + echo ' |
|
1024 | 1065 | <div class="infobox">', $txt['settings_saved'], '</div>'; |
1066 | + } |
|
1025 | 1067 | |
1026 | 1068 | // Standard fields. |
1027 | 1069 | template_show_list('standard_profile_fields'); |
@@ -1053,11 +1095,12 @@ discard block |
||
1053 | 1095 | if (isset($_GET['msg'])) |
1054 | 1096 | { |
1055 | 1097 | loadLanguage('Errors'); |
1056 | - if (isset($txt['custom_option_' . $_GET['msg']])) |
|
1057 | - echo ' |
|
1098 | + if (isset($txt['custom_option_' . $_GET['msg']])) { |
|
1099 | + echo ' |
|
1058 | 1100 | <div class="errorbox">', |
1059 | 1101 | $txt['custom_option_' . $_GET['msg']], ' |
1060 | 1102 | </div>'; |
1103 | + } |
|
1061 | 1104 | } |
1062 | 1105 | |
1063 | 1106 | echo ' |
@@ -1123,9 +1166,10 @@ discard block |
||
1123 | 1166 | <dd> |
1124 | 1167 | <select name="placement" id="placement">'; |
1125 | 1168 | |
1126 | - foreach ($context['cust_profile_fields_placement'] as $order => $name) |
|
1127 | - echo ' |
|
1169 | + foreach ($context['cust_profile_fields_placement'] as $order => $name) { |
|
1170 | + echo ' |
|
1128 | 1171 | <option value="', $order, '"', $context['field']['placement'] == $order ? ' selected' : '', '>', $txt['custom_profile_placement_' . $name], '</option>'; |
1172 | + } |
|
1129 | 1173 | |
1130 | 1174 | echo ' |
1131 | 1175 | </select> |
@@ -1148,9 +1192,10 @@ discard block |
||
1148 | 1192 | </dt> |
1149 | 1193 | <dd> |
1150 | 1194 | <select name="field_type" id="field_type" onchange="updateInputBoxes();">'; |
1151 | - foreach (array('text', 'textarea', 'select', 'radio', 'check') as $field_type) |
|
1152 | - echo ' |
|
1195 | + foreach (array('text', 'textarea', 'select', 'radio', 'check') as $field_type) { |
|
1196 | + echo ' |
|
1153 | 1197 | <option value="', $field_type, '"', $context['field']['type'] == $field_type ? ' selected' : '', '>', $txt['custom_profile_type_' . $field_type], '</option>'; |
1198 | + } |
|
1154 | 1199 | |
1155 | 1200 | echo ' |
1156 | 1201 | </select> |
@@ -1251,9 +1296,10 @@ discard block |
||
1251 | 1296 | </fieldset> |
1252 | 1297 | <input type="submit" name="save" value="', $txt['save'], '" class="button_submit">'; |
1253 | 1298 | |
1254 | - if ($context['fid']) |
|
1255 | - echo ' |
|
1299 | + if ($context['fid']) { |
|
1300 | + echo ' |
|
1256 | 1301 | <input type="submit" name="delete" value="', $txt['delete'], '" data-confirm="', $txt['custom_edit_delete_sure'], '" class="button_submit you_sure">'; |
1302 | + } |
|
1257 | 1303 | |
1258 | 1304 | echo ' |
1259 | 1305 | </div> |
@@ -1296,8 +1342,7 @@ discard block |
||
1296 | 1342 | { |
1297 | 1343 | echo ' |
1298 | 1344 | <p class="centertext"><strong>', $txt['admin_search_results_none'], '</strong></p>'; |
1299 | - } |
|
1300 | - else |
|
1345 | + } else |
|
1301 | 1346 | { |
1302 | 1347 | echo ' |
1303 | 1348 | <ol class="search_results">'; |
@@ -1323,9 +1368,10 @@ discard block |
||
1323 | 1368 | <li> |
1324 | 1369 | <a href="', $result['url'], '"><strong>', $result['name'], '</strong></a> [', isset($txt['admin_search_section_' . $result['type']]) ? $txt['admin_search_section_' . $result['type']] : $result['type'], ']'; |
1325 | 1370 | |
1326 | - if ($result['help']) |
|
1327 | - echo ' |
|
1371 | + if ($result['help']) { |
|
1372 | + echo ' |
|
1328 | 1373 | <p class="double_height">', $result['help'], '</p>'; |
1374 | + } |
|
1329 | 1375 | |
1330 | 1376 | echo ' |
1331 | 1377 | </li>'; |
@@ -1365,18 +1411,20 @@ discard block |
||
1365 | 1411 | <strong>', $txt['setup_verification_answer'], '</strong> |
1366 | 1412 | </dd>'; |
1367 | 1413 | |
1368 | - if (!empty($context['qa_by_lang'][$lang_id])) |
|
1369 | - foreach ($context['qa_by_lang'][$lang_id] as $q_id) |
|
1414 | + if (!empty($context['qa_by_lang'][$lang_id])) { |
|
1415 | + foreach ($context['qa_by_lang'][$lang_id] as $q_id) |
|
1370 | 1416 | { |
1371 | 1417 | $question = $context['question_answers'][$q_id]; |
1418 | + } |
|
1372 | 1419 | echo ' |
1373 | 1420 | <dt> |
1374 | 1421 | <input type="text" name="question[', $lang_id, '][', $q_id, ']" value="', $question['question'], '" size="50" class="input_text verification_question"> |
1375 | 1422 | </dt> |
1376 | 1423 | <dd>'; |
1377 | - foreach ($question['answers'] as $answer) |
|
1378 | - echo ' |
|
1424 | + foreach ($question['answers'] as $answer) { |
|
1425 | + echo ' |
|
1379 | 1426 | <input type="text" name="answer[', $lang_id, '][', $q_id, '][]" value="', $answer, '" size="50" class="input_text verification_answer">'; |
1427 | + } |
|
1380 | 1428 | |
1381 | 1429 | echo ' |
1382 | 1430 | <div class="qa_add_answer"><a href="javascript:void(0);" onclick="return addAnswer(this);">[ ', $txt['setup_verification_add_answer'], ' ]</a></div> |
@@ -1415,11 +1463,12 @@ discard block |
||
1415 | 1463 | ', $txt['errors_found'], ': |
1416 | 1464 | <ul>'; |
1417 | 1465 | |
1418 | - foreach ($context['repair_errors'] as $error) |
|
1419 | - echo ' |
|
1466 | + foreach ($context['repair_errors'] as $error) { |
|
1467 | + echo ' |
|
1420 | 1468 | <li> |
1421 | 1469 | ', $error, ' |
1422 | 1470 | </li>'; |
1471 | + } |
|
1423 | 1472 | |
1424 | 1473 | echo ' |
1425 | 1474 | </ul> |
@@ -1429,16 +1478,15 @@ discard block |
||
1429 | 1478 | <p class="padding"> |
1430 | 1479 | <strong><a href="', $scripturl, '?action=admin;area=repairboards;fixErrors;', $context['session_var'], '=', $context['session_id'], '">', $txt['yes'], '</a> - <a href="', $scripturl, '?action=admin;area=maintain">', $txt['no'], '</a></strong> |
1431 | 1480 | </p>'; |
1432 | - } |
|
1433 | - else |
|
1434 | - echo ' |
|
1481 | + } else { |
|
1482 | + echo ' |
|
1435 | 1483 | <p>', $txt['maintain_no_errors'], '</p> |
1436 | 1484 | <p class="padding"> |
1437 | 1485 | <a href="', $scripturl, '?action=admin;area=maintain;sa=routine">', $txt['maintain_return'], '</a> |
1438 | 1486 | </p>'; |
1487 | + } |
|
1439 | 1488 | |
1440 | - } |
|
1441 | - else |
|
1489 | + } else |
|
1442 | 1490 | { |
1443 | 1491 | if (!empty($context['redirect_to_recount'])) |
1444 | 1492 | { |
@@ -1450,8 +1498,7 @@ discard block |
||
1450 | 1498 | <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '"> |
1451 | 1499 | <input type="submit" name="recount" id="recount_now" value="', $txt['errors_recount_now'], '"> |
1452 | 1500 | </form>'; |
1453 | - } |
|
1454 | - else |
|
1501 | + } else |
|
1455 | 1502 | { |
1456 | 1503 | echo ' |
1457 | 1504 | <p>', $txt['errors_fixed'], '</p> |
@@ -1603,8 +1650,8 @@ discard block |
||
1603 | 1650 | function template_admin_quick_search() |
1604 | 1651 | { |
1605 | 1652 | global $context, $txt; |
1606 | - if ($context['user']['is_admin']) |
|
1607 | - echo ' |
|
1653 | + if ($context['user']['is_admin']) { |
|
1654 | + echo ' |
|
1608 | 1655 | <span class="floatright admin_search"> |
1609 | 1656 | <span class="generic_icons filter centericon"></span> |
1610 | 1657 | <input type="search" name="search_term" value="', $txt['admin_search'], '" onclick="if (this.value == \'', $txt['admin_search'], '\') this.value = \'\';" class="input_text"> |
@@ -1615,6 +1662,7 @@ discard block |
||
1615 | 1662 | </select> |
1616 | 1663 | <input type="submit" name="search_go" id="search_go" value="', $txt['admin_search_go'], '" class="button_submit"> |
1617 | 1664 | </span>'; |
1618 | -} |
|
1665 | + } |
|
1666 | + } |
|
1619 | 1667 | |
1620 | 1668 | ?> |
1621 | 1669 | \ No newline at end of file |
@@ -16,8 +16,9 @@ discard block |
||
16 | 16 | * @version 2.1 Beta 3 |
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,26 +3205,30 @@ 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 | |
3045 | 3217 | if (file_exists($output_file . $output_ext)) |
3046 | 3218 | { |
3047 | 3219 | $i = 2; |
3048 | - while (file_exists($output_file . '_' . $i . $output_ext)) |
|
3049 | - $i++; |
|
3220 | + while (file_exists($output_file . '_' . $i . $output_ext)) { |
|
3221 | + $i++; |
|
3222 | + } |
|
3050 | 3223 | $output_file = $output_file . '_' . $i . $output_ext; |
3224 | + } else { |
|
3225 | + $output_file .= $output_ext; |
|
3051 | 3226 | } |
3052 | - else |
|
3053 | - $output_file .= $output_ext; |
|
3054 | 3227 | |
3055 | 3228 | @set_time_limit(300); |
3056 | - if (function_exists('apache_reset_timeout')) |
|
3057 | - @apache_reset_timeout(); |
|
3229 | + if (function_exists('apache_reset_timeout')) { |
|
3230 | + @apache_reset_timeout(); |
|
3231 | + } |
|
3058 | 3232 | |
3059 | 3233 | $a = new PharData($output_file); |
3060 | 3234 | $a->buildFromIterator($iterator); |
@@ -3066,8 +3240,7 @@ discard block |
||
3066 | 3240 | */ |
3067 | 3241 | unset($a); |
3068 | 3242 | unlink($output_file); |
3069 | - } |
|
3070 | - catch (Exception $e) |
|
3243 | + } catch (Exception $e) |
|
3071 | 3244 | { |
3072 | 3245 | log_error($e->getMessage(), 'backup'); |
3073 | 3246 | |
@@ -3099,32 +3272,35 @@ discard block |
||
3099 | 3272 | preg_match('~^(http|ftp)(s)?://([^/:]+)(:(\d+))?(.+)$~', $url, $match); |
3100 | 3273 | |
3101 | 3274 | // An FTP url. We should try connecting and RETRieving it... |
3102 | - if (empty($match[1])) |
|
3103 | - return false; |
|
3104 | - elseif ($match[1] == 'ftp') |
|
3275 | + if (empty($match[1])) { |
|
3276 | + return false; |
|
3277 | + } elseif ($match[1] == 'ftp') |
|
3105 | 3278 | { |
3106 | 3279 | // Include the file containing the ftp_connection class. |
3107 | 3280 | require_once($sourcedir . '/Class-Package.php'); |
3108 | 3281 | |
3109 | 3282 | // Establish a connection and attempt to enable passive mode. |
3110 | 3283 | $ftp = new ftp_connection(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? 21 : $match[5], 'anonymous', $webmaster_email); |
3111 | - if ($ftp->error !== false || !$ftp->passive()) |
|
3112 | - return false; |
|
3284 | + if ($ftp->error !== false || !$ftp->passive()) { |
|
3285 | + return false; |
|
3286 | + } |
|
3113 | 3287 | |
3114 | 3288 | // I want that one *points*! |
3115 | 3289 | fwrite($ftp->connection, 'RETR ' . $match[6] . "\r\n"); |
3116 | 3290 | |
3117 | 3291 | // Since passive mode worked (or we would have returned already!) open the connection. |
3118 | 3292 | $fp = @fsockopen($ftp->pasv['ip'], $ftp->pasv['port'], $err, $err, 5); |
3119 | - if (!$fp) |
|
3120 | - return false; |
|
3293 | + if (!$fp) { |
|
3294 | + return false; |
|
3295 | + } |
|
3121 | 3296 | |
3122 | 3297 | // The server should now say something in acknowledgement. |
3123 | 3298 | $ftp->check_response(150); |
3124 | 3299 | |
3125 | 3300 | $data = ''; |
3126 | - while (!feof($fp)) |
|
3127 | - $data .= fread($fp, 4096); |
|
3301 | + while (!feof($fp)) { |
|
3302 | + $data .= fread($fp, 4096); |
|
3303 | + } |
|
3128 | 3304 | fclose($fp); |
3129 | 3305 | |
3130 | 3306 | // All done, right? Good. |
@@ -3141,22 +3317,25 @@ discard block |
||
3141 | 3317 | $fetch_data->get_url_data($url, $post_data); |
3142 | 3318 | |
3143 | 3319 | // no errors and a 200 result, then we have a good dataset, well we at least have data ;) |
3144 | - if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) |
|
3145 | - $data = $fetch_data->result('body'); |
|
3146 | - else |
|
3147 | - return false; |
|
3320 | + if ($fetch_data->result('code') == 200 && !$fetch_data->result('error')) { |
|
3321 | + $data = $fetch_data->result('body'); |
|
3322 | + } else { |
|
3323 | + return false; |
|
3324 | + } |
|
3148 | 3325 | } |
3149 | 3326 | // This is more likely; a standard HTTP URL. |
3150 | 3327 | elseif (isset($match[1]) && $match[1] == 'http') |
3151 | 3328 | { |
3152 | - if ($keep_alive && $match[3] == $keep_alive_dom) |
|
3153 | - $fp = $keep_alive_fp; |
|
3329 | + if ($keep_alive && $match[3] == $keep_alive_dom) { |
|
3330 | + $fp = $keep_alive_fp; |
|
3331 | + } |
|
3154 | 3332 | if (empty($fp)) |
3155 | 3333 | { |
3156 | 3334 | // Open the socket on the port we want... |
3157 | 3335 | $fp = @fsockopen(($match[2] ? 'ssl://' : '') . $match[3], empty($match[5]) ? ($match[2] ? 443 : 80) : $match[5], $err, $err, 5); |
3158 | - if (!$fp) |
|
3159 | - return false; |
|
3336 | + if (!$fp) { |
|
3337 | + return false; |
|
3338 | + } |
|
3160 | 3339 | } |
3161 | 3340 | |
3162 | 3341 | if ($keep_alive) |
@@ -3171,20 +3350,21 @@ discard block |
||
3171 | 3350 | fwrite($fp, 'GET ' . ($match[6] !== '/' ? str_replace(' ', '%20', $match[6]) : '') . ' HTTP/1.0' . "\r\n"); |
3172 | 3351 | fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n"); |
3173 | 3352 | fwrite($fp, 'User-Agent: PHP/SMF' . "\r\n"); |
3174 | - if ($keep_alive) |
|
3175 | - fwrite($fp, 'Connection: Keep-Alive' . "\r\n\r\n"); |
|
3176 | - else |
|
3177 | - fwrite($fp, 'Connection: close' . "\r\n\r\n"); |
|
3178 | - } |
|
3179 | - else |
|
3353 | + if ($keep_alive) { |
|
3354 | + fwrite($fp, 'Connection: Keep-Alive' . "\r\n\r\n"); |
|
3355 | + } else { |
|
3356 | + fwrite($fp, 'Connection: close' . "\r\n\r\n"); |
|
3357 | + } |
|
3358 | + } else |
|
3180 | 3359 | { |
3181 | 3360 | fwrite($fp, 'POST ' . ($match[6] !== '/' ? $match[6] : '') . ' HTTP/1.0' . "\r\n"); |
3182 | 3361 | fwrite($fp, 'Host: ' . $match[3] . (empty($match[5]) ? ($match[2] ? ':443' : '') : ':' . $match[5]) . "\r\n"); |
3183 | 3362 | fwrite($fp, 'User-Agent: PHP/SMF' . "\r\n"); |
3184 | - if ($keep_alive) |
|
3185 | - fwrite($fp, 'Connection: Keep-Alive' . "\r\n"); |
|
3186 | - else |
|
3187 | - fwrite($fp, 'Connection: close' . "\r\n"); |
|
3363 | + if ($keep_alive) { |
|
3364 | + fwrite($fp, 'Connection: Keep-Alive' . "\r\n"); |
|
3365 | + } else { |
|
3366 | + fwrite($fp, 'Connection: close' . "\r\n"); |
|
3367 | + } |
|
3188 | 3368 | fwrite($fp, 'Content-Type: application/x-www-form-urlencoded' . "\r\n"); |
3189 | 3369 | fwrite($fp, 'Content-Length: ' . strlen($post_data) . "\r\n\r\n"); |
3190 | 3370 | fwrite($fp, $post_data); |
@@ -3197,30 +3377,33 @@ discard block |
||
3197 | 3377 | { |
3198 | 3378 | $header = ''; |
3199 | 3379 | $location = ''; |
3200 | - while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') |
|
3201 | - if (strpos($header, 'Location:') !== false) |
|
3380 | + while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') { |
|
3381 | + if (strpos($header, 'Location:') !== false) |
|
3202 | 3382 | $location = trim(substr($header, strpos($header, ':') + 1)); |
3383 | + } |
|
3203 | 3384 | |
3204 | - if (empty($location)) |
|
3205 | - return false; |
|
3206 | - else |
|
3385 | + if (empty($location)) { |
|
3386 | + return false; |
|
3387 | + } else |
|
3207 | 3388 | { |
3208 | - if (!$keep_alive) |
|
3209 | - fclose($fp); |
|
3389 | + if (!$keep_alive) { |
|
3390 | + fclose($fp); |
|
3391 | + } |
|
3210 | 3392 | return fetch_web_data($location, $post_data, $keep_alive, $redirection_level + 1); |
3211 | 3393 | } |
3212 | 3394 | } |
3213 | 3395 | |
3214 | 3396 | // Make sure we get a 200 OK. |
3215 | - elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) |
|
3216 | - return false; |
|
3397 | + elseif (preg_match('~^HTTP/\S+\s+20[01]~i', $response) === 0) { |
|
3398 | + return false; |
|
3399 | + } |
|
3217 | 3400 | |
3218 | 3401 | // Skip the headers... |
3219 | 3402 | while (!feof($fp) && trim($header = fgets($fp, 4096)) != '') |
3220 | 3403 | { |
3221 | - if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) |
|
3222 | - $content_length = $match[1]; |
|
3223 | - elseif (preg_match('~connection:\s*close~i', $header) != 0) |
|
3404 | + if (preg_match('~content-length:\s*(\d+)~i', $header, $match) != 0) { |
|
3405 | + $content_length = $match[1]; |
|
3406 | + } elseif (preg_match('~connection:\s*close~i', $header) != 0) |
|
3224 | 3407 | { |
3225 | 3408 | $keep_alive_dom = null; |
3226 | 3409 | $keep_alive = false; |
@@ -3232,19 +3415,20 @@ discard block |
||
3232 | 3415 | $data = ''; |
3233 | 3416 | if (isset($content_length)) |
3234 | 3417 | { |
3235 | - while (!feof($fp) && strlen($data) < $content_length) |
|
3236 | - $data .= fread($fp, $content_length - strlen($data)); |
|
3237 | - } |
|
3238 | - else |
|
3418 | + while (!feof($fp) && strlen($data) < $content_length) { |
|
3419 | + $data .= fread($fp, $content_length - strlen($data)); |
|
3420 | + } |
|
3421 | + } else |
|
3239 | 3422 | { |
3240 | - while (!feof($fp)) |
|
3241 | - $data .= fread($fp, 4096); |
|
3423 | + while (!feof($fp)) { |
|
3424 | + $data .= fread($fp, 4096); |
|
3425 | + } |
|
3242 | 3426 | } |
3243 | 3427 | |
3244 | - if (!$keep_alive) |
|
3245 | - fclose($fp); |
|
3246 | - } |
|
3247 | - else |
|
3428 | + if (!$keep_alive) { |
|
3429 | + fclose($fp); |
|
3430 | + } |
|
3431 | + } else |
|
3248 | 3432 | { |
3249 | 3433 | // Umm, this shouldn't happen? |
3250 | 3434 | trigger_error('fetch_web_data(): Bad URL', E_USER_NOTICE); |
@@ -20,8 +20,9 @@ discard block |
||
20 | 20 | // ><html dir="ltr"><head><title>Error!</title></head><body>Sorry, this installer requires PHP!<div style="display: none;"> |
21 | 21 | |
22 | 22 | // Let's pull in useful classes |
23 | -if (!defined('SMF')) |
|
23 | +if (!defined('SMF')) { |
|
24 | 24 | define('SMF', 1); |
25 | +} |
|
25 | 26 | |
26 | 27 | require_once('Sources/Class-Package.php'); |
27 | 28 | |
@@ -63,10 +64,11 @@ discard block |
||
63 | 64 | |
64 | 65 | list ($charcode) = pg_fetch_row($request); |
65 | 66 | |
66 | - if ($charcode == 'UTF8') |
|
67 | - return true; |
|
68 | - else |
|
69 | - return false; |
|
67 | + if ($charcode == 'UTF8') { |
|
68 | + return true; |
|
69 | + } else { |
|
70 | + return false; |
|
71 | + } |
|
70 | 72 | }, |
71 | 73 | 'utf8_version' => '8.0', |
72 | 74 | 'utf8_version_check' => '$request = pg_query(\'SELECT version()\'); list ($version) = pg_fetch_row($request); list($pgl, $version) = explode(" ", $version); return $version;', |
@@ -76,12 +78,14 @@ discard block |
||
76 | 78 | $value = preg_replace('~[^A-Za-z0-9_\$]~', '', $value); |
77 | 79 | |
78 | 80 | // Is it reserved? |
79 | - if ($value == 'pg_') |
|
80 | - return $txt['error_db_prefix_reserved']; |
|
81 | + if ($value == 'pg_') { |
|
82 | + return $txt['error_db_prefix_reserved']; |
|
83 | + } |
|
81 | 84 | |
82 | 85 | // Is the prefix numeric? |
83 | - if (preg_match('~^\d~', $value)) |
|
84 | - return $txt['error_db_prefix_numeric']; |
|
86 | + if (preg_match('~^\d~', $value)) { |
|
87 | + return $txt['error_db_prefix_numeric']; |
|
88 | + } |
|
85 | 89 | |
86 | 90 | return true; |
87 | 91 | }, |
@@ -128,10 +132,11 @@ discard block |
||
128 | 132 | $incontext['skip'] = false; |
129 | 133 | |
130 | 134 | // Call the step and if it returns false that means pause! |
131 | - if (function_exists($step[2]) && $step[2]() === false) |
|
132 | - break; |
|
133 | - elseif (function_exists($step[2])) |
|
134 | - $incontext['current_step']++; |
|
135 | + if (function_exists($step[2]) && $step[2]() === false) { |
|
136 | + break; |
|
137 | + } elseif (function_exists($step[2])) { |
|
138 | + $incontext['current_step']++; |
|
139 | + } |
|
135 | 140 | |
136 | 141 | // No warnings pass on. |
137 | 142 | $incontext['warning'] = ''; |
@@ -147,8 +152,9 @@ discard block |
||
147 | 152 | global $databases; |
148 | 153 | |
149 | 154 | // Just so people using older versions of PHP aren't left in the cold. |
150 | - if (!isset($_SERVER['PHP_SELF'])) |
|
151 | - $_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php'; |
|
155 | + if (!isset($_SERVER['PHP_SELF'])) { |
|
156 | + $_SERVER['PHP_SELF'] = isset($GLOBALS['HTTP_SERVER_VARS']['PHP_SELF']) ? $GLOBALS['HTTP_SERVER_VARS']['PHP_SELF'] : 'install.php'; |
|
157 | + } |
|
152 | 158 | |
153 | 159 | // Enable error reporting. |
154 | 160 | error_reporting(E_ALL); |
@@ -164,21 +170,23 @@ discard block |
||
164 | 170 | { |
165 | 171 | ob_start(); |
166 | 172 | |
167 | - if (ini_get('session.save_handler') == 'user') |
|
168 | - @ini_set('session.save_handler', 'files'); |
|
169 | - if (function_exists('session_start')) |
|
170 | - @session_start(); |
|
171 | - } |
|
172 | - else |
|
173 | + if (ini_get('session.save_handler') == 'user') { |
|
174 | + @ini_set('session.save_handler', 'files'); |
|
175 | + } |
|
176 | + if (function_exists('session_start')) { |
|
177 | + @session_start(); |
|
178 | + } |
|
179 | + } else |
|
173 | 180 | { |
174 | 181 | ob_start('ob_gzhandler'); |
175 | 182 | |
176 | - if (ini_get('session.save_handler') == 'user') |
|
177 | - @ini_set('session.save_handler', 'files'); |
|
183 | + if (ini_get('session.save_handler') == 'user') { |
|
184 | + @ini_set('session.save_handler', 'files'); |
|
185 | + } |
|
178 | 186 | session_start(); |
179 | 187 | |
180 | - if (!headers_sent()) |
|
181 | - echo '<!DOCTYPE html> |
|
188 | + if (!headers_sent()) { |
|
189 | + echo '<!DOCTYPE html> |
|
182 | 190 | <html> |
183 | 191 | <head> |
184 | 192 | <title>', htmlspecialchars($_GET['pass_string']), '</title> |
@@ -187,14 +195,16 @@ discard block |
||
187 | 195 | <strong>', htmlspecialchars($_GET['pass_string']), '</strong> |
188 | 196 | </body> |
189 | 197 | </html>'; |
198 | + } |
|
190 | 199 | exit; |
191 | 200 | } |
192 | 201 | |
193 | 202 | // Add slashes, as long as they aren't already being added. |
194 | - if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) |
|
195 | - foreach ($_POST as $k => $v) |
|
203 | + if (!function_exists('get_magic_quotes_gpc') || @get_magic_quotes_gpc() == 0) { |
|
204 | + foreach ($_POST as $k => $v) |
|
196 | 205 | if (strpos($k, 'password') === false && strpos($k, 'db_passwd') === false) |
197 | 206 | $_POST[$k] = addslashes($v); |
207 | + } |
|
198 | 208 | |
199 | 209 | // This is really quite simple; if ?delete is on the URL, delete the installer... |
200 | 210 | if (isset($_GET['delete'])) |
@@ -215,8 +225,7 @@ discard block |
||
215 | 225 | $ftp->close(); |
216 | 226 | |
217 | 227 | unset($_SESSION['installer_temp_ftp']); |
218 | - } |
|
219 | - else |
|
228 | + } else |
|
220 | 229 | { |
221 | 230 | @unlink(__FILE__); |
222 | 231 | |
@@ -237,10 +246,11 @@ discard block |
||
237 | 246 | { |
238 | 247 | // Get PHP's default timezone, if set |
239 | 248 | $ini_tz = ini_get('date.timezone'); |
240 | - if (!empty($ini_tz)) |
|
241 | - $timezone_id = $ini_tz; |
|
242 | - else |
|
243 | - $timezone_id = ''; |
|
249 | + if (!empty($ini_tz)) { |
|
250 | + $timezone_id = $ini_tz; |
|
251 | + } else { |
|
252 | + $timezone_id = ''; |
|
253 | + } |
|
244 | 254 | |
245 | 255 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
246 | 256 | if (!in_array($timezone_id, timezone_identifiers_list())) |
@@ -270,8 +280,9 @@ discard block |
||
270 | 280 | $dir = dir(dirname(__FILE__) . '/Themes/default/languages'); |
271 | 281 | while ($entry = $dir->read()) |
272 | 282 | { |
273 | - if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') |
|
274 | - $incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12)); |
|
283 | + if (substr($entry, 0, 8) == 'Install.' && substr($entry, -4) == '.php') { |
|
284 | + $incontext['detected_languages'][$entry] = ucfirst(substr($entry, 8, strlen($entry) - 12)); |
|
285 | + } |
|
275 | 286 | } |
276 | 287 | $dir->close(); |
277 | 288 | } |
@@ -306,10 +317,11 @@ discard block |
||
306 | 317 | } |
307 | 318 | |
308 | 319 | // Override the language file? |
309 | - if (isset($_GET['lang_file'])) |
|
310 | - $_SESSION['installer_temp_lang'] = $_GET['lang_file']; |
|
311 | - elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) |
|
312 | - $_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file']; |
|
320 | + if (isset($_GET['lang_file'])) { |
|
321 | + $_SESSION['installer_temp_lang'] = $_GET['lang_file']; |
|
322 | + } elseif (isset($GLOBALS['HTTP_GET_VARS']['lang_file'])) { |
|
323 | + $_SESSION['installer_temp_lang'] = $GLOBALS['HTTP_GET_VARS']['lang_file']; |
|
324 | + } |
|
313 | 325 | |
314 | 326 | // Make sure it exists, if it doesn't reset it. |
315 | 327 | if (!isset($_SESSION['installer_temp_lang']) || preg_match('~[^\\w_\\-.]~', $_SESSION['installer_temp_lang']) === 1 || !file_exists(dirname(__FILE__) . '/Themes/default/languages/' . $_SESSION['installer_temp_lang'])) |
@@ -318,8 +330,9 @@ discard block |
||
318 | 330 | list ($_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
319 | 331 | |
320 | 332 | // If we have english and some other language, use the other language. We Americans hate english :P. |
321 | - if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) |
|
322 | - list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
|
333 | + if ($_SESSION['installer_temp_lang'] == 'Install.english.php' && count($incontext['detected_languages']) > 1) { |
|
334 | + list (, $_SESSION['installer_temp_lang']) = array_keys($incontext['detected_languages']); |
|
335 | + } |
|
323 | 336 | } |
324 | 337 | |
325 | 338 | // And now include the actual language file itself. |
@@ -332,15 +345,18 @@ discard block |
||
332 | 345 | global $db_prefix, $db_connection, $sourcedir, $smcFunc, $modSettings; |
333 | 346 | global $db_server, $db_passwd, $db_type, $db_name, $db_user, $db_persist; |
334 | 347 | |
335 | - if (empty($sourcedir)) |
|
336 | - $sourcedir = dirname(__FILE__) . '/Sources'; |
|
348 | + if (empty($sourcedir)) { |
|
349 | + $sourcedir = dirname(__FILE__) . '/Sources'; |
|
350 | + } |
|
337 | 351 | |
338 | 352 | // Need this to check whether we need the database password. |
339 | 353 | require(dirname(__FILE__) . '/Settings.php'); |
340 | - if (!defined('SMF')) |
|
341 | - define('SMF', 1); |
|
342 | - if (empty($smcFunc)) |
|
343 | - $smcFunc = array(); |
|
354 | + if (!defined('SMF')) { |
|
355 | + define('SMF', 1); |
|
356 | + } |
|
357 | + if (empty($smcFunc)) { |
|
358 | + $smcFunc = array(); |
|
359 | + } |
|
344 | 360 | |
345 | 361 | $modSettings['disableQueryCheck'] = true; |
346 | 362 | |
@@ -348,8 +364,9 @@ discard block |
||
348 | 364 | if (!$db_connection) |
349 | 365 | { |
350 | 366 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
351 | - if (version_compare(PHP_VERSION, '5', '<')) |
|
352 | - require_once($sourcedir . '/Subs-Compat.php'); |
|
367 | + if (version_compare(PHP_VERSION, '5', '<')) { |
|
368 | + require_once($sourcedir . '/Subs-Compat.php'); |
|
369 | + } |
|
353 | 370 | |
354 | 371 | $db_options = array('persist' => $db_persist); |
355 | 372 | $port = ''; |
@@ -360,19 +377,20 @@ discard block |
||
360 | 377 | if ($db_type == 'mysql') |
361 | 378 | { |
362 | 379 | $port = ((int) $_POST['db_port'] == ini_get($db_type . 'default_port')) ? '' : (int) $_POST['db_port']; |
363 | - } |
|
364 | - elseif ($db_type == 'postgresql') |
|
380 | + } elseif ($db_type == 'postgresql') |
|
365 | 381 | { |
366 | 382 | // PostgreSQL doesn't have a default port setting in php.ini, so just check against the default |
367 | 383 | $port = ((int) $_POST['db_port'] == 5432) ? '' : (int) $_POST['db_port']; |
368 | 384 | } |
369 | 385 | } |
370 | 386 | |
371 | - if (!empty($port)) |
|
372 | - $db_options['port'] = $port; |
|
387 | + if (!empty($port)) { |
|
388 | + $db_options['port'] = $port; |
|
389 | + } |
|
373 | 390 | |
374 | - if (!$db_connection) |
|
375 | - $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options); |
|
391 | + if (!$db_connection) { |
|
392 | + $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options); |
|
393 | + } |
|
376 | 394 | } |
377 | 395 | } |
378 | 396 | |
@@ -400,8 +418,9 @@ discard block |
||
400 | 418 | // @todo REMOVE THIS!! |
401 | 419 | else |
402 | 420 | { |
403 | - if (function_exists('doStep' . $_GET['step'])) |
|
404 | - call_user_func('doStep' . $_GET['step']); |
|
421 | + if (function_exists('doStep' . $_GET['step'])) { |
|
422 | + call_user_func('doStep' . $_GET['step']); |
|
423 | + } |
|
405 | 424 | } |
406 | 425 | // Show the footer. |
407 | 426 | template_install_below(); |
@@ -419,8 +438,9 @@ discard block |
||
419 | 438 | $incontext['sub_template'] = 'welcome_message'; |
420 | 439 | |
421 | 440 | // Done the submission? |
422 | - if (isset($_POST['contbutt'])) |
|
423 | - return true; |
|
441 | + if (isset($_POST['contbutt'])) { |
|
442 | + return true; |
|
443 | + } |
|
424 | 444 | |
425 | 445 | // See if we think they have already installed it? |
426 | 446 | if (is_readable(dirname(__FILE__) . '/Settings.php')) |
@@ -428,14 +448,17 @@ discard block |
||
428 | 448 | $probably_installed = 0; |
429 | 449 | foreach (file(dirname(__FILE__) . '/Settings.php') as $line) |
430 | 450 | { |
431 | - if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) |
|
432 | - $probably_installed++; |
|
433 | - if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) |
|
434 | - $probably_installed++; |
|
451 | + if (preg_match('~^\$db_passwd\s=\s\'([^\']+)\';$~', $line)) { |
|
452 | + $probably_installed++; |
|
453 | + } |
|
454 | + if (preg_match('~^\$boardurl\s=\s\'([^\']+)\';~', $line) && !preg_match('~^\$boardurl\s=\s\'http://127\.0\.0\.1/smf\';~', $line)) { |
|
455 | + $probably_installed++; |
|
456 | + } |
|
435 | 457 | } |
436 | 458 | |
437 | - if ($probably_installed == 2) |
|
438 | - $incontext['warning'] = $txt['error_already_installed']; |
|
459 | + if ($probably_installed == 2) { |
|
460 | + $incontext['warning'] = $txt['error_already_installed']; |
|
461 | + } |
|
439 | 462 | } |
440 | 463 | |
441 | 464 | // Is some database support even compiled in? |
@@ -450,36 +473,43 @@ discard block |
||
450 | 473 | $databases[$key]['supported'] = false; |
451 | 474 | $notFoundSQLFile = true; |
452 | 475 | $txt['error_db_script_missing'] = sprintf($txt['error_db_script_missing'], 'install_' . $GLOBALS['db_script_version'] . '_' . $type . '.sql'); |
476 | + } else { |
|
477 | + $incontext['supported_databases'][] = $db; |
|
453 | 478 | } |
454 | - else |
|
455 | - $incontext['supported_databases'][] = $db; |
|
456 | 479 | } |
457 | 480 | } |
458 | 481 | |
459 | 482 | // Check the PHP version. |
460 | - if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>'))) |
|
461 | - $error = 'error_php_too_low'; |
|
483 | + if ((!function_exists('version_compare') || version_compare($GLOBALS['required_php_version'], PHP_VERSION, '>'))) { |
|
484 | + $error = 'error_php_too_low'; |
|
485 | + } |
|
462 | 486 | // Make sure we have a supported database |
463 | - elseif (empty($incontext['supported_databases'])) |
|
464 | - $error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing'; |
|
487 | + elseif (empty($incontext['supported_databases'])) { |
|
488 | + $error = empty($notFoundSQLFile) ? 'error_db_missing' : 'error_db_script_missing'; |
|
489 | + } |
|
465 | 490 | // How about session support? Some crazy sysadmin remove it? |
466 | - elseif (!function_exists('session_start')) |
|
467 | - $error = 'error_session_missing'; |
|
491 | + elseif (!function_exists('session_start')) { |
|
492 | + $error = 'error_session_missing'; |
|
493 | + } |
|
468 | 494 | // Make sure they uploaded all the files. |
469 | - elseif (!file_exists(dirname(__FILE__) . '/index.php')) |
|
470 | - $error = 'error_missing_files'; |
|
495 | + elseif (!file_exists(dirname(__FILE__) . '/index.php')) { |
|
496 | + $error = 'error_missing_files'; |
|
497 | + } |
|
471 | 498 | // Very simple check on the session.save_path for Windows. |
472 | 499 | // @todo Move this down later if they don't use database-driven sessions? |
473 | - elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') |
|
474 | - $error = 'error_session_save_path'; |
|
500 | + elseif (@ini_get('session.save_path') == '/tmp' && substr(__FILE__, 1, 2) == ':\\') { |
|
501 | + $error = 'error_session_save_path'; |
|
502 | + } |
|
475 | 503 | |
476 | 504 | // Since each of the three messages would look the same, anyway... |
477 | - if (isset($error)) |
|
478 | - $incontext['error'] = $txt[$error]; |
|
505 | + if (isset($error)) { |
|
506 | + $incontext['error'] = $txt[$error]; |
|
507 | + } |
|
479 | 508 | |
480 | 509 | // Mod_security blocks everything that smells funny. Let SMF handle security. |
481 | - if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) |
|
482 | - $incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again']; |
|
510 | + if (!fixModSecurity() && !isset($_GET['overmodsecurity'])) { |
|
511 | + $incontext['error'] = $txt['error_mod_security'] . '<br><br><a href="' . $installurl . '?overmodsecurity=true">' . $txt['error_message_click'] . '</a> ' . $txt['error_message_bad_try_again']; |
|
512 | + } |
|
483 | 513 | |
484 | 514 | return false; |
485 | 515 | } |
@@ -505,12 +535,14 @@ discard block |
||
505 | 535 | 'db_last_error.php', |
506 | 536 | ); |
507 | 537 | |
508 | - foreach ($incontext['detected_languages'] as $lang => $temp) |
|
509 | - $extra_files[] = 'Themes/default/languages/' . $lang; |
|
538 | + foreach ($incontext['detected_languages'] as $lang => $temp) { |
|
539 | + $extra_files[] = 'Themes/default/languages/' . $lang; |
|
540 | + } |
|
510 | 541 | |
511 | 542 | // With mod_security installed, we could attempt to fix it with .htaccess. |
512 | - if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) |
|
513 | - $writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.'; |
|
543 | + if (function_exists('apache_get_modules') && in_array('mod_security', apache_get_modules())) { |
|
544 | + $writable_files[] = file_exists(dirname(__FILE__) . '/.htaccess') ? '.htaccess' : '.'; |
|
545 | + } |
|
514 | 546 | |
515 | 547 | $failed_files = array(); |
516 | 548 | |
@@ -526,12 +558,14 @@ discard block |
||
526 | 558 | @chmod(dirname(__FILE__) . '/' . $file, 0755); |
527 | 559 | |
528 | 560 | // Well, 755 hopefully worked... if not, try 777. |
529 | - if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) |
|
530 | - $failed_files[] = $file; |
|
561 | + if (!is_writable(dirname(__FILE__) . '/' . $file) && !@chmod(dirname(__FILE__) . '/' . $file, 0777)) { |
|
562 | + $failed_files[] = $file; |
|
563 | + } |
|
531 | 564 | } |
532 | 565 | } |
533 | - foreach ($extra_files as $file) |
|
534 | - @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
566 | + foreach ($extra_files as $file) { |
|
567 | + @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
568 | + } |
|
535 | 569 | } |
536 | 570 | // Windows is trickier. Let's try opening for r+... |
537 | 571 | else |
@@ -541,30 +575,35 @@ discard block |
||
541 | 575 | foreach ($writable_files as $file) |
542 | 576 | { |
543 | 577 | // Folders can't be opened for write... but the index.php in them can ;) |
544 | - if (is_dir(dirname(__FILE__) . '/' . $file)) |
|
545 | - $file .= '/index.php'; |
|
578 | + if (is_dir(dirname(__FILE__) . '/' . $file)) { |
|
579 | + $file .= '/index.php'; |
|
580 | + } |
|
546 | 581 | |
547 | 582 | // Funny enough, chmod actually does do something on windows - it removes the read only attribute. |
548 | 583 | @chmod(dirname(__FILE__) . '/' . $file, 0777); |
549 | 584 | $fp = @fopen(dirname(__FILE__) . '/' . $file, 'r+'); |
550 | 585 | |
551 | 586 | // Hmm, okay, try just for write in that case... |
552 | - if (!is_resource($fp)) |
|
553 | - $fp = @fopen(dirname(__FILE__) . '/' . $file, 'w'); |
|
587 | + if (!is_resource($fp)) { |
|
588 | + $fp = @fopen(dirname(__FILE__) . '/' . $file, 'w'); |
|
589 | + } |
|
554 | 590 | |
555 | - if (!is_resource($fp)) |
|
556 | - $failed_files[] = $file; |
|
591 | + if (!is_resource($fp)) { |
|
592 | + $failed_files[] = $file; |
|
593 | + } |
|
557 | 594 | |
558 | 595 | @fclose($fp); |
559 | 596 | } |
560 | - foreach ($extra_files as $file) |
|
561 | - @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
597 | + foreach ($extra_files as $file) { |
|
598 | + @chmod(dirname(__FILE__) . (empty($file) ? '' : '/' . $file), 0777); |
|
599 | + } |
|
562 | 600 | } |
563 | 601 | |
564 | 602 | $failure = count($failed_files) >= 1; |
565 | 603 | |
566 | - if (!isset($_SERVER)) |
|
567 | - return !$failure; |
|
604 | + if (!isset($_SERVER)) { |
|
605 | + return !$failure; |
|
606 | + } |
|
568 | 607 | |
569 | 608 | // Put the list into context. |
570 | 609 | $incontext['failed_files'] = $failed_files; |
@@ -612,19 +651,23 @@ discard block |
||
612 | 651 | |
613 | 652 | if (!isset($ftp) || $ftp->error !== false) |
614 | 653 | { |
615 | - if (!isset($ftp)) |
|
616 | - $ftp = new ftp_connection(null); |
|
654 | + if (!isset($ftp)) { |
|
655 | + $ftp = new ftp_connection(null); |
|
656 | + } |
|
617 | 657 | // Save the error so we can mess with listing... |
618 | - elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) |
|
619 | - $incontext['ftp_errors'][] = $ftp->last_message; |
|
658 | + elseif ($ftp->error !== false && empty($incontext['ftp_errors']) && !empty($ftp->last_message)) { |
|
659 | + $incontext['ftp_errors'][] = $ftp->last_message; |
|
660 | + } |
|
620 | 661 | |
621 | 662 | list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__)); |
622 | 663 | |
623 | - if (empty($_POST['ftp_path']) && $found_path) |
|
624 | - $_POST['ftp_path'] = $detect_path; |
|
664 | + if (empty($_POST['ftp_path']) && $found_path) { |
|
665 | + $_POST['ftp_path'] = $detect_path; |
|
666 | + } |
|
625 | 667 | |
626 | - if (!isset($_POST['ftp_username'])) |
|
627 | - $_POST['ftp_username'] = $username; |
|
668 | + if (!isset($_POST['ftp_username'])) { |
|
669 | + $_POST['ftp_username'] = $username; |
|
670 | + } |
|
628 | 671 | |
629 | 672 | // Set the username etc, into context. |
630 | 673 | $incontext['ftp'] = array( |
@@ -636,8 +679,7 @@ discard block |
||
636 | 679 | ); |
637 | 680 | |
638 | 681 | return false; |
639 | - } |
|
640 | - else |
|
682 | + } else |
|
641 | 683 | { |
642 | 684 | $_SESSION['installer_temp_ftp'] = array( |
643 | 685 | 'server' => $_POST['ftp_server'], |
@@ -651,10 +693,12 @@ discard block |
||
651 | 693 | |
652 | 694 | foreach ($failed_files as $file) |
653 | 695 | { |
654 | - if (!is_writable(dirname(__FILE__) . '/' . $file)) |
|
655 | - $ftp->chmod($file, 0755); |
|
656 | - if (!is_writable(dirname(__FILE__) . '/' . $file)) |
|
657 | - $ftp->chmod($file, 0777); |
|
696 | + if (!is_writable(dirname(__FILE__) . '/' . $file)) { |
|
697 | + $ftp->chmod($file, 0755); |
|
698 | + } |
|
699 | + if (!is_writable(dirname(__FILE__) . '/' . $file)) { |
|
700 | + $ftp->chmod($file, 0777); |
|
701 | + } |
|
658 | 702 | if (!is_writable(dirname(__FILE__) . '/' . $file)) |
659 | 703 | { |
660 | 704 | $failed_files_updated[] = $file; |
@@ -710,15 +754,17 @@ discard block |
||
710 | 754 | |
711 | 755 | if (!$foundOne) |
712 | 756 | { |
713 | - if (isset($db['default_host'])) |
|
714 | - $incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost'; |
|
757 | + if (isset($db['default_host'])) { |
|
758 | + $incontext['db']['server'] = ini_get($db['default_host']) or $incontext['db']['server'] = 'localhost'; |
|
759 | + } |
|
715 | 760 | if (isset($db['default_user'])) |
716 | 761 | { |
717 | 762 | $incontext['db']['user'] = ini_get($db['default_user']); |
718 | 763 | $incontext['db']['name'] = ini_get($db['default_user']); |
719 | 764 | } |
720 | - if (isset($db['default_password'])) |
|
721 | - $incontext['db']['pass'] = ini_get($db['default_password']); |
|
765 | + if (isset($db['default_password'])) { |
|
766 | + $incontext['db']['pass'] = ini_get($db['default_password']); |
|
767 | + } |
|
722 | 768 | |
723 | 769 | // For simplicity and less confusion, leave the port blank by default |
724 | 770 | $incontext['db']['port'] = ''; |
@@ -737,10 +783,10 @@ discard block |
||
737 | 783 | $incontext['db']['server'] = $_POST['db_server']; |
738 | 784 | $incontext['db']['prefix'] = $_POST['db_prefix']; |
739 | 785 | |
740 | - if (!empty($_POST['db_port'])) |
|
741 | - $incontext['db']['port'] = $_POST['db_port']; |
|
742 | - } |
|
743 | - else |
|
786 | + if (!empty($_POST['db_port'])) { |
|
787 | + $incontext['db']['port'] = $_POST['db_port']; |
|
788 | + } |
|
789 | + } else |
|
744 | 790 | { |
745 | 791 | $incontext['db']['prefix'] = 'smf_'; |
746 | 792 | } |
@@ -776,10 +822,11 @@ discard block |
||
776 | 822 | if (!empty($_POST['db_port'])) |
777 | 823 | { |
778 | 824 | // For MySQL, we can get the "default port" from PHP. PostgreSQL has no such option though. |
779 | - if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) |
|
780 | - $vars['db_port'] = (int) $_POST['db_port']; |
|
781 | - elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) |
|
782 | - $vars['db_port'] = (int) $_POST['db_port']; |
|
825 | + if (($db_type == 'mysql' || $db_type == 'mysqli') && $_POST['db_port'] != ini_get($db_type . '.default_port')) { |
|
826 | + $vars['db_port'] = (int) $_POST['db_port']; |
|
827 | + } elseif ($db_type == 'postgresql' && $_POST['db_port'] != 5432) { |
|
828 | + $vars['db_port'] = (int) $_POST['db_port']; |
|
829 | + } |
|
783 | 830 | } |
784 | 831 | |
785 | 832 | // God I hope it saved! |
@@ -792,8 +839,9 @@ discard block |
||
792 | 839 | // Make sure it works. |
793 | 840 | require(dirname(__FILE__) . '/Settings.php'); |
794 | 841 | |
795 | - if (empty($sourcedir)) |
|
796 | - $sourcedir = dirname(__FILE__) . '/Sources'; |
|
842 | + if (empty($sourcedir)) { |
|
843 | + $sourcedir = dirname(__FILE__) . '/Sources'; |
|
844 | + } |
|
797 | 845 | |
798 | 846 | // Better find the database file! |
799 | 847 | if (!file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) |
@@ -803,18 +851,21 @@ discard block |
||
803 | 851 | } |
804 | 852 | |
805 | 853 | // Now include it for database functions! |
806 | - if (!defined('SMF')) |
|
807 | - define('SMF', 1); |
|
854 | + if (!defined('SMF')) { |
|
855 | + define('SMF', 1); |
|
856 | + } |
|
808 | 857 | |
809 | 858 | $modSettings['disableQueryCheck'] = true; |
810 | - if (empty($smcFunc)) |
|
811 | - $smcFunc = array(); |
|
859 | + if (empty($smcFunc)) { |
|
860 | + $smcFunc = array(); |
|
861 | + } |
|
812 | 862 | |
813 | 863 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
814 | 864 | |
815 | 865 | // What - running PHP4? The shame! |
816 | - if (version_compare(PHP_VERSION, '5', '<')) |
|
817 | - require_once($sourcedir . '/Subs-Compat.php'); |
|
866 | + if (version_compare(PHP_VERSION, '5', '<')) { |
|
867 | + require_once($sourcedir . '/Subs-Compat.php'); |
|
868 | + } |
|
818 | 869 | |
819 | 870 | // Attempt a connection. |
820 | 871 | $needsDB = !empty($databases[$db_type]['always_has_db']); |
@@ -902,12 +953,14 @@ discard block |
||
902 | 953 | $incontext['page_title'] = $txt['install_settings']; |
903 | 954 | |
904 | 955 | // Let's see if we got the database type correct. |
905 | - if (isset($_POST['db_type'], $databases[$_POST['db_type']])) |
|
906 | - $db_type = $_POST['db_type']; |
|
956 | + if (isset($_POST['db_type'], $databases[$_POST['db_type']])) { |
|
957 | + $db_type = $_POST['db_type']; |
|
958 | + } |
|
907 | 959 | |
908 | 960 | // Else we'd better be able to get the connection. |
909 | - else |
|
910 | - load_database(); |
|
961 | + else { |
|
962 | + load_database(); |
|
963 | + } |
|
911 | 964 | |
912 | 965 | $db_type = isset($_POST['db_type']) ? $_POST['db_type'] : $db_type; |
913 | 966 | |
@@ -927,12 +980,14 @@ discard block |
||
927 | 980 | // Submitting? |
928 | 981 | if (isset($_POST['boardurl'])) |
929 | 982 | { |
930 | - if (substr($_POST['boardurl'], -10) == '/index.php') |
|
931 | - $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10); |
|
932 | - elseif (substr($_POST['boardurl'], -1) == '/') |
|
933 | - $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1); |
|
934 | - if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') |
|
935 | - $_POST['boardurl'] = 'http://' . $_POST['boardurl']; |
|
983 | + if (substr($_POST['boardurl'], -10) == '/index.php') { |
|
984 | + $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10); |
|
985 | + } elseif (substr($_POST['boardurl'], -1) == '/') { |
|
986 | + $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1); |
|
987 | + } |
|
988 | + if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') { |
|
989 | + $_POST['boardurl'] = 'http://' . $_POST['boardurl']; |
|
990 | + } |
|
936 | 991 | |
937 | 992 | // Save these variables. |
938 | 993 | $vars = array( |
@@ -969,10 +1024,10 @@ discard block |
||
969 | 1024 | { |
970 | 1025 | $incontext['error'] = sprintf($txt['error_utf8_version'], $databases[$db_type]['utf8_version']); |
971 | 1026 | return false; |
972 | - } |
|
973 | - else |
|
974 | - // Set the character set here. |
|
1027 | + } else { |
|
1028 | + // Set the character set here. |
|
975 | 1029 | updateSettingsFile(array('db_character_set' => 'utf8')); |
1030 | + } |
|
976 | 1031 | } |
977 | 1032 | |
978 | 1033 | // Good, skip on. |
@@ -992,8 +1047,9 @@ discard block |
||
992 | 1047 | $incontext['continue'] = 1; |
993 | 1048 | |
994 | 1049 | // Already done? |
995 | - if (isset($_POST['pop_done'])) |
|
996 | - return true; |
|
1050 | + if (isset($_POST['pop_done'])) { |
|
1051 | + return true; |
|
1052 | + } |
|
997 | 1053 | |
998 | 1054 | // Reload settings. |
999 | 1055 | require(dirname(__FILE__) . '/Settings.php'); |
@@ -1011,8 +1067,9 @@ discard block |
||
1011 | 1067 | $modSettings = array(); |
1012 | 1068 | if ($result !== false) |
1013 | 1069 | { |
1014 | - while ($row = $smcFunc['db_fetch_assoc']($result)) |
|
1015 | - $modSettings[$row['variable']] = $row['value']; |
|
1070 | + while ($row = $smcFunc['db_fetch_assoc']($result)) { |
|
1071 | + $modSettings[$row['variable']] = $row['value']; |
|
1072 | + } |
|
1016 | 1073 | $smcFunc['db_free_result']($result); |
1017 | 1074 | |
1018 | 1075 | // Do they match? If so, this is just a refresh so charge on! |
@@ -1025,20 +1082,22 @@ discard block |
||
1025 | 1082 | $modSettings['disableQueryCheck'] = true; |
1026 | 1083 | |
1027 | 1084 | // If doing UTF8, select it. PostgreSQL requires passing it as a string... |
1028 | - if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) |
|
1029 | - $smcFunc['db_query']('', ' |
|
1085 | + if (!empty($db_character_set) && $db_character_set == 'utf8' && !empty($databases[$db_type]['utf8_support'])) { |
|
1086 | + $smcFunc['db_query']('', ' |
|
1030 | 1087 | SET NAMES {string:utf8}', |
1031 | 1088 | array( |
1032 | 1089 | 'db_error_skip' => true, |
1033 | 1090 | 'utf8' => 'utf8', |
1034 | 1091 | ) |
1035 | 1092 | ); |
1093 | + } |
|
1036 | 1094 | |
1037 | 1095 | // Windows likes to leave the trailing slash, which yields to C:\path\to\SMF\/attachments... |
1038 | - if (substr(__DIR__, -1) == '\\') |
|
1039 | - $attachdir = __DIR__ . 'attachments'; |
|
1040 | - else |
|
1041 | - $attachdir = __DIR__ . '/attachments'; |
|
1096 | + if (substr(__DIR__, -1) == '\\') { |
|
1097 | + $attachdir = __DIR__ . 'attachments'; |
|
1098 | + } else { |
|
1099 | + $attachdir = __DIR__ . '/attachments'; |
|
1100 | + } |
|
1042 | 1101 | |
1043 | 1102 | $replaces = array( |
1044 | 1103 | '{$db_prefix}' => $db_prefix, |
@@ -1055,8 +1114,9 @@ discard block |
||
1055 | 1114 | |
1056 | 1115 | foreach ($txt as $key => $value) |
1057 | 1116 | { |
1058 | - if (substr($key, 0, 8) == 'default_') |
|
1059 | - $replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value); |
|
1117 | + if (substr($key, 0, 8) == 'default_') { |
|
1118 | + $replaces['{$' . $key . '}'] = $smcFunc['db_escape_string']($value); |
|
1119 | + } |
|
1060 | 1120 | } |
1061 | 1121 | $replaces['{$default_reserved_names}'] = strtr($replaces['{$default_reserved_names}'], array('\\\\n' => '\\n')); |
1062 | 1122 | |
@@ -1071,8 +1131,9 @@ discard block |
||
1071 | 1131 | |
1072 | 1132 | while ($row = $smcFunc['db_fetch_assoc']($get_engines)) |
1073 | 1133 | { |
1074 | - if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') |
|
1075 | - $engines[] = $row['Engine']; |
|
1134 | + if ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT') { |
|
1135 | + $engines[] = $row['Engine']; |
|
1136 | + } |
|
1076 | 1137 | } |
1077 | 1138 | |
1078 | 1139 | // Done with this now |
@@ -1096,8 +1157,7 @@ discard block |
||
1096 | 1157 | $replaces['START TRANSACTION;'] = ''; |
1097 | 1158 | $replaces['COMMIT;'] = ''; |
1098 | 1159 | } |
1099 | - } |
|
1100 | - else |
|
1160 | + } else |
|
1101 | 1161 | { |
1102 | 1162 | $has_innodb = false; |
1103 | 1163 | } |
@@ -1119,21 +1179,24 @@ discard block |
||
1119 | 1179 | foreach ($sql_lines as $count => $line) |
1120 | 1180 | { |
1121 | 1181 | // No comments allowed! |
1122 | - if (substr(trim($line), 0, 1) != '#') |
|
1123 | - $current_statement .= "\n" . rtrim($line); |
|
1182 | + if (substr(trim($line), 0, 1) != '#') { |
|
1183 | + $current_statement .= "\n" . rtrim($line); |
|
1184 | + } |
|
1124 | 1185 | |
1125 | 1186 | // Is this the end of the query string? |
1126 | - if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) |
|
1127 | - continue; |
|
1187 | + if (empty($current_statement) || (preg_match('~;[\s]*$~s', $line) == 0 && $count != count($sql_lines))) { |
|
1188 | + continue; |
|
1189 | + } |
|
1128 | 1190 | |
1129 | 1191 | // Does this table already exist? If so, don't insert more data into it! |
1130 | 1192 | if (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) != 0 && in_array($match[1], $exists)) |
1131 | 1193 | { |
1132 | 1194 | preg_match_all('~\)[,;]~', $current_statement, $matches); |
1133 | - if (!empty($matches[0])) |
|
1134 | - $incontext['sql_results']['insert_dups'] += count($matches[0]); |
|
1135 | - else |
|
1136 | - $incontext['sql_results']['insert_dups']++; |
|
1195 | + if (!empty($matches[0])) { |
|
1196 | + $incontext['sql_results']['insert_dups'] += count($matches[0]); |
|
1197 | + } else { |
|
1198 | + $incontext['sql_results']['insert_dups']++; |
|
1199 | + } |
|
1137 | 1200 | |
1138 | 1201 | $current_statement = ''; |
1139 | 1202 | continue; |
@@ -1142,8 +1205,9 @@ discard block |
||
1142 | 1205 | if ($smcFunc['db_query']('', $current_statement, array('security_override' => true, 'db_error_skip' => true), $db_connection) === false) |
1143 | 1206 | { |
1144 | 1207 | // Use the appropriate function based on the DB type |
1145 | - if ($db_type == 'mysql' || $db_type == 'mysqli') |
|
1146 | - $db_errorno = $db_type . '_errno'; |
|
1208 | + if ($db_type == 'mysql' || $db_type == 'mysqli') { |
|
1209 | + $db_errorno = $db_type . '_errno'; |
|
1210 | + } |
|
1147 | 1211 | |
1148 | 1212 | // Error 1050: Table already exists! |
1149 | 1213 | // @todo Needs to be made better! |
@@ -1158,18 +1222,18 @@ discard block |
||
1158 | 1222 | // MySQLi requires a connection object. It's optional with MySQL and Postgres |
1159 | 1223 | $incontext['failures'][$count] = $smcFunc['db_error']($db_connection); |
1160 | 1224 | } |
1161 | - } |
|
1162 | - else |
|
1225 | + } else |
|
1163 | 1226 | { |
1164 | - if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) |
|
1165 | - $incontext['sql_results']['tables']++; |
|
1166 | - elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1) |
|
1227 | + if (preg_match('~^\s*CREATE TABLE ([^\s\n\r]+?)~', $current_statement, $match) == 1) { |
|
1228 | + $incontext['sql_results']['tables']++; |
|
1229 | + } elseif (preg_match('~^\s*INSERT INTO ([^\s\n\r]+?)~', $current_statement, $match) == 1) |
|
1167 | 1230 | { |
1168 | 1231 | preg_match_all('~\)[,;]~', $current_statement, $matches); |
1169 | - if (!empty($matches[0])) |
|
1170 | - $incontext['sql_results']['inserts'] += count($matches[0]); |
|
1171 | - else |
|
1172 | - $incontext['sql_results']['inserts']++; |
|
1232 | + if (!empty($matches[0])) { |
|
1233 | + $incontext['sql_results']['inserts'] += count($matches[0]); |
|
1234 | + } else { |
|
1235 | + $incontext['sql_results']['inserts']++; |
|
1236 | + } |
|
1173 | 1237 | } |
1174 | 1238 | } |
1175 | 1239 | |
@@ -1182,15 +1246,17 @@ discard block |
||
1182 | 1246 | // Sort out the context for the SQL. |
1183 | 1247 | foreach ($incontext['sql_results'] as $key => $number) |
1184 | 1248 | { |
1185 | - if ($number == 0) |
|
1186 | - unset($incontext['sql_results'][$key]); |
|
1187 | - else |
|
1188 | - $incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number); |
|
1249 | + if ($number == 0) { |
|
1250 | + unset($incontext['sql_results'][$key]); |
|
1251 | + } else { |
|
1252 | + $incontext['sql_results'][$key] = sprintf($txt['db_populate_' . $key], $number); |
|
1253 | + } |
|
1189 | 1254 | } |
1190 | 1255 | |
1191 | 1256 | // Make sure UTF will be used globally. |
1192 | - if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) |
|
1193 | - $newSettings[] = array('global_character_set', 'UTF-8'); |
|
1257 | + if ((!empty($databases[$db_type]['utf8_support']) && !empty($databases[$db_type]['utf8_required'])) || (empty($databases[$db_type]['utf8_required']) && !empty($databases[$db_type]['utf8_support']) && isset($_POST['utf8']))) { |
|
1258 | + $newSettings[] = array('global_character_set', 'UTF-8'); |
|
1259 | + } |
|
1194 | 1260 | |
1195 | 1261 | // Maybe we can auto-detect better cookie settings? |
1196 | 1262 | preg_match('~^http[s]?://([^\.]+?)([^/]*?)(/.*)?$~', $boardurl, $matches); |
@@ -1201,16 +1267,20 @@ discard block |
||
1201 | 1267 | $globalCookies = false; |
1202 | 1268 | |
1203 | 1269 | // Okay... let's see. Using a subdomain other than www.? (not a perfect check.) |
1204 | - if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www')))) |
|
1205 | - $globalCookies = true; |
|
1270 | + if ($matches[2] != '' && (strpos(substr($matches[2], 1), '.') === false || in_array($matches[1], array('forum', 'board', 'community', 'forums', 'support', 'chat', 'help', 'talk', 'boards', 'www')))) { |
|
1271 | + $globalCookies = true; |
|
1272 | + } |
|
1206 | 1273 | // If there's a / in the middle of the path, or it starts with ~... we want local. |
1207 | - if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false)) |
|
1208 | - $localCookies = true; |
|
1274 | + if (isset($matches[3]) && strlen($matches[3]) > 3 && (substr($matches[3], 0, 2) == '/~' || strpos(substr($matches[3], 1), '/') !== false)) { |
|
1275 | + $localCookies = true; |
|
1276 | + } |
|
1209 | 1277 | |
1210 | - if ($globalCookies) |
|
1211 | - $newSettings[] = array('globalCookies', '1'); |
|
1212 | - if ($localCookies) |
|
1213 | - $newSettings[] = array('localCookies', '1'); |
|
1278 | + if ($globalCookies) { |
|
1279 | + $newSettings[] = array('globalCookies', '1'); |
|
1280 | + } |
|
1281 | + if ($localCookies) { |
|
1282 | + $newSettings[] = array('localCookies', '1'); |
|
1283 | + } |
|
1214 | 1284 | } |
1215 | 1285 | |
1216 | 1286 | // Are we allowing stat collection? |
@@ -1226,32 +1296,36 @@ discard block |
||
1226 | 1296 | fwrite($fp, $out); |
1227 | 1297 | |
1228 | 1298 | $return_data = ''; |
1229 | - while (!feof($fp)) |
|
1230 | - $return_data .= fgets($fp, 128); |
|
1299 | + while (!feof($fp)) { |
|
1300 | + $return_data .= fgets($fp, 128); |
|
1301 | + } |
|
1231 | 1302 | |
1232 | 1303 | fclose($fp); |
1233 | 1304 | |
1234 | 1305 | // Get the unique site ID. |
1235 | 1306 | preg_match('~SITE-ID:\s(\w{10})~', $return_data, $ID); |
1236 | 1307 | |
1237 | - if (!empty($ID[1])) |
|
1238 | - $newSettings[] = array('allow_sm_stats', $ID[1]); |
|
1308 | + if (!empty($ID[1])) { |
|
1309 | + $newSettings[] = array('allow_sm_stats', $ID[1]); |
|
1310 | + } |
|
1239 | 1311 | } |
1240 | 1312 | } |
1241 | 1313 | |
1242 | 1314 | // Are we enabling SSL? |
1243 | - if (!empty($_POST['force_ssl'])) |
|
1244 | - $newSettings[] = array('force_ssl', 2); |
|
1315 | + if (!empty($_POST['force_ssl'])) { |
|
1316 | + $newSettings[] = array('force_ssl', 2); |
|
1317 | + } |
|
1245 | 1318 | |
1246 | 1319 | // Setting a timezone is required. |
1247 | 1320 | if (!isset($modSettings['default_timezone']) && function_exists('date_default_timezone_set')) |
1248 | 1321 | { |
1249 | 1322 | // Get PHP's default timezone, if set |
1250 | 1323 | $ini_tz = ini_get('date.timezone'); |
1251 | - if (!empty($ini_tz)) |
|
1252 | - $timezone_id = $ini_tz; |
|
1253 | - else |
|
1254 | - $timezone_id = ''; |
|
1324 | + if (!empty($ini_tz)) { |
|
1325 | + $timezone_id = $ini_tz; |
|
1326 | + } else { |
|
1327 | + $timezone_id = ''; |
|
1328 | + } |
|
1255 | 1329 | |
1256 | 1330 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
1257 | 1331 | if (!in_array($timezone_id, timezone_identifiers_list())) |
@@ -1260,8 +1334,9 @@ discard block |
||
1260 | 1334 | $timezone_id = timezone_name_from_abbr('', $server_offset, 0); |
1261 | 1335 | } |
1262 | 1336 | |
1263 | - if (date_default_timezone_set($timezone_id)) |
|
1264 | - $newSettings[] = array('default_timezone', $timezone_id); |
|
1337 | + if (date_default_timezone_set($timezone_id)) { |
|
1338 | + $newSettings[] = array('default_timezone', $timezone_id); |
|
1339 | + } |
|
1265 | 1340 | } |
1266 | 1341 | |
1267 | 1342 | if (!empty($newSettings)) |
@@ -1292,16 +1367,18 @@ discard block |
||
1292 | 1367 | } |
1293 | 1368 | |
1294 | 1369 | // MySQL specific stuff |
1295 | - if (substr($db_type, 0, 5) != 'mysql') |
|
1296 | - return false; |
|
1370 | + if (substr($db_type, 0, 5) != 'mysql') { |
|
1371 | + return false; |
|
1372 | + } |
|
1297 | 1373 | |
1298 | 1374 | // Find database user privileges. |
1299 | 1375 | $privs = array(); |
1300 | 1376 | $get_privs = $smcFunc['db_query']('', 'SHOW PRIVILEGES', array()); |
1301 | 1377 | while ($row = $smcFunc['db_fetch_assoc']($get_privs)) |
1302 | 1378 | { |
1303 | - if ($row['Privilege'] == 'Alter') |
|
1304 | - $privs[] = $row['Privilege']; |
|
1379 | + if ($row['Privilege'] == 'Alter') { |
|
1380 | + $privs[] = $row['Privilege']; |
|
1381 | + } |
|
1305 | 1382 | } |
1306 | 1383 | $smcFunc['db_free_result']($get_privs); |
1307 | 1384 | |
@@ -1331,8 +1408,9 @@ discard block |
||
1331 | 1408 | $incontext['continue'] = 1; |
1332 | 1409 | |
1333 | 1410 | // Skipping? |
1334 | - if (!empty($_POST['skip'])) |
|
1335 | - return true; |
|
1411 | + if (!empty($_POST['skip'])) { |
|
1412 | + return true; |
|
1413 | + } |
|
1336 | 1414 | |
1337 | 1415 | // Need this to check whether we need the database password. |
1338 | 1416 | require(dirname(__FILE__) . '/Settings.php'); |
@@ -1345,18 +1423,22 @@ discard block |
||
1345 | 1423 | // We need this to properly hash the password for Admin |
1346 | 1424 | $smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : function($string) { |
1347 | 1425 | global $sourcedir; |
1348 | - if (function_exists('mb_strtolower')) |
|
1349 | - return mb_strtolower($string, 'UTF-8'); |
|
1426 | + if (function_exists('mb_strtolower')) { |
|
1427 | + return mb_strtolower($string, 'UTF-8'); |
|
1428 | + } |
|
1350 | 1429 | require_once($sourcedir . '/Subs-Charset.php'); |
1351 | 1430 | return utf8_strtolower($string); |
1352 | 1431 | }; |
1353 | 1432 | |
1354 | - if (!isset($_POST['username'])) |
|
1355 | - $_POST['username'] = ''; |
|
1356 | - if (!isset($_POST['email'])) |
|
1357 | - $_POST['email'] = ''; |
|
1358 | - if (!isset($_POST['server_email'])) |
|
1359 | - $_POST['server_email'] = ''; |
|
1433 | + if (!isset($_POST['username'])) { |
|
1434 | + $_POST['username'] = ''; |
|
1435 | + } |
|
1436 | + if (!isset($_POST['email'])) { |
|
1437 | + $_POST['email'] = ''; |
|
1438 | + } |
|
1439 | + if (!isset($_POST['server_email'])) { |
|
1440 | + $_POST['server_email'] = ''; |
|
1441 | + } |
|
1360 | 1442 | |
1361 | 1443 | $incontext['username'] = htmlspecialchars(stripslashes($_POST['username'])); |
1362 | 1444 | $incontext['email'] = htmlspecialchars(stripslashes($_POST['email'])); |
@@ -1375,8 +1457,9 @@ discard block |
||
1375 | 1457 | 'admin_group' => 1, |
1376 | 1458 | ) |
1377 | 1459 | ); |
1378 | - if ($smcFunc['db_num_rows']($request) != 0) |
|
1379 | - $incontext['skip'] = 1; |
|
1460 | + if ($smcFunc['db_num_rows']($request) != 0) { |
|
1461 | + $incontext['skip'] = 1; |
|
1462 | + } |
|
1380 | 1463 | $smcFunc['db_free_result']($request); |
1381 | 1464 | |
1382 | 1465 | // Trying to create an account? |
@@ -1407,8 +1490,9 @@ discard block |
||
1407 | 1490 | } |
1408 | 1491 | |
1409 | 1492 | // Update the webmaster's email? |
1410 | - if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) |
|
1411 | - updateSettingsFile(array('webmaster_email' => $_POST['server_email'])); |
|
1493 | + if (!empty($_POST['server_email']) && (empty($webmaster_email) || $webmaster_email == '[email protected]')) { |
|
1494 | + updateSettingsFile(array('webmaster_email' => $_POST['server_email'])); |
|
1495 | + } |
|
1412 | 1496 | |
1413 | 1497 | // Work out whether we're going to have dodgy characters and remove them. |
1414 | 1498 | $invalid_characters = preg_match('~[<>&"\'=\\\]~', $_POST['username']) != 0; |
@@ -1431,32 +1515,27 @@ discard block |
||
1431 | 1515 | $smcFunc['db_free_result']($result); |
1432 | 1516 | |
1433 | 1517 | $incontext['account_existed'] = $txt['error_user_settings_taken']; |
1434 | - } |
|
1435 | - elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25) |
|
1518 | + } elseif ($_POST['username'] == '' || strlen($_POST['username']) > 25) |
|
1436 | 1519 | { |
1437 | 1520 | // Try the previous step again. |
1438 | 1521 | $incontext['error'] = $_POST['username'] == '' ? $txt['error_username_left_empty'] : $txt['error_username_too_long']; |
1439 | 1522 | return false; |
1440 | - } |
|
1441 | - elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false) |
|
1523 | + } elseif ($invalid_characters || $_POST['username'] == '_' || $_POST['username'] == '|' || strpos($_POST['username'], '[code') !== false || strpos($_POST['username'], '[/code') !== false) |
|
1442 | 1524 | { |
1443 | 1525 | // Try the previous step again. |
1444 | 1526 | $incontext['error'] = $txt['error_invalid_characters_username']; |
1445 | 1527 | return false; |
1446 | - } |
|
1447 | - elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255) |
|
1528 | + } elseif (empty($_POST['email']) || !filter_var(stripslashes($_POST['email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['email'])) > 255) |
|
1448 | 1529 | { |
1449 | 1530 | // One step back, this time fill out a proper admin email address. |
1450 | 1531 | $incontext['error'] = sprintf($txt['error_valid_admin_email_needed'], $_POST['username']); |
1451 | 1532 | return false; |
1452 | - } |
|
1453 | - elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255) |
|
1533 | + } elseif (empty($_POST['server_email']) || !filter_var(stripslashes($_POST['server_email']), FILTER_VALIDATE_EMAIL) || strlen(stripslashes($_POST['server_email'])) > 255) |
|
1454 | 1534 | { |
1455 | 1535 | // One step back, this time fill out a proper admin email address. |
1456 | 1536 | $incontext['error'] = $txt['error_valid_server_email_needed']; |
1457 | 1537 | return false; |
1458 | - } |
|
1459 | - elseif ($_POST['username'] != '') |
|
1538 | + } elseif ($_POST['username'] != '') |
|
1460 | 1539 | { |
1461 | 1540 | $incontext['member_salt'] = substr(md5(mt_rand()), 0, 4); |
1462 | 1541 | |
@@ -1521,17 +1600,19 @@ discard block |
||
1521 | 1600 | require_once($sourcedir . '/Subs-Auth.php'); |
1522 | 1601 | |
1523 | 1602 | // Bring a warning over. |
1524 | - if (!empty($incontext['account_existed'])) |
|
1525 | - $incontext['warning'] = $incontext['account_existed']; |
|
1603 | + if (!empty($incontext['account_existed'])) { |
|
1604 | + $incontext['warning'] = $incontext['account_existed']; |
|
1605 | + } |
|
1526 | 1606 | |
1527 | - if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) |
|
1528 | - $smcFunc['db_query']('', ' |
|
1607 | + if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) { |
|
1608 | + $smcFunc['db_query']('', ' |
|
1529 | 1609 | SET NAMES {string:db_character_set}', |
1530 | 1610 | array( |
1531 | 1611 | 'db_character_set' => $db_character_set, |
1532 | 1612 | 'db_error_skip' => true, |
1533 | 1613 | ) |
1534 | 1614 | ); |
1615 | + } |
|
1535 | 1616 | |
1536 | 1617 | // As track stats is by default enabled let's add some activity. |
1537 | 1618 | $smcFunc['db_insert']('ignore', |
@@ -1552,14 +1633,16 @@ discard block |
||
1552 | 1633 | // Only proceed if we can load the data. |
1553 | 1634 | if ($request) |
1554 | 1635 | { |
1555 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
1556 | - $modSettings[$row[0]] = $row[1]; |
|
1636 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
1637 | + $modSettings[$row[0]] = $row[1]; |
|
1638 | + } |
|
1557 | 1639 | $smcFunc['db_free_result']($request); |
1558 | 1640 | } |
1559 | 1641 | |
1560 | 1642 | // Automatically log them in ;) |
1561 | - if (isset($incontext['member_id']) && isset($incontext['member_salt'])) |
|
1562 | - setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt'])); |
|
1643 | + if (isset($incontext['member_id']) && isset($incontext['member_salt'])) { |
|
1644 | + setLoginCookie(3153600 * 60, $incontext['member_id'], hash_salt($_POST['password1'], $incontext['member_salt'])); |
|
1645 | + } |
|
1563 | 1646 | |
1564 | 1647 | $result = $smcFunc['db_query']('', ' |
1565 | 1648 | SELECT value |
@@ -1570,13 +1653,14 @@ discard block |
||
1570 | 1653 | 'db_error_skip' => true, |
1571 | 1654 | ) |
1572 | 1655 | ); |
1573 | - if ($smcFunc['db_num_rows']($result) != 0) |
|
1574 | - list ($db_sessions) = $smcFunc['db_fetch_row']($result); |
|
1656 | + if ($smcFunc['db_num_rows']($result) != 0) { |
|
1657 | + list ($db_sessions) = $smcFunc['db_fetch_row']($result); |
|
1658 | + } |
|
1575 | 1659 | $smcFunc['db_free_result']($result); |
1576 | 1660 | |
1577 | - if (empty($db_sessions)) |
|
1578 | - $_SESSION['admin_time'] = time(); |
|
1579 | - else |
|
1661 | + if (empty($db_sessions)) { |
|
1662 | + $_SESSION['admin_time'] = time(); |
|
1663 | + } else |
|
1580 | 1664 | { |
1581 | 1665 | $_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211); |
1582 | 1666 | |
@@ -1600,8 +1684,9 @@ discard block |
||
1600 | 1684 | $smcFunc['strtolower'] = $db_character_set != 'utf8' && $txt['lang_character_set'] != 'UTF-8' ? 'strtolower' : |
1601 | 1685 | function($string){ |
1602 | 1686 | global $sourcedir; |
1603 | - if (function_exists('mb_strtolower')) |
|
1604 | - return mb_strtolower($string, 'UTF-8'); |
|
1687 | + if (function_exists('mb_strtolower')) { |
|
1688 | + return mb_strtolower($string, 'UTF-8'); |
|
1689 | + } |
|
1605 | 1690 | require_once($sourcedir . '/Subs-Charset.php'); |
1606 | 1691 | return utf8_strtolower($string); |
1607 | 1692 | }; |
@@ -1617,8 +1702,9 @@ discard block |
||
1617 | 1702 | ) |
1618 | 1703 | ); |
1619 | 1704 | $context['utf8'] = $db_character_set === 'utf8' || $txt['lang_character_set'] === 'UTF-8'; |
1620 | - if ($smcFunc['db_num_rows']($request) > 0) |
|
1621 | - updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject'])); |
|
1705 | + if ($smcFunc['db_num_rows']($request) > 0) { |
|
1706 | + updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject'])); |
|
1707 | + } |
|
1622 | 1708 | $smcFunc['db_free_result']($request); |
1623 | 1709 | |
1624 | 1710 | // Now is the perfect time to fetch the SM files. |
@@ -1637,8 +1723,9 @@ discard block |
||
1637 | 1723 | |
1638 | 1724 | // Check if we need some stupid MySQL fix. |
1639 | 1725 | $server_version = $smcFunc['db_server_info'](); |
1640 | - if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) |
|
1641 | - updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
1726 | + if (($db_type == 'mysql' || $db_type == 'mysqli') && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) { |
|
1727 | + updateSettings(array('db_mysql_group_by_fix' => '1')); |
|
1728 | + } |
|
1642 | 1729 | |
1643 | 1730 | // Some final context for the template. |
1644 | 1731 | $incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\'; |
@@ -1658,8 +1745,9 @@ discard block |
||
1658 | 1745 | $settingsArray = file(dirname(__FILE__) . '/Settings.php'); |
1659 | 1746 | |
1660 | 1747 | // @todo Do we just want to read the file in clean, and split it this way always? |
1661 | - if (count($settingsArray) == 1) |
|
1662 | - $settingsArray = preg_split('~[\r\n]~', $settingsArray[0]); |
|
1748 | + if (count($settingsArray) == 1) { |
|
1749 | + $settingsArray = preg_split('~[\r\n]~', $settingsArray[0]); |
|
1750 | + } |
|
1663 | 1751 | |
1664 | 1752 | for ($i = 0, $n = count($settingsArray); $i < $n; $i++) |
1665 | 1753 | { |
@@ -1674,19 +1762,22 @@ discard block |
||
1674 | 1762 | continue; |
1675 | 1763 | } |
1676 | 1764 | |
1677 | - if (trim($settingsArray[$i]) == '?' . '>') |
|
1678 | - $settingsArray[$i] = ''; |
|
1765 | + if (trim($settingsArray[$i]) == '?' . '>') { |
|
1766 | + $settingsArray[$i] = ''; |
|
1767 | + } |
|
1679 | 1768 | |
1680 | 1769 | // Don't trim or bother with it if it's not a variable. |
1681 | - if (substr($settingsArray[$i], 0, 1) != '$') |
|
1682 | - continue; |
|
1770 | + if (substr($settingsArray[$i], 0, 1) != '$') { |
|
1771 | + continue; |
|
1772 | + } |
|
1683 | 1773 | |
1684 | 1774 | $settingsArray[$i] = rtrim($settingsArray[$i]) . "\n"; |
1685 | 1775 | |
1686 | - foreach ($vars as $var => $val) |
|
1687 | - if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) |
|
1776 | + foreach ($vars as $var => $val) { |
|
1777 | + if (strncasecmp($settingsArray[$i], '$' . $var, 1 + strlen($var)) == 0) |
|
1688 | 1778 | { |
1689 | 1779 | $comment = strstr($settingsArray[$i], '#'); |
1780 | + } |
|
1690 | 1781 | $settingsArray[$i] = '$' . $var . ' = \'' . $val . '\';' . ($comment != '' ? "\t\t" . $comment : "\n"); |
1691 | 1782 | unset($vars[$var]); |
1692 | 1783 | } |
@@ -1696,36 +1787,41 @@ discard block |
||
1696 | 1787 | if (!empty($vars)) |
1697 | 1788 | { |
1698 | 1789 | $settingsArray[$i++] = ''; |
1699 | - foreach ($vars as $var => $val) |
|
1700 | - $settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n"; |
|
1790 | + foreach ($vars as $var => $val) { |
|
1791 | + $settingsArray[$i++] = '$' . $var . ' = \'' . $val . '\';' . "\n"; |
|
1792 | + } |
|
1701 | 1793 | } |
1702 | 1794 | |
1703 | 1795 | // Blank out the file - done to fix a oddity with some servers. |
1704 | 1796 | $fp = @fopen(dirname(__FILE__) . '/Settings.php', 'w'); |
1705 | - if (!$fp) |
|
1706 | - return false; |
|
1797 | + if (!$fp) { |
|
1798 | + return false; |
|
1799 | + } |
|
1707 | 1800 | fclose($fp); |
1708 | 1801 | |
1709 | 1802 | $fp = fopen(dirname(__FILE__) . '/Settings.php', 'r+'); |
1710 | 1803 | |
1711 | 1804 | // Gotta have one of these ;) |
1712 | - if (trim($settingsArray[0]) != '<?php') |
|
1713 | - fwrite($fp, "<?php\n"); |
|
1805 | + if (trim($settingsArray[0]) != '<?php') { |
|
1806 | + fwrite($fp, "<?php\n"); |
|
1807 | + } |
|
1714 | 1808 | |
1715 | 1809 | $lines = count($settingsArray); |
1716 | 1810 | for ($i = 0; $i < $lines - 1; $i++) |
1717 | 1811 | { |
1718 | 1812 | // Don't just write a bunch of blank lines. |
1719 | - if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') |
|
1720 | - fwrite($fp, strtr($settingsArray[$i], "\r", '')); |
|
1813 | + if ($settingsArray[$i] != '' || @$settingsArray[$i - 1] != '') { |
|
1814 | + fwrite($fp, strtr($settingsArray[$i], "\r", '')); |
|
1815 | + } |
|
1721 | 1816 | } |
1722 | 1817 | fwrite($fp, $settingsArray[$i] . '?' . '>'); |
1723 | 1818 | fclose($fp); |
1724 | 1819 | |
1725 | 1820 | // Even though on normal installations the filemtime should prevent this being used by the installer incorrectly |
1726 | 1821 | // it seems that there are times it might not. So let's MAKE it dump the cache. |
1727 | - if (function_exists('opcache_invalidate')) |
|
1728 | - opcache_invalidate(dirname(__FILE__) . '/Settings.php', true); |
|
1822 | + if (function_exists('opcache_invalidate')) { |
|
1823 | + opcache_invalidate(dirname(__FILE__) . '/Settings.php', true); |
|
1824 | + } |
|
1729 | 1825 | |
1730 | 1826 | return true; |
1731 | 1827 | } |
@@ -1750,9 +1846,9 @@ discard block |
||
1750 | 1846 | SecFilterScanPOST Off |
1751 | 1847 | </IfModule>'; |
1752 | 1848 | |
1753 | - if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) |
|
1754 | - return true; |
|
1755 | - elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess')) |
|
1849 | + if (!function_exists('apache_get_modules') || !in_array('mod_security', apache_get_modules())) { |
|
1850 | + return true; |
|
1851 | + } elseif (file_exists(dirname(__FILE__) . '/.htaccess') && is_writable(dirname(__FILE__) . '/.htaccess')) |
|
1756 | 1852 | { |
1757 | 1853 | $current_htaccess = implode('', file(dirname(__FILE__) . '/.htaccess')); |
1758 | 1854 | |
@@ -1764,29 +1860,28 @@ discard block |
||
1764 | 1860 | fwrite($ht_handle, $htaccess_addition); |
1765 | 1861 | fclose($ht_handle); |
1766 | 1862 | return true; |
1863 | + } else { |
|
1864 | + return false; |
|
1767 | 1865 | } |
1768 | - else |
|
1769 | - return false; |
|
1866 | + } else { |
|
1867 | + return true; |
|
1770 | 1868 | } |
1771 | - else |
|
1772 | - return true; |
|
1773 | - } |
|
1774 | - elseif (file_exists(dirname(__FILE__) . '/.htaccess')) |
|
1775 | - return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false; |
|
1776 | - elseif (is_writable(dirname(__FILE__))) |
|
1869 | + } elseif (file_exists(dirname(__FILE__) . '/.htaccess')) { |
|
1870 | + return strpos(implode('', file(dirname(__FILE__) . '/.htaccess')), '<IfModule mod_security.c>') !== false; |
|
1871 | + } elseif (is_writable(dirname(__FILE__))) |
|
1777 | 1872 | { |
1778 | 1873 | if ($ht_handle = fopen(dirname(__FILE__) . '/.htaccess', 'w')) |
1779 | 1874 | { |
1780 | 1875 | fwrite($ht_handle, $htaccess_addition); |
1781 | 1876 | fclose($ht_handle); |
1782 | 1877 | return true; |
1878 | + } else { |
|
1879 | + return false; |
|
1783 | 1880 | } |
1784 | - else |
|
1881 | + } else { |
|
1785 | 1882 | return false; |
1786 | 1883 | } |
1787 | - else |
|
1788 | - return false; |
|
1789 | -} |
|
1884 | + } |
|
1790 | 1885 | |
1791 | 1886 | function template_install_above() |
1792 | 1887 | { |
@@ -1824,9 +1919,10 @@ discard block |
||
1824 | 1919 | <label for="installer_language">', $txt['installer_language'], ':</label> |
1825 | 1920 | <select id="installer_language" name="lang_file" onchange="location.href = \'', $installurl, '?lang_file=\' + this.options[this.selectedIndex].value;">'; |
1826 | 1921 | |
1827 | - foreach ($incontext['detected_languages'] as $lang => $name) |
|
1828 | - echo ' |
|
1922 | + foreach ($incontext['detected_languages'] as $lang => $name) { |
|
1923 | + echo ' |
|
1829 | 1924 | <option', isset($_SESSION['installer_temp_lang']) && $_SESSION['installer_temp_lang'] == $lang ? ' selected' : '', ' value="', $lang, '">', $name, '</option>'; |
1925 | + } |
|
1830 | 1926 | |
1831 | 1927 | echo ' |
1832 | 1928 | </select> |
@@ -1846,9 +1942,10 @@ discard block |
||
1846 | 1942 | <h2>', $txt['upgrade_progress'], '</h2> |
1847 | 1943 | <ul>'; |
1848 | 1944 | |
1849 | - foreach ($incontext['steps'] as $num => $step) |
|
1850 | - echo ' |
|
1945 | + foreach ($incontext['steps'] as $num => $step) { |
|
1946 | + echo ' |
|
1851 | 1947 | <li class="', $num < $incontext['current_step'] ? 'stepdone' : ($num == $incontext['current_step'] ? 'stepcurrent' : 'stepwaiting'), '">', $txt['upgrade_step'], ' ', $step[0], ': ', $step[1], '</li>'; |
1948 | + } |
|
1852 | 1949 | |
1853 | 1950 | echo ' |
1854 | 1951 | </ul> |
@@ -1873,20 +1970,23 @@ discard block |
||
1873 | 1970 | echo ' |
1874 | 1971 | <div>'; |
1875 | 1972 | |
1876 | - if (!empty($incontext['continue'])) |
|
1877 | - echo ' |
|
1973 | + if (!empty($incontext['continue'])) { |
|
1974 | + echo ' |
|
1878 | 1975 | <input type="submit" id="contbutt" name="contbutt" value="', $txt['upgrade_continue'], '" onclick="return submitThisOnce(this);" class="button_submit" />'; |
1879 | - if (!empty($incontext['skip'])) |
|
1880 | - echo ' |
|
1976 | + } |
|
1977 | + if (!empty($incontext['skip'])) { |
|
1978 | + echo ' |
|
1881 | 1979 | <input type="submit" id="skip" name="skip" value="', $txt['upgrade_skip'], '" onclick="return submitThisOnce(this);" class="button_submit" />'; |
1980 | + } |
|
1882 | 1981 | echo ' |
1883 | 1982 | </div>'; |
1884 | 1983 | } |
1885 | 1984 | |
1886 | 1985 | // Show the closing form tag and other data only if not in the last step |
1887 | - if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) |
|
1888 | - echo ' |
|
1986 | + if (count($incontext['steps']) - 1 !== (int) $incontext['current_step']) { |
|
1987 | + echo ' |
|
1889 | 1988 | </form>'; |
1989 | + } |
|
1890 | 1990 | |
1891 | 1991 | echo ' |
1892 | 1992 | </div> |
@@ -1921,13 +2021,15 @@ discard block |
||
1921 | 2021 | </div>'; |
1922 | 2022 | |
1923 | 2023 | // Show the warnings, or not. |
1924 | - if (template_warning_divs()) |
|
1925 | - echo ' |
|
2024 | + if (template_warning_divs()) { |
|
2025 | + echo ' |
|
1926 | 2026 | <h3>', $txt['install_all_lovely'], '</h3>'; |
2027 | + } |
|
1927 | 2028 | |
1928 | 2029 | // Say we want the continue button! |
1929 | - if (empty($incontext['error'])) |
|
1930 | - $incontext['continue'] = 1; |
|
2030 | + if (empty($incontext['error'])) { |
|
2031 | + $incontext['continue'] = 1; |
|
2032 | + } |
|
1931 | 2033 | |
1932 | 2034 | // For the latest version stuff. |
1933 | 2035 | echo ' |
@@ -1961,8 +2063,8 @@ discard block |
||
1961 | 2063 | global $txt, $incontext; |
1962 | 2064 | |
1963 | 2065 | // Errors are very serious.. |
1964 | - if (!empty($incontext['error'])) |
|
1965 | - echo ' |
|
2066 | + if (!empty($incontext['error'])) { |
|
2067 | + echo ' |
|
1966 | 2068 | <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
1967 | 2069 | <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div> |
1968 | 2070 | <strong style="text-decoration: underline;">', $txt['upgrade_critical_error'], '</strong><br> |
@@ -1970,9 +2072,10 @@ discard block |
||
1970 | 2072 | ', $incontext['error'], ' |
1971 | 2073 | </div> |
1972 | 2074 | </div>'; |
2075 | + } |
|
1973 | 2076 | // A warning message? |
1974 | - elseif (!empty($incontext['warning'])) |
|
1975 | - echo ' |
|
2077 | + elseif (!empty($incontext['warning'])) { |
|
2078 | + echo ' |
|
1976 | 2079 | <div style="margin: 2ex; padding: 2ex; border: 2px dashed #cc3344; color: black; background-color: #ffe4e9;"> |
1977 | 2080 | <div style="float: left; width: 2ex; font-size: 2em; color: red;">!!</div> |
1978 | 2081 | <strong style="text-decoration: underline;">', $txt['upgrade_warning'], '</strong><br> |
@@ -1980,6 +2083,7 @@ discard block |
||
1980 | 2083 | ', $incontext['warning'], ' |
1981 | 2084 | </div> |
1982 | 2085 | </div>'; |
2086 | + } |
|
1983 | 2087 | |
1984 | 2088 | return empty($incontext['error']) && empty($incontext['warning']); |
1985 | 2089 | } |
@@ -1995,27 +2099,30 @@ discard block |
||
1995 | 2099 | <li>', $incontext['failed_files']), '</li> |
1996 | 2100 | </ul>'; |
1997 | 2101 | |
1998 | - if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') |
|
1999 | - echo ' |
|
2102 | + if (isset($incontext['systemos'], $incontext['detected_path']) && $incontext['systemos'] == 'linux') { |
|
2103 | + echo ' |
|
2000 | 2104 | <hr> |
2001 | 2105 | <p>', $txt['chmod_linux_info'], '</p> |
2002 | 2106 | <tt># chmod a+w ', implode(' ' . $incontext['detected_path'] . '/', $incontext['failed_files']), '</tt>'; |
2107 | + } |
|
2003 | 2108 | |
2004 | 2109 | // This is serious! |
2005 | - if (!template_warning_divs()) |
|
2006 | - return; |
|
2110 | + if (!template_warning_divs()) { |
|
2111 | + return; |
|
2112 | + } |
|
2007 | 2113 | |
2008 | 2114 | echo ' |
2009 | 2115 | <hr> |
2010 | 2116 | <p>', $txt['ftp_setup_info'], '</p>'; |
2011 | 2117 | |
2012 | - if (!empty($incontext['ftp_errors'])) |
|
2013 | - echo ' |
|
2118 | + if (!empty($incontext['ftp_errors'])) { |
|
2119 | + echo ' |
|
2014 | 2120 | <div class="error_message"> |
2015 | 2121 | ', $txt['error_ftp_no_connect'], '<br><br> |
2016 | 2122 | <code>', implode('<br>', $incontext['ftp_errors']), '</code> |
2017 | 2123 | </div> |
2018 | 2124 | <br>'; |
2125 | + } |
|
2019 | 2126 | |
2020 | 2127 | echo ' |
2021 | 2128 | <form action="', $incontext['form_url'], '" method="post"> |
@@ -2075,17 +2182,17 @@ discard block |
||
2075 | 2182 | <td> |
2076 | 2183 | <select name="db_type" id="db_type_input" onchange="toggleDBInput();">'; |
2077 | 2184 | |
2078 | - foreach ($incontext['supported_databases'] as $key => $db) |
|
2079 | - echo ' |
|
2185 | + foreach ($incontext['supported_databases'] as $key => $db) { |
|
2186 | + echo ' |
|
2080 | 2187 | <option value="', $key, '"', isset($_POST['db_type']) && $_POST['db_type'] == $key ? ' selected' : '', '>', $db['name'], '</option>'; |
2188 | + } |
|
2081 | 2189 | |
2082 | 2190 | echo ' |
2083 | 2191 | </select> |
2084 | 2192 | <div class="smalltext block">', $txt['db_settings_type_info'], '</div> |
2085 | 2193 | </td> |
2086 | 2194 | </tr>'; |
2087 | - } |
|
2088 | - else |
|
2195 | + } else |
|
2089 | 2196 | { |
2090 | 2197 | echo ' |
2091 | 2198 | <tr style="display: none;"> |
@@ -2277,9 +2384,10 @@ discard block |
||
2277 | 2384 | <div style="color: red;">', $txt['error_db_queries'], '</div> |
2278 | 2385 | <ul>'; |
2279 | 2386 | |
2280 | - foreach ($incontext['failures'] as $line => $fail) |
|
2281 | - echo ' |
|
2387 | + foreach ($incontext['failures'] as $line => $fail) { |
|
2388 | + echo ' |
|
2282 | 2389 | <li><strong>', $txt['error_db_queries_line'], $line + 1, ':</strong> ', nl2br(htmlspecialchars($fail)), '</li>'; |
2390 | + } |
|
2283 | 2391 | |
2284 | 2392 | echo ' |
2285 | 2393 | </ul>'; |
@@ -2340,15 +2448,16 @@ discard block |
||
2340 | 2448 | </tr> |
2341 | 2449 | </table>'; |
2342 | 2450 | |
2343 | - if ($incontext['require_db_confirm']) |
|
2344 | - echo ' |
|
2451 | + if ($incontext['require_db_confirm']) { |
|
2452 | + echo ' |
|
2345 | 2453 | <h2>', $txt['user_settings_database'], '</h2> |
2346 | 2454 | <p>', $txt['user_settings_database_info'], '</p> |
2347 | 2455 | |
2348 | 2456 | <div style="margin-bottom: 2ex; padding-', $txt['lang_rtl'] == false ? 'left' : 'right', ': 50px;"> |
2349 | 2457 | <input type="password" name="password3" size="30" class="input_password" /> |
2350 | 2458 | </div>'; |
2351 | -} |
|
2459 | + } |
|
2460 | + } |
|
2352 | 2461 | |
2353 | 2462 | // Tell them it's done, and to delete. |
2354 | 2463 | function template_delete_install() |
@@ -2361,14 +2470,15 @@ discard block |
||
2361 | 2470 | template_warning_divs(); |
2362 | 2471 | |
2363 | 2472 | // Install directory still writable? |
2364 | - if ($incontext['dir_still_writable']) |
|
2365 | - echo ' |
|
2473 | + if ($incontext['dir_still_writable']) { |
|
2474 | + echo ' |
|
2366 | 2475 | <em>', $txt['still_writable'], '</em><br> |
2367 | 2476 | <br>'; |
2477 | + } |
|
2368 | 2478 | |
2369 | 2479 | // Don't show the box if it's like 99% sure it won't work :P. |
2370 | - if ($incontext['probably_delete_install']) |
|
2371 | - echo ' |
|
2480 | + if ($incontext['probably_delete_install']) { |
|
2481 | + echo ' |
|
2372 | 2482 | <div style="margin: 1ex; font-weight: bold;"> |
2373 | 2483 | <label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete();" class="input_check" /> ', $txt['delete_installer'], !isset($_SESSION['installer_temp_ftp']) ? ' ' . $txt['delete_installer_maybe'] : '', '</label> |
2374 | 2484 | </div> |
@@ -2384,6 +2494,7 @@ discard block |
||
2384 | 2494 | } |
2385 | 2495 | </script> |
2386 | 2496 | <br>'; |
2497 | + } |
|
2387 | 2498 | |
2388 | 2499 | echo ' |
2389 | 2500 | ', sprintf($txt['go_to_your_forum'], $boardurl . '/index.php'), '<br> |