@@ -1719,7 +1719,7 @@ |
||
1719 | 1719 | $id_theme = $modSettings['theme_guests']; |
1720 | 1720 | |
1721 | 1721 | // We already load the basic stuff? |
1722 | - if (empty($settings['theme_id']) || $settings['theme_id'] != $id_theme ) |
|
1722 | + if (empty($settings['theme_id']) || $settings['theme_id'] != $id_theme) |
|
1723 | 1723 | { |
1724 | 1724 | // Verify the id_theme... no foul play. |
1725 | 1725 | // Always allow the board specific theme, if they are overriding. |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * @version 2.1 Beta 4 |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF')) |
|
16 | +if (!defined('SMF')) { |
|
17 | 17 | die('No direct access...'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * 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,28 +48,36 @@ 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 | 73 | // We excpiclity do not use $smcFunc['json_decode'] here yet, as $smcFunc is not fully loaded. |
66 | - if (!is_array($modSettings['attachmentUploadDir'])) |
|
67 | - $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
74 | + if (!is_array($modSettings['attachmentUploadDir'])) { |
|
75 | + $modSettings['attachmentUploadDir'] = smf_json_decode($modSettings['attachmentUploadDir'], true); |
|
76 | + } |
|
68 | 77 | |
69 | - if (!empty($cache_enable)) |
|
70 | - cache_put_data('modSettings', $modSettings, 90); |
|
78 | + if (!empty($cache_enable)) { |
|
79 | + cache_put_data('modSettings', $modSettings, 90); |
|
80 | + } |
|
71 | 81 | } |
72 | 82 | |
73 | 83 | $modSettings['cache_enable'] = $cache_enable; |
@@ -87,8 +97,9 @@ discard block |
||
87 | 97 | }; |
88 | 98 | $fix_utf8mb4 = function($string) use ($utf8, $smcFunc) |
89 | 99 | { |
90 | - if (!$utf8 || $smcFunc['db_mb4']) |
|
91 | - return $string; |
|
100 | + if (!$utf8 || $smcFunc['db_mb4']) { |
|
101 | + return $string; |
|
102 | + } |
|
92 | 103 | |
93 | 104 | $i = 0; |
94 | 105 | $len = strlen($string); |
@@ -100,18 +111,15 @@ discard block |
||
100 | 111 | { |
101 | 112 | $new_string .= $string[$i]; |
102 | 113 | $i++; |
103 | - } |
|
104 | - elseif ($ord < 224) |
|
114 | + } elseif ($ord < 224) |
|
105 | 115 | { |
106 | 116 | $new_string .= $string[$i] . $string[$i + 1]; |
107 | 117 | $i += 2; |
108 | - } |
|
109 | - elseif ($ord < 240) |
|
118 | + } elseif ($ord < 240) |
|
110 | 119 | { |
111 | 120 | $new_string .= $string[$i] . $string[$i + 1] . $string[$i + 2]; |
112 | 121 | $i += 3; |
113 | - } |
|
114 | - elseif ($ord < 248) |
|
122 | + } elseif ($ord < 248) |
|
115 | 123 | { |
116 | 124 | // Magic happens. |
117 | 125 | $val = (ord($string[$i]) & 0x07) << 18; |
@@ -155,8 +163,7 @@ discard block |
||
155 | 163 | { |
156 | 164 | $result = array_search($needle, array_slice($haystack_arr, $offset)); |
157 | 165 | return is_int($result) ? $result + $offset : false; |
158 | - } |
|
159 | - else |
|
166 | + } else |
|
160 | 167 | { |
161 | 168 | $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); |
162 | 169 | $needle_size = count($needle_arr); |
@@ -165,8 +172,9 @@ discard block |
||
165 | 172 | while ((int) $result === $result) |
166 | 173 | { |
167 | 174 | $offset += $result; |
168 | - if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) |
|
169 | - return $offset; |
|
175 | + if (array_slice($haystack_arr, $offset, $needle_size) === $needle_arr) { |
|
176 | + return $offset; |
|
177 | + } |
|
170 | 178 | $result = array_search($needle_arr[0], array_slice($haystack_arr, ++$offset)); |
171 | 179 | } |
172 | 180 | return false; |
@@ -204,8 +212,9 @@ discard block |
||
204 | 212 | $string = $ent_check($string); |
205 | 213 | preg_match('~^(' . $ent_list . '|.){' . $smcFunc['strlen'](substr($string, 0, $length)) . '}~' . ($utf8 ? 'u' : ''), $string, $matches); |
206 | 214 | $string = $matches[0]; |
207 | - while (strlen($string) > $length) |
|
208 | - $string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string); |
|
215 | + while (strlen($string) > $length) { |
|
216 | + $string = preg_replace('~(?:' . $ent_list . '|.)$~' . ($utf8 ? 'u' : ''), '', $string); |
|
217 | + } |
|
209 | 218 | return $string; |
210 | 219 | }, |
211 | 220 | 'ucfirst' => $utf8 ? function($string) use (&$smcFunc) |
@@ -215,8 +224,9 @@ discard block |
||
215 | 224 | 'ucwords' => $utf8 ? function($string) use (&$smcFunc) |
216 | 225 | { |
217 | 226 | $words = preg_split('~([\s\r\n\t]+)~', $string, -1, PREG_SPLIT_DELIM_CAPTURE); |
218 | - for ($i = 0, $n = count($words); $i < $n; $i += 2) |
|
219 | - $words[$i] = $smcFunc['ucfirst']($words[$i]); |
|
227 | + for ($i = 0, $n = count($words); $i < $n; $i += 2) { |
|
228 | + $words[$i] = $smcFunc['ucfirst']($words[$i]); |
|
229 | + } |
|
220 | 230 | return implode('', $words); |
221 | 231 | } : 'ucwords', |
222 | 232 | 'json_decode' => 'smf_json_decode', |
@@ -224,16 +234,17 @@ discard block |
||
224 | 234 | ); |
225 | 235 | |
226 | 236 | // Setting the timezone is a requirement for some functions. |
227 | - if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) |
|
228 | - date_default_timezone_set($modSettings['default_timezone']); |
|
229 | - else |
|
237 | + if (isset($modSettings['default_timezone']) && in_array($modSettings['default_timezone'], timezone_identifiers_list())) { |
|
238 | + date_default_timezone_set($modSettings['default_timezone']); |
|
239 | + } else |
|
230 | 240 | { |
231 | 241 | // Get PHP's default timezone, if set |
232 | 242 | $ini_tz = ini_get('date.timezone'); |
233 | - if (!empty($ini_tz)) |
|
234 | - $modSettings['default_timezone'] = $ini_tz; |
|
235 | - else |
|
236 | - $modSettings['default_timezone'] = ''; |
|
243 | + if (!empty($ini_tz)) { |
|
244 | + $modSettings['default_timezone'] = $ini_tz; |
|
245 | + } else { |
|
246 | + $modSettings['default_timezone'] = ''; |
|
247 | + } |
|
237 | 248 | |
238 | 249 | // If date.timezone is unset, invalid, or just plain weird, make a best guess |
239 | 250 | if (!in_array($modSettings['default_timezone'], timezone_identifiers_list())) |
@@ -251,22 +262,26 @@ discard block |
||
251 | 262 | if (($modSettings['load_average'] = cache_get_data('loadavg', 90)) == null) |
252 | 263 | { |
253 | 264 | $modSettings['load_average'] = @file_get_contents('/proc/loadavg'); |
254 | - if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) |
|
255 | - $modSettings['load_average'] = (float) $matches[1]; |
|
256 | - elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) |
|
257 | - $modSettings['load_average'] = (float) $matches[1]; |
|
258 | - else |
|
259 | - unset($modSettings['load_average']); |
|
265 | + if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) != 0) { |
|
266 | + $modSettings['load_average'] = (float) $matches[1]; |
|
267 | + } elseif (($modSettings['load_average'] = @`uptime`) != null && preg_match('~load average[s]?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) != 0) { |
|
268 | + $modSettings['load_average'] = (float) $matches[1]; |
|
269 | + } else { |
|
270 | + unset($modSettings['load_average']); |
|
271 | + } |
|
260 | 272 | |
261 | - if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
|
262 | - cache_put_data('loadavg', $modSettings['load_average'], 90); |
|
273 | + if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) { |
|
274 | + cache_put_data('loadavg', $modSettings['load_average'], 90); |
|
275 | + } |
|
263 | 276 | } |
264 | 277 | |
265 | - if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
|
266 | - call_integration_hook('integrate_load_average', array($modSettings['load_average'])); |
|
278 | + if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) { |
|
279 | + call_integration_hook('integrate_load_average', array($modSettings['load_average'])); |
|
280 | + } |
|
267 | 281 | |
268 | - if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) |
|
269 | - display_loadavg_error(); |
|
282 | + if (!empty($modSettings['loadavg_forum']) && !empty($modSettings['load_average']) && $modSettings['load_average'] >= $modSettings['loadavg_forum']) { |
|
283 | + display_loadavg_error(); |
|
284 | + } |
|
270 | 285 | } |
271 | 286 | |
272 | 287 | // Is post moderation alive and well? Everywhere else assumes this has been defined, so let's make sure it is. |
@@ -287,8 +302,9 @@ discard block |
||
287 | 302 | if (defined('SMF_INTEGRATION_SETTINGS')) |
288 | 303 | { |
289 | 304 | $integration_settings = $smcFunc['json_decode'](SMF_INTEGRATION_SETTINGS, true); |
290 | - foreach ($integration_settings as $hook => $function) |
|
291 | - add_integration_function($hook, $function, '', false); |
|
305 | + foreach ($integration_settings as $hook => $function) { |
|
306 | + add_integration_function($hook, $function, '', false); |
|
307 | + } |
|
292 | 308 | } |
293 | 309 | |
294 | 310 | // Any files to pre include? |
@@ -298,8 +314,9 @@ discard block |
||
298 | 314 | foreach ($pre_includes as $include) |
299 | 315 | { |
300 | 316 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
301 | - if (file_exists($include)) |
|
302 | - require_once($include); |
|
317 | + if (file_exists($include)) { |
|
318 | + require_once($include); |
|
319 | + } |
|
303 | 320 | } |
304 | 321 | } |
305 | 322 | |
@@ -403,27 +420,28 @@ discard block |
||
403 | 420 | break; |
404 | 421 | } |
405 | 422 | } |
423 | + } else { |
|
424 | + $id_member = 0; |
|
406 | 425 | } |
407 | - else |
|
408 | - $id_member = 0; |
|
409 | 426 | |
410 | 427 | if (empty($id_member) && isset($_COOKIE[$cookiename])) |
411 | 428 | { |
412 | 429 | $cookie_data = $smcFunc['json_decode']($_COOKIE[$cookiename], true, false); |
413 | 430 | |
414 | - if (empty($cookie_data)) |
|
415 | - $cookie_data = safe_unserialize($_COOKIE[$cookiename]); |
|
431 | + if (empty($cookie_data)) { |
|
432 | + $cookie_data = safe_unserialize($_COOKIE[$cookiename]); |
|
433 | + } |
|
416 | 434 | |
417 | 435 | list ($id_member, $password) = $cookie_data; |
418 | 436 | $id_member = !empty($id_member) && strlen($password) > 0 ? (int) $id_member : 0; |
419 | - } |
|
420 | - elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA']))) |
|
437 | + } elseif (empty($id_member) && isset($_SESSION['login_' . $cookiename]) && ($_SESSION['USER_AGENT'] == $_SERVER['HTTP_USER_AGENT'] || !empty($modSettings['disableCheckUA']))) |
|
421 | 438 | { |
422 | 439 | // @todo Perhaps we can do some more checking on this, such as on the first octet of the IP? |
423 | 440 | $cookie_data = $smcFunc['json_decode']($_SESSION['login_' . $cookiename]); |
424 | 441 | |
425 | - if (empty($cookie_data)) |
|
426 | - $cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
442 | + if (empty($cookie_data)) { |
|
443 | + $cookie_data = safe_unserialize($_SESSION['login_' . $cookiename]); |
|
444 | + } |
|
427 | 445 | |
428 | 446 | list ($id_member, $password, $login_span) = $cookie_data; |
429 | 447 | $id_member = !empty($id_member) && strlen($password) == 128 && $login_span > time() ? (int) $id_member : 0; |
@@ -448,30 +466,34 @@ discard block |
||
448 | 466 | $user_settings = $smcFunc['db_fetch_assoc']($request); |
449 | 467 | $smcFunc['db_free_result']($request); |
450 | 468 | |
451 | - if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) |
|
452 | - $user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret); |
|
469 | + if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($user_settings['avatar'], 'http://') !== false) { |
|
470 | + $user_settings['avatar'] = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($user_settings['avatar']) . '&hash=' . md5($user_settings['avatar'] . $image_proxy_secret); |
|
471 | + } |
|
453 | 472 | |
454 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
455 | - cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
473 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
474 | + cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
475 | + } |
|
456 | 476 | } |
457 | 477 | |
458 | 478 | // Did we find 'im? If not, junk it. |
459 | 479 | if (!empty($user_settings)) |
460 | 480 | { |
461 | 481 | // As much as the password should be right, we can assume the integration set things up. |
462 | - if (!empty($already_verified) && $already_verified === true) |
|
463 | - $check = true; |
|
482 | + if (!empty($already_verified) && $already_verified === true) { |
|
483 | + $check = true; |
|
484 | + } |
|
464 | 485 | // SHA-512 hash should be 128 characters long. |
465 | - elseif (strlen($password) == 128) |
|
466 | - $check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password; |
|
467 | - else |
|
468 | - $check = false; |
|
486 | + elseif (strlen($password) == 128) { |
|
487 | + $check = hash_salt($user_settings['passwd'], $user_settings['password_salt']) == $password; |
|
488 | + } else { |
|
489 | + $check = false; |
|
490 | + } |
|
469 | 491 | |
470 | 492 | // Wrong password or not activated - either way, you're going nowhere. |
471 | 493 | $id_member = $check && ($user_settings['is_activated'] == 1 || $user_settings['is_activated'] == 11) ? (int) $user_settings['id_member'] : 0; |
494 | + } else { |
|
495 | + $id_member = 0; |
|
472 | 496 | } |
473 | - else |
|
474 | - $id_member = 0; |
|
475 | 497 | |
476 | 498 | // If we no longer have the member maybe they're being all hackey, stop brute force! |
477 | 499 | if (!$id_member) |
@@ -500,8 +522,9 @@ discard block |
||
500 | 522 | |
501 | 523 | list ($tfamember, $tfasecret) = $tfa_data; |
502 | 524 | |
503 | - if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) |
|
504 | - $tfasecret = null; |
|
525 | + if (!isset($tfamember, $tfasecret) || (int) $tfamember != $id_member) { |
|
526 | + $tfasecret = null; |
|
527 | + } |
|
505 | 528 | } |
506 | 529 | |
507 | 530 | if (empty($tfasecret) || hash_salt($user_settings['tfa_backup'], $user_settings['password_salt']) != $tfasecret) |
@@ -521,10 +544,12 @@ discard block |
||
521 | 544 | // Are we forcing 2FA? Need to check if the user groups actually require 2FA |
522 | 545 | elseif (!empty($modSettings['tfa_mode']) && $modSettings['tfa_mode'] >= 2 && $id_member && empty($user_settings['tfa_secret'])) |
523 | 546 | { |
524 | - if ($modSettings['tfa_mode'] == 2) //only do this if we are just forcing SOME membergroups |
|
547 | + if ($modSettings['tfa_mode'] == 2) { |
|
548 | + //only do this if we are just forcing SOME membergroups |
|
525 | 549 | { |
526 | 550 | //Build an array of ALL user membergroups. |
527 | 551 | $full_groups = array($user_settings['id_group']); |
552 | + } |
|
528 | 553 | if (!empty($user_settings['additional_groups'])) |
529 | 554 | { |
530 | 555 | $full_groups = array_merge($full_groups, explode(',', $user_settings['additional_groups'])); |
@@ -544,15 +569,17 @@ discard block |
||
544 | 569 | ); |
545 | 570 | $row = $smcFunc['db_fetch_assoc']($request); |
546 | 571 | $smcFunc['db_free_result']($request); |
572 | + } else { |
|
573 | + $row['total'] = 1; |
|
547 | 574 | } |
548 | - else |
|
549 | - $row['total'] = 1; //simplifies logics in the next "if" |
|
575 | + //simplifies logics in the next "if" |
|
550 | 576 | |
551 | 577 | $area = !empty($_REQUEST['area']) ? $_REQUEST['area'] : ''; |
552 | 578 | $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : ''; |
553 | 579 | |
554 | - if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) |
|
555 | - redirectexit('action=profile;area=tfasetup;forced'); |
|
580 | + if ($row['total'] > 0 && !in_array($action, array('profile', 'logout')) || ($action == 'profile' && $area != 'tfasetup')) { |
|
581 | + redirectexit('action=profile;area=tfasetup;forced'); |
|
582 | + } |
|
556 | 583 | } |
557 | 584 | } |
558 | 585 | |
@@ -589,33 +616,37 @@ discard block |
||
589 | 616 | 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'])); |
590 | 617 | $user_settings['last_login'] = time(); |
591 | 618 | |
592 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
593 | - cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
619 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
620 | + cache_put_data('user_settings-' . $id_member, $user_settings, 60); |
|
621 | + } |
|
594 | 622 | |
595 | - if (!empty($modSettings['cache_enable'])) |
|
596 | - cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600); |
|
623 | + if (!empty($modSettings['cache_enable'])) { |
|
624 | + cache_put_data('user_last_visit-' . $id_member, $_SESSION['id_msg_last_visit'], 5 * 3600); |
|
625 | + } |
|
597 | 626 | } |
627 | + } elseif (empty($_SESSION['id_msg_last_visit'])) { |
|
628 | + $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit']; |
|
598 | 629 | } |
599 | - elseif (empty($_SESSION['id_msg_last_visit'])) |
|
600 | - $_SESSION['id_msg_last_visit'] = $user_settings['id_msg_last_visit']; |
|
601 | 630 | |
602 | 631 | $username = $user_settings['member_name']; |
603 | 632 | |
604 | - if (empty($user_settings['additional_groups'])) |
|
605 | - $user_info = array( |
|
633 | + if (empty($user_settings['additional_groups'])) { |
|
634 | + $user_info = array( |
|
606 | 635 | 'groups' => array($user_settings['id_group'], $user_settings['id_post_group']) |
607 | 636 | ); |
608 | - else |
|
609 | - $user_info = array( |
|
637 | + } else { |
|
638 | + $user_info = array( |
|
610 | 639 | 'groups' => array_merge( |
611 | 640 | array($user_settings['id_group'], $user_settings['id_post_group']), |
612 | 641 | explode(',', $user_settings['additional_groups']) |
613 | 642 | ) |
614 | 643 | ); |
644 | + } |
|
615 | 645 | |
616 | 646 | // Because history has proven that it is possible for groups to go bad - clean up in case. |
617 | - foreach ($user_info['groups'] as $k => $v) |
|
618 | - $user_info['groups'][$k] = (int) $v; |
|
647 | + foreach ($user_info['groups'] as $k => $v) { |
|
648 | + $user_info['groups'][$k] = (int) $v; |
|
649 | + } |
|
619 | 650 | |
620 | 651 | // This is a logged in user, so definitely not a spider. |
621 | 652 | $user_info['possibly_robot'] = false; |
@@ -629,8 +660,7 @@ discard block |
||
629 | 660 | $time_system = new DateTime('now', $tz_system); |
630 | 661 | $time_user = new DateTime('now', $tz_user); |
631 | 662 | $user_info['time_offset'] = ($tz_user->getOffset($time_user) - $tz_system->getOffset($time_system)) / 3600; |
632 | - } |
|
633 | - else |
|
663 | + } else |
|
634 | 664 | { |
635 | 665 | // !!! Compatibility. |
636 | 666 | $user_info['time_offset'] = empty($user_settings['time_offset']) ? 0 : $user_settings['time_offset']; |
@@ -644,8 +674,9 @@ discard block |
||
644 | 674 | $user_info = array('groups' => array(-1)); |
645 | 675 | $user_settings = array(); |
646 | 676 | |
647 | - if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) |
|
648 | - $_COOKIE[$cookiename] = ''; |
|
677 | + if (isset($_COOKIE[$cookiename]) && empty($context['tfa_member'])) { |
|
678 | + $_COOKIE[$cookiename] = ''; |
|
679 | + } |
|
649 | 680 | |
650 | 681 | // Expire the 2FA cookie |
651 | 682 | if (isset($_COOKIE[$cookiename . '_tfa']) && empty($context['tfa_member'])) |
@@ -662,19 +693,20 @@ discard block |
||
662 | 693 | } |
663 | 694 | |
664 | 695 | // Create a login token if it doesn't exist yet. |
665 | - if (!isset($_SESSION['token']['post-login'])) |
|
666 | - createToken('login'); |
|
667 | - else |
|
668 | - 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 | + } |
|
669 | 701 | |
670 | 702 | // Do we perhaps think this is a search robot? Check every five minutes just in case... |
671 | 703 | if ((!empty($modSettings['spider_mode']) || !empty($modSettings['spider_group'])) && (!isset($_SESSION['robot_check']) || $_SESSION['robot_check'] < time() - 300)) |
672 | 704 | { |
673 | 705 | require_once($sourcedir . '/ManageSearchEngines.php'); |
674 | 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; |
|
675 | 709 | } |
676 | - elseif (!empty($modSettings['spider_mode'])) |
|
677 | - $user_info['possibly_robot'] = isset($_SESSION['id_robot']) ? $_SESSION['id_robot'] : 0; |
|
678 | 710 | // If we haven't turned on proper spider hunts then have a guess! |
679 | 711 | else |
680 | 712 | { |
@@ -722,8 +754,9 @@ discard block |
||
722 | 754 | $user_info['groups'] = array_unique($user_info['groups']); |
723 | 755 | |
724 | 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. |
725 | - if (!empty($user_info['ignoreboards']) && empty($user_info['ignoreboards'][$tmp = count($user_info['ignoreboards']) - 1])) |
|
726 | - 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 | + } |
|
727 | 760 | |
728 | 761 | // Allow the user to change their language. |
729 | 762 | if (!empty($modSettings['userLanguage'])) |
@@ -736,31 +769,36 @@ discard block |
||
736 | 769 | $user_info['language'] = strtr($_GET['language'], './\\:', '____'); |
737 | 770 | |
738 | 771 | // Make it permanent for members. |
739 | - if (!empty($user_info['id'])) |
|
740 | - updateMemberData($user_info['id'], array('lngfile' => $user_info['language'])); |
|
741 | - else |
|
742 | - $_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'], './\\:', '____'); |
|
743 | 779 | } |
744 | - elseif (!empty($_SESSION['language']) && isset($languages[strtr($_SESSION['language'], './\\:', '____')])) |
|
745 | - $user_info['language'] = strtr($_SESSION['language'], './\\:', '____'); |
|
746 | 780 | } |
747 | 781 | |
748 | 782 | // Just build this here, it makes it easier to change/use - administrators can see all boards. |
749 | - if ($user_info['is_admin']) |
|
750 | - $user_info['query_see_board'] = '1=1'; |
|
783 | + if ($user_info['is_admin']) { |
|
784 | + $user_info['query_see_board'] = '1=1'; |
|
785 | + } |
|
751 | 786 | // Otherwise just the groups in $user_info['groups']. |
752 | - else |
|
753 | - $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 | + } |
|
754 | 790 | |
755 | 791 | // Build the list of boards they WANT to see. |
756 | 792 | // This will take the place of query_see_boards in certain spots, so it better include the boards they can see also |
757 | 793 | |
758 | 794 | // If they aren't ignoring any boards then they want to see all the boards they can see |
759 | - if (empty($user_info['ignoreboards'])) |
|
760 | - $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 | + } |
|
761 | 798 | // Ok I guess they don't want to see all the boards |
762 | - else |
|
763 | - $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 | + } |
|
764 | 802 | |
765 | 803 | call_integration_hook('integrate_user_info'); |
766 | 804 | } |
@@ -818,9 +856,9 @@ discard block |
||
818 | 856 | } |
819 | 857 | |
820 | 858 | // Remember redirection is the key to avoiding fallout from your bosses. |
821 | - if (!empty($topic)) |
|
822 | - redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']); |
|
823 | - else |
|
859 | + if (!empty($topic)) { |
|
860 | + redirectexit('topic=' . $topic . '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg']); |
|
861 | + } else |
|
824 | 862 | { |
825 | 863 | loadPermissions(); |
826 | 864 | loadTheme(); |
@@ -838,10 +876,11 @@ discard block |
||
838 | 876 | if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3)) |
839 | 877 | { |
840 | 878 | // @todo SLOW? |
841 | - if (!empty($topic)) |
|
842 | - $temp = cache_get_data('topic_board-' . $topic, 120); |
|
843 | - else |
|
844 | - $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 | + } |
|
845 | 884 | |
846 | 885 | if (!empty($temp)) |
847 | 886 | { |
@@ -879,8 +918,9 @@ discard block |
||
879 | 918 | $row = $smcFunc['db_fetch_assoc']($request); |
880 | 919 | |
881 | 920 | // Set the current board. |
882 | - if (!empty($row['id_board'])) |
|
883 | - $board = $row['id_board']; |
|
921 | + if (!empty($row['id_board'])) { |
|
922 | + $board = $row['id_board']; |
|
923 | + } |
|
884 | 924 | |
885 | 925 | // Basic operating information. (globals... :/) |
886 | 926 | $board_info = array( |
@@ -916,21 +956,23 @@ discard block |
||
916 | 956 | |
917 | 957 | do |
918 | 958 | { |
919 | - if (!empty($row['id_moderator'])) |
|
920 | - $board_info['moderators'][$row['id_moderator']] = array( |
|
959 | + if (!empty($row['id_moderator'])) { |
|
960 | + $board_info['moderators'][$row['id_moderator']] = array( |
|
921 | 961 | 'id' => $row['id_moderator'], |
922 | 962 | 'name' => $row['real_name'], |
923 | 963 | 'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'], |
924 | 964 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>' |
925 | 965 | ); |
966 | + } |
|
926 | 967 | |
927 | - if (!empty($row['id_moderator_group'])) |
|
928 | - $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( |
|
929 | 970 | 'id' => $row['id_moderator_group'], |
930 | 971 | 'name' => $row['group_name'], |
931 | 972 | 'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'], |
932 | 973 | 'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>' |
933 | 974 | ); |
975 | + } |
|
934 | 976 | } |
935 | 977 | while ($row = $smcFunc['db_fetch_assoc']($request)); |
936 | 978 | |
@@ -962,12 +1004,12 @@ discard block |
||
962 | 1004 | if (!empty($modSettings['cache_enable']) && (empty($topic) || $modSettings['cache_enable'] >= 3)) |
963 | 1005 | { |
964 | 1006 | // @todo SLOW? |
965 | - if (!empty($topic)) |
|
966 | - cache_put_data('topic_board-' . $topic, $board_info, 120); |
|
1007 | + if (!empty($topic)) { |
|
1008 | + cache_put_data('topic_board-' . $topic, $board_info, 120); |
|
1009 | + } |
|
967 | 1010 | cache_put_data('board-' . $board, $board_info, 120); |
968 | 1011 | } |
969 | - } |
|
970 | - else |
|
1012 | + } else |
|
971 | 1013 | { |
972 | 1014 | // Otherwise the topic is invalid, there are no moderators, etc. |
973 | 1015 | $board_info = array( |
@@ -981,8 +1023,9 @@ discard block |
||
981 | 1023 | $smcFunc['db_free_result']($request); |
982 | 1024 | } |
983 | 1025 | |
984 | - if (!empty($topic)) |
|
985 | - $_GET['board'] = (int) $board; |
|
1026 | + if (!empty($topic)) { |
|
1027 | + $_GET['board'] = (int) $board; |
|
1028 | + } |
|
986 | 1029 | |
987 | 1030 | if (!empty($board)) |
988 | 1031 | { |
@@ -992,10 +1035,12 @@ discard block |
||
992 | 1035 | // Now check if the user is a moderator. |
993 | 1036 | $user_info['is_mod'] = isset($board_info['moderators'][$user_info['id']]) || count(array_intersect($user_info['groups'], $moderator_groups)) != 0; |
994 | 1037 | |
995 | - if (count(array_intersect($user_info['groups'], $board_info['groups'])) == 0 && !$user_info['is_admin']) |
|
996 | - $board_info['error'] = 'access'; |
|
997 | - if (!empty($modSettings['deny_boards_access']) && count(array_intersect($user_info['groups'], $board_info['deny_groups'])) != 0 && !$user_info['is_admin']) |
|
998 | - $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 | + } |
|
999 | 1044 | |
1000 | 1045 | // Build up the linktree. |
1001 | 1046 | $context['linktree'] = array_merge( |
@@ -1018,8 +1063,9 @@ discard block |
||
1018 | 1063 | $context['current_board'] = $board; |
1019 | 1064 | |
1020 | 1065 | // No posting in redirection boards! |
1021 | - if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'post' && !empty($board_info['redirect'])) |
|
1022 | - $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 | + } |
|
1023 | 1069 | |
1024 | 1070 | // Hacker... you can't see this topic, I'll tell you that. (but moderators can!) |
1025 | 1071 | if (!empty($board_info['error']) && (!empty($modSettings['deny_boards_access']) || $board_info['error'] != 'access' || !$user_info['is_mod'])) |
@@ -1045,24 +1091,23 @@ discard block |
||
1045 | 1091 | ob_end_clean(); |
1046 | 1092 | header('HTTP/1.1 403 Forbidden'); |
1047 | 1093 | die; |
1048 | - } |
|
1049 | - elseif ($board_info['error'] == 'post_in_redirect') |
|
1094 | + } elseif ($board_info['error'] == 'post_in_redirect') |
|
1050 | 1095 | { |
1051 | 1096 | // Slightly different error message here... |
1052 | 1097 | fatal_lang_error('cannot_post_redirect', false); |
1053 | - } |
|
1054 | - elseif ($user_info['is_guest']) |
|
1098 | + } elseif ($user_info['is_guest']) |
|
1055 | 1099 | { |
1056 | 1100 | loadLanguage('Errors'); |
1057 | 1101 | is_not_guest($txt['topic_gone']); |
1102 | + } else { |
|
1103 | + fatal_lang_error('topic_gone', false); |
|
1058 | 1104 | } |
1059 | - else |
|
1060 | - fatal_lang_error('topic_gone', false); |
|
1061 | 1105 | } |
1062 | 1106 | |
1063 | - if ($user_info['is_mod']) |
|
1064 | - $user_info['groups'][] = 3; |
|
1065 | -} |
|
1107 | + if ($user_info['is_mod']) { |
|
1108 | + $user_info['groups'][] = 3; |
|
1109 | + } |
|
1110 | + } |
|
1066 | 1111 | |
1067 | 1112 | /** |
1068 | 1113 | * Load this user's permissions. |
@@ -1083,8 +1128,9 @@ discard block |
||
1083 | 1128 | asort($cache_groups); |
1084 | 1129 | $cache_groups = implode(',', $cache_groups); |
1085 | 1130 | // If it's a spider then cache it different. |
1086 | - if ($user_info['possibly_robot']) |
|
1087 | - $cache_groups .= '-spider'; |
|
1131 | + if ($user_info['possibly_robot']) { |
|
1132 | + $cache_groups .= '-spider'; |
|
1133 | + } |
|
1088 | 1134 | |
1089 | 1135 | if ($modSettings['cache_enable'] >= 2 && !empty($board) && ($temp = cache_get_data('permissions:' . $cache_groups . ':' . $board, 240)) != null && time() - 240 > $modSettings['settings_updated']) |
1090 | 1136 | { |
@@ -1092,9 +1138,9 @@ discard block |
||
1092 | 1138 | banPermissions(); |
1093 | 1139 | |
1094 | 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; |
|
1095 | 1143 | } |
1096 | - elseif (($temp = cache_get_data('permissions:' . $cache_groups, 240)) != null && time() - 240 > $modSettings['settings_updated']) |
|
1097 | - list ($user_info['permissions'], $removals) = $temp; |
|
1098 | 1144 | } |
1099 | 1145 | |
1100 | 1146 | // If it is detected as a robot, and we are restricting permissions as a special group - then implement this. |
@@ -1116,23 +1162,26 @@ discard block |
||
1116 | 1162 | $removals = array(); |
1117 | 1163 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1118 | 1164 | { |
1119 | - if (empty($row['add_deny'])) |
|
1120 | - $removals[] = $row['permission']; |
|
1121 | - else |
|
1122 | - $user_info['permissions'][] = $row['permission']; |
|
1165 | + if (empty($row['add_deny'])) { |
|
1166 | + $removals[] = $row['permission']; |
|
1167 | + } else { |
|
1168 | + $user_info['permissions'][] = $row['permission']; |
|
1169 | + } |
|
1123 | 1170 | } |
1124 | 1171 | $smcFunc['db_free_result']($request); |
1125 | 1172 | |
1126 | - if (isset($cache_groups)) |
|
1127 | - 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 | + } |
|
1128 | 1176 | } |
1129 | 1177 | |
1130 | 1178 | // Get the board permissions. |
1131 | 1179 | if (!empty($board)) |
1132 | 1180 | { |
1133 | 1181 | // Make sure the board (if any) has been loaded by loadBoard(). |
1134 | - if (!isset($board_info['profile'])) |
|
1135 | - fatal_lang_error('no_board'); |
|
1182 | + if (!isset($board_info['profile'])) { |
|
1183 | + fatal_lang_error('no_board'); |
|
1184 | + } |
|
1136 | 1185 | |
1137 | 1186 | $request = $smcFunc['db_query']('', ' |
1138 | 1187 | SELECT permission, add_deny |
@@ -1148,20 +1197,23 @@ discard block |
||
1148 | 1197 | ); |
1149 | 1198 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1150 | 1199 | { |
1151 | - if (empty($row['add_deny'])) |
|
1152 | - $removals[] = $row['permission']; |
|
1153 | - else |
|
1154 | - $user_info['permissions'][] = $row['permission']; |
|
1200 | + if (empty($row['add_deny'])) { |
|
1201 | + $removals[] = $row['permission']; |
|
1202 | + } else { |
|
1203 | + $user_info['permissions'][] = $row['permission']; |
|
1204 | + } |
|
1155 | 1205 | } |
1156 | 1206 | $smcFunc['db_free_result']($request); |
1157 | 1207 | } |
1158 | 1208 | |
1159 | 1209 | // Remove all the permissions they shouldn't have ;). |
1160 | - if (!empty($modSettings['permission_enable_deny'])) |
|
1161 | - $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 | + } |
|
1162 | 1213 | |
1163 | - if (isset($cache_groups) && !empty($board) && $modSettings['cache_enable'] >= 2) |
|
1164 | - 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 | + } |
|
1165 | 1217 | |
1166 | 1218 | // Banned? Watch, don't touch.. |
1167 | 1219 | banPermissions(); |
@@ -1173,17 +1225,18 @@ discard block |
||
1173 | 1225 | { |
1174 | 1226 | require_once($sourcedir . '/Subs-Auth.php'); |
1175 | 1227 | rebuildModCache(); |
1228 | + } else { |
|
1229 | + $user_info['mod_cache'] = $_SESSION['mc']; |
|
1176 | 1230 | } |
1177 | - else |
|
1178 | - $user_info['mod_cache'] = $_SESSION['mc']; |
|
1179 | 1231 | |
1180 | 1232 | // This is a useful phantom permission added to the current user, and only the current user while they are logged in. |
1181 | 1233 | // For example this drastically simplifies certain changes to the profile area. |
1182 | 1234 | $user_info['permissions'][] = 'is_not_guest'; |
1183 | 1235 | // And now some backwards compatibility stuff for mods and whatnot that aren't expecting the new permissions. |
1184 | 1236 | $user_info['permissions'][] = 'profile_view_own'; |
1185 | - if (in_array('profile_view', $user_info['permissions'])) |
|
1186 | - $user_info['permissions'][] = 'profile_view_any'; |
|
1237 | + if (in_array('profile_view', $user_info['permissions'])) { |
|
1238 | + $user_info['permissions'][] = 'profile_view_any'; |
|
1239 | + } |
|
1187 | 1240 | } |
1188 | 1241 | } |
1189 | 1242 | |
@@ -1201,8 +1254,9 @@ discard block |
||
1201 | 1254 | global $image_proxy_enabled, $image_proxy_secret, $boardurl; |
1202 | 1255 | |
1203 | 1256 | // Can't just look for no users :P. |
1204 | - if (empty($users)) |
|
1205 | - return array(); |
|
1257 | + if (empty($users)) { |
|
1258 | + return array(); |
|
1259 | + } |
|
1206 | 1260 | |
1207 | 1261 | // Pass the set value |
1208 | 1262 | $context['loadMemberContext_set'] = $set; |
@@ -1217,8 +1271,9 @@ discard block |
||
1217 | 1271 | for ($i = 0, $n = count($users); $i < $n; $i++) |
1218 | 1272 | { |
1219 | 1273 | $data = cache_get_data('member_data-' . $set . '-' . $users[$i], 240); |
1220 | - if ($data == null) |
|
1221 | - continue; |
|
1274 | + if ($data == null) { |
|
1275 | + continue; |
|
1276 | + } |
|
1222 | 1277 | |
1223 | 1278 | $loaded_ids[] = $data['id_member']; |
1224 | 1279 | $user_profile[$data['id_member']] = $data; |
@@ -1285,16 +1340,19 @@ discard block |
||
1285 | 1340 | $row['avatar_original'] = !empty($row['avatar']) ? $row['avatar'] : ''; |
1286 | 1341 | |
1287 | 1342 | // Take care of proxying avatar if required, do this here for maximum reach |
1288 | - if ($image_proxy_enabled && !empty($row['avatar']) && stripos($row['avatar'], 'http://') !== false) |
|
1289 | - $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 | + } |
|
1290 | 1346 | |
1291 | 1347 | // Keep track of the member's normal member group |
1292 | 1348 | $row['primary_group'] = $row['member_group']; |
1293 | 1349 | |
1294 | - if (isset($row['member_ip'])) |
|
1295 | - $row['member_ip'] = inet_dtop($row['member_ip']); |
|
1296 | - if (isset($row['member_ip2'])) |
|
1297 | - $row['member_ip2'] = inet_dtop($row['member_ip2']); |
|
1350 | + if (isset($row['member_ip'])) { |
|
1351 | + $row['member_ip'] = inet_dtop($row['member_ip']); |
|
1352 | + } |
|
1353 | + if (isset($row['member_ip2'])) { |
|
1354 | + $row['member_ip2'] = inet_dtop($row['member_ip2']); |
|
1355 | + } |
|
1298 | 1356 | $new_loaded_ids[] = $row['id_member']; |
1299 | 1357 | $loaded_ids[] = $row['id_member']; |
1300 | 1358 | $row['options'] = array(); |
@@ -1313,8 +1371,9 @@ discard block |
||
1313 | 1371 | 'loaded_ids' => $new_loaded_ids, |
1314 | 1372 | ) |
1315 | 1373 | ); |
1316 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
1317 | - $user_profile[$row['id_member']]['options'][$row['variable']] = $row['value']; |
|
1374 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
1375 | + $user_profile[$row['id_member']]['options'][$row['variable']] = $row['value']; |
|
1376 | + } |
|
1318 | 1377 | $smcFunc['db_free_result']($request); |
1319 | 1378 | } |
1320 | 1379 | |
@@ -1325,10 +1384,11 @@ discard block |
||
1325 | 1384 | { |
1326 | 1385 | foreach ($loaded_ids as $a_member) |
1327 | 1386 | { |
1328 | - if (!empty($user_profile[$a_member]['additional_groups'])) |
|
1329 | - $groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups'])); |
|
1330 | - else |
|
1331 | - $groups = array($user_profile[$a_member]['id_group']); |
|
1387 | + if (!empty($user_profile[$a_member]['additional_groups'])) { |
|
1388 | + $groups = array_merge(array($user_profile[$a_member]['id_group']), explode(',', $user_profile[$a_member]['additional_groups'])); |
|
1389 | + } else { |
|
1390 | + $groups = array($user_profile[$a_member]['id_group']); |
|
1391 | + } |
|
1332 | 1392 | |
1333 | 1393 | $temp = array_intersect($groups, array_keys($board_info['moderator_groups'])); |
1334 | 1394 | |
@@ -1341,8 +1401,9 @@ discard block |
||
1341 | 1401 | |
1342 | 1402 | if (!empty($new_loaded_ids) && !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) |
1343 | 1403 | { |
1344 | - for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) |
|
1345 | - cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240); |
|
1404 | + for ($i = 0, $n = count($new_loaded_ids); $i < $n; $i++) { |
|
1405 | + cache_put_data('member_data-' . $set . '-' . $new_loaded_ids[$i], $user_profile[$new_loaded_ids[$i]], 240); |
|
1406 | + } |
|
1346 | 1407 | } |
1347 | 1408 | |
1348 | 1409 | // Are we loading any moderators? If so, fix their group data... |
@@ -1368,14 +1429,17 @@ discard block |
||
1368 | 1429 | foreach ($temp_mods as $id) |
1369 | 1430 | { |
1370 | 1431 | // By popular demand, don't show admins or global moderators as moderators. |
1371 | - if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) |
|
1372 | - $user_profile[$id]['member_group'] = $row['member_group']; |
|
1432 | + if ($user_profile[$id]['id_group'] != 1 && $user_profile[$id]['id_group'] != 2) { |
|
1433 | + $user_profile[$id]['member_group'] = $row['member_group']; |
|
1434 | + } |
|
1373 | 1435 | |
1374 | 1436 | // If the Moderator group has no color or icons, but their group does... don't overwrite. |
1375 | - if (!empty($row['icons'])) |
|
1376 | - $user_profile[$id]['icons'] = $row['icons']; |
|
1377 | - if (!empty($row['member_group_color'])) |
|
1378 | - $user_profile[$id]['member_group_color'] = $row['member_group_color']; |
|
1437 | + if (!empty($row['icons'])) { |
|
1438 | + $user_profile[$id]['icons'] = $row['icons']; |
|
1439 | + } |
|
1440 | + if (!empty($row['member_group_color'])) { |
|
1441 | + $user_profile[$id]['member_group_color'] = $row['member_group_color']; |
|
1442 | + } |
|
1379 | 1443 | } |
1380 | 1444 | } |
1381 | 1445 | |
@@ -1397,12 +1461,14 @@ discard block |
||
1397 | 1461 | static $loadedLanguages = array(); |
1398 | 1462 | |
1399 | 1463 | // If this person's data is already loaded, skip it. |
1400 | - if (isset($dataLoaded[$user])) |
|
1401 | - return true; |
|
1464 | + if (isset($dataLoaded[$user])) { |
|
1465 | + return true; |
|
1466 | + } |
|
1402 | 1467 | |
1403 | 1468 | // We can't load guests or members not loaded by loadMemberData()! |
1404 | - if ($user == 0) |
|
1405 | - return false; |
|
1469 | + if ($user == 0) { |
|
1470 | + return false; |
|
1471 | + } |
|
1406 | 1472 | if (!isset($user_profile[$user])) |
1407 | 1473 | { |
1408 | 1474 | trigger_error('loadMemberContext(): member id ' . $user . ' not previously loaded by loadMemberData()', E_USER_WARNING); |
@@ -1428,12 +1494,16 @@ discard block |
||
1428 | 1494 | $buddy_list = !empty($profile['buddy_list']) ? explode(',', $profile['buddy_list']) : array(); |
1429 | 1495 | |
1430 | 1496 | //We need a little fallback for the membergroup icons. If it doesn't exist in the current theme, fallback to default theme |
1431 | - if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) //icon is set and exists |
|
1497 | + if (isset($profile['icons'][1]) && file_exists($settings['actual_theme_dir'] . '/images/membericons/' . $profile['icons'][1])) { |
|
1498 | + //icon is set and exists |
|
1432 | 1499 | $group_icon_url = $settings['images_url'] . '/membericons/' . $profile['icons'][1]; |
1433 | - elseif (isset($profile['icons'][1])) //icon is set and doesn't exist, fallback to default |
|
1500 | + } elseif (isset($profile['icons'][1])) { |
|
1501 | + //icon is set and doesn't exist, fallback to default |
|
1434 | 1502 | $group_icon_url = $settings['default_images_url'] . '/membericons/' . $profile['icons'][1]; |
1435 | - else //not set, bye bye |
|
1503 | + } else { |
|
1504 | + //not set, bye bye |
|
1436 | 1505 | $group_icon_url = ''; |
1506 | + } |
|
1437 | 1507 | |
1438 | 1508 | // These minimal values are always loaded |
1439 | 1509 | $memberContext[$user] = array( |
@@ -1452,8 +1522,9 @@ discard block |
||
1452 | 1522 | if ($context['loadMemberContext_set'] != 'minimal') |
1453 | 1523 | { |
1454 | 1524 | // Go the extra mile and load the user's native language name. |
1455 | - if (empty($loadedLanguages)) |
|
1456 | - $loadedLanguages = getLanguages(); |
|
1525 | + if (empty($loadedLanguages)) { |
|
1526 | + $loadedLanguages = getLanguages(); |
|
1527 | + } |
|
1457 | 1528 | |
1458 | 1529 | $memberContext[$user] += array( |
1459 | 1530 | 'username_color' => '<span ' . (!empty($profile['member_group_color']) ? 'style="color:' . $profile['member_group_color'] . ';"' : '') . '>' . $profile['member_name'] . '</span>', |
@@ -1508,31 +1579,33 @@ discard block |
||
1508 | 1579 | { |
1509 | 1580 | if (!empty($modSettings['gravatarOverride']) || (!empty($modSettings['gravatarEnabled']) && stristr($profile['avatar'], 'gravatar://'))) |
1510 | 1581 | { |
1511 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) |
|
1512 | - $image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11)); |
|
1513 | - else |
|
1514 | - $image = get_gravatar_url($profile['email_address']); |
|
1515 | - } |
|
1516 | - else |
|
1582 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && stristr($profile['avatar'], 'gravatar://') && strlen($profile['avatar']) > 11) { |
|
1583 | + $image = get_gravatar_url($smcFunc['substr']($profile['avatar'], 11)); |
|
1584 | + } else { |
|
1585 | + $image = get_gravatar_url($profile['email_address']); |
|
1586 | + } |
|
1587 | + } else |
|
1517 | 1588 | { |
1518 | 1589 | // So it's stored in the member table? |
1519 | 1590 | if (!empty($profile['avatar'])) |
1520 | 1591 | { |
1521 | 1592 | $image = (stristr($profile['avatar'], 'http://') || stristr($profile['avatar'], 'https://')) ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar']; |
1593 | + } elseif (!empty($profile['filename'])) { |
|
1594 | + $image = $modSettings['custom_avatar_url'] . '/' . $profile['filename']; |
|
1522 | 1595 | } |
1523 | - elseif (!empty($profile['filename'])) |
|
1524 | - $image = $modSettings['custom_avatar_url'] . '/' . $profile['filename']; |
|
1525 | 1596 | // Right... no avatar...use the default one |
1526 | - else |
|
1527 | - $image = $modSettings['avatar_url'] . '/default.png'; |
|
1597 | + else { |
|
1598 | + $image = $modSettings['avatar_url'] . '/default.png'; |
|
1599 | + } |
|
1528 | 1600 | } |
1529 | - if (!empty($image)) |
|
1530 | - $memberContext[$user]['avatar'] = array( |
|
1601 | + if (!empty($image)) { |
|
1602 | + $memberContext[$user]['avatar'] = array( |
|
1531 | 1603 | 'name' => $profile['avatar'], |
1532 | 1604 | 'image' => '<img class="avatar" src="' . $image . '" alt="avatar_' . $profile['member_name'] . '">', |
1533 | 1605 | 'href' => $image, |
1534 | 1606 | 'url' => $image, |
1535 | 1607 | ); |
1608 | + } |
|
1536 | 1609 | } |
1537 | 1610 | |
1538 | 1611 | // Are we also loading the members custom fields into context? |
@@ -1540,35 +1613,41 @@ discard block |
||
1540 | 1613 | { |
1541 | 1614 | $memberContext[$user]['custom_fields'] = array(); |
1542 | 1615 | |
1543 | - if (!isset($context['display_fields'])) |
|
1544 | - $context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true); |
|
1616 | + if (!isset($context['display_fields'])) { |
|
1617 | + $context['display_fields'] = $smcFunc['json_decode']($modSettings['displayFields'], true); |
|
1618 | + } |
|
1545 | 1619 | |
1546 | 1620 | foreach ($context['display_fields'] as $custom) |
1547 | 1621 | { |
1548 | - if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) |
|
1549 | - continue; |
|
1622 | + if (!isset($custom['col_name']) || trim($custom['col_name']) == '' || empty($profile['options'][$custom['col_name']])) { |
|
1623 | + continue; |
|
1624 | + } |
|
1550 | 1625 | |
1551 | 1626 | $value = $profile['options'][$custom['col_name']]; |
1552 | 1627 | |
1553 | 1628 | // Don't show the "disabled" option for the "gender" field. |
1554 | - if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') |
|
1555 | - continue; |
|
1629 | + if ($custom['col_name'] == 'cust_gender' && $value == 'Disabled') { |
|
1630 | + continue; |
|
1631 | + } |
|
1556 | 1632 | |
1557 | 1633 | // BBC? |
1558 | - if ($custom['bbc']) |
|
1559 | - $value = parse_bbc($value); |
|
1634 | + if ($custom['bbc']) { |
|
1635 | + $value = parse_bbc($value); |
|
1636 | + } |
|
1560 | 1637 | // ... or checkbox? |
1561 | - elseif (isset($custom['type']) && $custom['type'] == 'check') |
|
1562 | - $value = $value ? $txt['yes'] : $txt['no']; |
|
1638 | + elseif (isset($custom['type']) && $custom['type'] == 'check') { |
|
1639 | + $value = $value ? $txt['yes'] : $txt['no']; |
|
1640 | + } |
|
1563 | 1641 | |
1564 | 1642 | // Enclosing the user input within some other text? |
1565 | - if (!empty($custom['enclose'])) |
|
1566 | - $value = strtr($custom['enclose'], array( |
|
1643 | + if (!empty($custom['enclose'])) { |
|
1644 | + $value = strtr($custom['enclose'], array( |
|
1567 | 1645 | '{SCRIPTURL}' => $scripturl, |
1568 | 1646 | '{IMAGES_URL}' => $settings['images_url'], |
1569 | 1647 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
1570 | 1648 | '{INPUT}' => $value, |
1571 | 1649 | )); |
1650 | + } |
|
1572 | 1651 | |
1573 | 1652 | $memberContext[$user]['custom_fields'][] = array( |
1574 | 1653 | 'title' => !empty($custom['title']) ? $custom['title'] : $custom['col_name'], |
@@ -1595,8 +1674,9 @@ discard block |
||
1595 | 1674 | global $smcFunc, $txt, $scripturl, $settings; |
1596 | 1675 | |
1597 | 1676 | // Do not waste my time... |
1598 | - if (empty($users) || empty($params)) |
|
1599 | - return false; |
|
1677 | + if (empty($users) || empty($params)) { |
|
1678 | + return false; |
|
1679 | + } |
|
1600 | 1680 | |
1601 | 1681 | // Make sure it's an array. |
1602 | 1682 | $users = !is_array($users) ? array($users) : array_unique($users); |
@@ -1620,31 +1700,36 @@ discard block |
||
1620 | 1700 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
1621 | 1701 | { |
1622 | 1702 | // BBC? |
1623 | - if (!empty($row['bbc'])) |
|
1624 | - $row['value'] = parse_bbc($row['value']); |
|
1703 | + if (!empty($row['bbc'])) { |
|
1704 | + $row['value'] = parse_bbc($row['value']); |
|
1705 | + } |
|
1625 | 1706 | |
1626 | 1707 | // ... or checkbox? |
1627 | - elseif (isset($row['type']) && $row['type'] == 'check') |
|
1628 | - $row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no']; |
|
1708 | + elseif (isset($row['type']) && $row['type'] == 'check') { |
|
1709 | + $row['value'] = !empty($row['value']) ? $txt['yes'] : $txt['no']; |
|
1710 | + } |
|
1629 | 1711 | |
1630 | 1712 | // Enclosing the user input within some other text? |
1631 | - if (!empty($row['enclose'])) |
|
1632 | - $row['value'] = strtr($row['enclose'], array( |
|
1713 | + if (!empty($row['enclose'])) { |
|
1714 | + $row['value'] = strtr($row['enclose'], array( |
|
1633 | 1715 | '{SCRIPTURL}' => $scripturl, |
1634 | 1716 | '{IMAGES_URL}' => $settings['images_url'], |
1635 | 1717 | '{DEFAULT_IMAGES_URL}' => $settings['default_images_url'], |
1636 | 1718 | '{INPUT}' => un_htmlspecialchars($row['value']), |
1637 | 1719 | )); |
1720 | + } |
|
1638 | 1721 | |
1639 | 1722 | // Send a simple array if there is just 1 param |
1640 | - if (count($params) == 1) |
|
1641 | - $return[$row['id_member']] = $row; |
|
1723 | + if (count($params) == 1) { |
|
1724 | + $return[$row['id_member']] = $row; |
|
1725 | + } |
|
1642 | 1726 | |
1643 | 1727 | // More than 1? knock yourself out... |
1644 | 1728 | else |
1645 | 1729 | { |
1646 | - if (!isset($return[$row['id_member']])) |
|
1647 | - $return[$row['id_member']] = array(); |
|
1730 | + if (!isset($return[$row['id_member']])) { |
|
1731 | + $return[$row['id_member']] = array(); |
|
1732 | + } |
|
1648 | 1733 | |
1649 | 1734 | $return[$row['id_member']][$row['variable']] = $row; |
1650 | 1735 | } |
@@ -1678,8 +1763,9 @@ discard block |
||
1678 | 1763 | global $context; |
1679 | 1764 | |
1680 | 1765 | // Don't know any browser! |
1681 | - if (empty($context['browser'])) |
|
1682 | - detectBrowser(); |
|
1766 | + if (empty($context['browser'])) { |
|
1767 | + detectBrowser(); |
|
1768 | + } |
|
1683 | 1769 | |
1684 | 1770 | return !empty($context['browser'][$browser]) || !empty($context['browser']['is_' . $browser]) ? true : false; |
1685 | 1771 | } |
@@ -1697,8 +1783,9 @@ discard block |
||
1697 | 1783 | global $context, $settings, $options, $sourcedir, $ssi_theme, $smcFunc, $language, $board, $image_proxy_enabled; |
1698 | 1784 | |
1699 | 1785 | // The theme was specified by parameter. |
1700 | - if (!empty($id_theme)) |
|
1701 | - $id_theme = (int) $id_theme; |
|
1786 | + if (!empty($id_theme)) { |
|
1787 | + $id_theme = (int) $id_theme; |
|
1788 | + } |
|
1702 | 1789 | // The theme was specified by REQUEST. |
1703 | 1790 | elseif (!empty($_REQUEST['theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) |
1704 | 1791 | { |
@@ -1706,54 +1793,61 @@ discard block |
||
1706 | 1793 | $_SESSION['id_theme'] = $id_theme; |
1707 | 1794 | } |
1708 | 1795 | // The theme was specified by REQUEST... previously. |
1709 | - elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) |
|
1710 | - $id_theme = (int) $_SESSION['id_theme']; |
|
1796 | + elseif (!empty($_SESSION['id_theme']) && (!empty($modSettings['theme_allow']) || allowedTo('admin_forum'))) { |
|
1797 | + $id_theme = (int) $_SESSION['id_theme']; |
|
1798 | + } |
|
1711 | 1799 | // The theme is just the user's choice. (might use ?board=1;theme=0 to force board theme.) |
1712 | - elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) |
|
1713 | - $id_theme = $user_info['theme']; |
|
1800 | + elseif (!empty($user_info['theme']) && !isset($_REQUEST['theme'])) { |
|
1801 | + $id_theme = $user_info['theme']; |
|
1802 | + } |
|
1714 | 1803 | // The theme was specified by the board. |
1715 | - elseif (!empty($board_info['theme'])) |
|
1716 | - $id_theme = $board_info['theme']; |
|
1804 | + elseif (!empty($board_info['theme'])) { |
|
1805 | + $id_theme = $board_info['theme']; |
|
1806 | + } |
|
1717 | 1807 | // The theme is the forum's default. |
1718 | - else |
|
1719 | - $id_theme = $modSettings['theme_guests']; |
|
1808 | + else { |
|
1809 | + $id_theme = $modSettings['theme_guests']; |
|
1810 | + } |
|
1720 | 1811 | |
1721 | 1812 | // We already load the basic stuff? |
1722 | 1813 | if (empty($settings['theme_id']) || $settings['theme_id'] != $id_theme ) |
1723 | 1814 | { |
1724 | 1815 | // Verify the id_theme... no foul play. |
1725 | 1816 | // Always allow the board specific theme, if they are overriding. |
1726 | - if (!empty($board_info['theme']) && $board_info['override_theme']) |
|
1727 | - $id_theme = $board_info['theme']; |
|
1817 | + if (!empty($board_info['theme']) && $board_info['override_theme']) { |
|
1818 | + $id_theme = $board_info['theme']; |
|
1819 | + } |
|
1728 | 1820 | // If they have specified a particular theme to use with SSI allow it to be used. |
1729 | - elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) |
|
1730 | - $id_theme = (int) $id_theme; |
|
1731 | - elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum')) |
|
1821 | + elseif (!empty($ssi_theme) && $id_theme == $ssi_theme) { |
|
1822 | + $id_theme = (int) $id_theme; |
|
1823 | + } elseif (!empty($modSettings['enableThemes']) && !allowedTo('admin_forum')) |
|
1732 | 1824 | { |
1733 | 1825 | $themes = explode(',', $modSettings['enableThemes']); |
1734 | - if (!in_array($id_theme, $themes)) |
|
1735 | - $id_theme = $modSettings['theme_guests']; |
|
1736 | - else |
|
1737 | - $id_theme = (int) $id_theme; |
|
1826 | + if (!in_array($id_theme, $themes)) { |
|
1827 | + $id_theme = $modSettings['theme_guests']; |
|
1828 | + } else { |
|
1829 | + $id_theme = (int) $id_theme; |
|
1830 | + } |
|
1831 | + } else { |
|
1832 | + $id_theme = (int) $id_theme; |
|
1738 | 1833 | } |
1739 | - else |
|
1740 | - $id_theme = (int) $id_theme; |
|
1741 | 1834 | |
1742 | 1835 | $member = empty($user_info['id']) ? -1 : $user_info['id']; |
1743 | 1836 | |
1744 | 1837 | // Disable image proxy if we don't have SSL enabled |
1745 | - if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) |
|
1746 | - $image_proxy_enabled = false; |
|
1838 | + if (empty($modSettings['force_ssl']) || $modSettings['force_ssl'] < 2) { |
|
1839 | + $image_proxy_enabled = false; |
|
1840 | + } |
|
1747 | 1841 | |
1748 | 1842 | 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']) |
1749 | 1843 | { |
1750 | 1844 | $themeData = $temp; |
1751 | 1845 | $flag = true; |
1846 | + } elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) { |
|
1847 | + $themeData = $temp + array($member => array()); |
|
1848 | + } else { |
|
1849 | + $themeData = array(-1 => array(), 0 => array(), $member => array()); |
|
1752 | 1850 | } |
1753 | - elseif (($temp = cache_get_data('theme_settings-' . $id_theme, 90)) != null && time() - 60 > $modSettings['settings_updated']) |
|
1754 | - $themeData = $temp + array($member => array()); |
|
1755 | - else |
|
1756 | - $themeData = array(-1 => array(), 0 => array(), $member => array()); |
|
1757 | 1851 | |
1758 | 1852 | if (empty($flag)) |
1759 | 1853 | { |
@@ -1772,31 +1866,37 @@ discard block |
||
1772 | 1866 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
1773 | 1867 | { |
1774 | 1868 | // There are just things we shouldn't be able to change as members. |
1775 | - 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'))) |
|
1776 | - continue; |
|
1869 | + 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'))) { |
|
1870 | + continue; |
|
1871 | + } |
|
1777 | 1872 | |
1778 | 1873 | // If this is the theme_dir of the default theme, store it. |
1779 | - if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) |
|
1780 | - $themeData[0]['default_' . $row['variable']] = $row['value']; |
|
1874 | + if (in_array($row['variable'], array('theme_dir', 'theme_url', 'images_url')) && $row['id_theme'] == '1' && empty($row['id_member'])) { |
|
1875 | + $themeData[0]['default_' . $row['variable']] = $row['value']; |
|
1876 | + } |
|
1781 | 1877 | |
1782 | 1878 | // If this isn't set yet, is a theme option, or is not the default theme.. |
1783 | - if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') |
|
1784 | - $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value']; |
|
1879 | + if (!isset($themeData[$row['id_member']][$row['variable']]) || $row['id_theme'] != '1') { |
|
1880 | + $themeData[$row['id_member']][$row['variable']] = substr($row['variable'], 0, 5) == 'show_' ? $row['value'] == '1' : $row['value']; |
|
1881 | + } |
|
1785 | 1882 | } |
1786 | 1883 | $smcFunc['db_free_result']($result); |
1787 | 1884 | |
1788 | - if (!empty($themeData[-1])) |
|
1789 | - foreach ($themeData[-1] as $k => $v) |
|
1885 | + if (!empty($themeData[-1])) { |
|
1886 | + foreach ($themeData[-1] as $k => $v) |
|
1790 | 1887 | { |
1791 | 1888 | if (!isset($themeData[$member][$k])) |
1792 | 1889 | $themeData[$member][$k] = $v; |
1890 | + } |
|
1793 | 1891 | } |
1794 | 1892 | |
1795 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
1796 | - cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60); |
|
1893 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
1894 | + cache_put_data('theme_settings-' . $id_theme . ':' . $member, $themeData, 60); |
|
1895 | + } |
|
1797 | 1896 | // Only if we didn't already load that part of the cache... |
1798 | - elseif (!isset($temp)) |
|
1799 | - cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90); |
|
1897 | + elseif (!isset($temp)) { |
|
1898 | + cache_put_data('theme_settings-' . $id_theme, array(-1 => $themeData[-1], 0 => $themeData[0]), 90); |
|
1899 | + } |
|
1800 | 1900 | } |
1801 | 1901 | |
1802 | 1902 | $settings = $themeData[0]; |
@@ -1813,22 +1913,26 @@ discard block |
||
1813 | 1913 | $settings['template_dirs'][] = $settings['theme_dir']; |
1814 | 1914 | |
1815 | 1915 | // Based on theme (if there is one). |
1816 | - if (!empty($settings['base_theme_dir'])) |
|
1817 | - $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
1916 | + if (!empty($settings['base_theme_dir'])) { |
|
1917 | + $settings['template_dirs'][] = $settings['base_theme_dir']; |
|
1918 | + } |
|
1818 | 1919 | |
1819 | 1920 | // Lastly the default theme. |
1820 | - if ($settings['theme_dir'] != $settings['default_theme_dir']) |
|
1821 | - $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
1921 | + if ($settings['theme_dir'] != $settings['default_theme_dir']) { |
|
1922 | + $settings['template_dirs'][] = $settings['default_theme_dir']; |
|
1923 | + } |
|
1822 | 1924 | } |
1823 | 1925 | |
1824 | 1926 | |
1825 | - if (!$initialize) |
|
1826 | - return; |
|
1927 | + if (!$initialize) { |
|
1928 | + return; |
|
1929 | + } |
|
1827 | 1930 | |
1828 | 1931 | // Check to see if we're forcing SSL |
1829 | 1932 | if (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] == 2 && empty($maintenance) && |
1830 | - (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') |
|
1831 | - redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://'))); |
|
1933 | + (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') && SMF != 'SSI') { |
|
1934 | + redirectexit(strtr($_SERVER['REQUEST_URL'], array('http://' => 'https://'))); |
|
1935 | + } |
|
1832 | 1936 | |
1833 | 1937 | // Check to see if they're accessing it from the wrong place. |
1834 | 1938 | if (isset($_SERVER['HTTP_HOST']) || isset($_SERVER['SERVER_NAME'])) |
@@ -1836,8 +1940,9 @@ discard block |
||
1836 | 1940 | $detected_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://'; |
1837 | 1941 | $detected_url .= empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST']; |
1838 | 1942 | $temp = preg_replace('~/' . basename($scripturl) . '(/.+)?$~', '', strtr(dirname($_SERVER['PHP_SELF']), '\\', '/')); |
1839 | - if ($temp != '/') |
|
1840 | - $detected_url .= $temp; |
|
1943 | + if ($temp != '/') { |
|
1944 | + $detected_url .= $temp; |
|
1945 | + } |
|
1841 | 1946 | } |
1842 | 1947 | if (isset($detected_url) && $detected_url != $boardurl) |
1843 | 1948 | { |
@@ -1849,8 +1954,9 @@ discard block |
||
1849 | 1954 | foreach ($aliases as $alias) |
1850 | 1955 | { |
1851 | 1956 | // Rip off all the boring parts, spaces, etc. |
1852 | - if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) |
|
1853 | - $do_fix = true; |
|
1957 | + if ($detected_url == trim($alias) || strtr($detected_url, array('http://' => '', 'https://' => '')) == trim($alias)) { |
|
1958 | + $do_fix = true; |
|
1959 | + } |
|
1854 | 1960 | } |
1855 | 1961 | } |
1856 | 1962 | |
@@ -1858,20 +1964,22 @@ discard block |
||
1858 | 1964 | if (empty($do_fix) && strtr($detected_url, array('://' => '://www.')) == $boardurl && (empty($_GET) || count($_GET) == 1) && SMF != 'SSI') |
1859 | 1965 | { |
1860 | 1966 | // Okay, this seems weird, but we don't want an endless loop - this will make $_GET not empty ;). |
1861 | - if (empty($_GET)) |
|
1862 | - redirectexit('wwwRedirect'); |
|
1863 | - else |
|
1967 | + if (empty($_GET)) { |
|
1968 | + redirectexit('wwwRedirect'); |
|
1969 | + } else |
|
1864 | 1970 | { |
1865 | 1971 | list ($k, $v) = each($_GET); |
1866 | 1972 | |
1867 | - if ($k != 'wwwRedirect') |
|
1868 | - redirectexit('wwwRedirect;' . $k . '=' . $v); |
|
1973 | + if ($k != 'wwwRedirect') { |
|
1974 | + redirectexit('wwwRedirect;' . $k . '=' . $v); |
|
1975 | + } |
|
1869 | 1976 | } |
1870 | 1977 | } |
1871 | 1978 | |
1872 | 1979 | // #3 is just a check for SSL... |
1873 | - if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) |
|
1874 | - $do_fix = true; |
|
1980 | + if (strtr($detected_url, array('https://' => 'http://')) == $boardurl) { |
|
1981 | + $do_fix = true; |
|
1982 | + } |
|
1875 | 1983 | |
1876 | 1984 | // Okay, #4 - perhaps it's an IP address? We're gonna want to use that one, then. (assuming it's the IP or something...) |
1877 | 1985 | if (!empty($do_fix) || preg_match('~^http[s]?://(?:[\d\.:]+|\[[\d:]+\](?::\d+)?)(?:$|/)~', $detected_url) == 1) |
@@ -1905,8 +2013,9 @@ discard block |
||
1905 | 2013 | $board_info['moderators'][$k]['link'] = strtr($dummy['link'], array('"' . $oldurl => '"' . $boardurl)); |
1906 | 2014 | } |
1907 | 2015 | } |
1908 | - foreach ($context['linktree'] as $k => $dummy) |
|
1909 | - $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl)); |
|
2016 | + foreach ($context['linktree'] as $k => $dummy) { |
|
2017 | + $context['linktree'][$k]['url'] = strtr($dummy['url'], array($oldurl => $boardurl)); |
|
2018 | + } |
|
1910 | 2019 | } |
1911 | 2020 | } |
1912 | 2021 | // Set up the contextual user array. |
@@ -1925,16 +2034,16 @@ discard block |
||
1925 | 2034 | 'email' => $user_info['email'], |
1926 | 2035 | 'ignoreusers' => $user_info['ignoreusers'], |
1927 | 2036 | ); |
1928 | - if (!$context['user']['is_guest']) |
|
1929 | - $context['user']['name'] = $user_info['name']; |
|
1930 | - elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) |
|
1931 | - $context['user']['name'] = $txt['guest_title']; |
|
2037 | + if (!$context['user']['is_guest']) { |
|
2038 | + $context['user']['name'] = $user_info['name']; |
|
2039 | + } elseif ($context['user']['is_guest'] && !empty($txt['guest_title'])) { |
|
2040 | + $context['user']['name'] = $txt['guest_title']; |
|
2041 | + } |
|
1932 | 2042 | |
1933 | 2043 | // Determine the current smiley set. |
1934 | 2044 | $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']; |
1935 | 2045 | $context['user']['smiley_set'] = $user_info['smiley_set']; |
1936 | - } |
|
1937 | - else |
|
2046 | + } else |
|
1938 | 2047 | { |
1939 | 2048 | $context['user'] = array( |
1940 | 2049 | 'id' => -1, |
@@ -1950,18 +2059,24 @@ discard block |
||
1950 | 2059 | } |
1951 | 2060 | |
1952 | 2061 | // Some basic information... |
1953 | - if (!isset($context['html_headers'])) |
|
1954 | - $context['html_headers'] = ''; |
|
1955 | - if (!isset($context['javascript_files'])) |
|
1956 | - $context['javascript_files'] = array(); |
|
1957 | - if (!isset($context['css_files'])) |
|
1958 | - $context['css_files'] = array(); |
|
1959 | - if (!isset($context['css_header'])) |
|
1960 | - $context['css_header'] = array(); |
|
1961 | - if (!isset($context['javascript_inline'])) |
|
1962 | - $context['javascript_inline'] = array('standard' => array(), 'defer' => array()); |
|
1963 | - if (!isset($context['javascript_vars'])) |
|
1964 | - $context['javascript_vars'] = array(); |
|
2062 | + if (!isset($context['html_headers'])) { |
|
2063 | + $context['html_headers'] = ''; |
|
2064 | + } |
|
2065 | + if (!isset($context['javascript_files'])) { |
|
2066 | + $context['javascript_files'] = array(); |
|
2067 | + } |
|
2068 | + if (!isset($context['css_files'])) { |
|
2069 | + $context['css_files'] = array(); |
|
2070 | + } |
|
2071 | + if (!isset($context['css_header'])) { |
|
2072 | + $context['css_header'] = array(); |
|
2073 | + } |
|
2074 | + if (!isset($context['javascript_inline'])) { |
|
2075 | + $context['javascript_inline'] = array('standard' => array(), 'defer' => array()); |
|
2076 | + } |
|
2077 | + if (!isset($context['javascript_vars'])) { |
|
2078 | + $context['javascript_vars'] = array(); |
|
2079 | + } |
|
1965 | 2080 | |
1966 | 2081 | $context['login_url'] = (!empty($modSettings['force_ssl']) && $modSettings['force_ssl'] < 2 ? strtr($scripturl, array('http://' => 'https://')) : $scripturl) . '?action=login2'; |
1967 | 2082 | $context['menu_separator'] = !empty($settings['use_image_buttons']) ? ' ' : ' | '; |
@@ -1973,8 +2088,9 @@ discard block |
||
1973 | 2088 | $context['current_action'] = isset($_REQUEST['action']) ? $smcFunc['htmlspecialchars']($_REQUEST['action']) : null; |
1974 | 2089 | $context['current_subaction'] = isset($_REQUEST['sa']) ? $_REQUEST['sa'] : null; |
1975 | 2090 | $context['can_register'] = empty($modSettings['registration_method']) || $modSettings['registration_method'] != 3; |
1976 | - if (isset($modSettings['load_average'])) |
|
1977 | - $context['load_average'] = $modSettings['load_average']; |
|
2091 | + if (isset($modSettings['load_average'])) { |
|
2092 | + $context['load_average'] = $modSettings['load_average']; |
|
2093 | + } |
|
1978 | 2094 | |
1979 | 2095 | // Detect the browser. This is separated out because it's also used in attachment downloads |
1980 | 2096 | detectBrowser(); |
@@ -1988,8 +2104,9 @@ discard block |
||
1988 | 2104 | // This allows sticking some HTML on the page output - useful for controls. |
1989 | 2105 | $context['insert_after_template'] = ''; |
1990 | 2106 | |
1991 | - if (!isset($txt)) |
|
1992 | - $txt = array(); |
|
2107 | + if (!isset($txt)) { |
|
2108 | + $txt = array(); |
|
2109 | + } |
|
1993 | 2110 | |
1994 | 2111 | $simpleActions = array( |
1995 | 2112 | 'findmember', |
@@ -2035,9 +2152,10 @@ discard block |
||
2035 | 2152 | |
2036 | 2153 | // See if theres any extra param to check. |
2037 | 2154 | $requiresXML = false; |
2038 | - foreach ($extraParams as $key => $extra) |
|
2039 | - if (isset($_REQUEST[$extra])) |
|
2155 | + foreach ($extraParams as $key => $extra) { |
|
2156 | + if (isset($_REQUEST[$extra])) |
|
2040 | 2157 | $requiresXML = true; |
2158 | + } |
|
2041 | 2159 | |
2042 | 2160 | // Output is fully XML, so no need for the index template. |
2043 | 2161 | if (isset($_REQUEST['xml']) && (in_array($context['current_action'], $xmlActions) || $requiresXML)) |
@@ -2052,37 +2170,39 @@ discard block |
||
2052 | 2170 | { |
2053 | 2171 | loadLanguage('index+Modifications'); |
2054 | 2172 | $context['template_layers'] = array(); |
2055 | - } |
|
2056 | - |
|
2057 | - else |
|
2173 | + } else |
|
2058 | 2174 | { |
2059 | 2175 | // Custom templates to load, or just default? |
2060 | - if (isset($settings['theme_templates'])) |
|
2061 | - $templates = explode(',', $settings['theme_templates']); |
|
2062 | - else |
|
2063 | - $templates = array('index'); |
|
2176 | + if (isset($settings['theme_templates'])) { |
|
2177 | + $templates = explode(',', $settings['theme_templates']); |
|
2178 | + } else { |
|
2179 | + $templates = array('index'); |
|
2180 | + } |
|
2064 | 2181 | |
2065 | 2182 | // Load each template... |
2066 | - foreach ($templates as $template) |
|
2067 | - loadTemplate($template); |
|
2183 | + foreach ($templates as $template) { |
|
2184 | + loadTemplate($template); |
|
2185 | + } |
|
2068 | 2186 | |
2069 | 2187 | // ...and attempt to load their associated language files. |
2070 | 2188 | $required_files = implode('+', array_merge($templates, array('Modifications'))); |
2071 | 2189 | loadLanguage($required_files, '', false); |
2072 | 2190 | |
2073 | 2191 | // Custom template layers? |
2074 | - if (isset($settings['theme_layers'])) |
|
2075 | - $context['template_layers'] = explode(',', $settings['theme_layers']); |
|
2076 | - else |
|
2077 | - $context['template_layers'] = array('html', 'body'); |
|
2192 | + if (isset($settings['theme_layers'])) { |
|
2193 | + $context['template_layers'] = explode(',', $settings['theme_layers']); |
|
2194 | + } else { |
|
2195 | + $context['template_layers'] = array('html', 'body'); |
|
2196 | + } |
|
2078 | 2197 | } |
2079 | 2198 | |
2080 | 2199 | // Initialize the theme. |
2081 | 2200 | loadSubTemplate('init', 'ignore'); |
2082 | 2201 | |
2083 | 2202 | // Allow overriding the board wide time/number formats. |
2084 | - if (empty($user_settings['time_format']) && !empty($txt['time_format'])) |
|
2085 | - $user_info['time_format'] = $txt['time_format']; |
|
2203 | + if (empty($user_settings['time_format']) && !empty($txt['time_format'])) { |
|
2204 | + $user_info['time_format'] = $txt['time_format']; |
|
2205 | + } |
|
2086 | 2206 | |
2087 | 2207 | // Set the character set from the template. |
2088 | 2208 | $context['character_set'] = empty($modSettings['global_character_set']) ? $txt['lang_character_set'] : $modSettings['global_character_set']; |
@@ -2090,12 +2210,14 @@ discard block |
||
2090 | 2210 | $context['right_to_left'] = !empty($txt['lang_rtl']); |
2091 | 2211 | |
2092 | 2212 | // Guests may still need a name. |
2093 | - if ($context['user']['is_guest'] && empty($context['user']['name'])) |
|
2094 | - $context['user']['name'] = $txt['guest_title']; |
|
2213 | + if ($context['user']['is_guest'] && empty($context['user']['name'])) { |
|
2214 | + $context['user']['name'] = $txt['guest_title']; |
|
2215 | + } |
|
2095 | 2216 | |
2096 | 2217 | // Any theme-related strings that need to be loaded? |
2097 | - if (!empty($settings['require_theme_strings'])) |
|
2098 | - loadLanguage('ThemeStrings', '', false); |
|
2218 | + if (!empty($settings['require_theme_strings'])) { |
|
2219 | + loadLanguage('ThemeStrings', '', false); |
|
2220 | + } |
|
2099 | 2221 | |
2100 | 2222 | // Make a special URL for the language. |
2101 | 2223 | $settings['lang_images_url'] = $settings['images_url'] . '/' . (!empty($txt['image_lang']) ? $txt['image_lang'] : $user_info['language']); |
@@ -2106,8 +2228,9 @@ discard block |
||
2106 | 2228 | // Here is my luvly Responsive CSS |
2107 | 2229 | loadCSSFile('responsive.css', array('force_current' => false, 'validate' => true, 'minimize' => true), 'smf_responsive'); |
2108 | 2230 | |
2109 | - if ($context['right_to_left']) |
|
2110 | - loadCSSFile('rtl.css', array(), 'smf_rtl'); |
|
2231 | + if ($context['right_to_left']) { |
|
2232 | + loadCSSFile('rtl.css', array(), 'smf_rtl'); |
|
2233 | + } |
|
2111 | 2234 | |
2112 | 2235 | // We allow theme variants, because we're cool. |
2113 | 2236 | $context['theme_variant'] = ''; |
@@ -2115,14 +2238,17 @@ discard block |
||
2115 | 2238 | if (!empty($settings['theme_variants'])) |
2116 | 2239 | { |
2117 | 2240 | // Overriding - for previews and that ilk. |
2118 | - if (!empty($_REQUEST['variant'])) |
|
2119 | - $_SESSION['id_variant'] = $_REQUEST['variant']; |
|
2241 | + if (!empty($_REQUEST['variant'])) { |
|
2242 | + $_SESSION['id_variant'] = $_REQUEST['variant']; |
|
2243 | + } |
|
2120 | 2244 | // User selection? |
2121 | - if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) |
|
2122 | - $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : ''); |
|
2245 | + if (empty($settings['disable_user_variant']) || allowedTo('admin_forum')) { |
|
2246 | + $context['theme_variant'] = !empty($_SESSION['id_variant']) ? $_SESSION['id_variant'] : (!empty($options['theme_variant']) ? $options['theme_variant'] : ''); |
|
2247 | + } |
|
2123 | 2248 | // If not a user variant, select the default. |
2124 | - if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) |
|
2125 | - $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0]; |
|
2249 | + if ($context['theme_variant'] == '' || !in_array($context['theme_variant'], $settings['theme_variants'])) { |
|
2250 | + $context['theme_variant'] = !empty($settings['default_variant']) && in_array($settings['default_variant'], $settings['theme_variants']) ? $settings['default_variant'] : $settings['theme_variants'][0]; |
|
2251 | + } |
|
2126 | 2252 | |
2127 | 2253 | // Do this to keep things easier in the templates. |
2128 | 2254 | $context['theme_variant'] = '_' . $context['theme_variant']; |
@@ -2131,20 +2257,23 @@ discard block |
||
2131 | 2257 | if (!empty($context['theme_variant'])) |
2132 | 2258 | { |
2133 | 2259 | loadCSSFile('index' . $context['theme_variant'] . '.css', array(), 'smf_index' . $context['theme_variant']); |
2134 | - if ($context['right_to_left']) |
|
2135 | - loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']); |
|
2260 | + if ($context['right_to_left']) { |
|
2261 | + loadCSSFile('rtl' . $context['theme_variant'] . '.css', array(), 'smf_rtl' . $context['theme_variant']); |
|
2262 | + } |
|
2136 | 2263 | } |
2137 | 2264 | } |
2138 | 2265 | |
2139 | 2266 | // Let's be compatible with old themes! |
2140 | - if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) |
|
2141 | - $context['template_layers'] = array('main'); |
|
2267 | + if (!function_exists('template_html_above') && in_array('html', $context['template_layers'])) { |
|
2268 | + $context['template_layers'] = array('main'); |
|
2269 | + } |
|
2142 | 2270 | |
2143 | 2271 | $context['tabindex'] = 1; |
2144 | 2272 | |
2145 | 2273 | // Compatibility. |
2146 | - if (!isset($settings['theme_version'])) |
|
2147 | - $modSettings['memberCount'] = $modSettings['totalMembers']; |
|
2274 | + if (!isset($settings['theme_version'])) { |
|
2275 | + $modSettings['memberCount'] = $modSettings['totalMembers']; |
|
2276 | + } |
|
2148 | 2277 | |
2149 | 2278 | // Default JS variables for use in every theme |
2150 | 2279 | $context['javascript_vars'] = array( |
@@ -2163,18 +2292,18 @@ discard block |
||
2163 | 2292 | ); |
2164 | 2293 | |
2165 | 2294 | // Add the JQuery library to the list of files to load. |
2166 | - if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') |
|
2167 | - loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2168 | - |
|
2169 | - elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') |
|
2170 | - loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery'); |
|
2171 | - |
|
2172 | - elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') |
|
2173 | - loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery'); |
|
2295 | + if (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'cdn') { |
|
2296 | + loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2297 | + } elseif (isset($modSettings['jquery_source']) && $modSettings['jquery_source'] == 'local') { |
|
2298 | + loadJavaScriptFile('jquery-3.1.1.min.js', array('seed' => false), 'smf_jquery'); |
|
2299 | + } elseif (isset($modSettings['jquery_source'], $modSettings['jquery_custom']) && $modSettings['jquery_source'] == 'custom') { |
|
2300 | + loadJavaScriptFile($modSettings['jquery_custom'], array('external' => true), 'smf_jquery'); |
|
2301 | + } |
|
2174 | 2302 | |
2175 | 2303 | // Auto loading? template_javascript() will take care of the local half of this. |
2176 | - else |
|
2177 | - loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2304 | + else { |
|
2305 | + loadJavaScriptFile('https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array('external' => true), 'smf_jquery'); |
|
2306 | + } |
|
2178 | 2307 | |
2179 | 2308 | // Queue our JQuery plugins! |
2180 | 2309 | loadJavaScriptFile('smf_jquery_plugins.js', array('minimize' => true), 'smf_jquery_plugins'); |
@@ -2197,12 +2326,12 @@ discard block |
||
2197 | 2326 | require_once($sourcedir . '/ScheduledTasks.php'); |
2198 | 2327 | |
2199 | 2328 | // What to do, what to do?! |
2200 | - if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) |
|
2201 | - AutoTask(); |
|
2202 | - else |
|
2203 | - ReduceMailQueue(); |
|
2204 | - } |
|
2205 | - else |
|
2329 | + if (empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time()) { |
|
2330 | + AutoTask(); |
|
2331 | + } else { |
|
2332 | + ReduceMailQueue(); |
|
2333 | + } |
|
2334 | + } else |
|
2206 | 2335 | { |
2207 | 2336 | $type = empty($modSettings['next_task_time']) || $modSettings['next_task_time'] < time() ? 'task' : 'mailq'; |
2208 | 2337 | $ts = $type == 'mailq' ? $modSettings['mail_next_send'] : $modSettings['next_task_time']; |
@@ -2253,8 +2382,9 @@ discard block |
||
2253 | 2382 | foreach ($theme_includes as $include) |
2254 | 2383 | { |
2255 | 2384 | $include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])); |
2256 | - if (file_exists($include)) |
|
2257 | - require_once($include); |
|
2385 | + if (file_exists($include)) { |
|
2386 | + require_once($include); |
|
2387 | + } |
|
2258 | 2388 | } |
2259 | 2389 | } |
2260 | 2390 | |
@@ -2284,16 +2414,19 @@ discard block |
||
2284 | 2414 | // Do any style sheets first, cause we're easy with those. |
2285 | 2415 | if (!empty($style_sheets)) |
2286 | 2416 | { |
2287 | - if (!is_array($style_sheets)) |
|
2288 | - $style_sheets = array($style_sheets); |
|
2417 | + if (!is_array($style_sheets)) { |
|
2418 | + $style_sheets = array($style_sheets); |
|
2419 | + } |
|
2289 | 2420 | |
2290 | - foreach ($style_sheets as $sheet) |
|
2291 | - loadCSSFile($sheet . '.css', array(), $sheet); |
|
2421 | + foreach ($style_sheets as $sheet) { |
|
2422 | + loadCSSFile($sheet . '.css', array(), $sheet); |
|
2423 | + } |
|
2292 | 2424 | } |
2293 | 2425 | |
2294 | 2426 | // No template to load? |
2295 | - if ($template_name === false) |
|
2296 | - return true; |
|
2427 | + if ($template_name === false) { |
|
2428 | + return true; |
|
2429 | + } |
|
2297 | 2430 | |
2298 | 2431 | $loaded = false; |
2299 | 2432 | foreach ($settings['template_dirs'] as $template_dir) |
@@ -2308,12 +2441,14 @@ discard block |
||
2308 | 2441 | |
2309 | 2442 | if ($loaded) |
2310 | 2443 | { |
2311 | - if ($db_show_debug === true) |
|
2312 | - $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; |
|
2444 | + if ($db_show_debug === true) { |
|
2445 | + $context['debug']['templates'][] = $template_name . ' (' . basename($template_dir) . ')'; |
|
2446 | + } |
|
2313 | 2447 | |
2314 | 2448 | // If they have specified an initialization function for this template, go ahead and call it now. |
2315 | - if (function_exists('template_' . $template_name . '_init')) |
|
2316 | - call_user_func('template_' . $template_name . '_init'); |
|
2449 | + if (function_exists('template_' . $template_name . '_init')) { |
|
2450 | + call_user_func('template_' . $template_name . '_init'); |
|
2451 | + } |
|
2317 | 2452 | } |
2318 | 2453 | // Hmmm... doesn't exist?! I don't suppose the directory is wrong, is it? |
2319 | 2454 | elseif (!file_exists($settings['default_theme_dir']) && file_exists($boarddir . '/Themes/default')) |
@@ -2333,13 +2468,14 @@ discard block |
||
2333 | 2468 | loadTemplate($template_name); |
2334 | 2469 | } |
2335 | 2470 | // Cause an error otherwise. |
2336 | - elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) |
|
2337 | - fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); |
|
2338 | - elseif ($fatal) |
|
2339 | - 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')); |
|
2340 | - else |
|
2341 | - return false; |
|
2342 | -} |
|
2471 | + elseif ($template_name != 'Errors' && $template_name != 'index' && $fatal) { |
|
2472 | + fatal_lang_error('theme_template_error', 'template', array((string) $template_name)); |
|
2473 | + } elseif ($fatal) { |
|
2474 | + 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')); |
|
2475 | + } else { |
|
2476 | + return false; |
|
2477 | + } |
|
2478 | + } |
|
2343 | 2479 | |
2344 | 2480 | /** |
2345 | 2481 | * Load a sub-template. |
@@ -2357,17 +2493,19 @@ discard block |
||
2357 | 2493 | { |
2358 | 2494 | global $context, $txt, $db_show_debug; |
2359 | 2495 | |
2360 | - if ($db_show_debug === true) |
|
2361 | - $context['debug']['sub_templates'][] = $sub_template_name; |
|
2496 | + if ($db_show_debug === true) { |
|
2497 | + $context['debug']['sub_templates'][] = $sub_template_name; |
|
2498 | + } |
|
2362 | 2499 | |
2363 | 2500 | // Figure out what the template function is named. |
2364 | 2501 | $theme_function = 'template_' . $sub_template_name; |
2365 | - if (function_exists($theme_function)) |
|
2366 | - $theme_function(); |
|
2367 | - elseif ($fatal === false) |
|
2368 | - fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name)); |
|
2369 | - elseif ($fatal !== 'ignore') |
|
2370 | - 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')); |
|
2502 | + if (function_exists($theme_function)) { |
|
2503 | + $theme_function(); |
|
2504 | + } elseif ($fatal === false) { |
|
2505 | + fatal_lang_error('theme_template_error', 'template', array((string) $sub_template_name)); |
|
2506 | + } elseif ($fatal !== 'ignore') { |
|
2507 | + 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')); |
|
2508 | + } |
|
2371 | 2509 | |
2372 | 2510 | // Are we showing debugging for templates? Just make sure not to do it before the doctype... |
2373 | 2511 | if (allowedTo('admin_forum') && isset($_REQUEST['debug']) && !in_array($sub_template_name, array('init', 'main_below')) && ob_get_length() > 0 && !isset($_REQUEST['xml'])) |
@@ -2404,8 +2542,9 @@ discard block |
||
2404 | 2542 | $params['validate'] = isset($params['validate']) ? $params['validate'] : true; |
2405 | 2543 | |
2406 | 2544 | // If this is an external file, automatically set this to false. |
2407 | - if (!empty($params['external'])) |
|
2408 | - $params['minimize'] = false; |
|
2545 | + if (!empty($params['external'])) { |
|
2546 | + $params['minimize'] = false; |
|
2547 | + } |
|
2409 | 2548 | |
2410 | 2549 | // Account for shorthand like admin.css?alp21 filenames |
2411 | 2550 | $has_seed = strpos($fileName, '.css?'); |
@@ -2422,13 +2561,10 @@ discard block |
||
2422 | 2561 | { |
2423 | 2562 | $fileUrl = $settings['default_theme_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
2424 | 2563 | $filePath = $settings['default_theme_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
2564 | + } else { |
|
2565 | + $fileUrl = false; |
|
2425 | 2566 | } |
2426 | - |
|
2427 | - else |
|
2428 | - $fileUrl = false; |
|
2429 | - } |
|
2430 | - |
|
2431 | - else |
|
2567 | + } else |
|
2432 | 2568 | { |
2433 | 2569 | $fileUrl = $settings[$themeRef . '_url'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
2434 | 2570 | $filePath = $settings[$themeRef . '_dir'] . '/css/' . $fileName . ($has_seed ? '' : $params['seed']); |
@@ -2443,12 +2579,14 @@ discard block |
||
2443 | 2579 | } |
2444 | 2580 | |
2445 | 2581 | // Add it to the array for use in the template |
2446 | - if (!empty($fileName)) |
|
2447 | - $context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
2582 | + if (!empty($fileName)) { |
|
2583 | + $context['css_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
2584 | + } |
|
2448 | 2585 | |
2449 | - if (!empty($context['right_to_left']) && !empty($params['rtl'])) |
|
2450 | - loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0))); |
|
2451 | -} |
|
2586 | + if (!empty($context['right_to_left']) && !empty($params['rtl'])) { |
|
2587 | + loadCSSFile($params['rtl'], array_diff_key($params, array('rtl' => 0))); |
|
2588 | + } |
|
2589 | + } |
|
2452 | 2590 | |
2453 | 2591 | /** |
2454 | 2592 | * Add a block of inline css code to be executed later |
@@ -2465,8 +2603,9 @@ discard block |
||
2465 | 2603 | global $context; |
2466 | 2604 | |
2467 | 2605 | // Gotta add something... |
2468 | - if (empty($css)) |
|
2469 | - return false; |
|
2606 | + if (empty($css)) { |
|
2607 | + return false; |
|
2608 | + } |
|
2470 | 2609 | |
2471 | 2610 | $context['css_header'][] = $css; |
2472 | 2611 | } |
@@ -2501,8 +2640,9 @@ discard block |
||
2501 | 2640 | $params['validate'] = isset($params['validate']) ? $params['validate'] : true; |
2502 | 2641 | |
2503 | 2642 | // If this is an external file, automatically set this to false. |
2504 | - if (!empty($params['external'])) |
|
2505 | - $params['minimize'] = false; |
|
2643 | + if (!empty($params['external'])) { |
|
2644 | + $params['minimize'] = false; |
|
2645 | + } |
|
2506 | 2646 | |
2507 | 2647 | // Account for shorthand like admin.js?alp21 filenames |
2508 | 2648 | $has_seed = strpos($fileName, '.js?'); |
@@ -2519,16 +2659,12 @@ discard block |
||
2519 | 2659 | { |
2520 | 2660 | $fileUrl = $settings['default_theme_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
2521 | 2661 | $filePath = $settings['default_theme_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
2522 | - } |
|
2523 | - |
|
2524 | - else |
|
2662 | + } else |
|
2525 | 2663 | { |
2526 | 2664 | $fileUrl = false; |
2527 | 2665 | $filePath = false; |
2528 | 2666 | } |
2529 | - } |
|
2530 | - |
|
2531 | - else |
|
2667 | + } else |
|
2532 | 2668 | { |
2533 | 2669 | $fileUrl = $settings[$themeRef . '_url'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
2534 | 2670 | $filePath = $settings[$themeRef . '_dir'] . '/scripts/' . $fileName . ($has_seed ? '' : $params['seed']); |
@@ -2543,9 +2679,10 @@ discard block |
||
2543 | 2679 | } |
2544 | 2680 | |
2545 | 2681 | // Add it to the array for use in the template |
2546 | - if (!empty($fileName)) |
|
2547 | - $context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
2548 | -} |
|
2682 | + if (!empty($fileName)) { |
|
2683 | + $context['javascript_files'][$id] = array('fileUrl' => $fileUrl, 'filePath' => $filePath, 'fileName' => $fileName, 'options' => $params); |
|
2684 | + } |
|
2685 | + } |
|
2549 | 2686 | |
2550 | 2687 | /** |
2551 | 2688 | * Add a Javascript variable for output later (for feeding text strings and similar to JS) |
@@ -2559,9 +2696,10 @@ discard block |
||
2559 | 2696 | { |
2560 | 2697 | global $context; |
2561 | 2698 | |
2562 | - if (!empty($key) && (!empty($value) || $value === '0')) |
|
2563 | - $context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value; |
|
2564 | -} |
|
2699 | + if (!empty($key) && (!empty($value) || $value === '0')) { |
|
2700 | + $context['javascript_vars'][$key] = !empty($escape) ? JavaScriptEscape($value) : $value; |
|
2701 | + } |
|
2702 | + } |
|
2565 | 2703 | |
2566 | 2704 | /** |
2567 | 2705 | * Add a block of inline Javascript code to be executed later |
@@ -2578,8 +2716,9 @@ discard block |
||
2578 | 2716 | { |
2579 | 2717 | global $context; |
2580 | 2718 | |
2581 | - if (empty($javascript)) |
|
2582 | - return false; |
|
2719 | + if (empty($javascript)) { |
|
2720 | + return false; |
|
2721 | + } |
|
2583 | 2722 | |
2584 | 2723 | $context['javascript_inline'][($defer === true ? 'defer' : 'standard')][] = $javascript; |
2585 | 2724 | } |
@@ -2600,15 +2739,18 @@ discard block |
||
2600 | 2739 | static $already_loaded = array(); |
2601 | 2740 | |
2602 | 2741 | // Default to the user's language. |
2603 | - if ($lang == '') |
|
2604 | - $lang = isset($user_info['language']) ? $user_info['language'] : $language; |
|
2742 | + if ($lang == '') { |
|
2743 | + $lang = isset($user_info['language']) ? $user_info['language'] : $language; |
|
2744 | + } |
|
2605 | 2745 | |
2606 | 2746 | // Do we want the English version of language file as fallback? |
2607 | - if (empty($modSettings['disable_language_fallback']) && $lang != 'english') |
|
2608 | - loadLanguage($template_name, 'english', false); |
|
2747 | + if (empty($modSettings['disable_language_fallback']) && $lang != 'english') { |
|
2748 | + loadLanguage($template_name, 'english', false); |
|
2749 | + } |
|
2609 | 2750 | |
2610 | - if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) |
|
2611 | - return $lang; |
|
2751 | + if (!$force_reload && isset($already_loaded[$template_name]) && $already_loaded[$template_name] == $lang) { |
|
2752 | + return $lang; |
|
2753 | + } |
|
2612 | 2754 | |
2613 | 2755 | // Make sure we have $settings - if not we're in trouble and need to find it! |
2614 | 2756 | if (empty($settings['default_theme_dir'])) |
@@ -2619,8 +2761,9 @@ discard block |
||
2619 | 2761 | |
2620 | 2762 | // What theme are we in? |
2621 | 2763 | $theme_name = basename($settings['theme_url']); |
2622 | - if (empty($theme_name)) |
|
2623 | - $theme_name = 'unknown'; |
|
2764 | + if (empty($theme_name)) { |
|
2765 | + $theme_name = 'unknown'; |
|
2766 | + } |
|
2624 | 2767 | |
2625 | 2768 | // For each file open it up and write it out! |
2626 | 2769 | foreach (explode('+', $template_name) as $template) |
@@ -2662,8 +2805,9 @@ discard block |
||
2662 | 2805 | $found = true; |
2663 | 2806 | |
2664 | 2807 | // setlocale is required for basename() & pathinfo() to work properly on the selected language |
2665 | - if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) |
|
2666 | - setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']); |
|
2808 | + if (!empty($txt['lang_locale']) && !empty($modSettings['global_character_set'])) { |
|
2809 | + setlocale(LC_CTYPE, $txt['lang_locale'] . '.' . $modSettings['global_character_set']); |
|
2810 | + } |
|
2667 | 2811 | |
2668 | 2812 | break; |
2669 | 2813 | } |
@@ -2703,8 +2847,9 @@ discard block |
||
2703 | 2847 | } |
2704 | 2848 | |
2705 | 2849 | // Keep track of what we're up to soldier. |
2706 | - if ($db_show_debug === true) |
|
2707 | - $context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')'; |
|
2850 | + if ($db_show_debug === true) { |
|
2851 | + $context['debug']['language_files'][] = $template_name . '.' . $lang . ' (' . $theme_name . ')'; |
|
2852 | + } |
|
2708 | 2853 | |
2709 | 2854 | // Remember what we have loaded, and in which language. |
2710 | 2855 | $already_loaded[$template_name] = $lang; |
@@ -2750,8 +2895,9 @@ discard block |
||
2750 | 2895 | ) |
2751 | 2896 | ); |
2752 | 2897 | // In the EXTREMELY unlikely event this happens, give an error message. |
2753 | - if ($smcFunc['db_num_rows']($result) == 0) |
|
2754 | - fatal_lang_error('parent_not_found', 'critical'); |
|
2898 | + if ($smcFunc['db_num_rows']($result) == 0) { |
|
2899 | + fatal_lang_error('parent_not_found', 'critical'); |
|
2900 | + } |
|
2755 | 2901 | while ($row = $smcFunc['db_fetch_assoc']($result)) |
2756 | 2902 | { |
2757 | 2903 | if (!isset($boards[$row['id_board']])) |
@@ -2768,8 +2914,8 @@ discard block |
||
2768 | 2914 | ); |
2769 | 2915 | } |
2770 | 2916 | // If a moderator exists for this board, add that moderator for all children too. |
2771 | - if (!empty($row['id_moderator'])) |
|
2772 | - foreach ($boards as $id => $dummy) |
|
2917 | + if (!empty($row['id_moderator'])) { |
|
2918 | + foreach ($boards as $id => $dummy) |
|
2773 | 2919 | { |
2774 | 2920 | $boards[$id]['moderators'][$row['id_moderator']] = array( |
2775 | 2921 | 'id' => $row['id_moderator'], |
@@ -2777,11 +2923,12 @@ discard block |
||
2777 | 2923 | 'href' => $scripturl . '?action=profile;u=' . $row['id_moderator'], |
2778 | 2924 | 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_moderator'] . '">' . $row['real_name'] . '</a>' |
2779 | 2925 | ); |
2926 | + } |
|
2780 | 2927 | } |
2781 | 2928 | |
2782 | 2929 | // If a moderator group exists for this board, add that moderator group for all children too |
2783 | - if (!empty($row['id_moderator_group'])) |
|
2784 | - foreach ($boards as $id => $dummy) |
|
2930 | + if (!empty($row['id_moderator_group'])) { |
|
2931 | + foreach ($boards as $id => $dummy) |
|
2785 | 2932 | { |
2786 | 2933 | $boards[$id]['moderator_groups'][$row['id_moderator_group']] = array( |
2787 | 2934 | 'id' => $row['id_moderator_group'], |
@@ -2789,6 +2936,7 @@ discard block |
||
2789 | 2936 | 'href' => $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'], |
2790 | 2937 | 'link' => '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_moderator_group'] . '">' . $row['group_name'] . '</a>' |
2791 | 2938 | ); |
2939 | + } |
|
2792 | 2940 | } |
2793 | 2941 | } |
2794 | 2942 | $smcFunc['db_free_result']($result); |
@@ -2815,23 +2963,27 @@ discard block |
||
2815 | 2963 | if (!$use_cache || ($context['languages'] = cache_get_data('known_languages', !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600)) == null) |
2816 | 2964 | { |
2817 | 2965 | // If we don't have our ucwords function defined yet, let's load the settings data. |
2818 | - if (empty($smcFunc['ucwords'])) |
|
2819 | - reloadSettings(); |
|
2966 | + if (empty($smcFunc['ucwords'])) { |
|
2967 | + reloadSettings(); |
|
2968 | + } |
|
2820 | 2969 | |
2821 | 2970 | // If we don't have our theme information yet, let's get it. |
2822 | - if (empty($settings['default_theme_dir'])) |
|
2823 | - loadTheme(0, false); |
|
2971 | + if (empty($settings['default_theme_dir'])) { |
|
2972 | + loadTheme(0, false); |
|
2973 | + } |
|
2824 | 2974 | |
2825 | 2975 | // Default language directories to try. |
2826 | 2976 | $language_directories = array( |
2827 | 2977 | $settings['default_theme_dir'] . '/languages', |
2828 | 2978 | ); |
2829 | - if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) |
|
2830 | - $language_directories[] = $settings['actual_theme_dir'] . '/languages'; |
|
2979 | + if (!empty($settings['actual_theme_dir']) && $settings['actual_theme_dir'] != $settings['default_theme_dir']) { |
|
2980 | + $language_directories[] = $settings['actual_theme_dir'] . '/languages'; |
|
2981 | + } |
|
2831 | 2982 | |
2832 | 2983 | // We possibly have a base theme directory. |
2833 | - if (!empty($settings['base_theme_dir'])) |
|
2834 | - $language_directories[] = $settings['base_theme_dir'] . '/languages'; |
|
2984 | + if (!empty($settings['base_theme_dir'])) { |
|
2985 | + $language_directories[] = $settings['base_theme_dir'] . '/languages'; |
|
2986 | + } |
|
2835 | 2987 | |
2836 | 2988 | // Remove any duplicates. |
2837 | 2989 | $language_directories = array_unique($language_directories); |
@@ -2845,20 +2997,21 @@ discard block |
||
2845 | 2997 | foreach ($language_directories as $language_dir) |
2846 | 2998 | { |
2847 | 2999 | // Can't look in here... doesn't exist! |
2848 | - if (!file_exists($language_dir)) |
|
2849 | - continue; |
|
3000 | + if (!file_exists($language_dir)) { |
|
3001 | + continue; |
|
3002 | + } |
|
2850 | 3003 | |
2851 | 3004 | $dir = dir($language_dir); |
2852 | 3005 | while ($entry = $dir->read()) |
2853 | 3006 | { |
2854 | 3007 | // Look for the index language file... For good measure skip any "index.language-utf8.php" files |
2855 | - if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) |
|
2856 | - continue; |
|
2857 | - |
|
2858 | - if (!empty($langList) && !empty($langList[$matches[1]])) |
|
2859 | - $langName = $langList[$matches[1]]; |
|
3008 | + if (!preg_match('~^index\.(.+[^-utf8])\.php$~', $entry, $matches)) { |
|
3009 | + continue; |
|
3010 | + } |
|
2860 | 3011 | |
2861 | - else |
|
3012 | + if (!empty($langList) && !empty($langList[$matches[1]])) { |
|
3013 | + $langName = $langList[$matches[1]]; |
|
3014 | + } else |
|
2862 | 3015 | { |
2863 | 3016 | $langName = $smcFunc['ucwords'](strtr($matches[1], array('_' => ' '))); |
2864 | 3017 | |
@@ -2899,12 +3052,14 @@ discard block |
||
2899 | 3052 | } |
2900 | 3053 | |
2901 | 3054 | // Do we need to store the lang list? |
2902 | - if (empty($langList)) |
|
2903 | - updateSettings(array('langList' => $smcFunc['json_encode']($catchLang))); |
|
3055 | + if (empty($langList)) { |
|
3056 | + updateSettings(array('langList' => $smcFunc['json_encode']($catchLang))); |
|
3057 | + } |
|
2904 | 3058 | |
2905 | 3059 | // Let's cash in on this deal. |
2906 | - if (!empty($modSettings['cache_enable'])) |
|
2907 | - cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600); |
|
3060 | + if (!empty($modSettings['cache_enable'])) { |
|
3061 | + cache_put_data('known_languages', $context['languages'], !empty($modSettings['cache_enable']) && $modSettings['cache_enable'] < 1 ? 86400 : 3600); |
|
3062 | + } |
|
2908 | 3063 | } |
2909 | 3064 | |
2910 | 3065 | return $context['languages']; |
@@ -2927,8 +3082,9 @@ discard block |
||
2927 | 3082 | global $modSettings, $options, $txt; |
2928 | 3083 | static $censor_vulgar = null, $censor_proper; |
2929 | 3084 | |
2930 | - if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') |
|
2931 | - return $text; |
|
3085 | + if ((!empty($options['show_no_censored']) && !empty($modSettings['allow_no_censored']) && !$force) || empty($modSettings['censor_vulgar']) || trim($text) === '') { |
|
3086 | + return $text; |
|
3087 | + } |
|
2932 | 3088 | |
2933 | 3089 | // If they haven't yet been loaded, load them. |
2934 | 3090 | if ($censor_vulgar == null) |
@@ -2956,9 +3112,9 @@ discard block |
||
2956 | 3112 | { |
2957 | 3113 | $func = !empty($modSettings['censorIgnoreCase']) ? 'str_ireplace' : 'str_replace'; |
2958 | 3114 | $text = $func($censor_vulgar, $censor_proper, $text); |
3115 | + } else { |
|
3116 | + $text = preg_replace($censor_vulgar, $censor_proper, $text); |
|
2959 | 3117 | } |
2960 | - else |
|
2961 | - $text = preg_replace($censor_vulgar, $censor_proper, $text); |
|
2962 | 3118 | |
2963 | 3119 | return $text; |
2964 | 3120 | } |
@@ -2984,38 +3140,42 @@ discard block |
||
2984 | 3140 | @ini_set('track_errors', '1'); |
2985 | 3141 | |
2986 | 3142 | // Don't include the file more than once, if $once is true. |
2987 | - if ($once && in_array($filename, $templates)) |
|
2988 | - return; |
|
3143 | + if ($once && in_array($filename, $templates)) { |
|
3144 | + return; |
|
3145 | + } |
|
2989 | 3146 | // Add this file to the include list, whether $once is true or not. |
2990 | - else |
|
2991 | - $templates[] = $filename; |
|
3147 | + else { |
|
3148 | + $templates[] = $filename; |
|
3149 | + } |
|
2992 | 3150 | |
2993 | 3151 | // Are we going to use eval? |
2994 | 3152 | if (empty($modSettings['disableTemplateEval'])) |
2995 | 3153 | { |
2996 | 3154 | $file_found = file_exists($filename) && eval('?' . '>' . rtrim(file_get_contents($filename))) !== false; |
2997 | 3155 | $settings['current_include_filename'] = $filename; |
2998 | - } |
|
2999 | - else |
|
3156 | + } else |
|
3000 | 3157 | { |
3001 | 3158 | $file_found = file_exists($filename); |
3002 | 3159 | |
3003 | - if ($once && $file_found) |
|
3004 | - require_once($filename); |
|
3005 | - elseif ($file_found) |
|
3006 | - require($filename); |
|
3160 | + if ($once && $file_found) { |
|
3161 | + require_once($filename); |
|
3162 | + } elseif ($file_found) { |
|
3163 | + require($filename); |
|
3164 | + } |
|
3007 | 3165 | } |
3008 | 3166 | |
3009 | 3167 | if ($file_found !== true) |
3010 | 3168 | { |
3011 | 3169 | ob_end_clean(); |
3012 | - if (!empty($modSettings['enableCompressedOutput'])) |
|
3013 | - @ob_start('ob_gzhandler'); |
|
3014 | - else |
|
3015 | - ob_start(); |
|
3170 | + if (!empty($modSettings['enableCompressedOutput'])) { |
|
3171 | + @ob_start('ob_gzhandler'); |
|
3172 | + } else { |
|
3173 | + ob_start(); |
|
3174 | + } |
|
3016 | 3175 | |
3017 | - if (isset($_GET['debug'])) |
|
3018 | - header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3176 | + if (isset($_GET['debug'])) { |
|
3177 | + header('Content-Type: application/xhtml+xml; charset=' . (empty($context['character_set']) ? 'ISO-8859-1' : $context['character_set'])); |
|
3178 | + } |
|
3019 | 3179 | |
3020 | 3180 | // Don't cache error pages!! |
3021 | 3181 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
@@ -3034,12 +3194,13 @@ discard block |
||
3034 | 3194 | echo '<!DOCTYPE html> |
3035 | 3195 | <html', !empty($context['right_to_left']) ? ' dir="rtl"' : '', '> |
3036 | 3196 | <head>'; |
3037 | - if (isset($context['character_set'])) |
|
3038 | - echo ' |
|
3197 | + if (isset($context['character_set'])) { |
|
3198 | + echo ' |
|
3039 | 3199 | <meta charset="', $context['character_set'], '">'; |
3200 | + } |
|
3040 | 3201 | |
3041 | - if (!empty($maintenance) && !allowedTo('admin_forum')) |
|
3042 | - echo ' |
|
3202 | + if (!empty($maintenance) && !allowedTo('admin_forum')) { |
|
3203 | + echo ' |
|
3043 | 3204 | <title>', $mtitle, '</title> |
3044 | 3205 | </head> |
3045 | 3206 | <body> |
@@ -3047,8 +3208,8 @@ discard block |
||
3047 | 3208 | ', $mmessage, ' |
3048 | 3209 | </body> |
3049 | 3210 | </html>'; |
3050 | - elseif (!allowedTo('admin_forum')) |
|
3051 | - echo ' |
|
3211 | + } elseif (!allowedTo('admin_forum')) { |
|
3212 | + echo ' |
|
3052 | 3213 | <title>', $txt['template_parse_error'], '</title> |
3053 | 3214 | </head> |
3054 | 3215 | <body> |
@@ -3056,16 +3217,18 @@ discard block |
||
3056 | 3217 | ', $txt['template_parse_error_message'], ' |
3057 | 3218 | </body> |
3058 | 3219 | </html>'; |
3059 | - else |
|
3220 | + } else |
|
3060 | 3221 | { |
3061 | 3222 | require_once($sourcedir . '/Subs-Package.php'); |
3062 | 3223 | |
3063 | 3224 | $error = fetch_web_data($boardurl . strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); |
3064 | 3225 | $error_array = error_get_last(); |
3065 | - if (empty($error) && ini_get('track_errors') && !empty($error_array)) |
|
3066 | - $error = $error_array['message']; |
|
3067 | - if (empty($error)) |
|
3068 | - $error = $txt['template_parse_errmsg']; |
|
3226 | + if (empty($error) && ini_get('track_errors') && !empty($error_array)) { |
|
3227 | + $error = $error_array['message']; |
|
3228 | + } |
|
3229 | + if (empty($error)) { |
|
3230 | + $error = $txt['template_parse_errmsg']; |
|
3231 | + } |
|
3069 | 3232 | |
3070 | 3233 | $error = strtr($error, array('<b>' => '<strong>', '</b>' => '</strong>')); |
3071 | 3234 | |
@@ -3076,11 +3239,12 @@ discard block |
||
3076 | 3239 | <h3>', $txt['template_parse_error'], '</h3> |
3077 | 3240 | ', sprintf($txt['template_parse_error_details'], strtr($filename, array($boarddir => '', strtr($boarddir, '\\', '/') => ''))); |
3078 | 3241 | |
3079 | - if (!empty($error)) |
|
3080 | - echo ' |
|
3242 | + if (!empty($error)) { |
|
3243 | + echo ' |
|
3081 | 3244 | <hr> |
3082 | 3245 | |
3083 | 3246 | <div style="margin: 0 20px;"><pre>', strtr(strtr($error, array('<strong>' . $boarddir => '<strong>...', '<strong>' . strtr($boarddir, '\\', '/') => '<strong>...')), '\\', '/'), '</pre></div>'; |
3247 | + } |
|
3084 | 3248 | |
3085 | 3249 | // I know, I know... this is VERY COMPLICATED. Still, it's good. |
3086 | 3250 | if (preg_match('~ <strong>(\d+)</strong><br( /)?' . '>$~i', $error, $match) != 0) |
@@ -3090,10 +3254,11 @@ discard block |
||
3090 | 3254 | $data2 = preg_split('~\<br( /)?\>~', $data2); |
3091 | 3255 | |
3092 | 3256 | // Fix the PHP code stuff... |
3093 | - if (!isBrowser('gecko')) |
|
3094 | - $data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2); |
|
3095 | - else |
|
3096 | - $data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2); |
|
3257 | + if (!isBrowser('gecko')) { |
|
3258 | + $data2 = str_replace("\t", '<span style="white-space: pre;">' . "\t" . '</span>', $data2); |
|
3259 | + } else { |
|
3260 | + $data2 = str_replace('<pre style="display: inline;">' . "\t" . '</pre>', "\t", $data2); |
|
3261 | + } |
|
3097 | 3262 | |
3098 | 3263 | // Now we get to work around a bug in PHP where it doesn't escape <br>s! |
3099 | 3264 | $j = -1; |
@@ -3101,8 +3266,9 @@ discard block |
||
3101 | 3266 | { |
3102 | 3267 | $j++; |
3103 | 3268 | |
3104 | - if (substr_count($line, '<br>') == 0) |
|
3105 | - continue; |
|
3269 | + if (substr_count($line, '<br>') == 0) { |
|
3270 | + continue; |
|
3271 | + } |
|
3106 | 3272 | |
3107 | 3273 | $n = substr_count($line, '<br>'); |
3108 | 3274 | for ($i = 0; $i < $n; $i++) |
@@ -3121,38 +3287,42 @@ discard block |
||
3121 | 3287 | // Figure out what the color coding was before... |
3122 | 3288 | $line = max($match[1] - 9, 1); |
3123 | 3289 | $last_line = ''; |
3124 | - for ($line2 = $line - 1; $line2 > 1; $line2--) |
|
3125 | - if (strpos($data2[$line2], '<') !== false) |
|
3290 | + for ($line2 = $line - 1; $line2 > 1; $line2--) { |
|
3291 | + if (strpos($data2[$line2], '<') !== false) |
|
3126 | 3292 | { |
3127 | 3293 | if (preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line2], $color_match) != 0) |
3128 | 3294 | $last_line = $color_match[1]; |
3295 | + } |
|
3129 | 3296 | break; |
3130 | 3297 | } |
3131 | 3298 | |
3132 | 3299 | // Show the relevant lines... |
3133 | 3300 | for ($n = min($match[1] + 4, count($data2) + 1); $line <= $n; $line++) |
3134 | 3301 | { |
3135 | - if ($line == $match[1]) |
|
3136 | - echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">'; |
|
3302 | + if ($line == $match[1]) { |
|
3303 | + echo '</pre><div style="background-color: #ffb0b5;"><pre style="margin: 0;">'; |
|
3304 | + } |
|
3137 | 3305 | |
3138 | 3306 | echo '<span style="color: black;">', sprintf('%' . strlen($n) . 's', $line), ':</span> '; |
3139 | - if (isset($data2[$line]) && $data2[$line] != '') |
|
3140 | - echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line]; |
|
3307 | + if (isset($data2[$line]) && $data2[$line] != '') { |
|
3308 | + echo substr($data2[$line], 0, 2) == '</' ? preg_replace('~^</[^>]+>~', '', $data2[$line]) : $last_line . $data2[$line]; |
|
3309 | + } |
|
3141 | 3310 | |
3142 | 3311 | if (isset($data2[$line]) && preg_match('~(<[^/>]+>)[^<]*$~', $data2[$line], $color_match) != 0) |
3143 | 3312 | { |
3144 | 3313 | $last_line = $color_match[1]; |
3145 | 3314 | echo '</', substr($last_line, 1, 4), '>'; |
3315 | + } elseif ($last_line != '' && strpos($data2[$line], '<') !== false) { |
|
3316 | + $last_line = ''; |
|
3317 | + } elseif ($last_line != '' && $data2[$line] != '') { |
|
3318 | + echo '</', substr($last_line, 1, 4), '>'; |
|
3146 | 3319 | } |
3147 | - elseif ($last_line != '' && strpos($data2[$line], '<') !== false) |
|
3148 | - $last_line = ''; |
|
3149 | - elseif ($last_line != '' && $data2[$line] != '') |
|
3150 | - echo '</', substr($last_line, 1, 4), '>'; |
|
3151 | 3320 | |
3152 | - if ($line == $match[1]) |
|
3153 | - echo '</pre></div><pre style="margin: 0;">'; |
|
3154 | - else |
|
3155 | - echo "\n"; |
|
3321 | + if ($line == $match[1]) { |
|
3322 | + echo '</pre></div><pre style="margin: 0;">'; |
|
3323 | + } else { |
|
3324 | + echo "\n"; |
|
3325 | + } |
|
3156 | 3326 | } |
3157 | 3327 | |
3158 | 3328 | echo '</pre></div>'; |
@@ -3176,8 +3346,9 @@ discard block |
||
3176 | 3346 | global $db_type, $db_name, $ssi_db_user, $ssi_db_passwd, $sourcedir, $db_prefix, $db_port; |
3177 | 3347 | |
3178 | 3348 | // Figure out what type of database we are using. |
3179 | - if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) |
|
3180 | - $db_type = 'mysql'; |
|
3349 | + if (empty($db_type) || !file_exists($sourcedir . '/Subs-Db-' . $db_type . '.php')) { |
|
3350 | + $db_type = 'mysql'; |
|
3351 | + } |
|
3181 | 3352 | |
3182 | 3353 | // Load the file for the database. |
3183 | 3354 | require_once($sourcedir . '/Subs-Db-' . $db_type . '.php'); |
@@ -3185,8 +3356,9 @@ discard block |
||
3185 | 3356 | $db_options = array(); |
3186 | 3357 | |
3187 | 3358 | // Add in the port if needed |
3188 | - if (!empty($db_port)) |
|
3189 | - $db_options['port'] = $db_port; |
|
3359 | + if (!empty($db_port)) { |
|
3360 | + $db_options['port'] = $db_port; |
|
3361 | + } |
|
3190 | 3362 | |
3191 | 3363 | // 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. |
3192 | 3364 | if (SMF == 'SSI' && !empty($ssi_db_user) && !empty($ssi_db_passwd)) |
@@ -3205,13 +3377,15 @@ discard block |
||
3205 | 3377 | } |
3206 | 3378 | |
3207 | 3379 | // Safe guard here, if there isn't a valid connection lets put a stop to it. |
3208 | - if (!$db_connection) |
|
3209 | - display_db_error(); |
|
3380 | + if (!$db_connection) { |
|
3381 | + display_db_error(); |
|
3382 | + } |
|
3210 | 3383 | |
3211 | 3384 | // If in SSI mode fix up the prefix. |
3212 | - if (SMF == 'SSI') |
|
3213 | - db_fix_prefix($db_prefix, $db_name); |
|
3214 | -} |
|
3385 | + if (SMF == 'SSI') { |
|
3386 | + db_fix_prefix($db_prefix, $db_name); |
|
3387 | + } |
|
3388 | + } |
|
3215 | 3389 | |
3216 | 3390 | /** |
3217 | 3391 | * Try to load up a supported caching method. This is saved in $cacheAPI if we are not overriding it. |
@@ -3225,10 +3399,11 @@ discard block |
||
3225 | 3399 | global $sourcedir, $cacheAPI, $cache_accelerator; |
3226 | 3400 | |
3227 | 3401 | // Not overriding this and we have a cacheAPI, send it back. |
3228 | - if (empty($overrideCache) && is_object($cacheAPI)) |
|
3229 | - return $cacheAPI; |
|
3230 | - elseif (is_null($cacheAPI)) |
|
3231 | - $cacheAPI = false; |
|
3402 | + if (empty($overrideCache) && is_object($cacheAPI)) { |
|
3403 | + return $cacheAPI; |
|
3404 | + } elseif (is_null($cacheAPI)) { |
|
3405 | + $cacheAPI = false; |
|
3406 | + } |
|
3232 | 3407 | |
3233 | 3408 | // Make sure our class is in session. |
3234 | 3409 | require_once($sourcedir . '/Class-CacheAPI.php'); |
@@ -3249,8 +3424,9 @@ discard block |
||
3249 | 3424 | if (!$testAPI->isSupported()) |
3250 | 3425 | { |
3251 | 3426 | // Can we save ourselves? |
3252 | - if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') |
|
3253 | - return loadCacheAccelerator(null, false); |
|
3427 | + if (!empty($fallbackSMF) && is_null($overrideCache) && $tryAccelerator != 'smf') { |
|
3428 | + return loadCacheAccelerator(null, false); |
|
3429 | + } |
|
3254 | 3430 | return false; |
3255 | 3431 | } |
3256 | 3432 | |
@@ -3262,9 +3438,9 @@ discard block |
||
3262 | 3438 | { |
3263 | 3439 | $cacheAPI = $testAPI; |
3264 | 3440 | return $cacheAPI; |
3441 | + } else { |
|
3442 | + return $testAPI; |
|
3265 | 3443 | } |
3266 | - else |
|
3267 | - return $testAPI; |
|
3268 | 3444 | } |
3269 | 3445 | } |
3270 | 3446 | |
@@ -3284,8 +3460,9 @@ discard block |
||
3284 | 3460 | |
3285 | 3461 | // @todo Why are we doing this if caching is disabled? |
3286 | 3462 | |
3287 | - if (function_exists('call_integration_hook')) |
|
3288 | - call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level)); |
|
3463 | + if (function_exists('call_integration_hook')) { |
|
3464 | + call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level)); |
|
3465 | + } |
|
3289 | 3466 | |
3290 | 3467 | /* Refresh the cache if either: |
3291 | 3468 | 1. Caching is disabled. |
@@ -3299,16 +3476,19 @@ discard block |
||
3299 | 3476 | require_once($sourcedir . '/' . $file); |
3300 | 3477 | $cache_block = call_user_func_array($function, $params); |
3301 | 3478 | |
3302 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) |
|
3303 | - cache_put_data($key, $cache_block, $cache_block['expires'] - time()); |
|
3479 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) { |
|
3480 | + cache_put_data($key, $cache_block, $cache_block['expires'] - time()); |
|
3481 | + } |
|
3304 | 3482 | } |
3305 | 3483 | |
3306 | 3484 | // Some cached data may need a freshening up after retrieval. |
3307 | - if (!empty($cache_block['post_retri_eval'])) |
|
3308 | - eval($cache_block['post_retri_eval']); |
|
3485 | + if (!empty($cache_block['post_retri_eval'])) { |
|
3486 | + eval($cache_block['post_retri_eval']); |
|
3487 | + } |
|
3309 | 3488 | |
3310 | - if (function_exists('call_integration_hook')) |
|
3311 | - call_integration_hook('post_cache_quick_get', array(&$cache_block)); |
|
3489 | + if (function_exists('call_integration_hook')) { |
|
3490 | + call_integration_hook('post_cache_quick_get', array(&$cache_block)); |
|
3491 | + } |
|
3312 | 3492 | |
3313 | 3493 | return $cache_block['data']; |
3314 | 3494 | } |
@@ -3335,8 +3515,9 @@ discard block |
||
3335 | 3515 | global $smcFunc, $cache_enable, $cacheAPI; |
3336 | 3516 | global $cache_hits, $cache_count, $db_show_debug; |
3337 | 3517 | |
3338 | - if (empty($cache_enable) || empty($cacheAPI)) |
|
3339 | - return; |
|
3518 | + if (empty($cache_enable) || empty($cacheAPI)) { |
|
3519 | + return; |
|
3520 | + } |
|
3340 | 3521 | |
3341 | 3522 | $cache_count = isset($cache_count) ? $cache_count + 1 : 1; |
3342 | 3523 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -3349,12 +3530,14 @@ discard block |
||
3349 | 3530 | $value = $value === null ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_encode']($value) : json_encode($value)); |
3350 | 3531 | $cacheAPI->putData($key, $value, $ttl); |
3351 | 3532 | |
3352 | - if (function_exists('call_integration_hook')) |
|
3353 | - call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl)); |
|
3533 | + if (function_exists('call_integration_hook')) { |
|
3534 | + call_integration_hook('cache_put_data', array(&$key, &$value, &$ttl)); |
|
3535 | + } |
|
3354 | 3536 | |
3355 | - if (isset($db_show_debug) && $db_show_debug === true) |
|
3356 | - $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
3357 | -} |
|
3537 | + if (isset($db_show_debug) && $db_show_debug === true) { |
|
3538 | + $cache_hits[$cache_count]['t'] = array_sum(explode(' ', microtime())) - array_sum(explode(' ', $st)); |
|
3539 | + } |
|
3540 | + } |
|
3358 | 3541 | |
3359 | 3542 | /** |
3360 | 3543 | * Gets the value from the cache specified by key, so long as it is not older than ttl seconds. |
@@ -3370,8 +3553,9 @@ discard block |
||
3370 | 3553 | global $smcFunc, $cache_enable, $cacheAPI; |
3371 | 3554 | global $cache_hits, $cache_count, $cache_misses, $cache_count_misses, $db_show_debug; |
3372 | 3555 | |
3373 | - if (empty($cache_enable) || empty($cacheAPI)) |
|
3374 | - return; |
|
3556 | + if (empty($cache_enable) || empty($cacheAPI)) { |
|
3557 | + return; |
|
3558 | + } |
|
3375 | 3559 | |
3376 | 3560 | $cache_count = isset($cache_count) ? $cache_count + 1 : 1; |
3377 | 3561 | if (isset($db_show_debug) && $db_show_debug === true) |
@@ -3391,16 +3575,18 @@ discard block |
||
3391 | 3575 | |
3392 | 3576 | if (empty($value)) |
3393 | 3577 | { |
3394 | - if (!is_array($cache_misses)) |
|
3395 | - $cache_misses = array(); |
|
3578 | + if (!is_array($cache_misses)) { |
|
3579 | + $cache_misses = array(); |
|
3580 | + } |
|
3396 | 3581 | |
3397 | 3582 | $cache_count_misses = isset($cache_count_misses) ? $cache_count_misses + 1 : 1; |
3398 | 3583 | $cache_misses[$cache_count_misses] = array('k' => $original_key, 'd' => 'get'); |
3399 | 3584 | } |
3400 | 3585 | } |
3401 | 3586 | |
3402 | - if (function_exists('call_integration_hook') && isset($value)) |
|
3403 | - call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value)); |
|
3587 | + if (function_exists('call_integration_hook') && isset($value)) { |
|
3588 | + call_integration_hook('cache_get_data', array(&$key, &$ttl, &$value)); |
|
3589 | + } |
|
3404 | 3590 | |
3405 | 3591 | return empty($value) ? null : (isset($smcFunc['json_encode']) ? $smcFunc['json_decode']($value, true) : smf_json_decode($value, true)); |
3406 | 3592 | } |
@@ -3422,8 +3608,9 @@ discard block |
||
3422 | 3608 | global $cacheAPI; |
3423 | 3609 | |
3424 | 3610 | // If we can't get to the API, can't do this. |
3425 | - if (empty($cacheAPI)) |
|
3426 | - return; |
|
3611 | + if (empty($cacheAPI)) { |
|
3612 | + return; |
|
3613 | + } |
|
3427 | 3614 | |
3428 | 3615 | // Ask the API to do the heavy lifting. cleanCache also calls invalidateCache to be sure. |
3429 | 3616 | $cacheAPI->cleanCache($type); |
@@ -3448,8 +3635,9 @@ discard block |
||
3448 | 3635 | global $modSettings, $boardurl, $smcFunc, $image_proxy_enabled, $image_proxy_secret; |
3449 | 3636 | |
3450 | 3637 | // Come on! |
3451 | - if (empty($data)) |
|
3452 | - return array(); |
|
3638 | + if (empty($data)) { |
|
3639 | + return array(); |
|
3640 | + } |
|
3453 | 3641 | |
3454 | 3642 | // Set a nice default var. |
3455 | 3643 | $image = ''; |
@@ -3457,11 +3645,11 @@ discard block |
||
3457 | 3645 | // Gravatar has been set as mandatory! |
3458 | 3646 | if (!empty($modSettings['gravatarOverride'])) |
3459 | 3647 | { |
3460 | - if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) |
|
3461 | - $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3462 | - |
|
3463 | - else if (!empty($data['email'])) |
|
3464 | - $image = get_gravatar_url($data['email']); |
|
3648 | + if (!empty($modSettings['gravatarAllowExtraEmail']) && !empty($data['avatar']) && stristr($data['avatar'], 'gravatar://')) { |
|
3649 | + $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3650 | + } else if (!empty($data['email'])) { |
|
3651 | + $image = get_gravatar_url($data['email']); |
|
3652 | + } |
|
3465 | 3653 | } |
3466 | 3654 | |
3467 | 3655 | // Look if the user has a gravatar field or has set an external url as avatar. |
@@ -3473,54 +3661,60 @@ discard block |
||
3473 | 3661 | // Gravatar. |
3474 | 3662 | if (stristr($data['avatar'], 'gravatar://')) |
3475 | 3663 | { |
3476 | - if ($data['avatar'] == 'gravatar://') |
|
3477 | - $image = get_gravatar_url($data['email']); |
|
3478 | - |
|
3479 | - elseif (!empty($modSettings['gravatarAllowExtraEmail'])) |
|
3480 | - $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3664 | + if ($data['avatar'] == 'gravatar://') { |
|
3665 | + $image = get_gravatar_url($data['email']); |
|
3666 | + } elseif (!empty($modSettings['gravatarAllowExtraEmail'])) { |
|
3667 | + $image = get_gravatar_url($smcFunc['substr']($data['avatar'], 11)); |
|
3668 | + } |
|
3481 | 3669 | } |
3482 | 3670 | |
3483 | 3671 | // External url. |
3484 | 3672 | else |
3485 | 3673 | { |
3486 | 3674 | // Using ssl? |
3487 | - if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) |
|
3488 | - $image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret); |
|
3675 | + if (!empty($modSettings['force_ssl']) && $image_proxy_enabled && stripos($data['avatar'], 'http://') !== false) { |
|
3676 | + $image = strtr($boardurl, array('http://' => 'https://')) . '/proxy.php?request=' . urlencode($data['avatar']) . '&hash=' . md5($data['avatar'] . $image_proxy_secret); |
|
3677 | + } |
|
3489 | 3678 | |
3490 | 3679 | // Just a plain external url. |
3491 | - else |
|
3492 | - $image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar']; |
|
3680 | + else { |
|
3681 | + $image = (stristr($data['avatar'], 'http://') || stristr($data['avatar'], 'https://')) ? $data['avatar'] : $modSettings['avatar_url'] . '/' . $data['avatar']; |
|
3682 | + } |
|
3493 | 3683 | } |
3494 | 3684 | } |
3495 | 3685 | |
3496 | 3686 | // Perhaps this user has an attachment as avatar... |
3497 | - else if (!empty($data['filename'])) |
|
3498 | - $image = $modSettings['custom_avatar_url'] . '/' . $data['filename']; |
|
3687 | + else if (!empty($data['filename'])) { |
|
3688 | + $image = $modSettings['custom_avatar_url'] . '/' . $data['filename']; |
|
3689 | + } |
|
3499 | 3690 | |
3500 | 3691 | // Right... no avatar... use our default image. |
3501 | - else |
|
3502 | - $image = $modSettings['avatar_url'] . '/default.png'; |
|
3692 | + else { |
|
3693 | + $image = $modSettings['avatar_url'] . '/default.png'; |
|
3694 | + } |
|
3503 | 3695 | } |
3504 | 3696 | |
3505 | 3697 | call_integration_hook('integrate_set_avatar_data', array(&$image, &$data)); |
3506 | 3698 | |
3507 | 3699 | // 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. |
3508 | - if (!empty($image)) |
|
3509 | - return array( |
|
3700 | + if (!empty($image)) { |
|
3701 | + return array( |
|
3510 | 3702 | 'name' => !empty($data['avatar']) ? $data['avatar'] : '', |
3511 | 3703 | 'image' => '<img class="avatar" src="' . $image . '" />', |
3512 | 3704 | 'href' => $image, |
3513 | 3705 | 'url' => $image, |
3514 | 3706 | ); |
3707 | + } |
|
3515 | 3708 | |
3516 | 3709 | // Fallback to make life easier for everyone... |
3517 | - else |
|
3518 | - return array( |
|
3710 | + else { |
|
3711 | + return array( |
|
3519 | 3712 | 'name' => '', |
3520 | 3713 | 'image' => '', |
3521 | 3714 | 'href' => '', |
3522 | 3715 | 'url' => '', |
3523 | 3716 | ); |
3524 | -} |
|
3717 | + } |
|
3718 | + } |
|
3525 | 3719 | |
3526 | 3720 | ?> |
3527 | 3721 | \ No newline at end of file |