@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @return array The truncated array |
25 | 25 | */ |
26 | -function truncateArray($arr, $max_length=1900) |
|
26 | +function truncateArray($arr, $max_length = 1900) |
|
27 | 27 | { |
28 | 28 | $curr_length = array_sum(array_map("strlen", $arr)); |
29 | 29 | if ($curr_length <= $max_length) |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | else |
32 | 32 | { |
33 | 33 | // Truncate each element's value to a reasonable length |
34 | - $param_max = floor($max_length/count($arr)); |
|
34 | + $param_max = floor($max_length / count($arr)); |
|
35 | 35 | foreach ($arr as $key => &$value) |
36 | 36 | $value = substr($value, 0, $param_max - strlen($key) - 5); |
37 | 37 | return $arr; |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | if (filemtime($boarddir . '/db_last_error.php') === $last_db_error_change) |
198 | 198 | { |
199 | 199 | // Write the change |
200 | - $write_db_change = '<' . '?' . "php\n" . '$db_last_error = ' . time() . ';' . "\n" . '?' . '>'; |
|
200 | + $write_db_change = '<' . '?' . "php\n" . '$db_last_error = ' . time() . ';' . "\n" . '?' . '>'; |
|
201 | 201 | $written_bytes = file_put_contents($boarddir . '/db_last_error.php', $write_db_change, LOCK_EX); |
202 | 202 | |
203 | 203 | // survey says ... |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | ', $txt['debug_language_files'], count($context['debug']['language_files']), ': <em>', implode('</em>, <em>', $context['debug']['language_files']), '</em>.<br> |
271 | 271 | ', $txt['debug_stylesheets'], count($context['debug']['sheets']), ': <em>', implode('</em>, <em>', $context['debug']['sheets']), '</em>.<br> |
272 | 272 | ', $txt['debug_hooks'], empty($context['debug']['hooks']) ? 0 : count($context['debug']['hooks']) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_hooks\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_hooks" style="display: none;"><em>' . implode('</em>, <em>', $context['debug']['hooks']), '</em></span>)', '<br> |
273 | - ',(isset($context['debug']['instances']) ? ($txt['debug_instances'] . (empty($context['debug']['instances']) ? 0 : count($context['debug']['instances'])) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_instances\').style.display = \'inline\'; this.style.display = \'none\'; return false;">'. $txt['debug_show'] .'</a><span id="debug_instances" style="display: none;"><em>'. implode('</em>, <em>', array_keys($context['debug']['instances'])) .'</em></span>)'. '<br>') : ''),' |
|
273 | + ',(isset($context['debug']['instances']) ? ($txt['debug_instances'] . (empty($context['debug']['instances']) ? 0 : count($context['debug']['instances'])) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_instances\').style.display = \'inline\'; this.style.display = \'none\'; return false;">' . $txt['debug_show'] . '</a><span id="debug_instances" style="display: none;"><em>' . implode('</em>, <em>', array_keys($context['debug']['instances'])) . '</em></span>)' . '<br>') : ''), ' |
|
274 | 274 | ', $txt['debug_files_included'], count($files), ' - ', round($total_size / 1024), $txt['debug_kb'], ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_include_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_include_info" style="display: none;"><em>', implode('</em>, <em>', $files), '</em></span>)<br>'; |
275 | 275 | |
276 | 276 | if (function_exists('memory_get_peak_usage')) |
@@ -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 | * Truncate the GET array to a specified length |
@@ -26,14 +27,15 @@ discard block |
||
26 | 27 | function truncateArray($arr, $max_length=1900) |
27 | 28 | { |
28 | 29 | $curr_length = array_sum(array_map("strlen", $arr)); |
29 | - if ($curr_length <= $max_length) |
|
30 | - return $arr; |
|
31 | - else |
|
30 | + if ($curr_length <= $max_length) { |
|
31 | + return $arr; |
|
32 | + } else |
|
32 | 33 | { |
33 | 34 | // Truncate each element's value to a reasonable length |
34 | 35 | $param_max = floor($max_length/count($arr)); |
35 | - foreach ($arr as $key => &$value) |
|
36 | - $value = substr($value, 0, $param_max - strlen($key) - 5); |
|
36 | + foreach ($arr as $key => &$value) { |
|
37 | + $value = substr($value, 0, $param_max - strlen($key) - 5); |
|
38 | + } |
|
37 | 39 | return $arr; |
38 | 40 | } |
39 | 41 | } |
@@ -55,8 +57,9 @@ discard block |
||
55 | 57 | // Don't update for every page - this isn't wholly accurate but who cares. |
56 | 58 | if ($topic) |
57 | 59 | { |
58 | - if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic) |
|
59 | - $force = false; |
|
60 | + if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic) { |
|
61 | + $force = false; |
|
62 | + } |
|
60 | 63 | $_SESSION['last_topic_id'] = $topic; |
61 | 64 | } |
62 | 65 | } |
@@ -69,22 +72,24 @@ discard block |
||
69 | 72 | } |
70 | 73 | |
71 | 74 | // Don't mark them as online more than every so often. |
72 | - if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force) |
|
73 | - return; |
|
75 | + if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force) { |
|
76 | + return; |
|
77 | + } |
|
74 | 78 | |
75 | 79 | if (!empty($modSettings['who_enabled'])) |
76 | 80 | { |
77 | 81 | $encoded_get = truncateArray($_GET) + array('USER_AGENT' => $_SERVER['HTTP_USER_AGENT']); |
78 | 82 | |
79 | 83 | // In the case of a dlattach action, session_var may not be set. |
80 | - if (!isset($context['session_var'])) |
|
81 | - $context['session_var'] = $_SESSION['session_var']; |
|
84 | + if (!isset($context['session_var'])) { |
|
85 | + $context['session_var'] = $_SESSION['session_var']; |
|
86 | + } |
|
82 | 87 | |
83 | 88 | unset($encoded_get['sesc'], $encoded_get[$context['session_var']]); |
84 | 89 | $encoded_get = $smcFunc['json_encode']($encoded_get); |
90 | + } else { |
|
91 | + $encoded_get = ''; |
|
85 | 92 | } |
86 | - else |
|
87 | - $encoded_get = ''; |
|
88 | 93 | |
89 | 94 | // Guests use 0, members use their session ID. |
90 | 95 | $session_id = $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id(); |
@@ -124,17 +129,18 @@ discard block |
||
124 | 129 | ); |
125 | 130 | |
126 | 131 | // Guess it got deleted. |
127 | - if ($smcFunc['db_affected_rows']() == 0) |
|
132 | + if ($smcFunc['db_affected_rows']() == 0) { |
|
133 | + $_SESSION['log_time'] = 0; |
|
134 | + } |
|
135 | + } else { |
|
128 | 136 | $_SESSION['log_time'] = 0; |
129 | 137 | } |
130 | - else |
|
131 | - $_SESSION['log_time'] = 0; |
|
132 | 138 | |
133 | 139 | // Otherwise, we have to delete and insert. |
134 | 140 | if (empty($_SESSION['log_time'])) |
135 | 141 | { |
136 | - if ($do_delete || !empty($user_info['id'])) |
|
137 | - $smcFunc['db_query']('', ' |
|
142 | + if ($do_delete || !empty($user_info['id'])) { |
|
143 | + $smcFunc['db_query']('', ' |
|
138 | 144 | DELETE FROM {db_prefix}log_online |
139 | 145 | WHERE ' . ($do_delete ? 'log_time < {int:log_time}' : '') . ($do_delete && !empty($user_info['id']) ? ' OR ' : '') . (empty($user_info['id']) ? '' : 'id_member = {int:current_member}'), |
140 | 146 | array( |
@@ -142,6 +148,7 @@ discard block |
||
142 | 148 | 'log_time' => time() - $modSettings['lastActive'] * 60, |
143 | 149 | ) |
144 | 150 | ); |
151 | + } |
|
145 | 152 | |
146 | 153 | $smcFunc['db_insert']($do_delete ? 'ignore' : 'replace', |
147 | 154 | '{db_prefix}log_online', |
@@ -155,21 +162,24 @@ discard block |
||
155 | 162 | $_SESSION['log_time'] = time(); |
156 | 163 | |
157 | 164 | // Well, they are online now. |
158 | - if (empty($_SESSION['timeOnlineUpdated'])) |
|
159 | - $_SESSION['timeOnlineUpdated'] = time(); |
|
165 | + if (empty($_SESSION['timeOnlineUpdated'])) { |
|
166 | + $_SESSION['timeOnlineUpdated'] = time(); |
|
167 | + } |
|
160 | 168 | |
161 | 169 | // Set their login time, if not already done within the last minute. |
162 | 170 | if (SMF != 'SSI' && !empty($user_info['last_login']) && $user_info['last_login'] < time() - 60 && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('.xml', 'login2', 'logintfa')))) |
163 | 171 | { |
164 | 172 | // Don't count longer than 15 minutes. |
165 | - if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15) |
|
166 | - $_SESSION['timeOnlineUpdated'] = time(); |
|
173 | + if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15) { |
|
174 | + $_SESSION['timeOnlineUpdated'] = time(); |
|
175 | + } |
|
167 | 176 | |
168 | 177 | $user_settings['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated']; |
169 | 178 | updateMemberData($user_info['id'], array('last_login' => time(), 'member_ip' => $user_info['ip'], 'member_ip2' => $_SERVER['BAN_CHECK_IP'], 'total_time_logged_in' => $user_settings['total_time_logged_in'])); |
170 | 179 | |
171 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
172 | - cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60); |
|
180 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
181 | + cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60); |
|
182 | + } |
|
173 | 183 | |
174 | 184 | $user_info['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated']; |
175 | 185 | $_SESSION['timeOnlineUpdated'] = time(); |
@@ -206,8 +216,7 @@ discard block |
||
206 | 216 | // Oops. maybe we have no more disk space left, or some other troubles, troubles... |
207 | 217 | // Copy the file back and run for your life! |
208 | 218 | @copy($boarddir . '/db_last_error_bak.php', $boarddir . '/db_last_error.php'); |
209 | - } |
|
210 | - else |
|
219 | + } else |
|
211 | 220 | { |
212 | 221 | @touch($boarddir . '/' . 'Settings.php'); |
213 | 222 | return true; |
@@ -227,22 +236,27 @@ discard block |
||
227 | 236 | global $db_cache, $db_count, $cache_misses, $cache_count_misses, $db_show_debug, $cache_count, $cache_hits, $smcFunc, $txt; |
228 | 237 | |
229 | 238 | // Add to Settings.php if you want to show the debugging information. |
230 | - if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery')) |
|
231 | - return; |
|
239 | + if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery')) { |
|
240 | + return; |
|
241 | + } |
|
232 | 242 | |
233 | - if (empty($_SESSION['view_queries'])) |
|
234 | - $_SESSION['view_queries'] = 0; |
|
235 | - if (empty($context['debug']['language_files'])) |
|
236 | - $context['debug']['language_files'] = array(); |
|
237 | - if (empty($context['debug']['sheets'])) |
|
238 | - $context['debug']['sheets'] = array(); |
|
243 | + if (empty($_SESSION['view_queries'])) { |
|
244 | + $_SESSION['view_queries'] = 0; |
|
245 | + } |
|
246 | + if (empty($context['debug']['language_files'])) { |
|
247 | + $context['debug']['language_files'] = array(); |
|
248 | + } |
|
249 | + if (empty($context['debug']['sheets'])) { |
|
250 | + $context['debug']['sheets'] = array(); |
|
251 | + } |
|
239 | 252 | |
240 | 253 | $files = get_included_files(); |
241 | 254 | $total_size = 0; |
242 | 255 | for ($i = 0, $n = count($files); $i < $n; $i++) |
243 | 256 | { |
244 | - if (file_exists($files[$i])) |
|
245 | - $total_size += filesize($files[$i]); |
|
257 | + if (file_exists($files[$i])) { |
|
258 | + $total_size += filesize($files[$i]); |
|
259 | + } |
|
246 | 260 | $files[$i] = strtr($files[$i], array($boarddir => '.', $sourcedir => '(Sources)', $cachedir => '(Cache)', $settings['actual_theme_dir'] => '(Current Theme)')); |
247 | 261 | } |
248 | 262 | |
@@ -251,8 +265,9 @@ discard block |
||
251 | 265 | { |
252 | 266 | foreach ($db_cache as $q => $qq) |
253 | 267 | { |
254 | - if (!empty($qq['w'])) |
|
255 | - $warnings += count($qq['w']); |
|
268 | + if (!empty($qq['w'])) { |
|
269 | + $warnings += count($qq['w']); |
|
270 | + } |
|
256 | 271 | } |
257 | 272 | |
258 | 273 | $_SESSION['debug'] = &$db_cache; |
@@ -273,12 +288,14 @@ discard block |
||
273 | 288 | ',(isset($context['debug']['instances']) ? ($txt['debug_instances'] . (empty($context['debug']['instances']) ? 0 : count($context['debug']['instances'])) . ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_instances\').style.display = \'inline\'; this.style.display = \'none\'; return false;">'. $txt['debug_show'] .'</a><span id="debug_instances" style="display: none;"><em>'. implode('</em>, <em>', array_keys($context['debug']['instances'])) .'</em></span>)'. '<br>') : ''),' |
274 | 289 | ', $txt['debug_files_included'], count($files), ' - ', round($total_size / 1024), $txt['debug_kb'], ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_include_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_include_info" style="display: none;"><em>', implode('</em>, <em>', $files), '</em></span>)<br>'; |
275 | 290 | |
276 | - if (function_exists('memory_get_peak_usage')) |
|
277 | - echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>'; |
|
291 | + if (function_exists('memory_get_peak_usage')) { |
|
292 | + echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>'; |
|
293 | + } |
|
278 | 294 | |
279 | 295 | // What tokens are active? |
280 | - if (isset($_SESSION['token'])) |
|
281 | - echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>'; |
|
296 | + if (isset($_SESSION['token'])) { |
|
297 | + echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>'; |
|
298 | + } |
|
282 | 299 | |
283 | 300 | if (!empty($modSettings['cache_enable']) && !empty($cache_hits)) |
284 | 301 | { |
@@ -292,10 +309,12 @@ discard block |
||
292 | 309 | $total_t += $cache_hit['t']; |
293 | 310 | $total_s += $cache_hit['s']; |
294 | 311 | } |
295 | - if (!isset($cache_misses)) |
|
296 | - $cache_misses = array(); |
|
297 | - foreach ($cache_misses as $missed) |
|
298 | - $missed_entries[] = $missed['d'] . ' ' . $missed['k']; |
|
312 | + if (!isset($cache_misses)) { |
|
313 | + $cache_misses = array(); |
|
314 | + } |
|
315 | + foreach ($cache_misses as $missed) { |
|
316 | + $missed_entries[] = $missed['d'] . ' ' . $missed['k']; |
|
317 | + } |
|
299 | 318 | |
300 | 319 | echo ' |
301 | 320 | ', $txt['debug_cache_hits'], $cache_count, ': ', sprintf($txt['debug_cache_seconds_bytes_total'], comma_format($total_t, 5), comma_format($total_s)), ' (<a href="javascript:void(0);" onclick="document.getElementById(\'debug_cache_info\').style.display = \'inline\'; this.style.display = \'none\'; return false;">', $txt['debug_show'], '</a><span id="debug_cache_info" style="display: none;"><em>', implode('</em>, <em>', $entries), '</em></span>)<br> |
@@ -306,38 +325,44 @@ discard block |
||
306 | 325 | <a href="', $scripturl, '?action=viewquery" target="_blank">', $warnings == 0 ? sprintf($txt['debug_queries_used'], (int) $db_count) : sprintf($txt['debug_queries_used_and_warnings'], (int) $db_count, $warnings), '</a><br> |
307 | 326 | <br>'; |
308 | 327 | |
309 | - if ($_SESSION['view_queries'] == 1 && !empty($db_cache)) |
|
310 | - foreach ($db_cache as $q => $qq) |
|
328 | + if ($_SESSION['view_queries'] == 1 && !empty($db_cache)) { |
|
329 | + foreach ($db_cache as $q => $qq) |
|
311 | 330 | { |
312 | 331 | $is_select = strpos(trim($qq['q']), 'SELECT') === 0 || preg_match('~^INSERT(?: IGNORE)? INTO \w+(?:\s+\([^)]+\))?\s+SELECT .+$~s', trim($qq['q'])) != 0; |
332 | + } |
|
313 | 333 | // Temporary tables created in earlier queries are not explainable. |
314 | 334 | if ($is_select) |
315 | 335 | { |
316 | - foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) |
|
317 | - if (strpos(trim($qq['q']), $tmp) !== false) |
|
336 | + foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) { |
|
337 | + if (strpos(trim($qq['q']), $tmp) !== false) |
|
318 | 338 | { |
319 | 339 | $is_select = false; |
340 | + } |
|
320 | 341 | break; |
321 | 342 | } |
322 | 343 | } |
323 | 344 | // But actual creation of the temporary tables are. |
324 | - elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($qq['q'])) != 0) |
|
325 | - $is_select = true; |
|
345 | + elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($qq['q'])) != 0) { |
|
346 | + $is_select = true; |
|
347 | + } |
|
326 | 348 | |
327 | 349 | // Make the filenames look a bit better. |
328 | - if (isset($qq['f'])) |
|
329 | - $qq['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $qq['f']); |
|
350 | + if (isset($qq['f'])) { |
|
351 | + $qq['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $qq['f']); |
|
352 | + } |
|
330 | 353 | |
331 | 354 | echo ' |
332 | 355 | <strong>', $is_select ? '<a href="' . $scripturl . '?action=viewquery;qq=' . ($q + 1) . '#qq' . $q . '" target="_blank" style="text-decoration: none;">' : '', nl2br(str_replace("\t", ' ', $smcFunc['htmlspecialchars'](ltrim($qq['q'], "\n\r")))) . ($is_select ? '</a></strong>' : '</strong>') . '<br> |
333 | 356 | '; |
334 | - if (!empty($qq['f']) && !empty($qq['l'])) |
|
335 | - echo sprintf($txt['debug_query_in_line'], $qq['f'], $qq['l']); |
|
357 | + if (!empty($qq['f']) && !empty($qq['l'])) { |
|
358 | + echo sprintf($txt['debug_query_in_line'], $qq['f'], $qq['l']); |
|
359 | + } |
|
336 | 360 | |
337 | - if (isset($qq['s'], $qq['t']) && isset($txt['debug_query_which_took_at'])) |
|
338 | - echo sprintf($txt['debug_query_which_took_at'], round($qq['t'], 8), round($qq['s'], 8)) . '<br>'; |
|
339 | - elseif (isset($qq['t'])) |
|
340 | - echo sprintf($txt['debug_query_which_took'], round($qq['t'], 8)) . '<br>'; |
|
361 | + if (isset($qq['s'], $qq['t']) && isset($txt['debug_query_which_took_at'])) { |
|
362 | + echo sprintf($txt['debug_query_which_took_at'], round($qq['t'], 8), round($qq['s'], 8)) . '<br>'; |
|
363 | + } elseif (isset($qq['t'])) { |
|
364 | + echo sprintf($txt['debug_query_which_took'], round($qq['t'], 8)) . '<br>'; |
|
365 | + } |
|
341 | 366 | echo ' |
342 | 367 | <br>'; |
343 | 368 | } |
@@ -362,12 +387,14 @@ discard block |
||
362 | 387 | global $modSettings, $smcFunc; |
363 | 388 | static $cache_stats = array(); |
364 | 389 | |
365 | - if (empty($modSettings['trackStats'])) |
|
366 | - return false; |
|
367 | - if (!empty($stats)) |
|
368 | - return $cache_stats = array_merge($cache_stats, $stats); |
|
369 | - elseif (empty($cache_stats)) |
|
370 | - return false; |
|
390 | + if (empty($modSettings['trackStats'])) { |
|
391 | + return false; |
|
392 | + } |
|
393 | + if (!empty($stats)) { |
|
394 | + return $cache_stats = array_merge($cache_stats, $stats); |
|
395 | + } elseif (empty($cache_stats)) { |
|
396 | + return false; |
|
397 | + } |
|
371 | 398 | |
372 | 399 | $setStringUpdate = ''; |
373 | 400 | $insert_keys = array(); |
@@ -380,10 +407,11 @@ discard block |
||
380 | 407 | $setStringUpdate .= ' |
381 | 408 | ' . $field . ' = ' . ($change === '+' ? $field . ' + 1' : '{int:' . $field . '}') . ','; |
382 | 409 | |
383 | - if ($change === '+') |
|
384 | - $cache_stats[$field] = 1; |
|
385 | - else |
|
386 | - $update_parameters[$field] = $change; |
|
410 | + if ($change === '+') { |
|
411 | + $cache_stats[$field] = 1; |
|
412 | + } else { |
|
413 | + $update_parameters[$field] = $change; |
|
414 | + } |
|
387 | 415 | $insert_keys[$field] = 'int'; |
388 | 416 | } |
389 | 417 | |
@@ -447,43 +475,50 @@ discard block |
||
447 | 475 | ); |
448 | 476 | |
449 | 477 | // Make sure this particular log is enabled first... |
450 | - if (empty($modSettings['modlog_enabled'])) |
|
451 | - unset ($log_types['moderate']); |
|
452 | - if (empty($modSettings['userlog_enabled'])) |
|
453 | - unset ($log_types['user']); |
|
454 | - if (empty($modSettings['adminlog_enabled'])) |
|
455 | - unset ($log_types['admin']); |
|
478 | + if (empty($modSettings['modlog_enabled'])) { |
|
479 | + unset ($log_types['moderate']); |
|
480 | + } |
|
481 | + if (empty($modSettings['userlog_enabled'])) { |
|
482 | + unset ($log_types['user']); |
|
483 | + } |
|
484 | + if (empty($modSettings['adminlog_enabled'])) { |
|
485 | + unset ($log_types['admin']); |
|
486 | + } |
|
456 | 487 | |
457 | 488 | call_integration_hook('integrate_log_types', array(&$log_types)); |
458 | 489 | |
459 | 490 | foreach ($logs as $log) |
460 | 491 | { |
461 | - if (!isset($log_types[$log['log_type']])) |
|
462 | - return false; |
|
492 | + if (!isset($log_types[$log['log_type']])) { |
|
493 | + return false; |
|
494 | + } |
|
463 | 495 | |
464 | - if (!is_array($log['extra'])) |
|
465 | - trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE); |
|
496 | + if (!is_array($log['extra'])) { |
|
497 | + trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE); |
|
498 | + } |
|
466 | 499 | |
467 | 500 | // Pull out the parts we want to store separately, but also make sure that the data is proper |
468 | 501 | if (isset($log['extra']['topic'])) |
469 | 502 | { |
470 | - if (!is_numeric($log['extra']['topic'])) |
|
471 | - trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE); |
|
503 | + if (!is_numeric($log['extra']['topic'])) { |
|
504 | + trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE); |
|
505 | + } |
|
472 | 506 | $topic_id = empty($log['extra']['topic']) ? 0 : (int) $log['extra']['topic']; |
473 | 507 | unset($log['extra']['topic']); |
508 | + } else { |
|
509 | + $topic_id = 0; |
|
474 | 510 | } |
475 | - else |
|
476 | - $topic_id = 0; |
|
477 | 511 | |
478 | 512 | if (isset($log['extra']['message'])) |
479 | 513 | { |
480 | - if (!is_numeric($log['extra']['message'])) |
|
481 | - trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE); |
|
514 | + if (!is_numeric($log['extra']['message'])) { |
|
515 | + trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE); |
|
516 | + } |
|
482 | 517 | $msg_id = empty($log['extra']['message']) ? 0 : (int) $log['extra']['message']; |
483 | 518 | unset($log['extra']['message']); |
519 | + } else { |
|
520 | + $msg_id = 0; |
|
484 | 521 | } |
485 | - else |
|
486 | - $msg_id = 0; |
|
487 | 522 | |
488 | 523 | // @todo cache this? |
489 | 524 | // Is there an associated report on this? |
@@ -510,23 +545,26 @@ discard block |
||
510 | 545 | $smcFunc['db_free_result']($request); |
511 | 546 | } |
512 | 547 | |
513 | - if (isset($log['extra']['member']) && !is_numeric($log['extra']['member'])) |
|
514 | - trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE); |
|
548 | + if (isset($log['extra']['member']) && !is_numeric($log['extra']['member'])) { |
|
549 | + trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE); |
|
550 | + } |
|
515 | 551 | |
516 | 552 | if (isset($log['extra']['board'])) |
517 | 553 | { |
518 | - if (!is_numeric($log['extra']['board'])) |
|
519 | - trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE); |
|
554 | + if (!is_numeric($log['extra']['board'])) { |
|
555 | + trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE); |
|
556 | + } |
|
520 | 557 | $board_id = empty($log['extra']['board']) ? 0 : (int) $log['extra']['board']; |
521 | 558 | unset($log['extra']['board']); |
559 | + } else { |
|
560 | + $board_id = 0; |
|
522 | 561 | } |
523 | - else |
|
524 | - $board_id = 0; |
|
525 | 562 | |
526 | 563 | if (isset($log['extra']['board_to'])) |
527 | 564 | { |
528 | - if (!is_numeric($log['extra']['board_to'])) |
|
529 | - trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE); |
|
565 | + if (!is_numeric($log['extra']['board_to'])) { |
|
566 | + trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE); |
|
567 | + } |
|
530 | 568 | if (empty($board_id)) |
531 | 569 | { |
532 | 570 | $board_id = empty($log['extra']['board_to']) ? 0 : (int) $log['extra']['board_to']; |
@@ -534,10 +572,11 @@ discard block |
||
534 | 572 | } |
535 | 573 | } |
536 | 574 | |
537 | - if (isset($log['extra']['member_affected'])) |
|
538 | - $memID = $log['extra']['member_affected']; |
|
539 | - else |
|
540 | - $memID = $user_info['id']; |
|
575 | + if (isset($log['extra']['member_affected'])) { |
|
576 | + $memID = $log['extra']['member_affected']; |
|
577 | + } else { |
|
578 | + $memID = $user_info['id']; |
|
579 | + } |
|
541 | 580 | |
542 | 581 | $inserts[] = array( |
543 | 582 | time(), $log_types[$log['log_type']], $memID, $user_info['ip'], $log['action'], |
@@ -251,7 +251,7 @@ |
||
251 | 251 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
252 | 252 | $fts_language[$row['cfgname']] = $row['cfgname']; |
253 | 253 | |
254 | - $config_vars = array_merge ($config_vars, array( |
|
254 | + $config_vars = array_merge($config_vars, array( |
|
255 | 255 | '', |
256 | 256 | array('search_language', $txt['search_language'], 'db', 'select', $fts_language, 'pgFulltextSearch') |
257 | 257 | ) |
@@ -59,8 +59,9 @@ discard block |
||
59 | 59 | * @version 2.1 Beta 4 |
60 | 60 | */ |
61 | 61 | |
62 | -if (!defined('SMF')) |
|
62 | +if (!defined('SMF')) { |
|
63 | 63 | die('No direct access...'); |
64 | +} |
|
64 | 65 | |
65 | 66 | /** |
66 | 67 | * This is the main dispatcher. Sets up all the available sub-actions, all the tabs and selects |
@@ -111,10 +112,11 @@ discard block |
||
111 | 112 | $settings_not_writable = !is_writable($boarddir . '/Settings.php'); |
112 | 113 | $settings_backup_fail = !@is_writable($boarddir . '/Settings_bak.php') || !@copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php'); |
113 | 114 | |
114 | - if ($settings_not_writable) |
|
115 | - $context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>'; |
|
116 | - elseif ($settings_backup_fail) |
|
117 | - $context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>'; |
|
115 | + if ($settings_not_writable) { |
|
116 | + $context['settings_message'] = '<div class="centertext"><strong>' . $txt['settings_not_writable'] . '</strong></div><br>'; |
|
117 | + } elseif ($settings_backup_fail) { |
|
118 | + $context['settings_message'] = '<div class="centertext"><strong>' . $txt['admin_backup_fail'] . '</strong></div><br>'; |
|
119 | + } |
|
118 | 120 | |
119 | 121 | $context['settings_not_writable'] = $settings_not_writable; |
120 | 122 | |
@@ -142,10 +144,11 @@ discard block |
||
142 | 144 | |
143 | 145 | // If no cert, force_ssl must remain 0 |
144 | 146 | require_once($sourcedir . '/Subs.php'); |
145 | - if (!ssl_cert_found($boardurl) && empty($modSettings['force_ssl'])) |
|
146 | - $disable_force_ssl = true; |
|
147 | - else |
|
148 | - $disable_force_ssl = false; |
|
147 | + if (!ssl_cert_found($boardurl) && empty($modSettings['force_ssl'])) { |
|
148 | + $disable_force_ssl = true; |
|
149 | + } else { |
|
150 | + $disable_force_ssl = false; |
|
151 | + } |
|
149 | 152 | |
150 | 153 | /* If you're writing a mod, it's a bad idea to add things here.... |
151 | 154 | For each option: |
@@ -175,8 +178,9 @@ discard block |
||
175 | 178 | |
176 | 179 | call_integration_hook('integrate_general_settings', array(&$config_vars)); |
177 | 180 | |
178 | - if ($return_config) |
|
179 | - return $config_vars; |
|
181 | + if ($return_config) { |
|
182 | + return $config_vars; |
|
183 | + } |
|
180 | 184 | |
181 | 185 | // Setup the template stuff. |
182 | 186 | $context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=general;save'; |
@@ -193,16 +197,18 @@ discard block |
||
193 | 197 | $registerSMStats = registerSMStats(); |
194 | 198 | |
195 | 199 | // Failed to register, disable it again. |
196 | - if (empty($registerSMStats)) |
|
197 | - $_POST['enable_sm_stats'] = 0; |
|
200 | + if (empty($registerSMStats)) { |
|
201 | + $_POST['enable_sm_stats'] = 0; |
|
202 | + } |
|
198 | 203 | } |
199 | 204 | |
200 | 205 | // Ensure all URLs are aligned with the new force_ssl setting |
201 | 206 | // Treat unset like 0 |
202 | - if (isset($_POST['force_ssl'])) |
|
203 | - AlignURLsWithSSLSetting($_POST['force_ssl']); |
|
204 | - else |
|
205 | - AlignURLsWithSSLSetting(0); |
|
207 | + if (isset($_POST['force_ssl'])) { |
|
208 | + AlignURLsWithSSLSetting($_POST['force_ssl']); |
|
209 | + } else { |
|
210 | + AlignURLsWithSSLSetting(0); |
|
211 | + } |
|
206 | 212 | |
207 | 213 | saveSettings($config_vars); |
208 | 214 | $_SESSION['adm-save'] = true; |
@@ -255,10 +261,11 @@ discard block |
||
255 | 261 | require_once($sourcedir . '/Subs-Admin.php'); |
256 | 262 | |
257 | 263 | // Check $boardurl |
258 | - if ($new_force_ssl == 2) |
|
259 | - $newval = strtr($boardurl, array('http://' => 'https://')); |
|
260 | - else |
|
261 | - $newval = strtr($boardurl, array('https://' => 'http://')); |
|
264 | + if ($new_force_ssl == 2) { |
|
265 | + $newval = strtr($boardurl, array('http://' => 'https://')); |
|
266 | + } else { |
|
267 | + $newval = strtr($boardurl, array('https://' => 'http://')); |
|
268 | + } |
|
262 | 269 | updateSettingsFile(array('boardurl' => '\'' . addslashes($newval) . '\'')); |
263 | 270 | |
264 | 271 | $new_settings = array(); |
@@ -266,20 +273,22 @@ discard block |
||
266 | 273 | // Check $smileys_url, but only if it points to a subfolder of $boardurl |
267 | 274 | if (BoardurlMatch($modSettings['smileys_url'])) |
268 | 275 | { |
269 | - if ($new_force_ssl == 2) |
|
270 | - $newval = strtr($modSettings['smileys_url'], array('http://' => 'https://')); |
|
271 | - else |
|
272 | - $newval = strtr($modSettings['smileys_url'], array('https://' => 'http://')); |
|
276 | + if ($new_force_ssl == 2) { |
|
277 | + $newval = strtr($modSettings['smileys_url'], array('http://' => 'https://')); |
|
278 | + } else { |
|
279 | + $newval = strtr($modSettings['smileys_url'], array('https://' => 'http://')); |
|
280 | + } |
|
273 | 281 | $new_settings['smileys_url'] = $newval; |
274 | 282 | } |
275 | 283 | |
276 | 284 | // Check $avatar_url, but only if it points to a subfolder of $boardurl |
277 | 285 | if (BoardurlMatch($modSettings['avatar_url'])) |
278 | 286 | { |
279 | - if ($new_force_ssl == 2) |
|
280 | - $newval = strtr($modSettings['avatar_url'], array('http://' => 'https://')); |
|
281 | - else |
|
282 | - $newval = strtr($modSettings['avatar_url'], array('https://' => 'http://')); |
|
287 | + if ($new_force_ssl == 2) { |
|
288 | + $newval = strtr($modSettings['avatar_url'], array('http://' => 'https://')); |
|
289 | + } else { |
|
290 | + $newval = strtr($modSettings['avatar_url'], array('https://' => 'http://')); |
|
291 | + } |
|
283 | 292 | $new_settings['avatar_url'] = $newval; |
284 | 293 | } |
285 | 294 | |
@@ -287,16 +296,18 @@ discard block |
||
287 | 296 | // This one had been optional in the past, make sure it is set first |
288 | 297 | if (isset($modSettings['custom_avatar_url']) && BoardurlMatch($modSettings['custom_avatar_url'])) |
289 | 298 | { |
290 | - if ($new_force_ssl == 2) |
|
291 | - $newval = strtr($modSettings['custom_avatar_url'], array('http://' => 'https://')); |
|
292 | - else |
|
293 | - $newval = strtr($modSettings['custom_avatar_url'], array('https://' => 'http://')); |
|
299 | + if ($new_force_ssl == 2) { |
|
300 | + $newval = strtr($modSettings['custom_avatar_url'], array('http://' => 'https://')); |
|
301 | + } else { |
|
302 | + $newval = strtr($modSettings['custom_avatar_url'], array('https://' => 'http://')); |
|
303 | + } |
|
294 | 304 | $new_settings['custom_avatar_url'] = $newval; |
295 | 305 | } |
296 | 306 | |
297 | 307 | // Save updates to the settings table |
298 | - if (!empty($new_settings)) |
|
299 | - updateSettings($new_settings, true); |
|
308 | + if (!empty($new_settings)) { |
|
309 | + updateSettings($new_settings, true); |
|
310 | + } |
|
300 | 311 | |
301 | 312 | // Now we move onto the themes. |
302 | 313 | // First, get a list of theme URLs... |
@@ -317,10 +328,11 @@ discard block |
||
317 | 328 | // First check to see if it points to a subfolder of $boardurl |
318 | 329 | if (BoardurlMatch($row['value'])) |
319 | 330 | { |
320 | - if ($new_force_ssl == 2) |
|
321 | - $newval = strtr($row['value'], array('http://' => 'https://')); |
|
322 | - else |
|
323 | - $newval = strtr($row['value'], array('https://' => 'http://')); |
|
331 | + if ($new_force_ssl == 2) { |
|
332 | + $newval = strtr($row['value'], array('http://' => 'https://')); |
|
333 | + } else { |
|
334 | + $newval = strtr($row['value'], array('https://' => 'http://')); |
|
335 | + } |
|
324 | 336 | $smcFunc['db_query']('', ' |
325 | 337 | UPDATE {db_prefix}themes |
326 | 338 | SET value = {string:theme_val} |
@@ -360,11 +372,12 @@ discard block |
||
360 | 372 | |
361 | 373 | // If leftmost portion of path matches boardurl, return true |
362 | 374 | $result = strpos($urlpath, $boardurlpath); |
363 | - if ($result === false || $result != 0) |
|
364 | - return false; |
|
365 | - else |
|
366 | - return true; |
|
367 | -} |
|
375 | + if ($result === false || $result != 0) { |
|
376 | + return false; |
|
377 | + } else { |
|
378 | + return true; |
|
379 | + } |
|
380 | + } |
|
368 | 381 | |
369 | 382 | /** |
370 | 383 | * Basic database and paths settings - database name, host, etc. |
@@ -402,8 +415,9 @@ discard block |
||
402 | 415 | $request = $smcFunc['db_query']('', 'SELECT cfgname FROM pg_ts_config', array()); |
403 | 416 | $fts_language = array(); |
404 | 417 | |
405 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
406 | - $fts_language[$row['cfgname']] = $row['cfgname']; |
|
418 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
419 | + $fts_language[$row['cfgname']] = $row['cfgname']; |
|
420 | + } |
|
407 | 421 | |
408 | 422 | $config_vars = array_merge ($config_vars, array( |
409 | 423 | '', |
@@ -415,8 +429,9 @@ discard block |
||
415 | 429 | |
416 | 430 | call_integration_hook('integrate_database_settings', array(&$config_vars)); |
417 | 431 | |
418 | - if ($return_config) |
|
419 | - return $config_vars; |
|
432 | + if ($return_config) { |
|
433 | + return $config_vars; |
|
434 | + } |
|
420 | 435 | |
421 | 436 | // Setup the template stuff. |
422 | 437 | $context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=database;save'; |
@@ -491,13 +506,15 @@ discard block |
||
491 | 506 | hideGlobalCookies(); |
492 | 507 | });', true); |
493 | 508 | |
494 | - if (empty($user_settings['tfa_secret'])) |
|
495 | - addInlineJavaScript(''); |
|
509 | + if (empty($user_settings['tfa_secret'])) { |
|
510 | + addInlineJavaScript(''); |
|
511 | + } |
|
496 | 512 | |
497 | 513 | call_integration_hook('integrate_cookie_settings', array(&$config_vars)); |
498 | 514 | |
499 | - if ($return_config) |
|
500 | - return $config_vars; |
|
515 | + if ($return_config) { |
|
516 | + return $config_vars; |
|
517 | + } |
|
501 | 518 | |
502 | 519 | $context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=cookie;save'; |
503 | 520 | $context['settings_title'] = $txt['cookies_sessions_settings']; |
@@ -508,11 +525,13 @@ discard block |
||
508 | 525 | call_integration_hook('integrate_save_cookie_settings'); |
509 | 526 | |
510 | 527 | // Local and global do not play nicely together. |
511 | - if (!empty($_POST['localCookies']) && empty($_POST['globalCookies'])) |
|
512 | - unset ($_POST['globalCookies']); |
|
528 | + if (!empty($_POST['localCookies']) && empty($_POST['globalCookies'])) { |
|
529 | + unset ($_POST['globalCookies']); |
|
530 | + } |
|
513 | 531 | |
514 | - if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false) |
|
515 | - fatal_lang_error('invalid_cookie_domain', false); |
|
532 | + if (!empty($_POST['globalCookiesDomain']) && strpos($boardurl, $_POST['globalCookiesDomain']) === false) { |
|
533 | + fatal_lang_error('invalid_cookie_domain', false); |
|
534 | + } |
|
516 | 535 | |
517 | 536 | saveSettings($config_vars); |
518 | 537 | |
@@ -595,8 +614,9 @@ discard block |
||
595 | 614 | |
596 | 615 | call_integration_hook('integrate_general_security_settings', array(&$config_vars)); |
597 | 616 | |
598 | - if ($return_config) |
|
599 | - return $config_vars; |
|
617 | + if ($return_config) { |
|
618 | + return $config_vars; |
|
619 | + } |
|
600 | 620 | |
601 | 621 | // Saving? |
602 | 622 | if (isset($_GET['save'])) |
@@ -635,8 +655,7 @@ discard block |
||
635 | 655 | $txt['cache_settings_message'] = $txt['detected_no_caching']; |
636 | 656 | $cache_level = array($txt['cache_off']); |
637 | 657 | $detected['none'] = $txt['cache_off']; |
638 | - } |
|
639 | - else |
|
658 | + } else |
|
640 | 659 | { |
641 | 660 | $txt['cache_settings_message'] = sprintf($txt['detected_accelerators'], implode(', ', $detected)); |
642 | 661 | $cache_level = array($txt['cache_off'], $txt['cache_level1'], $txt['cache_level2'], $txt['cache_level3']); |
@@ -673,8 +692,9 @@ discard block |
||
673 | 692 | } |
674 | 693 | } |
675 | 694 | } |
676 | - if ($return_config) |
|
677 | - return $config_vars; |
|
695 | + if ($return_config) { |
|
696 | + return $config_vars; |
|
697 | + } |
|
678 | 698 | |
679 | 699 | // Saving again? |
680 | 700 | if (isset($_GET['save'])) |
@@ -702,8 +722,9 @@ discard block |
||
702 | 722 | $context['save_disabled'] = $context['settings_not_writable']; |
703 | 723 | |
704 | 724 | // Decide what message to show. |
705 | - if (!$context['save_disabled']) |
|
706 | - $context['settings_message'] = $txt['caching_information']; |
|
725 | + if (!$context['save_disabled']) { |
|
726 | + $context['settings_message'] = $txt['caching_information']; |
|
727 | + } |
|
707 | 728 | |
708 | 729 | // Prepare the template. |
709 | 730 | prepareServerSettingsContext($config_vars); |
@@ -726,24 +747,25 @@ discard block |
||
726 | 747 | if (stripos(PHP_OS, 'win') === 0) |
727 | 748 | { |
728 | 749 | $context['settings_message'] = $txt['loadavg_disabled_windows']; |
729 | - if (isset($_GET['save'])) |
|
730 | - $_SESSION['adm-save'] = $txt['loadavg_disabled_windows']; |
|
731 | - } |
|
732 | - elseif (stripos(PHP_OS, 'darwin') === 0) |
|
750 | + if (isset($_GET['save'])) { |
|
751 | + $_SESSION['adm-save'] = $txt['loadavg_disabled_windows']; |
|
752 | + } |
|
753 | + } elseif (stripos(PHP_OS, 'darwin') === 0) |
|
733 | 754 | { |
734 | 755 | $context['settings_message'] = $txt['loadavg_disabled_osx']; |
735 | - if (isset($_GET['save'])) |
|
736 | - $_SESSION['adm-save'] = $txt['loadavg_disabled_osx']; |
|
737 | - } |
|
738 | - else |
|
756 | + if (isset($_GET['save'])) { |
|
757 | + $_SESSION['adm-save'] = $txt['loadavg_disabled_osx']; |
|
758 | + } |
|
759 | + } else |
|
739 | 760 | { |
740 | 761 | $modSettings['load_average'] = @file_get_contents('/proc/loadavg'); |
741 | - if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0) |
|
742 | - $modSettings['load_average'] = (float) $matches[1]; |
|
743 | - elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0) |
|
744 | - $modSettings['load_average'] = (float) $matches[1]; |
|
745 | - else |
|
746 | - unset($modSettings['load_average']); |
|
762 | + if (!empty($modSettings['load_average']) && preg_match('~^([^ ]+?) ([^ ]+?) ([^ ]+)~', $modSettings['load_average'], $matches) !== 0) { |
|
763 | + $modSettings['load_average'] = (float) $matches[1]; |
|
764 | + } elseif (($modSettings['load_average'] = @`uptime`) !== null && preg_match('~load averages?: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)~i', $modSettings['load_average'], $matches) !== 0) { |
|
765 | + $modSettings['load_average'] = (float) $matches[1]; |
|
766 | + } else { |
|
767 | + unset($modSettings['load_average']); |
|
768 | + } |
|
747 | 769 | |
748 | 770 | if (!empty($modSettings['load_average']) || $modSettings['load_average'] === 0.0) |
749 | 771 | { |
@@ -779,8 +801,9 @@ discard block |
||
779 | 801 | |
780 | 802 | call_integration_hook('integrate_loadavg_settings', array(&$config_vars)); |
781 | 803 | |
782 | - if ($return_config) |
|
783 | - return $config_vars; |
|
804 | + if ($return_config) { |
|
805 | + return $config_vars; |
|
806 | + } |
|
784 | 807 | |
785 | 808 | $context['post_url'] = $scripturl . '?action=admin;area=serversettings;sa=loads;save'; |
786 | 809 | $context['settings_title'] = $txt['load_balancing_settings']; |
@@ -791,24 +814,27 @@ discard block |
||
791 | 814 | // Stupidity is not allowed. |
792 | 815 | foreach ($_POST as $key => $value) |
793 | 816 | { |
794 | - if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values))) |
|
795 | - continue; |
|
796 | - else |
|
797 | - $_POST[$key] = (float) $value; |
|
798 | - |
|
799 | - if ($key == 'loadavg_auto_opt' && $value <= 1) |
|
800 | - $_POST['loadavg_auto_opt'] = 1.0; |
|
801 | - elseif ($key == 'loadavg_forum' && $value < 10) |
|
802 | - $_POST['loadavg_forum'] = 10.0; |
|
803 | - elseif ($value < 2) |
|
804 | - $_POST[$key] = 2.0; |
|
817 | + if (strpos($key, 'loadavg') === 0 || $key === 'loadavg_enable' || !in_array($key, array_keys($default_values))) { |
|
818 | + continue; |
|
819 | + } else { |
|
820 | + $_POST[$key] = (float) $value; |
|
821 | + } |
|
822 | + |
|
823 | + if ($key == 'loadavg_auto_opt' && $value <= 1) { |
|
824 | + $_POST['loadavg_auto_opt'] = 1.0; |
|
825 | + } elseif ($key == 'loadavg_forum' && $value < 10) { |
|
826 | + $_POST['loadavg_forum'] = 10.0; |
|
827 | + } elseif ($value < 2) { |
|
828 | + $_POST[$key] = 2.0; |
|
829 | + } |
|
805 | 830 | } |
806 | 831 | |
807 | 832 | call_integration_hook('integrate_save_loadavg_settings'); |
808 | 833 | |
809 | 834 | saveDBSettings($config_vars); |
810 | - if (!isset($_SESSION['adm-save'])) |
|
811 | - $_SESSION['adm-save'] = true; |
|
835 | + if (!isset($_SESSION['adm-save'])) { |
|
836 | + $_SESSION['adm-save'] = true; |
|
837 | + } |
|
812 | 838 | redirectexit('action=admin;area=serversettings;sa=loads;' . $context['session_var'] . '=' . $context['session_id']); |
813 | 839 | } |
814 | 840 | |
@@ -844,10 +870,11 @@ discard block |
||
844 | 870 | |
845 | 871 | if (isset($_SESSION['adm-save'])) |
846 | 872 | { |
847 | - if ($_SESSION['adm-save'] === true) |
|
848 | - $context['saved_successful'] = true; |
|
849 | - else |
|
850 | - $context['saved_failed'] = $_SESSION['adm-save']; |
|
873 | + if ($_SESSION['adm-save'] === true) { |
|
874 | + $context['saved_successful'] = true; |
|
875 | + } else { |
|
876 | + $context['saved_failed'] = $_SESSION['adm-save']; |
|
877 | + } |
|
851 | 878 | |
852 | 879 | unset($_SESSION['adm-save']); |
853 | 880 | } |
@@ -855,9 +882,9 @@ discard block |
||
855 | 882 | $context['config_vars'] = array(); |
856 | 883 | foreach ($config_vars as $identifier => $config_var) |
857 | 884 | { |
858 | - if (!is_array($config_var) || !isset($config_var[1])) |
|
859 | - $context['config_vars'][] = $config_var; |
|
860 | - else |
|
885 | + if (!is_array($config_var) || !isset($config_var[1])) { |
|
886 | + $context['config_vars'][] = $config_var; |
|
887 | + } else |
|
861 | 888 | { |
862 | 889 | $varname = $config_var[0]; |
863 | 890 | global $$varname; |
@@ -892,16 +919,19 @@ discard block |
||
892 | 919 | if ($config_var[3] == 'int' || $config_var[3] == 'float') |
893 | 920 | { |
894 | 921 | // Default to a min of 0 if one isn't set |
895 | - if (isset($config_var['min'])) |
|
896 | - $context['config_vars'][$config_var[0]]['min'] = $config_var['min']; |
|
897 | - else |
|
898 | - $context['config_vars'][$config_var[0]]['min'] = 0; |
|
922 | + if (isset($config_var['min'])) { |
|
923 | + $context['config_vars'][$config_var[0]]['min'] = $config_var['min']; |
|
924 | + } else { |
|
925 | + $context['config_vars'][$config_var[0]]['min'] = 0; |
|
926 | + } |
|
899 | 927 | |
900 | - if (isset($config_var['max'])) |
|
901 | - $context['config_vars'][$config_var[0]]['max'] = $config_var['max']; |
|
928 | + if (isset($config_var['max'])) { |
|
929 | + $context['config_vars'][$config_var[0]]['max'] = $config_var['max']; |
|
930 | + } |
|
902 | 931 | |
903 | - if (isset($config_var['step'])) |
|
904 | - $context['config_vars'][$config_var[0]]['step'] = $config_var['step']; |
|
932 | + if (isset($config_var['step'])) { |
|
933 | + $context['config_vars'][$config_var[0]]['step'] = $config_var['step']; |
|
934 | + } |
|
905 | 935 | } |
906 | 936 | |
907 | 937 | // If this is a select box handle any data. |
@@ -909,12 +939,13 @@ discard block |
||
909 | 939 | { |
910 | 940 | // If it's associative |
911 | 941 | $config_values = array_values($config_var[4]); |
912 | - if (isset($config_values[0]) && is_array($config_values[0])) |
|
913 | - $context['config_vars'][$config_var[0]]['data'] = $config_var[4]; |
|
914 | - else |
|
942 | + if (isset($config_values[0]) && is_array($config_values[0])) { |
|
943 | + $context['config_vars'][$config_var[0]]['data'] = $config_var[4]; |
|
944 | + } else |
|
915 | 945 | { |
916 | - foreach ($config_var[4] as $key => $item) |
|
917 | - $context['config_vars'][$config_var[0]]['data'][] = array($key, $item); |
|
946 | + foreach ($config_var[4] as $key => $item) { |
|
947 | + $context['config_vars'][$config_var[0]]['data'][] = array($key, $item); |
|
948 | + } |
|
918 | 949 | } |
919 | 950 | } |
920 | 951 | } |
@@ -939,10 +970,11 @@ discard block |
||
939 | 970 | |
940 | 971 | if (isset($_SESSION['adm-save'])) |
941 | 972 | { |
942 | - if ($_SESSION['adm-save'] === true) |
|
943 | - $context['saved_successful'] = true; |
|
944 | - else |
|
945 | - $context['saved_failed'] = $_SESSION['adm-save']; |
|
973 | + if ($_SESSION['adm-save'] === true) { |
|
974 | + $context['saved_successful'] = true; |
|
975 | + } else { |
|
976 | + $context['saved_failed'] = $_SESSION['adm-save']; |
|
977 | + } |
|
946 | 978 | |
947 | 979 | unset($_SESSION['adm-save']); |
948 | 980 | } |
@@ -954,26 +986,30 @@ discard block |
||
954 | 986 | foreach ($config_vars as $config_var) |
955 | 987 | { |
956 | 988 | // HR? |
957 | - if (!is_array($config_var)) |
|
958 | - $context['config_vars'][] = $config_var; |
|
959 | - else |
|
989 | + if (!is_array($config_var)) { |
|
990 | + $context['config_vars'][] = $config_var; |
|
991 | + } else |
|
960 | 992 | { |
961 | 993 | // If it has no name it doesn't have any purpose! |
962 | - if (empty($config_var[1])) |
|
963 | - continue; |
|
994 | + if (empty($config_var[1])) { |
|
995 | + continue; |
|
996 | + } |
|
964 | 997 | |
965 | 998 | // Special case for inline permissions |
966 | - if ($config_var[0] == 'permissions' && allowedTo('manage_permissions')) |
|
967 | - $inlinePermissions[] = $config_var[1]; |
|
968 | - elseif ($config_var[0] == 'permissions') |
|
969 | - continue; |
|
999 | + if ($config_var[0] == 'permissions' && allowedTo('manage_permissions')) { |
|
1000 | + $inlinePermissions[] = $config_var[1]; |
|
1001 | + } elseif ($config_var[0] == 'permissions') { |
|
1002 | + continue; |
|
1003 | + } |
|
970 | 1004 | |
971 | - if ($config_var[0] == 'boards') |
|
972 | - $board_list = true; |
|
1005 | + if ($config_var[0] == 'boards') { |
|
1006 | + $board_list = true; |
|
1007 | + } |
|
973 | 1008 | |
974 | 1009 | // Are we showing the BBC selection box? |
975 | - if ($config_var[0] == 'bbc') |
|
976 | - $bbcChoice[] = $config_var[1]; |
|
1010 | + if ($config_var[0] == 'bbc') { |
|
1011 | + $bbcChoice[] = $config_var[1]; |
|
1012 | + } |
|
977 | 1013 | |
978 | 1014 | // We need to do some parsing of the value before we pass it in. |
979 | 1015 | if (isset($modSettings[$config_var[1]])) |
@@ -992,8 +1028,7 @@ discard block |
||
992 | 1028 | default: |
993 | 1029 | $value = $smcFunc['htmlspecialchars']($modSettings[$config_var[1]]); |
994 | 1030 | } |
995 | - } |
|
996 | - else |
|
1031 | + } else |
|
997 | 1032 | { |
998 | 1033 | // Darn, it's empty. What type is expected? |
999 | 1034 | switch ($config_var[0]) |
@@ -1033,16 +1068,19 @@ discard block |
||
1033 | 1068 | if ($config_var[0] == 'int' || $config_var[0] == 'float') |
1034 | 1069 | { |
1035 | 1070 | // Default to a min of 0 if one isn't set |
1036 | - if (isset($config_var['min'])) |
|
1037 | - $context['config_vars'][$config_var[1]]['min'] = $config_var['min']; |
|
1038 | - else |
|
1039 | - $context['config_vars'][$config_var[1]]['min'] = 0; |
|
1071 | + if (isset($config_var['min'])) { |
|
1072 | + $context['config_vars'][$config_var[1]]['min'] = $config_var['min']; |
|
1073 | + } else { |
|
1074 | + $context['config_vars'][$config_var[1]]['min'] = 0; |
|
1075 | + } |
|
1040 | 1076 | |
1041 | - if (isset($config_var['max'])) |
|
1042 | - $context['config_vars'][$config_var[1]]['max'] = $config_var['max']; |
|
1077 | + if (isset($config_var['max'])) { |
|
1078 | + $context['config_vars'][$config_var[1]]['max'] = $config_var['max']; |
|
1079 | + } |
|
1043 | 1080 | |
1044 | - if (isset($config_var['step'])) |
|
1045 | - $context['config_vars'][$config_var[1]]['step'] = $config_var['step']; |
|
1081 | + if (isset($config_var['step'])) { |
|
1082 | + $context['config_vars'][$config_var[1]]['step'] = $config_var['step']; |
|
1083 | + } |
|
1046 | 1084 | } |
1047 | 1085 | |
1048 | 1086 | // If this is a select box handle any data. |
@@ -1056,12 +1094,13 @@ discard block |
||
1056 | 1094 | } |
1057 | 1095 | |
1058 | 1096 | // If it's associative |
1059 | - if (isset($config_var[2][0]) && is_array($config_var[2][0])) |
|
1060 | - $context['config_vars'][$config_var[1]]['data'] = $config_var[2]; |
|
1061 | - else |
|
1097 | + if (isset($config_var[2][0]) && is_array($config_var[2][0])) { |
|
1098 | + $context['config_vars'][$config_var[1]]['data'] = $config_var[2]; |
|
1099 | + } else |
|
1062 | 1100 | { |
1063 | - foreach ($config_var[2] as $key => $item) |
|
1064 | - $context['config_vars'][$config_var[1]]['data'][] = array($key, $item); |
|
1101 | + foreach ($config_var[2] as $key => $item) { |
|
1102 | + $context['config_vars'][$config_var[1]]['data'][] = array($key, $item); |
|
1103 | + } |
|
1065 | 1104 | } |
1066 | 1105 | } |
1067 | 1106 | |
@@ -1070,17 +1109,19 @@ discard block |
||
1070 | 1109 | { |
1071 | 1110 | if (!is_numeric($k)) |
1072 | 1111 | { |
1073 | - if (substr($k, 0, 2) == 'on') |
|
1074 | - $context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"'; |
|
1075 | - else |
|
1076 | - $context['config_vars'][$config_var[1]][$k] = $v; |
|
1112 | + if (substr($k, 0, 2) == 'on') { |
|
1113 | + $context['config_vars'][$config_var[1]]['javascript'] .= ' ' . $k . '="' . $v . '"'; |
|
1114 | + } else { |
|
1115 | + $context['config_vars'][$config_var[1]][$k] = $v; |
|
1116 | + } |
|
1077 | 1117 | } |
1078 | 1118 | |
1079 | 1119 | // See if there are any other labels that might fit? |
1080 | - if (isset($txt['setting_' . $config_var[1]])) |
|
1081 | - $context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]]; |
|
1082 | - elseif (isset($txt['groups_' . $config_var[1]])) |
|
1083 | - $context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]]; |
|
1120 | + if (isset($txt['setting_' . $config_var[1]])) { |
|
1121 | + $context['config_vars'][$config_var[1]]['label'] = $txt['setting_' . $config_var[1]]; |
|
1122 | + } elseif (isset($txt['groups_' . $config_var[1]])) { |
|
1123 | + $context['config_vars'][$config_var[1]]['label'] = $txt['groups_' . $config_var[1]]; |
|
1124 | + } |
|
1084 | 1125 | } |
1085 | 1126 | |
1086 | 1127 | // Set the subtext in case it's part of the label. |
@@ -1113,8 +1154,9 @@ discard block |
||
1113 | 1154 | // What are the options, eh? |
1114 | 1155 | $temp = parse_bbc(false); |
1115 | 1156 | $bbcTags = array(); |
1116 | - foreach ($temp as $tag) |
|
1117 | - $bbcTags[] = $tag['tag']; |
|
1157 | + foreach ($temp as $tag) { |
|
1158 | + $bbcTags[] = $tag['tag']; |
|
1159 | + } |
|
1118 | 1160 | |
1119 | 1161 | $bbcTags = array_unique($bbcTags); |
1120 | 1162 | $totalTags = count($bbcTags); |
@@ -1129,8 +1171,9 @@ discard block |
||
1129 | 1171 | $col = 0; $i = 0; |
1130 | 1172 | foreach ($bbcTags as $tag) |
1131 | 1173 | { |
1132 | - if ($i % $tagsPerColumn == 0 && $i != 0) |
|
1133 | - $col++; |
|
1174 | + if ($i % $tagsPerColumn == 0 && $i != 0) { |
|
1175 | + $col++; |
|
1176 | + } |
|
1134 | 1177 | |
1135 | 1178 | $context['bbc_columns'][$col][] = array( |
1136 | 1179 | 'tag' => $tag, |
@@ -1173,18 +1216,21 @@ discard block |
||
1173 | 1216 | validateToken('admin-ssc'); |
1174 | 1217 | |
1175 | 1218 | // Fix the darn stupid cookiename! (more may not be allowed, but these for sure!) |
1176 | - if (isset($_POST['cookiename'])) |
|
1177 | - $_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']); |
|
1219 | + if (isset($_POST['cookiename'])) { |
|
1220 | + $_POST['cookiename'] = preg_replace('~[,;\s\.$]+~' . ($context['utf8'] ? 'u' : ''), '', $_POST['cookiename']); |
|
1221 | + } |
|
1178 | 1222 | |
1179 | 1223 | // Fix the forum's URL if necessary. |
1180 | 1224 | if (isset($_POST['boardurl'])) |
1181 | 1225 | { |
1182 | - if (substr($_POST['boardurl'], -10) == '/index.php') |
|
1183 | - $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10); |
|
1184 | - elseif (substr($_POST['boardurl'], -1) == '/') |
|
1185 | - $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1); |
|
1186 | - if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') |
|
1187 | - $_POST['boardurl'] = 'http://' . $_POST['boardurl']; |
|
1226 | + if (substr($_POST['boardurl'], -10) == '/index.php') { |
|
1227 | + $_POST['boardurl'] = substr($_POST['boardurl'], 0, -10); |
|
1228 | + } elseif (substr($_POST['boardurl'], -1) == '/') { |
|
1229 | + $_POST['boardurl'] = substr($_POST['boardurl'], 0, -1); |
|
1230 | + } |
|
1231 | + if (substr($_POST['boardurl'], 0, 7) != 'http://' && substr($_POST['boardurl'], 0, 7) != 'file://' && substr($_POST['boardurl'], 0, 8) != 'https://') { |
|
1232 | + $_POST['boardurl'] = 'http://' . $_POST['boardurl']; |
|
1233 | + } |
|
1188 | 1234 | } |
1189 | 1235 | |
1190 | 1236 | // Any passwords? |
@@ -1219,21 +1265,21 @@ discard block |
||
1219 | 1265 | // Figure out which config vars we're saving here... |
1220 | 1266 | foreach ($config_vars as $var) |
1221 | 1267 | { |
1222 | - if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]]))) |
|
1223 | - continue; |
|
1268 | + if (!is_array($var) || $var[2] != 'file' || (!in_array($var[0], $config_bools) && !isset($_POST[$var[0]]))) { |
|
1269 | + continue; |
|
1270 | + } |
|
1224 | 1271 | |
1225 | 1272 | $config_var = $var[0]; |
1226 | 1273 | |
1227 | 1274 | if (in_array($config_var, $config_passwords)) |
1228 | 1275 | { |
1229 | - if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1]) |
|
1230 | - $new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\''; |
|
1231 | - } |
|
1232 | - elseif (in_array($config_var, $config_strs)) |
|
1276 | + if (isset($_POST[$config_var][1]) && $_POST[$config_var][0] == $_POST[$config_var][1]) { |
|
1277 | + $new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var][0], '\'\\') . '\''; |
|
1278 | + } |
|
1279 | + } elseif (in_array($config_var, $config_strs)) |
|
1233 | 1280 | { |
1234 | 1281 | $new_settings[$config_var] = '\'' . addcslashes($_POST[$config_var], '\'\\') . '\''; |
1235 | - } |
|
1236 | - elseif (in_array($config_var, $config_ints)) |
|
1282 | + } elseif (in_array($config_var, $config_ints)) |
|
1237 | 1283 | { |
1238 | 1284 | $new_settings[$config_var] = (int) $_POST[$config_var]; |
1239 | 1285 | |
@@ -1242,17 +1288,17 @@ discard block |
||
1242 | 1288 | $new_settings[$config_var] = max($min, $new_settings[$config_var]); |
1243 | 1289 | |
1244 | 1290 | // Is there a max value for this as well? |
1245 | - if (isset($var['max'])) |
|
1246 | - $new_settings[$config_var] = min($var['max'], $new_settings[$config_var]); |
|
1247 | - } |
|
1248 | - elseif (in_array($config_var, $config_bools)) |
|
1291 | + if (isset($var['max'])) { |
|
1292 | + $new_settings[$config_var] = min($var['max'], $new_settings[$config_var]); |
|
1293 | + } |
|
1294 | + } elseif (in_array($config_var, $config_bools)) |
|
1249 | 1295 | { |
1250 | - if (!empty($_POST[$config_var])) |
|
1251 | - $new_settings[$config_var] = '1'; |
|
1252 | - else |
|
1253 | - $new_settings[$config_var] = '0'; |
|
1254 | - } |
|
1255 | - else |
|
1296 | + if (!empty($_POST[$config_var])) { |
|
1297 | + $new_settings[$config_var] = '1'; |
|
1298 | + } else { |
|
1299 | + $new_settings[$config_var] = '0'; |
|
1300 | + } |
|
1301 | + } else |
|
1256 | 1302 | { |
1257 | 1303 | // This shouldn't happen, but it might... |
1258 | 1304 | fatal_error('Unknown config_var \'' . $config_var . '\''); |
@@ -1268,30 +1314,35 @@ discard block |
||
1268 | 1314 | foreach ($config_vars as $config_var) |
1269 | 1315 | { |
1270 | 1316 | // We just saved the file-based settings, so skip their definitions. |
1271 | - if (!is_array($config_var) || $config_var[2] == 'file') |
|
1272 | - continue; |
|
1317 | + if (!is_array($config_var) || $config_var[2] == 'file') { |
|
1318 | + continue; |
|
1319 | + } |
|
1273 | 1320 | |
1274 | 1321 | $new_setting = array($config_var[3], $config_var[0]); |
1275 | 1322 | |
1276 | 1323 | // Select options need carried over, too. |
1277 | - if (isset($config_var[4])) |
|
1278 | - $new_setting[] = $config_var[4]; |
|
1324 | + if (isset($config_var[4])) { |
|
1325 | + $new_setting[] = $config_var[4]; |
|
1326 | + } |
|
1279 | 1327 | |
1280 | 1328 | // Include min and max if necessary |
1281 | - if (isset($config_var['min'])) |
|
1282 | - $new_setting['min'] = $config_var['min']; |
|
1329 | + if (isset($config_var['min'])) { |
|
1330 | + $new_setting['min'] = $config_var['min']; |
|
1331 | + } |
|
1283 | 1332 | |
1284 | - if (isset($config_var['max'])) |
|
1285 | - $new_setting['max'] = $config_var['max']; |
|
1333 | + if (isset($config_var['max'])) { |
|
1334 | + $new_setting['max'] = $config_var['max']; |
|
1335 | + } |
|
1286 | 1336 | |
1287 | 1337 | // Rewrite the definition a bit. |
1288 | 1338 | $new_settings[] = $new_setting; |
1289 | 1339 | } |
1290 | 1340 | |
1291 | 1341 | // Save the new database-based settings, if any. |
1292 | - if (!empty($new_settings)) |
|
1293 | - saveDBSettings($new_settings); |
|
1294 | -} |
|
1342 | + if (!empty($new_settings)) { |
|
1343 | + saveDBSettings($new_settings); |
|
1344 | + } |
|
1345 | + } |
|
1295 | 1346 | |
1296 | 1347 | /** |
1297 | 1348 | * Helper function for saving database settings. |
@@ -1309,22 +1360,25 @@ discard block |
||
1309 | 1360 | $inlinePermissions = array(); |
1310 | 1361 | foreach ($config_vars as $var) |
1311 | 1362 | { |
1312 | - if (!isset($var[1]) || (!isset($_POST[$var[1]]) && $var[0] != 'check' && $var[0] != 'permissions' && $var[0] != 'boards' && ($var[0] != 'bbc' || !isset($_POST[$var[1] . '_enabledTags'])))) |
|
1313 | - continue; |
|
1363 | + if (!isset($var[1]) || (!isset($_POST[$var[1]]) && $var[0] != 'check' && $var[0] != 'permissions' && $var[0] != 'boards' && ($var[0] != 'bbc' || !isset($_POST[$var[1] . '_enabledTags'])))) { |
|
1364 | + continue; |
|
1365 | + } |
|
1314 | 1366 | |
1315 | 1367 | // Checkboxes! |
1316 | - elseif ($var[0] == 'check') |
|
1317 | - $setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0'; |
|
1368 | + elseif ($var[0] == 'check') { |
|
1369 | + $setArray[$var[1]] = !empty($_POST[$var[1]]) ? '1' : '0'; |
|
1370 | + } |
|
1318 | 1371 | // Select boxes! |
1319 | - elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2]))) |
|
1320 | - $setArray[$var[1]] = $_POST[$var[1]]; |
|
1321 | - elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array()) |
|
1372 | + elseif ($var[0] == 'select' && in_array($_POST[$var[1]], array_keys($var[2]))) { |
|
1373 | + $setArray[$var[1]] = $_POST[$var[1]]; |
|
1374 | + } elseif ($var[0] == 'select' && !empty($var['multiple']) && array_intersect($_POST[$var[1]], array_keys($var[2])) != array()) |
|
1322 | 1375 | { |
1323 | 1376 | // For security purposes we validate this line by line. |
1324 | 1377 | $lOptions = array(); |
1325 | - foreach ($_POST[$var[1]] as $invar) |
|
1326 | - if (in_array($invar, array_keys($var[2]))) |
|
1378 | + foreach ($_POST[$var[1]] as $invar) { |
|
1379 | + if (in_array($invar, array_keys($var[2]))) |
|
1327 | 1380 | $lOptions[] = $invar; |
1381 | + } |
|
1328 | 1382 | |
1329 | 1383 | $setArray[$var[1]] = $smcFunc['json_encode']($lOptions); |
1330 | 1384 | } |
@@ -1338,18 +1392,20 @@ discard block |
||
1338 | 1392 | $request = $smcFunc['db_query']('', ' |
1339 | 1393 | SELECT id_board |
1340 | 1394 | FROM {db_prefix}boards'); |
1341 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
1342 | - $board_list[$row[0]] = true; |
|
1395 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
1396 | + $board_list[$row[0]] = true; |
|
1397 | + } |
|
1343 | 1398 | |
1344 | 1399 | $smcFunc['db_free_result']($request); |
1345 | 1400 | } |
1346 | 1401 | |
1347 | 1402 | $lOptions = array(); |
1348 | 1403 | |
1349 | - if (!empty($_POST[$var[1]])) |
|
1350 | - foreach ($_POST[$var[1]] as $invar => $dummy) |
|
1404 | + if (!empty($_POST[$var[1]])) { |
|
1405 | + foreach ($_POST[$var[1]] as $invar => $dummy) |
|
1351 | 1406 | if (isset($board_list[$invar])) |
1352 | 1407 | $lOptions[] = $invar; |
1408 | + } |
|
1353 | 1409 | |
1354 | 1410 | $setArray[$var[1]] = !empty($lOptions) ? implode(',', $lOptions) : ''; |
1355 | 1411 | } |
@@ -1363,8 +1419,9 @@ discard block |
||
1363 | 1419 | $setArray[$var[1]] = max($min, $setArray[$var[1]]); |
1364 | 1420 | |
1365 | 1421 | // Do we have a max value for this as well? |
1366 | - if (isset($var['max'])) |
|
1367 | - $setArray[$var[1]] = min($var['max'], $setArray[$var[1]]); |
|
1422 | + if (isset($var['max'])) { |
|
1423 | + $setArray[$var[1]] = min($var['max'], $setArray[$var[1]]); |
|
1424 | + } |
|
1368 | 1425 | } |
1369 | 1426 | // Floating point! |
1370 | 1427 | elseif ($var[0] == 'float') |
@@ -1376,40 +1433,47 @@ discard block |
||
1376 | 1433 | $setArray[$var[1]] = max($min, $setArray[$var[1]]); |
1377 | 1434 | |
1378 | 1435 | // Do we have a max value for this as well? |
1379 | - if (isset($var['max'])) |
|
1380 | - $setArray[$var[1]] = min($var['max'], $setArray[$var[1]]); |
|
1436 | + if (isset($var['max'])) { |
|
1437 | + $setArray[$var[1]] = min($var['max'], $setArray[$var[1]]); |
|
1438 | + } |
|
1381 | 1439 | } |
1382 | 1440 | // Text! |
1383 | - elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time'))) |
|
1384 | - $setArray[$var[1]] = $_POST[$var[1]]; |
|
1441 | + elseif (in_array($var[0], array('text', 'large_text', 'color', 'date', 'datetime', 'datetime-local', 'email', 'month', 'time'))) { |
|
1442 | + $setArray[$var[1]] = $_POST[$var[1]]; |
|
1443 | + } |
|
1385 | 1444 | // Passwords! |
1386 | 1445 | elseif ($var[0] == 'password') |
1387 | 1446 | { |
1388 | - if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1]) |
|
1389 | - $setArray[$var[1]] = $_POST[$var[1]][0]; |
|
1447 | + if (isset($_POST[$var[1]][1]) && $_POST[$var[1]][0] == $_POST[$var[1]][1]) { |
|
1448 | + $setArray[$var[1]] = $_POST[$var[1]][0]; |
|
1449 | + } |
|
1390 | 1450 | } |
1391 | 1451 | // BBC. |
1392 | 1452 | elseif ($var[0] == 'bbc') |
1393 | 1453 | { |
1394 | 1454 | |
1395 | 1455 | $bbcTags = array(); |
1396 | - foreach (parse_bbc(false) as $tag) |
|
1397 | - $bbcTags[] = $tag['tag']; |
|
1456 | + foreach (parse_bbc(false) as $tag) { |
|
1457 | + $bbcTags[] = $tag['tag']; |
|
1458 | + } |
|
1398 | 1459 | |
1399 | - if (!isset($_POST[$var[1] . '_enabledTags'])) |
|
1400 | - $_POST[$var[1] . '_enabledTags'] = array(); |
|
1401 | - elseif (!is_array($_POST[$var[1] . '_enabledTags'])) |
|
1402 | - $_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']); |
|
1460 | + if (!isset($_POST[$var[1] . '_enabledTags'])) { |
|
1461 | + $_POST[$var[1] . '_enabledTags'] = array(); |
|
1462 | + } elseif (!is_array($_POST[$var[1] . '_enabledTags'])) { |
|
1463 | + $_POST[$var[1] . '_enabledTags'] = array($_POST[$var[1] . '_enabledTags']); |
|
1464 | + } |
|
1403 | 1465 | |
1404 | 1466 | $setArray[$var[1]] = implode(',', array_diff($bbcTags, $_POST[$var[1] . '_enabledTags'])); |
1405 | 1467 | } |
1406 | 1468 | // Permissions? |
1407 | - elseif ($var[0] == 'permissions') |
|
1408 | - $inlinePermissions[] = $var[1]; |
|
1469 | + elseif ($var[0] == 'permissions') { |
|
1470 | + $inlinePermissions[] = $var[1]; |
|
1471 | + } |
|
1409 | 1472 | } |
1410 | 1473 | |
1411 | - if (!empty($setArray)) |
|
1412 | - updateSettings($setArray); |
|
1474 | + if (!empty($setArray)) { |
|
1475 | + updateSettings($setArray); |
|
1476 | + } |
|
1413 | 1477 | |
1414 | 1478 | // If we have inline permissions we need to save them. |
1415 | 1479 | if (!empty($inlinePermissions) && allowedTo('manage_permissions')) |
@@ -1446,18 +1510,21 @@ discard block |
||
1446 | 1510 | // put all of it into an array |
1447 | 1511 | foreach ($info_lines as $line) |
1448 | 1512 | { |
1449 | - if (preg_match('~(' . $remove . ')~', $line)) |
|
1450 | - continue; |
|
1513 | + if (preg_match('~(' . $remove . ')~', $line)) { |
|
1514 | + continue; |
|
1515 | + } |
|
1451 | 1516 | |
1452 | 1517 | // new category? |
1453 | - if (strpos($line, '<h2>') !== false) |
|
1454 | - $category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category; |
|
1518 | + if (strpos($line, '<h2>') !== false) { |
|
1519 | + $category = preg_match('~<h2>(.*)</h2>~', $line, $title) ? $category = $title[1] : $category; |
|
1520 | + } |
|
1455 | 1521 | |
1456 | 1522 | // load it as setting => value or the old setting local master |
1457 | - if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) |
|
1458 | - $pinfo[$category][$val[1]] = $val[2]; |
|
1459 | - elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) |
|
1460 | - $pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]); |
|
1523 | + if (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) { |
|
1524 | + $pinfo[$category][$val[1]] = $val[2]; |
|
1525 | + } elseif (preg_match('~<tr><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td><td[^>]+>([^<]*)</td></tr>~', $line, $val)) { |
|
1526 | + $pinfo[$category][$val[1]] = array($txt['phpinfo_localsettings'] => $val[2], $txt['phpinfo_defaultsettings'] => $val[3]); |
|
1527 | + } |
|
1461 | 1528 | } |
1462 | 1529 | |
1463 | 1530 | // load it in to context and display it |
@@ -1492,8 +1559,9 @@ discard block |
||
1492 | 1559 | $testAPI = new $cache_class_name(); |
1493 | 1560 | |
1494 | 1561 | // No Support? NEXT! |
1495 | - if (!$testAPI->isSupported(true)) |
|
1496 | - continue; |
|
1562 | + if (!$testAPI->isSupported(true)) { |
|
1563 | + continue; |
|
1564 | + } |
|
1497 | 1565 | |
1498 | 1566 | $apis[$tryCache] = isset($txt[$tryCache . '_cache']) ? $txt[$tryCache . '_cache'] : $tryCache; |
1499 | 1567 | } |
@@ -1518,8 +1586,9 @@ discard block |
||
1518 | 1586 | global $modSettings, $boardurl, $smcFunc; |
1519 | 1587 | |
1520 | 1588 | // Already have a key? Can't register again. |
1521 | - if (!empty($modSettings['sm_stats_key'])) |
|
1522 | - return true; |
|
1589 | + if (!empty($modSettings['sm_stats_key'])) { |
|
1590 | + return true; |
|
1591 | + } |
|
1523 | 1592 | |
1524 | 1593 | $fp = @fsockopen('www.simplemachines.org', 80, $errno, $errstr); |
1525 | 1594 | if ($fp) |
@@ -1530,8 +1599,9 @@ discard block |
||
1530 | 1599 | fwrite($fp, $out); |
1531 | 1600 | |
1532 | 1601 | $return_data = ''; |
1533 | - while (!feof($fp)) |
|
1534 | - $return_data .= fgets($fp, 128); |
|
1602 | + while (!feof($fp)) { |
|
1603 | + $return_data .= fgets($fp, 128); |
|
1604 | + } |
|
1535 | 1605 | |
1536 | 1606 | fclose($fp); |
1537 | 1607 |
@@ -38,12 +38,12 @@ discard block |
||
38 | 38 | $version = $smcFunc['db_get_version'](); |
39 | 39 | // if we got a Beta Version |
40 | 40 | if (stripos($version, 'beta') !== false) |
41 | - $version = substr($version, 0, stripos($version, 'beta')).'.0'; |
|
41 | + $version = substr($version, 0, stripos($version, 'beta')) . '.0'; |
|
42 | 42 | // or RC |
43 | 43 | if (stripos($version, 'rc') !== false) |
44 | - $version = substr($version, 0, stripos($version, 'rc')).'.0'; |
|
44 | + $version = substr($version, 0, stripos($version, 'rc')) . '.0'; |
|
45 | 45 | |
46 | - if (version_compare($version,'9.5.0','>=')) |
|
46 | + if (version_compare($version, '9.5.0', '>=')) |
|
47 | 47 | $smcFunc['db_support_ignore'] = true; |
48 | 48 | } |
49 | 49 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | */ |
56 | 56 | function smf_db_search_support($search_type) |
57 | 57 | { |
58 | - $supported_types = array('custom','fulltext'); |
|
58 | + $supported_types = array('custom', 'fulltext'); |
|
59 | 59 | |
60 | 60 | return in_array($search_type, $supported_types); |
61 | 61 | } |
@@ -109,9 +109,9 @@ discard block |
||
109 | 109 | if (preg_match('~^\s*INSERT\sIGNORE~i', $db_string) != 0) |
110 | 110 | { |
111 | 111 | $db_string = preg_replace('~^\s*INSERT\sIGNORE~i', 'INSERT', $db_string); |
112 | - if ($smcFunc['db_support_ignore']){ |
|
112 | + if ($smcFunc['db_support_ignore']) { |
|
113 | 113 | //pg style "INSERT INTO.... ON CONFLICT DO NOTHING" |
114 | - $db_string = $db_string.' ON CONFLICT DO NOTHING'; |
|
114 | + $db_string = $db_string . ' ON CONFLICT DO NOTHING'; |
|
115 | 115 | } |
116 | 116 | else |
117 | 117 | { |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | $language_ftx = $modSettings['search_language']; |
169 | 169 | else |
170 | 170 | { |
171 | - $request = $smcFunc['db_query']('',' |
|
171 | + $request = $smcFunc['db_query']('', ' |
|
172 | 172 | SELECT cfgname FROM pg_ts_config WHERE oid = current_setting({string:default_language})::regconfig', |
173 | 173 | array( |
174 | 174 | 'default_language' => 'default_text_search_config' |
@@ -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 | * Add the file functions to the $smcFunc array. |
@@ -23,29 +24,33 @@ discard block |
||
23 | 24 | { |
24 | 25 | global $smcFunc; |
25 | 26 | |
26 | - if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_search_query') |
|
27 | - $smcFunc += array( |
|
27 | + if (!isset($smcFunc['db_search_query']) || $smcFunc['db_search_query'] != 'smf_db_search_query') { |
|
28 | + $smcFunc += array( |
|
28 | 29 | 'db_search_query' => 'smf_db_search_query', |
29 | 30 | 'db_search_support' => 'smf_db_search_support', |
30 | 31 | 'db_create_word_search' => 'smf_db_create_word_search', |
31 | 32 | 'db_support_ignore' => false, |
32 | 33 | 'db_search_language' => 'smf_db_search_language', |
33 | 34 | ); |
35 | + } |
|
34 | 36 | |
35 | 37 | db_extend(); |
36 | 38 | |
37 | 39 | //pg 9.5 got ignore support |
38 | 40 | $version = $smcFunc['db_get_version'](); |
39 | 41 | // if we got a Beta Version |
40 | - if (stripos($version, 'beta') !== false) |
|
41 | - $version = substr($version, 0, stripos($version, 'beta')).'.0'; |
|
42 | + if (stripos($version, 'beta') !== false) { |
|
43 | + $version = substr($version, 0, stripos($version, 'beta')).'.0'; |
|
44 | + } |
|
42 | 45 | // or RC |
43 | - if (stripos($version, 'rc') !== false) |
|
44 | - $version = substr($version, 0, stripos($version, 'rc')).'.0'; |
|
46 | + if (stripos($version, 'rc') !== false) { |
|
47 | + $version = substr($version, 0, stripos($version, 'rc')).'.0'; |
|
48 | + } |
|
45 | 49 | |
46 | - if (version_compare($version,'9.5.0','>=')) |
|
47 | - $smcFunc['db_support_ignore'] = true; |
|
48 | -} |
|
50 | + if (version_compare($version,'9.5.0','>=')) { |
|
51 | + $smcFunc['db_support_ignore'] = true; |
|
52 | + } |
|
53 | + } |
|
49 | 54 | |
50 | 55 | /** |
51 | 56 | * This function will tell you whether this database type supports this search type. |
@@ -104,16 +109,16 @@ discard block |
||
104 | 109 | ), |
105 | 110 | ); |
106 | 111 | |
107 | - if (isset($replacements[$identifier])) |
|
108 | - $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
112 | + if (isset($replacements[$identifier])) { |
|
113 | + $db_string = preg_replace(array_keys($replacements[$identifier]), array_values($replacements[$identifier]), $db_string); |
|
114 | + } |
|
109 | 115 | if (preg_match('~^\s*INSERT\sIGNORE~i', $db_string) != 0) |
110 | 116 | { |
111 | 117 | $db_string = preg_replace('~^\s*INSERT\sIGNORE~i', 'INSERT', $db_string); |
112 | 118 | if ($smcFunc['db_support_ignore']){ |
113 | 119 | //pg style "INSERT INTO.... ON CONFLICT DO NOTHING" |
114 | 120 | $db_string = $db_string.' ON CONFLICT DO NOTHING'; |
115 | - } |
|
116 | - else |
|
121 | + } else |
|
117 | 122 | { |
118 | 123 | // Don't error on multi-insert. |
119 | 124 | $db_values['db_error_skip'] = true; |
@@ -121,8 +126,9 @@ discard block |
||
121 | 126 | } |
122 | 127 | |
123 | 128 | //fix double quotes |
124 | - if ($identifier == 'insert_into_log_messages_fulltext') |
|
125 | - $db_values = str_replace('"', "'", $db_values); |
|
129 | + if ($identifier == 'insert_into_log_messages_fulltext') { |
|
130 | + $db_values = str_replace('"', "'", $db_values); |
|
131 | + } |
|
126 | 132 | |
127 | 133 | $return = $smcFunc['db_query']('', $db_string, |
128 | 134 | $db_values, $connection |
@@ -164,9 +170,9 @@ discard block |
||
164 | 170 | |
165 | 171 | $language_ftx = 'english'; |
166 | 172 | |
167 | - if (!empty($modSettings['search_language'])) |
|
168 | - $language_ftx = $modSettings['search_language']; |
|
169 | - else |
|
173 | + if (!empty($modSettings['search_language'])) { |
|
174 | + $language_ftx = $modSettings['search_language']; |
|
175 | + } else |
|
170 | 176 | { |
171 | 177 | $request = $smcFunc['db_query']('',' |
172 | 178 | SELECT cfgname FROM pg_ts_config WHERE oid = current_setting({string:default_language})::regconfig', |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | /** |
82 | 82 | * Make files writable. First try to use regular chmod, but if that fails, try to use FTP. |
83 | 83 | * |
84 | - * @param $files |
|
84 | + * @param string[] $files |
|
85 | 85 | * @return bool |
86 | 86 | */ |
87 | 87 | function makeFilesWritable(&$files) |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | /** |
323 | 323 | * Prints an error to stderr. |
324 | 324 | * |
325 | - * @param $message |
|
325 | + * @param string $message |
|
326 | 326 | * @param bool $fatal |
327 | 327 | */ |
328 | 328 | function print_error($message, $fatal = false) |
@@ -13,8 +13,9 @@ discard block |
||
13 | 13 | * This file contains helper functions for upgrade.php |
14 | 14 | */ |
15 | 15 | |
16 | -if (!defined('SMF_VERSION')) |
|
16 | +if (!defined('SMF_VERSION')) { |
|
17 | 17 | die('No direct access!'); |
18 | +} |
|
18 | 19 | |
19 | 20 | /** |
20 | 21 | * Clean the cache using the SMF 2.1 CacheAPI. |
@@ -45,8 +46,9 @@ discard block |
||
45 | 46 | global $smcFunc; |
46 | 47 | static $member_groups = array(); |
47 | 48 | |
48 | - if (!empty($member_groups)) |
|
49 | - return $member_groups; |
|
49 | + if (!empty($member_groups)) { |
|
50 | + return $member_groups; |
|
51 | + } |
|
50 | 52 | |
51 | 53 | $request = $smcFunc['db_query']('', ' |
52 | 54 | SELECT group_name, id_group |
@@ -71,8 +73,9 @@ discard block |
||
71 | 73 | ) |
72 | 74 | ); |
73 | 75 | } |
74 | - while ($row = $smcFunc['db_fetch_row']($request)) |
|
75 | - $member_groups[trim($row[0])] = $row[1]; |
|
76 | + while ($row = $smcFunc['db_fetch_row']($request)) { |
|
77 | + $member_groups[trim($row[0])] = $row[1]; |
|
78 | + } |
|
76 | 79 | $smcFunc['db_free_result']($request); |
77 | 80 | |
78 | 81 | return $member_groups; |
@@ -88,8 +91,9 @@ discard block |
||
88 | 91 | { |
89 | 92 | global $upcontext, $boarddir, $sourcedir; |
90 | 93 | |
91 | - if (empty($files)) |
|
92 | - return true; |
|
94 | + if (empty($files)) { |
|
95 | + return true; |
|
96 | + } |
|
93 | 97 | |
94 | 98 | $failure = false; |
95 | 99 | // On linux, it's easy - just use is_writable! |
@@ -100,22 +104,25 @@ discard block |
||
100 | 104 | foreach ($files as $k => $file) |
101 | 105 | { |
102 | 106 | // Some files won't exist, try to address up front |
103 | - if (!file_exists($file)) |
|
104 | - @touch($file); |
|
107 | + if (!file_exists($file)) { |
|
108 | + @touch($file); |
|
109 | + } |
|
105 | 110 | // NOW do the writable check... |
106 | 111 | if (!is_writable($file)) |
107 | 112 | { |
108 | 113 | @chmod($file, 0755); |
109 | 114 | |
110 | 115 | // Well, 755 hopefully worked... if not, try 777. |
111 | - if (!is_writable($file) && !@chmod($file, 0777)) |
|
112 | - $failure = true; |
|
116 | + if (!is_writable($file) && !@chmod($file, 0777)) { |
|
117 | + $failure = true; |
|
118 | + } |
|
113 | 119 | // Otherwise remove it as it's good! |
114 | - else |
|
115 | - unset($files[$k]); |
|
120 | + else { |
|
121 | + unset($files[$k]); |
|
122 | + } |
|
123 | + } else { |
|
124 | + unset($files[$k]); |
|
116 | 125 | } |
117 | - else |
|
118 | - unset($files[$k]); |
|
119 | 126 | } |
120 | 127 | } |
121 | 128 | // Windows is trickier. Let's try opening for r+... |
@@ -126,30 +133,35 @@ discard block |
||
126 | 133 | foreach ($files as $k => $file) |
127 | 134 | { |
128 | 135 | // Folders can't be opened for write... but the index.php in them can ;). |
129 | - if (is_dir($file)) |
|
130 | - $file .= '/index.php'; |
|
136 | + if (is_dir($file)) { |
|
137 | + $file .= '/index.php'; |
|
138 | + } |
|
131 | 139 | |
132 | 140 | // Funny enough, chmod actually does do something on windows - it removes the read only attribute. |
133 | 141 | @chmod($file, 0777); |
134 | 142 | $fp = @fopen($file, 'r+'); |
135 | 143 | |
136 | 144 | // Hmm, okay, try just for write in that case... |
137 | - if (!$fp) |
|
138 | - $fp = @fopen($file, 'w'); |
|
145 | + if (!$fp) { |
|
146 | + $fp = @fopen($file, 'w'); |
|
147 | + } |
|
139 | 148 | |
140 | - if (!$fp) |
|
141 | - $failure = true; |
|
142 | - else |
|
143 | - unset($files[$k]); |
|
149 | + if (!$fp) { |
|
150 | + $failure = true; |
|
151 | + } else { |
|
152 | + unset($files[$k]); |
|
153 | + } |
|
144 | 154 | @fclose($fp); |
145 | 155 | } |
146 | 156 | } |
147 | 157 | |
148 | - if (empty($files)) |
|
149 | - return true; |
|
158 | + if (empty($files)) { |
|
159 | + return true; |
|
160 | + } |
|
150 | 161 | |
151 | - if (!isset($_SERVER)) |
|
152 | - return !$failure; |
|
162 | + if (!isset($_SERVER)) { |
|
163 | + return !$failure; |
|
164 | + } |
|
153 | 165 | |
154 | 166 | // What still needs to be done? |
155 | 167 | $upcontext['chmod']['files'] = $files; |
@@ -201,36 +213,40 @@ discard block |
||
201 | 213 | |
202 | 214 | if (!isset($ftp) || $ftp->error !== false) |
203 | 215 | { |
204 | - if (!isset($ftp)) |
|
205 | - $ftp = new ftp_connection(null); |
|
216 | + if (!isset($ftp)) { |
|
217 | + $ftp = new ftp_connection(null); |
|
218 | + } |
|
206 | 219 | // Save the error so we can mess with listing... |
207 | - elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error'])) |
|
208 | - $upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message; |
|
220 | + elseif ($ftp->error !== false && !isset($upcontext['chmod']['ftp_error'])) { |
|
221 | + $upcontext['chmod']['ftp_error'] = $ftp->last_message === null ? '' : $ftp->last_message; |
|
222 | + } |
|
209 | 223 | |
210 | 224 | list ($username, $detect_path, $found_path) = $ftp->detect_path(dirname(__FILE__)); |
211 | 225 | |
212 | - if ($found_path || !isset($upcontext['chmod']['path'])) |
|
213 | - $upcontext['chmod']['path'] = $detect_path; |
|
226 | + if ($found_path || !isset($upcontext['chmod']['path'])) { |
|
227 | + $upcontext['chmod']['path'] = $detect_path; |
|
228 | + } |
|
214 | 229 | |
215 | - if (!isset($upcontext['chmod']['username'])) |
|
216 | - $upcontext['chmod']['username'] = $username; |
|
230 | + if (!isset($upcontext['chmod']['username'])) { |
|
231 | + $upcontext['chmod']['username'] = $username; |
|
232 | + } |
|
217 | 233 | |
218 | 234 | // Don't forget the login token. |
219 | 235 | $upcontext += createToken('login'); |
220 | 236 | |
221 | 237 | return false; |
222 | - } |
|
223 | - else |
|
238 | + } else |
|
224 | 239 | { |
225 | 240 | // We want to do a relative path for FTP. |
226 | 241 | if (!in_array($upcontext['chmod']['path'], array('', '/'))) |
227 | 242 | { |
228 | 243 | $ftp_root = strtr($boarddir, array($upcontext['chmod']['path'] => '')); |
229 | - if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/')) |
|
230 | - $ftp_root = substr($ftp_root, 0, -1); |
|
244 | + if (substr($ftp_root, -1) == '/' && ($upcontext['chmod']['path'] == '' || $upcontext['chmod']['path'][0] === '/')) { |
|
245 | + $ftp_root = substr($ftp_root, 0, -1); |
|
246 | + } |
|
247 | + } else { |
|
248 | + $ftp_root = $boarddir; |
|
231 | 249 | } |
232 | - else |
|
233 | - $ftp_root = $boarddir; |
|
234 | 250 | |
235 | 251 | // Save the info for next time! |
236 | 252 | $_SESSION['installer_temp_ftp'] = array( |
@@ -244,10 +260,12 @@ discard block |
||
244 | 260 | |
245 | 261 | foreach ($files as $k => $file) |
246 | 262 | { |
247 | - if (!is_writable($file)) |
|
248 | - $ftp->chmod($file, 0755); |
|
249 | - if (!is_writable($file)) |
|
250 | - $ftp->chmod($file, 0777); |
|
263 | + if (!is_writable($file)) { |
|
264 | + $ftp->chmod($file, 0755); |
|
265 | + } |
|
266 | + if (!is_writable($file)) { |
|
267 | + $ftp->chmod($file, 0777); |
|
268 | + } |
|
251 | 269 | |
252 | 270 | // Assuming that didn't work calculate the path without the boarddir. |
253 | 271 | if (!is_writable($file)) |
@@ -256,19 +274,23 @@ discard block |
||
256 | 274 | { |
257 | 275 | $ftp_file = strtr($file, array($_SESSION['installer_temp_ftp']['root'] => '')); |
258 | 276 | $ftp->chmod($ftp_file, 0755); |
259 | - if (!is_writable($file)) |
|
260 | - $ftp->chmod($ftp_file, 0777); |
|
277 | + if (!is_writable($file)) { |
|
278 | + $ftp->chmod($ftp_file, 0777); |
|
279 | + } |
|
261 | 280 | // Sometimes an extra slash can help... |
262 | 281 | $ftp_file = '/' . $ftp_file; |
263 | - if (!is_writable($file)) |
|
264 | - $ftp->chmod($ftp_file, 0755); |
|
265 | - if (!is_writable($file)) |
|
266 | - $ftp->chmod($ftp_file, 0777); |
|
282 | + if (!is_writable($file)) { |
|
283 | + $ftp->chmod($ftp_file, 0755); |
|
284 | + } |
|
285 | + if (!is_writable($file)) { |
|
286 | + $ftp->chmod($ftp_file, 0777); |
|
287 | + } |
|
267 | 288 | } |
268 | 289 | } |
269 | 290 | |
270 | - if (is_writable($file)) |
|
271 | - unset($files[$k]); |
|
291 | + if (is_writable($file)) { |
|
292 | + unset($files[$k]); |
|
293 | + } |
|
272 | 294 | } |
273 | 295 | |
274 | 296 | $ftp->close(); |
@@ -278,8 +300,9 @@ discard block |
||
278 | 300 | // What remains? |
279 | 301 | $upcontext['chmod']['files'] = $files; |
280 | 302 | |
281 | - if (empty($files)) |
|
282 | - return true; |
|
303 | + if (empty($files)) { |
|
304 | + return true; |
|
305 | + } |
|
283 | 306 | |
284 | 307 | return false; |
285 | 308 | } |
@@ -294,12 +317,14 @@ discard block |
||
294 | 317 | { |
295 | 318 | |
296 | 319 | // Some files won't exist, try to address up front |
297 | - if (!file_exists($file)) |
|
298 | - @touch($file); |
|
320 | + if (!file_exists($file)) { |
|
321 | + @touch($file); |
|
322 | + } |
|
299 | 323 | |
300 | 324 | // NOW do the writable check... |
301 | - if (is_writable($file)) |
|
302 | - return true; |
|
325 | + if (is_writable($file)) { |
|
326 | + return true; |
|
327 | + } |
|
303 | 328 | |
304 | 329 | @chmod($file, 0755); |
305 | 330 | |
@@ -309,10 +334,11 @@ discard block |
||
309 | 334 | foreach ($chmod_values as $val) |
310 | 335 | { |
311 | 336 | // If it's writable, break out of the loop |
312 | - if (is_writable($file)) |
|
313 | - break; |
|
314 | - else |
|
315 | - @chmod($file, $val); |
|
337 | + if (is_writable($file)) { |
|
338 | + break; |
|
339 | + } else { |
|
340 | + @chmod($file, $val); |
|
341 | + } |
|
316 | 342 | } |
317 | 343 | |
318 | 344 | return is_writable($file); |
@@ -339,14 +365,16 @@ discard block |
||
339 | 365 | { |
340 | 366 | static $fp = null; |
341 | 367 | |
342 | - if ($fp === null) |
|
343 | - $fp = fopen('php://stderr', 'wb'); |
|
368 | + if ($fp === null) { |
|
369 | + $fp = fopen('php://stderr', 'wb'); |
|
370 | + } |
|
344 | 371 | |
345 | 372 | fwrite($fp, $message . "\n"); |
346 | 373 | |
347 | - if ($fatal) |
|
348 | - exit; |
|
349 | -} |
|
374 | + if ($fatal) { |
|
375 | + exit; |
|
376 | + } |
|
377 | + } |
|
350 | 378 | |
351 | 379 | /** |
352 | 380 | * Throws a graphical error message. |
@@ -16,8 +16,9 @@ discard block |
||
16 | 16 | * @version 2.1 Beta 4 |
17 | 17 | */ |
18 | 18 | |
19 | -if (!defined('SMF')) |
|
19 | +if (!defined('SMF')) { |
|
20 | 20 | die('No direct access...'); |
21 | +} |
|
21 | 22 | |
22 | 23 | |
23 | 24 | /** |
@@ -28,14 +29,16 @@ discard block |
||
28 | 29 | function sha1_smf($str) |
29 | 30 | { |
30 | 31 | // If we have mhash loaded in, use it instead! |
31 | - if (function_exists('mhash') && defined('MHASH_SHA1')) |
|
32 | - return bin2hex(mhash(MHASH_SHA1, $str)); |
|
32 | + if (function_exists('mhash') && defined('MHASH_SHA1')) { |
|
33 | + return bin2hex(mhash(MHASH_SHA1, $str)); |
|
34 | + } |
|
33 | 35 | |
34 | 36 | $nblk = (strlen($str) + 8 >> 6) + 1; |
35 | 37 | $blks = array_pad(array(), $nblk * 16, 0); |
36 | 38 | |
37 | - for ($i = 0; $i < strlen($str); $i++) |
|
38 | - $blks[$i >> 2] |= ord($str{$i}) << (24 - ($i % 4) * 8); |
|
39 | + for ($i = 0; $i < strlen($str); $i++) { |
|
40 | + $blks[$i >> 2] |= ord($str{$i}) << (24 - ($i % 4) * 8); |
|
41 | + } |
|
39 | 42 | |
40 | 43 | $blks[$i >> 2] |= 0x80 << (24 - ($i % 4) * 8); |
41 | 44 | |
@@ -70,10 +73,11 @@ discard block |
||
70 | 73 | |
71 | 74 | for ($j = 0; $j < 80; $j++) |
72 | 75 | { |
73 | - if ($j < 16) |
|
74 | - $w[$j] = isset($x[$i + $j]) ? $x[$i + $j] : 0; |
|
75 | - else |
|
76 | - $w[$j] = sha1_rol($w[$j - 3] ^ $w[$j - 8] ^ $w[$j - 14] ^ $w[$j - 16], 1); |
|
76 | + if ($j < 16) { |
|
77 | + $w[$j] = isset($x[$i + $j]) ? $x[$i + $j] : 0; |
|
78 | + } else { |
|
79 | + $w[$j] = sha1_rol($w[$j - 3] ^ $w[$j - 8] ^ $w[$j - 14] ^ $w[$j - 16], 1); |
|
80 | + } |
|
77 | 81 | |
78 | 82 | $t = sha1_rol($a, 5) + sha1_ft($j, $b, $c, $d) + $e + $w[$j] + sha1_kt($j); |
79 | 83 | $e = $d; |
@@ -103,12 +107,15 @@ discard block |
||
103 | 107 | */ |
104 | 108 | function sha1_ft($t, $b, $c, $d) |
105 | 109 | { |
106 | - if ($t < 20) |
|
107 | - return ($b & $c) | ((~$b) & $d); |
|
108 | - if ($t < 40) |
|
109 | - return $b ^ $c ^ $d; |
|
110 | - if ($t < 60) |
|
111 | - return ($b & $c) | ($b & $d) | ($c & $d); |
|
110 | + if ($t < 20) { |
|
111 | + return ($b & $c) | ((~$b) & $d); |
|
112 | + } |
|
113 | + if ($t < 40) { |
|
114 | + return $b ^ $c ^ $d; |
|
115 | + } |
|
116 | + if ($t < 60) { |
|
117 | + return ($b & $c) | ($b & $d) | ($c & $d); |
|
118 | + } |
|
112 | 119 | |
113 | 120 | return $b ^ $c ^ $d; |
114 | 121 | } |
@@ -132,10 +139,11 @@ discard block |
||
132 | 139 | function sha1_rol($num, $cnt) |
133 | 140 | { |
134 | 141 | // Unfortunately, PHP uses unsigned 32-bit longs only. So we have to kludge it a bit. |
135 | - if ($num & 0x80000000) |
|
136 | - $a = ($num >> 1 & 0x7fffffff) >> (31 - $cnt); |
|
137 | - else |
|
138 | - $a = $num >> (32 - $cnt); |
|
142 | + if ($num & 0x80000000) { |
|
143 | + $a = ($num >> 1 & 0x7fffffff) >> (31 - $cnt); |
|
144 | + } else { |
|
145 | + $a = $num >> (32 - $cnt); |
|
146 | + } |
|
139 | 147 | |
140 | 148 | return ($num << $cnt) | $a; |
141 | 149 | } |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 4 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | /** |
21 | 22 | * This function allows to move a topic, making sure to ask the moderator |
@@ -32,8 +33,9 @@ discard block |
||
32 | 33 | { |
33 | 34 | global $txt, $board, $topic, $user_info, $context, $language, $scripturl, $smcFunc, $modSettings, $sourcedir; |
34 | 35 | |
35 | - if (empty($topic)) |
|
36 | - fatal_lang_error('no_access', false); |
|
36 | + if (empty($topic)) { |
|
37 | + fatal_lang_error('no_access', false); |
|
38 | + } |
|
37 | 39 | |
38 | 40 | $request = $smcFunc['db_query']('', ' |
39 | 41 | SELECT t.id_member_started, ms.subject, t.approved |
@@ -49,8 +51,9 @@ discard block |
||
49 | 51 | $smcFunc['db_free_result']($request); |
50 | 52 | |
51 | 53 | // Can they see it - if not approved? |
52 | - if ($modSettings['postmod_active'] && !$context['is_approved']) |
|
53 | - isAllowedTo('approve_posts'); |
|
54 | + if ($modSettings['postmod_active'] && !$context['is_approved']) { |
|
55 | + isAllowedTo('approve_posts'); |
|
56 | + } |
|
54 | 57 | |
55 | 58 | // Permission check! |
56 | 59 | // @todo |
@@ -59,9 +62,9 @@ discard block |
||
59 | 62 | if ($id_member_started == $user_info['id']) |
60 | 63 | { |
61 | 64 | isAllowedTo('move_own'); |
65 | + } else { |
|
66 | + isAllowedTo('move_any'); |
|
62 | 67 | } |
63 | - else |
|
64 | - isAllowedTo('move_any'); |
|
65 | 68 | } |
66 | 69 | |
67 | 70 | $context['move_any'] = $user_info['is_admin'] || $modSettings['topic_move_any']; |
@@ -83,11 +86,13 @@ discard block |
||
83 | 86 | 'not_redirection' => true, |
84 | 87 | ); |
85 | 88 | |
86 | - if (!empty($_SESSION['move_to_topic']) && $_SESSION['move_to_topic'] != $board) |
|
87 | - $options['selected_board'] = $_SESSION['move_to_topic']; |
|
89 | + if (!empty($_SESSION['move_to_topic']) && $_SESSION['move_to_topic'] != $board) { |
|
90 | + $options['selected_board'] = $_SESSION['move_to_topic']; |
|
91 | + } |
|
88 | 92 | |
89 | - if (!$context['move_any']) |
|
90 | - $options['included_boards'] = $boards; |
|
93 | + if (!$context['move_any']) { |
|
94 | + $options['included_boards'] = $boards; |
|
95 | + } |
|
91 | 96 | |
92 | 97 | require_once($sourcedir . '/Subs-MessageIndex.php'); |
93 | 98 | $context['categories'] = getBoardList($options); |
@@ -138,12 +143,14 @@ discard block |
||
138 | 143 | global $txt, $topic, $scripturl, $sourcedir, $context; |
139 | 144 | global $board, $language, $user_info, $smcFunc; |
140 | 145 | |
141 | - if (empty($topic)) |
|
142 | - fatal_lang_error('no_access', false); |
|
146 | + if (empty($topic)) { |
|
147 | + fatal_lang_error('no_access', false); |
|
148 | + } |
|
143 | 149 | |
144 | 150 | // You can't choose to have a redirection topic and use an empty reason. |
145 | - if (isset($_POST['postRedirect']) && (!isset($_POST['reason']) || trim($_POST['reason']) == '')) |
|
146 | - fatal_lang_error('movetopic_no_reason', false); |
|
151 | + if (isset($_POST['postRedirect']) && (!isset($_POST['reason']) || trim($_POST['reason']) == '')) { |
|
152 | + fatal_lang_error('movetopic_no_reason', false); |
|
153 | + } |
|
147 | 154 | |
148 | 155 | moveTopicConcurrence(); |
149 | 156 | |
@@ -163,16 +170,18 @@ discard block |
||
163 | 170 | $smcFunc['db_free_result']($request); |
164 | 171 | |
165 | 172 | // Can they see it? |
166 | - if (!$context['is_approved']) |
|
167 | - isAllowedTo('approve_posts'); |
|
173 | + if (!$context['is_approved']) { |
|
174 | + isAllowedTo('approve_posts'); |
|
175 | + } |
|
168 | 176 | |
169 | 177 | // Can they move topics on this board? |
170 | 178 | if (!allowedTo('move_any')) |
171 | 179 | { |
172 | - if ($id_member_started == $user_info['id']) |
|
173 | - isAllowedTo('move_own'); |
|
174 | - else |
|
175 | - isAllowedTo('move_any'); |
|
180 | + if ($id_member_started == $user_info['id']) { |
|
181 | + isAllowedTo('move_own'); |
|
182 | + } else { |
|
183 | + isAllowedTo('move_any'); |
|
184 | + } |
|
176 | 185 | } |
177 | 186 | |
178 | 187 | checkSession(); |
@@ -197,8 +206,9 @@ discard block |
||
197 | 206 | 'blank_redirect' => '', |
198 | 207 | ) |
199 | 208 | ); |
200 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
201 | - fatal_lang_error('no_board'); |
|
209 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
210 | + fatal_lang_error('no_board'); |
|
211 | + } |
|
202 | 212 | list ($pcounter, $board_name, $subject) = $smcFunc['db_fetch_row']($request); |
203 | 213 | $smcFunc['db_free_result']($request); |
204 | 214 | |
@@ -210,8 +220,9 @@ discard block |
||
210 | 220 | { |
211 | 221 | $_POST['custom_subject'] = strtr($smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['custom_subject'])), array("\r" => '', "\n" => '', "\t" => '')); |
212 | 222 | // Keep checking the length. |
213 | - if ($smcFunc['strlen']($_POST['custom_subject']) > 100) |
|
214 | - $_POST['custom_subject'] = $smcFunc['substr']($_POST['custom_subject'], 0, 100); |
|
223 | + if ($smcFunc['strlen']($_POST['custom_subject']) > 100) { |
|
224 | + $_POST['custom_subject'] = $smcFunc['substr']($_POST['custom_subject'], 0, 100); |
|
225 | + } |
|
215 | 226 | |
216 | 227 | // If it's still valid move onwards and upwards. |
217 | 228 | if ($_POST['custom_subject'] != '') |
@@ -221,9 +232,9 @@ discard block |
||
221 | 232 | // Get a response prefix, but in the forum's default language. |
222 | 233 | if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) |
223 | 234 | { |
224 | - if ($language === $user_info['language']) |
|
225 | - $context['response_prefix'] = $txt['response_prefix']; |
|
226 | - else |
|
235 | + if ($language === $user_info['language']) { |
|
236 | + $context['response_prefix'] = $txt['response_prefix']; |
|
237 | + } else |
|
227 | 238 | { |
228 | 239 | loadLanguage('index', $language, false); |
229 | 240 | $context['response_prefix'] = $txt['response_prefix']; |
@@ -263,8 +274,9 @@ discard block |
||
263 | 274 | if (isset($_POST['postRedirect'])) |
264 | 275 | { |
265 | 276 | // Should be in the boardwide language. |
266 | - if ($user_info['language'] != $language) |
|
267 | - loadLanguage('index', $language); |
|
277 | + if ($user_info['language'] != $language) { |
|
278 | + loadLanguage('index', $language); |
|
279 | + } |
|
268 | 280 | |
269 | 281 | $_POST['reason'] = $smcFunc['htmlspecialchars']($_POST['reason'], ENT_QUOTES); |
270 | 282 | preparsecode($_POST['reason']); |
@@ -328,8 +340,9 @@ discard block |
||
328 | 340 | $posters = array(); |
329 | 341 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
330 | 342 | { |
331 | - if (!isset($posters[$row['id_member']])) |
|
332 | - $posters[$row['id_member']] = 0; |
|
343 | + if (!isset($posters[$row['id_member']])) { |
|
344 | + $posters[$row['id_member']] = 0; |
|
345 | + } |
|
333 | 346 | |
334 | 347 | $posters[$row['id_member']]++; |
335 | 348 | } |
@@ -338,11 +351,13 @@ discard block |
||
338 | 351 | foreach ($posters as $id_member => $posts) |
339 | 352 | { |
340 | 353 | // The board we're moving from counted posts, but not to. |
341 | - if (empty($pcounter_from)) |
|
342 | - updateMemberData($id_member, array('posts' => 'posts - ' . $posts)); |
|
354 | + if (empty($pcounter_from)) { |
|
355 | + updateMemberData($id_member, array('posts' => 'posts - ' . $posts)); |
|
356 | + } |
|
343 | 357 | // The reverse: from didn't, to did. |
344 | - else |
|
345 | - updateMemberData($id_member, array('posts' => 'posts + ' . $posts)); |
|
358 | + else { |
|
359 | + updateMemberData($id_member, array('posts' => 'posts + ' . $posts)); |
|
360 | + } |
|
346 | 361 | } |
347 | 362 | } |
348 | 363 | |
@@ -350,17 +365,19 @@ discard block |
||
350 | 365 | moveTopics($topic, $_POST['toboard']); |
351 | 366 | |
352 | 367 | // Log that they moved this topic. |
353 | - if (!allowedTo('move_own') || $id_member_started != $user_info['id']) |
|
354 | - logAction('move', array('topic' => $topic, 'board_from' => $board, 'board_to' => $_POST['toboard'])); |
|
368 | + if (!allowedTo('move_own') || $id_member_started != $user_info['id']) { |
|
369 | + logAction('move', array('topic' => $topic, 'board_from' => $board, 'board_to' => $_POST['toboard'])); |
|
370 | + } |
|
355 | 371 | // Notify people that this topic has been moved? |
356 | 372 | sendNotifications($topic, 'move'); |
357 | 373 | |
358 | 374 | // Why not go back to the original board in case they want to keep moving? |
359 | - if (!isset($_REQUEST['goback'])) |
|
360 | - redirectexit('board=' . $board . '.0'); |
|
361 | - else |
|
362 | - redirectexit('topic=' . $topic . '.0'); |
|
363 | -} |
|
375 | + if (!isset($_REQUEST['goback'])) { |
|
376 | + redirectexit('board=' . $board . '.0'); |
|
377 | + } else { |
|
378 | + redirectexit('topic=' . $topic . '.0'); |
|
379 | + } |
|
380 | + } |
|
364 | 381 | |
365 | 382 | /** |
366 | 383 | * Moves one or more topics to a specific board. (doesn't check permissions.) |
@@ -376,18 +393,21 @@ discard block |
||
376 | 393 | global $sourcedir, $user_info, $modSettings, $smcFunc; |
377 | 394 | |
378 | 395 | // Empty array? |
379 | - if (empty($topics)) |
|
380 | - return; |
|
396 | + if (empty($topics)) { |
|
397 | + return; |
|
398 | + } |
|
381 | 399 | |
382 | 400 | // Only a single topic. |
383 | - if (is_numeric($topics)) |
|
384 | - $topics = array($topics); |
|
401 | + if (is_numeric($topics)) { |
|
402 | + $topics = array($topics); |
|
403 | + } |
|
385 | 404 | |
386 | 405 | $fromBoards = array(); |
387 | 406 | |
388 | 407 | // Destination board empty or equal to 0? |
389 | - if (empty($toBoard)) |
|
390 | - return; |
|
408 | + if (empty($toBoard)) { |
|
409 | + return; |
|
410 | + } |
|
391 | 411 | |
392 | 412 | // Are we moving to the recycle board? |
393 | 413 | $isRecycleDest = !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $toBoard; |
@@ -395,8 +415,9 @@ discard block |
||
395 | 415 | // Callback for search APIs to do their thing |
396 | 416 | require_once($sourcedir . '/Search.php'); |
397 | 417 | $searchAPI = findSearchAPI(); |
398 | - if ($searchAPI->supportsMethod('topicsMoved')) |
|
399 | - $searchAPI->topicsMoved($topics, $toBoard); |
|
418 | + if ($searchAPI->supportsMethod('topicsMoved')) { |
|
419 | + $searchAPI->topicsMoved($topics, $toBoard); |
|
420 | + } |
|
400 | 421 | |
401 | 422 | // Determine the source boards... |
402 | 423 | $request = $smcFunc['db_query']('', ' |
@@ -410,8 +431,9 @@ discard block |
||
410 | 431 | ) |
411 | 432 | ); |
412 | 433 | // Num of rows = 0 -> no topics found. Num of rows > 1 -> topics are on multiple boards. |
413 | - if ($smcFunc['db_num_rows']($request) == 0) |
|
414 | - return; |
|
434 | + if ($smcFunc['db_num_rows']($request) == 0) { |
|
435 | + return; |
|
436 | + } |
|
415 | 437 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
416 | 438 | { |
417 | 439 | if (!isset($fromBoards[$row['id_board']]['num_posts'])) |
@@ -429,10 +451,11 @@ discard block |
||
429 | 451 | $fromBoards[$row['id_board']]['unapproved_posts'] += $row['unapproved_posts']; |
430 | 452 | |
431 | 453 | // Add the topics to the right type. |
432 | - if ($row['approved']) |
|
433 | - $fromBoards[$row['id_board']]['num_topics'] += $row['num_topics']; |
|
434 | - else |
|
435 | - $fromBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics']; |
|
454 | + if ($row['approved']) { |
|
455 | + $fromBoards[$row['id_board']]['num_topics'] += $row['num_topics']; |
|
456 | + } else { |
|
457 | + $fromBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics']; |
|
458 | + } |
|
436 | 459 | } |
437 | 460 | $smcFunc['db_free_result']($request); |
438 | 461 | |
@@ -558,13 +581,14 @@ discard block |
||
558 | 581 | ) |
559 | 582 | ); |
560 | 583 | $approval_msgs = array(); |
561 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
562 | - $approval_msgs[] = $row['id_msg']; |
|
584 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
585 | + $approval_msgs[] = $row['id_msg']; |
|
586 | + } |
|
563 | 587 | $smcFunc['db_free_result']($request); |
564 | 588 | |
565 | 589 | // Empty the approval queue for these, as we're going to approve them next. |
566 | - if (!empty($approval_msgs)) |
|
567 | - $smcFunc['db_query']('', ' |
|
590 | + if (!empty($approval_msgs)) { |
|
591 | + $smcFunc['db_query']('', ' |
|
568 | 592 | DELETE FROM {db_prefix}approval_queue |
569 | 593 | WHERE id_msg IN ({array_int:message_list}) |
570 | 594 | AND id_attach = {int:id_attach}', |
@@ -573,6 +597,7 @@ discard block |
||
573 | 597 | 'id_attach' => 0, |
574 | 598 | ) |
575 | 599 | ); |
600 | + } |
|
576 | 601 | |
577 | 602 | // Get all the current max and mins. |
578 | 603 | $request = $smcFunc['db_query']('', ' |
@@ -606,8 +631,8 @@ discard block |
||
606 | 631 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
607 | 632 | { |
608 | 633 | // If not, update. |
609 | - if ($row['first_msg'] != $topicMaxMin[$row['id_topic']]['min'] || $row['last_msg'] != $topicMaxMin[$row['id_topic']]['max']) |
|
610 | - $smcFunc['db_query']('', ' |
|
634 | + if ($row['first_msg'] != $topicMaxMin[$row['id_topic']]['min'] || $row['last_msg'] != $topicMaxMin[$row['id_topic']]['max']) { |
|
635 | + $smcFunc['db_query']('', ' |
|
611 | 636 | UPDATE {db_prefix}topics |
612 | 637 | SET id_first_msg = {int:first_msg}, id_last_msg = {int:last_msg} |
613 | 638 | WHERE id_topic = {int:selected_topic}', |
@@ -617,6 +642,7 @@ discard block |
||
617 | 642 | 'selected_topic' => $row['id_topic'], |
618 | 643 | ) |
619 | 644 | ); |
645 | + } |
|
620 | 646 | } |
621 | 647 | $smcFunc['db_free_result']($request); |
622 | 648 | } |
@@ -675,9 +701,10 @@ discard block |
||
675 | 701 | } |
676 | 702 | |
677 | 703 | // Update the cache? |
678 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) |
|
679 | - foreach ($topics as $topic_id) |
|
704 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 3) { |
|
705 | + foreach ($topics as $topic_id) |
|
680 | 706 | cache_put_data('topic_board-' . $topic_id, null, 120); |
707 | + } |
|
681 | 708 | |
682 | 709 | require_once($sourcedir . '/Subs-Post.php'); |
683 | 710 | |
@@ -701,15 +728,17 @@ discard block |
||
701 | 728 | { |
702 | 729 | global $board, $topic, $smcFunc, $scripturl; |
703 | 730 | |
704 | - if (isset($_GET['current_board'])) |
|
705 | - $move_from = (int) $_GET['current_board']; |
|
731 | + if (isset($_GET['current_board'])) { |
|
732 | + $move_from = (int) $_GET['current_board']; |
|
733 | + } |
|
706 | 734 | |
707 | - if (empty($move_from) || empty($board) || empty($topic)) |
|
708 | - return true; |
|
735 | + if (empty($move_from) || empty($board) || empty($topic)) { |
|
736 | + return true; |
|
737 | + } |
|
709 | 738 | |
710 | - if ($move_from == $board) |
|
711 | - return true; |
|
712 | - else |
|
739 | + if ($move_from == $board) { |
|
740 | + return true; |
|
741 | + } else |
|
713 | 742 | { |
714 | 743 | $request = $smcFunc['db_query']('', ' |
715 | 744 | SELECT m.subject, b.name |
@@ -14,8 +14,9 @@ discard block |
||
14 | 14 | * @version 2.1 Beta 4 |
15 | 15 | */ |
16 | 16 | |
17 | -if (!defined('SMF')) |
|
17 | +if (!defined('SMF')) { |
|
18 | 18 | die('No direct access...'); |
19 | +} |
|
19 | 20 | |
20 | 21 | /** |
21 | 22 | * View the forum's error log. |
@@ -30,8 +31,9 @@ discard block |
||
30 | 31 | global $scripturl, $txt, $context, $modSettings, $user_profile, $filter, $smcFunc; |
31 | 32 | |
32 | 33 | // Viewing contents of a file? |
33 | - if (isset($_GET['file'])) |
|
34 | - return ViewFile(); |
|
34 | + if (isset($_GET['file'])) { |
|
35 | + return ViewFile(); |
|
36 | + } |
|
35 | 37 | |
36 | 38 | // Check for the administrative permission to do this. |
37 | 39 | isAllowedTo('admin_forum'); |
@@ -85,8 +87,8 @@ discard block |
||
85 | 87 | ); |
86 | 88 | |
87 | 89 | // Set up the filtering... |
88 | - if (isset($_GET['value'], $_GET['filter']) && isset($filters[$_GET['filter']])) |
|
89 | - $filter = array( |
|
90 | + if (isset($_GET['value'], $_GET['filter']) && isset($filters[$_GET['filter']])) { |
|
91 | + $filter = array( |
|
90 | 92 | 'variable' => $_GET['filter'], |
91 | 93 | 'value' => array( |
92 | 94 | 'sql' => in_array($_GET['filter'], array('message', 'url', 'file')) ? base64_decode(strtr($_GET['value'], array(' ' => '+'))) : $smcFunc['db_escape_wildcard_string']($_GET['value']), |
@@ -94,10 +96,12 @@ discard block |
||
94 | 96 | 'href' => ';filter=' . $_GET['filter'] . ';value=' . $_GET['value'], |
95 | 97 | 'entity' => $filters[$_GET['filter']]['txt'] |
96 | 98 | ); |
99 | + } |
|
97 | 100 | |
98 | 101 | // Deleting, are we? |
99 | - if (isset($_POST['delall']) || isset($_POST['delete'])) |
|
100 | - deleteErrors(); |
|
102 | + if (isset($_POST['delall']) || isset($_POST['delete'])) { |
|
103 | + deleteErrors(); |
|
104 | + } |
|
101 | 105 | |
102 | 106 | // Just how many errors are there? |
103 | 107 | $result = $smcFunc['db_query']('', ' |
@@ -112,12 +116,14 @@ discard block |
||
112 | 116 | $smcFunc['db_free_result']($result); |
113 | 117 | |
114 | 118 | // If this filter is empty... |
115 | - if ($num_errors == 0 && isset($filter)) |
|
116 | - redirectexit('action=admin;area=logs;sa=errorlog' . (isset($_REQUEST['desc']) ? ';desc' : '')); |
|
119 | + if ($num_errors == 0 && isset($filter)) { |
|
120 | + redirectexit('action=admin;area=logs;sa=errorlog' . (isset($_REQUEST['desc']) ? ';desc' : '')); |
|
121 | + } |
|
117 | 122 | |
118 | 123 | // Clean up start. |
119 | - if (!isset($_GET['start']) || $_GET['start'] < 0) |
|
120 | - $_GET['start'] = 0; |
|
124 | + if (!isset($_GET['start']) || $_GET['start'] < 0) { |
|
125 | + $_GET['start'] = 0; |
|
126 | + } |
|
121 | 127 | |
122 | 128 | // Do we want to reverse error listing? |
123 | 129 | $context['sort_direction'] = isset($_REQUEST['desc']) ? 'down' : 'up'; |
@@ -127,9 +133,9 @@ discard block |
||
127 | 133 | $context['start'] = $_GET['start']; |
128 | 134 | |
129 | 135 | // Update the error count |
130 | - if (!isset($filter)) |
|
131 | - $context['num_errors'] = $num_errors; |
|
132 | - else |
|
136 | + if (!isset($filter)) { |
|
137 | + $context['num_errors'] = $num_errors; |
|
138 | + } else |
|
133 | 139 | { |
134 | 140 | // We want all errors, not just the number of filtered messages... |
135 | 141 | $query = $smcFunc['db_query']('', ' |
@@ -161,8 +167,9 @@ discard block |
||
161 | 167 | for ($i = 0; $row = $smcFunc['db_fetch_assoc']($request); $i++) |
162 | 168 | { |
163 | 169 | $search_message = preg_replace('~<span class="remove">(.+?)</span>~', '%', $smcFunc['db_escape_wildcard_string']($row['message'])); |
164 | - if ($search_message == $filter['value']['sql']) |
|
165 | - $search_message = $smcFunc['db_escape_wildcard_string']($row['message']); |
|
170 | + if ($search_message == $filter['value']['sql']) { |
|
171 | + $search_message = $smcFunc['db_escape_wildcard_string']($row['message']); |
|
172 | + } |
|
166 | 173 | $show_message = strtr(strtr(preg_replace('~<span class="remove">(.+?)</span>~', '$1', $row['message']), array("\r" => '', '<br>' => "\n", '<' => '<', '>' => '>', '"' => '"')), array("\n" => '<br>')); |
167 | 174 | |
168 | 175 | $context['errors'][$row['id_error']] = array( |
@@ -221,8 +228,9 @@ discard block |
||
221 | 228 | 'members' => count($members), |
222 | 229 | ) |
223 | 230 | ); |
224 | - while ($row = $smcFunc['db_fetch_assoc']($request)) |
|
225 | - $members[$row['id_member']] = $row; |
|
231 | + while ($row = $smcFunc['db_fetch_assoc']($request)) { |
|
232 | + $members[$row['id_member']] = $row; |
|
233 | + } |
|
226 | 234 | $smcFunc['db_free_result']($request); |
227 | 235 | |
228 | 236 | // This is a guest... |
@@ -254,20 +262,18 @@ discard block |
||
254 | 262 | $id = $filter['value']['sql']; |
255 | 263 | loadMemberData($id, false, 'minimal'); |
256 | 264 | $context['filter']['value']['html'] = '<a href="' . $scripturl . '?action=profile;u=' . $id . '">' . $user_profile[$id]['real_name'] . '</a>'; |
257 | - } |
|
258 | - elseif ($filter['variable'] == 'url') |
|
259 | - $context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']((substr($filter['value']['sql'], 0, 1) == '?' ? $scripturl : '') . $filter['value']['sql']), array('\_' => '_')) . '\''; |
|
260 | - elseif ($filter['variable'] == 'message') |
|
265 | + } elseif ($filter['variable'] == 'url') { |
|
266 | + $context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']((substr($filter['value']['sql'], 0, 1) == '?' ? $scripturl : '') . $filter['value']['sql']), array('\_' => '_')) . '\''; |
|
267 | + } elseif ($filter['variable'] == 'message') |
|
261 | 268 | { |
262 | 269 | $context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']($filter['value']['sql']), array("\n" => '<br>', '<br />' => '<br>', "\t" => ' ', '\_' => '_', '\\%' => '%', '\\\\' => '\\')) . '\''; |
263 | 270 | $context['filter']['value']['html'] = preg_replace('~&lt;span class=&quot;remove&quot;&gt;(.+?)&lt;/span&gt;~', '$1', $context['filter']['value']['html']); |
264 | - } |
|
265 | - elseif ($filter['variable'] == 'error_type') |
|
271 | + } elseif ($filter['variable'] == 'error_type') |
|
266 | 272 | { |
267 | 273 | $context['filter']['value']['html'] = '\'' . strtr($smcFunc['htmlspecialchars']($filter['value']['sql']), array("\n" => '<br>', '<br />' => '<br>', "\t" => ' ', '\_' => '_', '\\%' => '%', '\\\\' => '\\')) . '\''; |
274 | + } else { |
|
275 | + $context['filter']['value']['html'] = &$filter['value']['sql']; |
|
268 | 276 | } |
269 | - else |
|
270 | - $context['filter']['value']['html'] = &$filter['value']['sql']; |
|
271 | 277 | } |
272 | 278 | |
273 | 279 | $context['error_types'] = array(); |
@@ -308,10 +314,11 @@ discard block |
||
308 | 314 | $context['error_types']['all']['label'] .= ' (' . $sum . ')'; |
309 | 315 | |
310 | 316 | // Finally, work out what is the last tab! |
311 | - if (isset($context['error_types'][$sum])) |
|
312 | - $context['error_types'][$sum]['is_last'] = true; |
|
313 | - else |
|
314 | - $context['error_types']['all']['is_last'] = true; |
|
317 | + if (isset($context['error_types'][$sum])) { |
|
318 | + $context['error_types'][$sum]['is_last'] = true; |
|
319 | + } else { |
|
320 | + $context['error_types']['all']['is_last'] = true; |
|
321 | + } |
|
315 | 322 | |
316 | 323 | // And this is pretty basic ;). |
317 | 324 | $context['page_title'] = $txt['errlog']; |
@@ -337,21 +344,23 @@ discard block |
||
337 | 344 | validateToken('admin-el'); |
338 | 345 | |
339 | 346 | // Delete all or just some? |
340 | - if (isset($_POST['delall']) && !isset($filter)) |
|
341 | - $smcFunc['db_query']('truncate_table', ' |
|
347 | + if (isset($_POST['delall']) && !isset($filter)) { |
|
348 | + $smcFunc['db_query']('truncate_table', ' |
|
342 | 349 | TRUNCATE {db_prefix}log_errors', |
343 | 350 | array( |
344 | 351 | ) |
345 | 352 | ); |
353 | + } |
|
346 | 354 | // Deleting all with a filter? |
347 | - elseif (isset($_POST['delall']) && isset($filter)) |
|
348 | - $smcFunc['db_query']('', ' |
|
355 | + elseif (isset($_POST['delall']) && isset($filter)) { |
|
356 | + $smcFunc['db_query']('', ' |
|
349 | 357 | DELETE FROM {db_prefix}log_errors |
350 | 358 | WHERE ' . $filter['variable'] . ' LIKE {string:filter}', |
351 | 359 | array( |
352 | 360 | 'filter' => $filter['value']['sql'], |
353 | 361 | ) |
354 | 362 | ); |
363 | + } |
|
355 | 364 | // Just specific errors? |
356 | 365 | elseif (!empty($_POST['delete'])) |
357 | 366 | { |
@@ -397,15 +406,17 @@ discard block |
||
397 | 406 | $line = isset($_REQUEST['line']) ? (int) $_REQUEST['line'] : 0; |
398 | 407 | |
399 | 408 | // Make sure the file we are looking for is one they are allowed to look at |
400 | - if ($ext != '.php' || (strpos($file, $real_board) === false && strpos($file, $real_source) === false) || ($basename == 'settings.php' || $basename == 'settings_bak.php') || strpos($file, $real_cache) !== false || !is_readable($file)) |
|
401 | - fatal_lang_error('error_bad_file', true, array($smcFunc['htmlspecialchars']($file))); |
|
409 | + if ($ext != '.php' || (strpos($file, $real_board) === false && strpos($file, $real_source) === false) || ($basename == 'settings.php' || $basename == 'settings_bak.php') || strpos($file, $real_cache) !== false || !is_readable($file)) { |
|
410 | + fatal_lang_error('error_bad_file', true, array($smcFunc['htmlspecialchars']($file))); |
|
411 | + } |
|
402 | 412 | |
403 | 413 | // get the min and max lines |
404 | 414 | $min = $line - 20 <= 0 ? 1 : $line - 20; |
405 | 415 | $max = $line + 21; // One additional line to make everything work out correctly |
406 | 416 | |
407 | - if ($max <= 0 || $min >= $max) |
|
408 | - fatal_lang_error('error_bad_line'); |
|
417 | + if ($max <= 0 || $min >= $max) { |
|
418 | + fatal_lang_error('error_bad_line'); |
|
419 | + } |
|
409 | 420 | |
410 | 421 | $file_data = explode('<br />', highlight_php_code($smcFunc['htmlspecialchars'](implode('', file($file))))); |
411 | 422 |
@@ -11,8 +11,9 @@ |
||
11 | 11 | * @version 2.1 Beta 4 |
12 | 12 | */ |
13 | 13 | |
14 | -if (!defined('SMF')) |
|
14 | +if (!defined('SMF')) { |
|
15 | 15 | die('No direct access...'); |
16 | +} |
|
16 | 17 | |
17 | 18 | /** |
18 | 19 | * Standard non full index, non custom index search |
@@ -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 | * Get the latest posts of a forum. |
@@ -59,8 +60,9 @@ discard block |
||
59 | 60 | censorText($row['body']); |
60 | 61 | |
61 | 62 | $row['body'] = strip_tags(strtr(parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']), array('<br>' => ' '))); |
62 | - if ($smcFunc['strlen']($row['body']) > 128) |
|
63 | - $row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...'; |
|
63 | + if ($smcFunc['strlen']($row['body']) > 128) { |
|
64 | + $row['body'] = $smcFunc['substr']($row['body'], 0, 128) . '...'; |
|
65 | + } |
|
64 | 66 | |
65 | 67 | // Build the array. |
66 | 68 | $posts[] = array( |