@@ -23,21 +23,21 @@ 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 = 0; |
| 29 | 29 | foreach ($arr as $key => $value) |
| 30 | 30 | if (is_array($value)) |
| 31 | 31 | foreach ($value as $key2 => $value2) |
| 32 | - $curr_length += strlen ($value2); |
|
| 32 | + $curr_length += strlen($value2); |
|
| 33 | 33 | else |
| 34 | - $curr_length += strlen ($value); |
|
| 34 | + $curr_length += strlen($value); |
|
| 35 | 35 | if ($curr_length <= $max_length) |
| 36 | 36 | return $arr; |
| 37 | 37 | else |
| 38 | 38 | { |
| 39 | 39 | // Truncate each element's value to a reasonable length |
| 40 | - $param_max = floor($max_length/count($arr)); |
|
| 40 | + $param_max = floor($max_length / count($arr)); |
|
| 41 | 41 | foreach ($arr as $key => &$value) |
| 42 | 42 | if (is_array($value)) |
| 43 | 43 | foreach ($value as $key2 => &$value2) |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | if (filemtime($cachedir . '/db_last_error.php') === $last_db_error_change) |
| 208 | 208 | { |
| 209 | 209 | // Write the change |
| 210 | - $write_db_change = '<' . '?' . "php\n" . '$db_last_error = ' . time() . ';' . "\n" . '?' . '>'; |
|
| 210 | + $write_db_change = '<' . '?' . "php\n" . '$db_last_error = ' . time() . ';' . "\n" . '?' . '>'; |
|
| 211 | 211 | $written_bytes = file_put_contents($cachedir . '/db_last_error.php', $write_db_change, LOCK_EX); |
| 212 | 212 | |
| 213 | 213 | // survey says ... |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | ', $txt['debug_language_files'], count($context['debug']['language_files']), ': <em>', implode('</em>, <em>', $context['debug']['language_files']), '</em>.<br> |
| 281 | 281 | ', $txt['debug_stylesheets'], count($context['debug']['sheets']), ': <em>', implode('</em>, <em>', $context['debug']['sheets']), '</em>.<br> |
| 282 | 282 | ', $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> |
| 283 | - ',(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>') : ''),' |
|
| 283 | + ',(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>') : ''), ' |
|
| 284 | 284 | ', $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>'; |
| 285 | 285 | |
| 286 | 286 | 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,24 +27,28 @@ discard block |
||
| 26 | 27 | function truncateArray($arr, $max_length=1900) |
| 27 | 28 | { |
| 28 | 29 | $curr_length = 0; |
| 29 | - foreach ($arr as $key => $value) |
|
| 30 | - if (is_array($value)) |
|
| 30 | + foreach ($arr as $key => $value) { |
|
| 31 | + if (is_array($value)) |
|
| 31 | 32 | foreach ($value as $key2 => $value2) |
| 32 | 33 | $curr_length += strlen ($value2); |
| 33 | - else |
|
| 34 | - $curr_length += strlen ($value); |
|
| 35 | - if ($curr_length <= $max_length) |
|
| 36 | - return $arr; |
|
| 37 | - else |
|
| 34 | + } |
|
| 35 | + else { |
|
| 36 | + $curr_length += strlen ($value); |
|
| 37 | + } |
|
| 38 | + if ($curr_length <= $max_length) { |
|
| 39 | + return $arr; |
|
| 40 | + } else |
|
| 38 | 41 | { |
| 39 | 42 | // Truncate each element's value to a reasonable length |
| 40 | 43 | $param_max = floor($max_length/count($arr)); |
| 41 | - foreach ($arr as $key => &$value) |
|
| 42 | - if (is_array($value)) |
|
| 44 | + foreach ($arr as $key => &$value) { |
|
| 45 | + if (is_array($value)) |
|
| 43 | 46 | foreach ($value as $key2 => &$value2) |
| 44 | 47 | $value2 = substr($value2, 0, $param_max - strlen($key) - 5); |
| 45 | - else |
|
| 46 | - $value = substr($value, 0, $param_max - strlen($key) - 5); |
|
| 48 | + } |
|
| 49 | + else { |
|
| 50 | + $value = substr($value, 0, $param_max - strlen($key) - 5); |
|
| 51 | + } |
|
| 47 | 52 | return $arr; |
| 48 | 53 | } |
| 49 | 54 | } |
@@ -65,8 +70,9 @@ discard block |
||
| 65 | 70 | // Don't update for every page - this isn't wholly accurate but who cares. |
| 66 | 71 | if ($topic) |
| 67 | 72 | { |
| 68 | - if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic) |
|
| 69 | - $force = false; |
|
| 73 | + if (isset($_SESSION['last_topic_id']) && $_SESSION['last_topic_id'] == $topic) { |
|
| 74 | + $force = false; |
|
| 75 | + } |
|
| 70 | 76 | $_SESSION['last_topic_id'] = $topic; |
| 71 | 77 | } |
| 72 | 78 | } |
@@ -79,22 +85,24 @@ discard block |
||
| 79 | 85 | } |
| 80 | 86 | |
| 81 | 87 | // Don't mark them as online more than every so often. |
| 82 | - if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force) |
|
| 83 | - return; |
|
| 88 | + if (!empty($_SESSION['log_time']) && $_SESSION['log_time'] >= (time() - 8) && !$force) { |
|
| 89 | + return; |
|
| 90 | + } |
|
| 84 | 91 | |
| 85 | 92 | if (!empty($modSettings['who_enabled'])) |
| 86 | 93 | { |
| 87 | 94 | $encoded_get = truncateArray($_GET) + array('USER_AGENT' => $_SERVER['HTTP_USER_AGENT']); |
| 88 | 95 | |
| 89 | 96 | // In the case of a dlattach action, session_var may not be set. |
| 90 | - if (!isset($context['session_var'])) |
|
| 91 | - $context['session_var'] = $_SESSION['session_var']; |
|
| 97 | + if (!isset($context['session_var'])) { |
|
| 98 | + $context['session_var'] = $_SESSION['session_var']; |
|
| 99 | + } |
|
| 92 | 100 | |
| 93 | 101 | unset($encoded_get['sesc'], $encoded_get[$context['session_var']]); |
| 94 | 102 | $encoded_get = $smcFunc['json_encode']($encoded_get); |
| 103 | + } else { |
|
| 104 | + $encoded_get = ''; |
|
| 95 | 105 | } |
| 96 | - else |
|
| 97 | - $encoded_get = ''; |
|
| 98 | 106 | |
| 99 | 107 | // Guests use 0, members use their session ID. |
| 100 | 108 | $session_id = $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id(); |
@@ -134,17 +142,18 @@ discard block |
||
| 134 | 142 | ); |
| 135 | 143 | |
| 136 | 144 | // Guess it got deleted. |
| 137 | - if ($smcFunc['db_affected_rows']() == 0) |
|
| 145 | + if ($smcFunc['db_affected_rows']() == 0) { |
|
| 146 | + $_SESSION['log_time'] = 0; |
|
| 147 | + } |
|
| 148 | + } else { |
|
| 138 | 149 | $_SESSION['log_time'] = 0; |
| 139 | 150 | } |
| 140 | - else |
|
| 141 | - $_SESSION['log_time'] = 0; |
|
| 142 | 151 | |
| 143 | 152 | // Otherwise, we have to delete and insert. |
| 144 | 153 | if (empty($_SESSION['log_time'])) |
| 145 | 154 | { |
| 146 | - if ($do_delete || !empty($user_info['id'])) |
|
| 147 | - $smcFunc['db_query']('', ' |
|
| 155 | + if ($do_delete || !empty($user_info['id'])) { |
|
| 156 | + $smcFunc['db_query']('', ' |
|
| 148 | 157 | DELETE FROM {db_prefix}log_online |
| 149 | 158 | WHERE ' . ($do_delete ? 'log_time < {int:log_time}' : '') . ($do_delete && !empty($user_info['id']) ? ' OR ' : '') . (empty($user_info['id']) ? '' : 'id_member = {int:current_member}'), |
| 150 | 159 | array( |
@@ -152,6 +161,7 @@ discard block |
||
| 152 | 161 | 'log_time' => time() - $modSettings['lastActive'] * 60, |
| 153 | 162 | ) |
| 154 | 163 | ); |
| 164 | + } |
|
| 155 | 165 | |
| 156 | 166 | $smcFunc['db_insert']($do_delete ? 'ignore' : 'replace', |
| 157 | 167 | '{db_prefix}log_online', |
@@ -165,21 +175,24 @@ discard block |
||
| 165 | 175 | $_SESSION['log_time'] = time(); |
| 166 | 176 | |
| 167 | 177 | // Well, they are online now. |
| 168 | - if (empty($_SESSION['timeOnlineUpdated'])) |
|
| 169 | - $_SESSION['timeOnlineUpdated'] = time(); |
|
| 178 | + if (empty($_SESSION['timeOnlineUpdated'])) { |
|
| 179 | + $_SESSION['timeOnlineUpdated'] = time(); |
|
| 180 | + } |
|
| 170 | 181 | |
| 171 | 182 | // Set their login time, if not already done within the last minute. |
| 172 | 183 | 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')))) |
| 173 | 184 | { |
| 174 | 185 | // Don't count longer than 15 minutes. |
| 175 | - if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15) |
|
| 176 | - $_SESSION['timeOnlineUpdated'] = time(); |
|
| 186 | + if (time() - $_SESSION['timeOnlineUpdated'] > 60 * 15) { |
|
| 187 | + $_SESSION['timeOnlineUpdated'] = time(); |
|
| 188 | + } |
|
| 177 | 189 | |
| 178 | 190 | $user_settings['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated']; |
| 179 | 191 | 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'])); |
| 180 | 192 | |
| 181 | - if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) |
|
| 182 | - cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60); |
|
| 193 | + if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) { |
|
| 194 | + cache_put_data('user_settings-' . $user_info['id'], $user_settings, 60); |
|
| 195 | + } |
|
| 183 | 196 | |
| 184 | 197 | $user_info['total_time_logged_in'] += time() - $_SESSION['timeOnlineUpdated']; |
| 185 | 198 | $_SESSION['timeOnlineUpdated'] = time(); |
@@ -216,8 +229,7 @@ discard block |
||
| 216 | 229 | // Oops. maybe we have no more disk space left, or some other troubles, troubles... |
| 217 | 230 | // Copy the file back and run for your life! |
| 218 | 231 | @copy($cachedir . '/db_last_error_bak.php', $cachedir . '/db_last_error.php'); |
| 219 | - } |
|
| 220 | - else |
|
| 232 | + } else |
|
| 221 | 233 | { |
| 222 | 234 | @touch($boarddir . '/' . 'Settings.php'); |
| 223 | 235 | return true; |
@@ -237,22 +249,27 @@ discard block |
||
| 237 | 249 | global $db_cache, $db_count, $cache_misses, $cache_count_misses, $db_show_debug, $cache_count, $cache_hits, $smcFunc, $txt; |
| 238 | 250 | |
| 239 | 251 | // Add to Settings.php if you want to show the debugging information. |
| 240 | - if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery')) |
|
| 241 | - return; |
|
| 252 | + if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery')) { |
|
| 253 | + return; |
|
| 254 | + } |
|
| 242 | 255 | |
| 243 | - if (empty($_SESSION['view_queries'])) |
|
| 244 | - $_SESSION['view_queries'] = 0; |
|
| 245 | - if (empty($context['debug']['language_files'])) |
|
| 246 | - $context['debug']['language_files'] = array(); |
|
| 247 | - if (empty($context['debug']['sheets'])) |
|
| 248 | - $context['debug']['sheets'] = array(); |
|
| 256 | + if (empty($_SESSION['view_queries'])) { |
|
| 257 | + $_SESSION['view_queries'] = 0; |
|
| 258 | + } |
|
| 259 | + if (empty($context['debug']['language_files'])) { |
|
| 260 | + $context['debug']['language_files'] = array(); |
|
| 261 | + } |
|
| 262 | + if (empty($context['debug']['sheets'])) { |
|
| 263 | + $context['debug']['sheets'] = array(); |
|
| 264 | + } |
|
| 249 | 265 | |
| 250 | 266 | $files = get_included_files(); |
| 251 | 267 | $total_size = 0; |
| 252 | 268 | for ($i = 0, $n = count($files); $i < $n; $i++) |
| 253 | 269 | { |
| 254 | - if (file_exists($files[$i])) |
|
| 255 | - $total_size += filesize($files[$i]); |
|
| 270 | + if (file_exists($files[$i])) { |
|
| 271 | + $total_size += filesize($files[$i]); |
|
| 272 | + } |
|
| 256 | 273 | $files[$i] = strtr($files[$i], array($boarddir => '.', $sourcedir => '(Sources)', $cachedir => '(Cache)', $settings['actual_theme_dir'] => '(Current Theme)')); |
| 257 | 274 | } |
| 258 | 275 | |
@@ -261,8 +278,9 @@ discard block |
||
| 261 | 278 | { |
| 262 | 279 | foreach ($db_cache as $q => $query_data) |
| 263 | 280 | { |
| 264 | - if (!empty($query_data['w'])) |
|
| 265 | - $warnings += count($query_data['w']); |
|
| 281 | + if (!empty($query_data['w'])) { |
|
| 282 | + $warnings += count($query_data['w']); |
|
| 283 | + } |
|
| 266 | 284 | } |
| 267 | 285 | |
| 268 | 286 | $_SESSION['debug'] = &$db_cache; |
@@ -283,12 +301,14 @@ discard block |
||
| 283 | 301 | ',(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>') : ''),' |
| 284 | 302 | ', $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>'; |
| 285 | 303 | |
| 286 | - if (function_exists('memory_get_peak_usage')) |
|
| 287 | - echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>'; |
|
| 304 | + if (function_exists('memory_get_peak_usage')) { |
|
| 305 | + echo $txt['debug_memory_use'], ceil(memory_get_peak_usage() / 1024), $txt['debug_kb'], '<br>'; |
|
| 306 | + } |
|
| 288 | 307 | |
| 289 | 308 | // What tokens are active? |
| 290 | - if (isset($_SESSION['token'])) |
|
| 291 | - echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>'; |
|
| 309 | + if (isset($_SESSION['token'])) { |
|
| 310 | + echo $txt['debug_tokens'] . '<em>' . implode(',</em> <em>', array_keys($_SESSION['token'])), '</em>.<br>'; |
|
| 311 | + } |
|
| 292 | 312 | |
| 293 | 313 | if (!empty($modSettings['cache_enable']) && !empty($cache_hits)) |
| 294 | 314 | { |
@@ -302,10 +322,12 @@ discard block |
||
| 302 | 322 | $total_t += $cache_hit['t']; |
| 303 | 323 | $total_s += $cache_hit['s']; |
| 304 | 324 | } |
| 305 | - if (!isset($cache_misses)) |
|
| 306 | - $cache_misses = array(); |
|
| 307 | - foreach ($cache_misses as $missed) |
|
| 308 | - $missed_entries[] = $missed['d'] . ' ' . $missed['k']; |
|
| 325 | + if (!isset($cache_misses)) { |
|
| 326 | + $cache_misses = array(); |
|
| 327 | + } |
|
| 328 | + foreach ($cache_misses as $missed) { |
|
| 329 | + $missed_entries[] = $missed['d'] . ' ' . $missed['k']; |
|
| 330 | + } |
|
| 309 | 331 | |
| 310 | 332 | echo ' |
| 311 | 333 | ', $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> |
@@ -316,38 +338,44 @@ discard block |
||
| 316 | 338 | <a href="', $scripturl, '?action=viewquery" target="_blank" rel="noopener">', $warnings == 0 ? sprintf($txt['debug_queries_used'], (int) $db_count) : sprintf($txt['debug_queries_used_and_warnings'], (int) $db_count, $warnings), '</a><br> |
| 317 | 339 | <br>'; |
| 318 | 340 | |
| 319 | - if ($_SESSION['view_queries'] == 1 && !empty($db_cache)) |
|
| 320 | - foreach ($db_cache as $q => $query_data) |
|
| 341 | + if ($_SESSION['view_queries'] == 1 && !empty($db_cache)) { |
|
| 342 | + foreach ($db_cache as $q => $query_data) |
|
| 321 | 343 | { |
| 322 | 344 | $is_select = strpos(trim($query_data['q']), 'SELECT') === 0 || preg_match('~^INSERT(?: IGNORE)? INTO \w+(?:\s+\([^)]+\))?\s+SELECT .+$~s', trim($query_data['q'])) != 0; |
| 345 | + } |
|
| 323 | 346 | // Temporary tables created in earlier queries are not explainable. |
| 324 | 347 | if ($is_select) |
| 325 | 348 | { |
| 326 | - foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) |
|
| 327 | - if (strpos(trim($query_data['q']), $tmp) !== false) |
|
| 349 | + foreach (array('log_topics_unread', 'topics_posted_in', 'tmp_log_search_topics', 'tmp_log_search_messages') as $tmp) { |
|
| 350 | + if (strpos(trim($query_data['q']), $tmp) !== false) |
|
| 328 | 351 | { |
| 329 | 352 | $is_select = false; |
| 353 | + } |
|
| 330 | 354 | break; |
| 331 | 355 | } |
| 332 | 356 | } |
| 333 | 357 | // But actual creation of the temporary tables are. |
| 334 | - elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($query_data['q'])) != 0) |
|
| 335 | - $is_select = true; |
|
| 358 | + elseif (preg_match('~^CREATE TEMPORARY TABLE .+?SELECT .+$~s', trim($query_data['q'])) != 0) { |
|
| 359 | + $is_select = true; |
|
| 360 | + } |
|
| 336 | 361 | |
| 337 | 362 | // Make the filenames look a bit better. |
| 338 | - if (isset($query_data['f'])) |
|
| 339 | - $query_data['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $query_data['f']); |
|
| 363 | + if (isset($query_data['f'])) { |
|
| 364 | + $query_data['f'] = preg_replace('~^' . preg_quote($boarddir, '~') . '~', '...', $query_data['f']); |
|
| 365 | + } |
|
| 340 | 366 | |
| 341 | 367 | echo ' |
| 342 | 368 | <strong>', $is_select ? '<a href="' . $scripturl . '?action=viewquery;qq=' . ($q + 1) . '#qq' . $q . '" target="_blank" rel="noopener" style="text-decoration: none;">' : '', nl2br(str_replace("\t", ' ', $smcFunc['htmlspecialchars'](ltrim($query_data['q'], "\n\r")))) . ($is_select ? '</a></strong>' : '</strong>') . '<br> |
| 343 | 369 | '; |
| 344 | - if (!empty($query_data['f']) && !empty($query_data['l'])) |
|
| 345 | - echo sprintf($txt['debug_query_in_line'], $query_data['f'], $query_data['l']); |
|
| 370 | + if (!empty($query_data['f']) && !empty($query_data['l'])) { |
|
| 371 | + echo sprintf($txt['debug_query_in_line'], $query_data['f'], $query_data['l']); |
|
| 372 | + } |
|
| 346 | 373 | |
| 347 | - if (isset($query_data['s'], $query_data['t']) && isset($txt['debug_query_which_took_at'])) |
|
| 348 | - echo sprintf($txt['debug_query_which_took_at'], round($query_data['t'], 8), round($query_data['s'], 8)) . '<br>'; |
|
| 349 | - elseif (isset($query_data['t'])) |
|
| 350 | - echo sprintf($txt['debug_query_which_took'], round($query_data['t'], 8)) . '<br>'; |
|
| 374 | + if (isset($query_data['s'], $query_data['t']) && isset($txt['debug_query_which_took_at'])) { |
|
| 375 | + echo sprintf($txt['debug_query_which_took_at'], round($query_data['t'], 8), round($query_data['s'], 8)) . '<br>'; |
|
| 376 | + } elseif (isset($query_data['t'])) { |
|
| 377 | + echo sprintf($txt['debug_query_which_took'], round($query_data['t'], 8)) . '<br>'; |
|
| 378 | + } |
|
| 351 | 379 | echo ' |
| 352 | 380 | <br>'; |
| 353 | 381 | } |
@@ -372,12 +400,14 @@ discard block |
||
| 372 | 400 | global $modSettings, $smcFunc; |
| 373 | 401 | static $cache_stats = array(); |
| 374 | 402 | |
| 375 | - if (empty($modSettings['trackStats'])) |
|
| 376 | - return false; |
|
| 377 | - if (!empty($stats)) |
|
| 378 | - return $cache_stats = array_merge($cache_stats, $stats); |
|
| 379 | - elseif (empty($cache_stats)) |
|
| 380 | - return false; |
|
| 403 | + if (empty($modSettings['trackStats'])) { |
|
| 404 | + return false; |
|
| 405 | + } |
|
| 406 | + if (!empty($stats)) { |
|
| 407 | + return $cache_stats = array_merge($cache_stats, $stats); |
|
| 408 | + } elseif (empty($cache_stats)) { |
|
| 409 | + return false; |
|
| 410 | + } |
|
| 381 | 411 | |
| 382 | 412 | $setStringUpdate = ''; |
| 383 | 413 | $insert_keys = array(); |
@@ -390,10 +420,11 @@ discard block |
||
| 390 | 420 | $setStringUpdate .= ' |
| 391 | 421 | ' . $field . ' = ' . ($change === '+' ? $field . ' + 1' : '{int:' . $field . '}') . ','; |
| 392 | 422 | |
| 393 | - if ($change === '+') |
|
| 394 | - $cache_stats[$field] = 1; |
|
| 395 | - else |
|
| 396 | - $update_parameters[$field] = $change; |
|
| 423 | + if ($change === '+') { |
|
| 424 | + $cache_stats[$field] = 1; |
|
| 425 | + } else { |
|
| 426 | + $update_parameters[$field] = $change; |
|
| 427 | + } |
|
| 397 | 428 | $insert_keys[$field] = 'int'; |
| 398 | 429 | } |
| 399 | 430 | |
@@ -457,43 +488,50 @@ discard block |
||
| 457 | 488 | ); |
| 458 | 489 | |
| 459 | 490 | // Make sure this particular log is enabled first... |
| 460 | - if (empty($modSettings['modlog_enabled'])) |
|
| 461 | - unset ($log_types['moderate']); |
|
| 462 | - if (empty($modSettings['userlog_enabled'])) |
|
| 463 | - unset ($log_types['user']); |
|
| 464 | - if (empty($modSettings['adminlog_enabled'])) |
|
| 465 | - unset ($log_types['admin']); |
|
| 491 | + if (empty($modSettings['modlog_enabled'])) { |
|
| 492 | + unset ($log_types['moderate']); |
|
| 493 | + } |
|
| 494 | + if (empty($modSettings['userlog_enabled'])) { |
|
| 495 | + unset ($log_types['user']); |
|
| 496 | + } |
|
| 497 | + if (empty($modSettings['adminlog_enabled'])) { |
|
| 498 | + unset ($log_types['admin']); |
|
| 499 | + } |
|
| 466 | 500 | |
| 467 | 501 | call_integration_hook('integrate_log_types', array(&$log_types)); |
| 468 | 502 | |
| 469 | 503 | foreach ($logs as $log) |
| 470 | 504 | { |
| 471 | - if (!isset($log_types[$log['log_type']])) |
|
| 472 | - return false; |
|
| 505 | + if (!isset($log_types[$log['log_type']])) { |
|
| 506 | + return false; |
|
| 507 | + } |
|
| 473 | 508 | |
| 474 | - if (!is_array($log['extra'])) |
|
| 475 | - trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE); |
|
| 509 | + if (!is_array($log['extra'])) { |
|
| 510 | + trigger_error('logActions(): data is not an array with action \'' . $log['action'] . '\'', E_USER_NOTICE); |
|
| 511 | + } |
|
| 476 | 512 | |
| 477 | 513 | // Pull out the parts we want to store separately, but also make sure that the data is proper |
| 478 | 514 | if (isset($log['extra']['topic'])) |
| 479 | 515 | { |
| 480 | - if (!is_numeric($log['extra']['topic'])) |
|
| 481 | - trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE); |
|
| 516 | + if (!is_numeric($log['extra']['topic'])) { |
|
| 517 | + trigger_error('logActions(): data\'s topic is not a number', E_USER_NOTICE); |
|
| 518 | + } |
|
| 482 | 519 | $topic_id = empty($log['extra']['topic']) ? 0 : (int) $log['extra']['topic']; |
| 483 | 520 | unset($log['extra']['topic']); |
| 521 | + } else { |
|
| 522 | + $topic_id = 0; |
|
| 484 | 523 | } |
| 485 | - else |
|
| 486 | - $topic_id = 0; |
|
| 487 | 524 | |
| 488 | 525 | if (isset($log['extra']['message'])) |
| 489 | 526 | { |
| 490 | - if (!is_numeric($log['extra']['message'])) |
|
| 491 | - trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE); |
|
| 527 | + if (!is_numeric($log['extra']['message'])) { |
|
| 528 | + trigger_error('logActions(): data\'s message is not a number', E_USER_NOTICE); |
|
| 529 | + } |
|
| 492 | 530 | $msg_id = empty($log['extra']['message']) ? 0 : (int) $log['extra']['message']; |
| 493 | 531 | unset($log['extra']['message']); |
| 532 | + } else { |
|
| 533 | + $msg_id = 0; |
|
| 494 | 534 | } |
| 495 | - else |
|
| 496 | - $msg_id = 0; |
|
| 497 | 535 | |
| 498 | 536 | // @todo cache this? |
| 499 | 537 | // Is there an associated report on this? |
@@ -520,23 +558,26 @@ discard block |
||
| 520 | 558 | $smcFunc['db_free_result']($request); |
| 521 | 559 | } |
| 522 | 560 | |
| 523 | - if (isset($log['extra']['member']) && !is_numeric($log['extra']['member'])) |
|
| 524 | - trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE); |
|
| 561 | + if (isset($log['extra']['member']) && !is_numeric($log['extra']['member'])) { |
|
| 562 | + trigger_error('logActions(): data\'s member is not a number', E_USER_NOTICE); |
|
| 563 | + } |
|
| 525 | 564 | |
| 526 | 565 | if (isset($log['extra']['board'])) |
| 527 | 566 | { |
| 528 | - if (!is_numeric($log['extra']['board'])) |
|
| 529 | - trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE); |
|
| 567 | + if (!is_numeric($log['extra']['board'])) { |
|
| 568 | + trigger_error('logActions(): data\'s board is not a number', E_USER_NOTICE); |
|
| 569 | + } |
|
| 530 | 570 | $board_id = empty($log['extra']['board']) ? 0 : (int) $log['extra']['board']; |
| 531 | 571 | unset($log['extra']['board']); |
| 572 | + } else { |
|
| 573 | + $board_id = 0; |
|
| 532 | 574 | } |
| 533 | - else |
|
| 534 | - $board_id = 0; |
|
| 535 | 575 | |
| 536 | 576 | if (isset($log['extra']['board_to'])) |
| 537 | 577 | { |
| 538 | - if (!is_numeric($log['extra']['board_to'])) |
|
| 539 | - trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE); |
|
| 578 | + if (!is_numeric($log['extra']['board_to'])) { |
|
| 579 | + trigger_error('logActions(): data\'s board_to is not a number', E_USER_NOTICE); |
|
| 580 | + } |
|
| 540 | 581 | if (empty($board_id)) |
| 541 | 582 | { |
| 542 | 583 | $board_id = empty($log['extra']['board_to']) ? 0 : (int) $log['extra']['board_to']; |
@@ -544,15 +585,17 @@ discard block |
||
| 544 | 585 | } |
| 545 | 586 | } |
| 546 | 587 | |
| 547 | - if (isset($log['extra']['member_affected'])) |
|
| 548 | - $memID = $log['extra']['member_affected']; |
|
| 549 | - else |
|
| 550 | - $memID = $user_info['id']; |
|
| 588 | + if (isset($log['extra']['member_affected'])) { |
|
| 589 | + $memID = $log['extra']['member_affected']; |
|
| 590 | + } else { |
|
| 591 | + $memID = $user_info['id']; |
|
| 592 | + } |
|
| 551 | 593 | |
| 552 | - if (isset($user_info['ip'])) |
|
| 553 | - $memIP = $user_info['ip']; |
|
| 554 | - else |
|
| 555 | - $memIP = 'null'; |
|
| 594 | + if (isset($user_info['ip'])) { |
|
| 595 | + $memIP = $user_info['ip']; |
|
| 596 | + } else { |
|
| 597 | + $memIP = 'null'; |
|
| 598 | + } |
|
| 556 | 599 | |
| 557 | 600 | $inserts[] = array( |
| 558 | 601 | time(), $log_types[$log['log_type']], $memID, $memIP, $log['action'], |
@@ -12,7 +12,8 @@ |
||
| 12 | 12 | header('location: ' . $boardurl); |
| 13 | 13 | } |
| 14 | 14 | // Can't find it... just forget it. |
| 15 | -else |
|
| 15 | +else { |
|
| 16 | 16 | exit; |
| 17 | +} |
|
| 17 | 18 | |
| 18 | 19 | ?> |
| 19 | 20 | \ No newline at end of file |
@@ -41,37 +41,43 @@ discard block |
||
| 41 | 41 | define('TIME_START', microtime(true)); |
| 42 | 42 | |
| 43 | 43 | // Just being safe... |
| 44 | -foreach (array('db_character_set', 'cachedir') as $variable) |
|
| 44 | +foreach (array('db_character_set', 'cachedir') as $variable) { |
|
| 45 | 45 | if (isset($GLOBALS[$variable])) |
| 46 | 46 | unset($GLOBALS[$variable]); |
| 47 | +} |
|
| 47 | 48 | |
| 48 | 49 | // Get the forum's settings for database and file paths. |
| 49 | 50 | require_once(dirname(__FILE__) . '/Settings.php'); |
| 50 | 51 | |
| 51 | 52 | // Make absolutely sure the cache directory is defined. |
| 52 | -if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) |
|
| 53 | +if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) { |
|
| 53 | 54 | $cachedir = $boarddir . '/cache'; |
| 55 | +} |
|
| 54 | 56 | |
| 55 | 57 | // Don't do john didley if the forum's been shut down competely. |
| 56 | -if ($maintenance == 2) |
|
| 58 | +if ($maintenance == 2) { |
|
| 57 | 59 | die($mmessage); |
| 60 | +} |
|
| 58 | 61 | |
| 59 | 62 | // Fix for using the current directory as a path. |
| 60 | -if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.') |
|
| 63 | +if (substr($sourcedir, 0, 1) == '.' && substr($sourcedir, 1, 1) != '.') { |
|
| 61 | 64 | $sourcedir = dirname(__FILE__) . substr($sourcedir, 1); |
| 65 | +} |
|
| 62 | 66 | |
| 63 | 67 | // Have we already turned this off? If so, exist gracefully. |
| 64 | -if (file_exists($cachedir . '/cron.lock')) |
|
| 68 | +if (file_exists($cachedir . '/cron.lock')) { |
|
| 65 | 69 | obExit_cron(); |
| 70 | +} |
|
| 66 | 71 | |
| 67 | 72 | // Before we go any further, if this is not a CLI request, we need to do some checking. |
| 68 | 73 | if (!FROM_CLI) |
| 69 | 74 | { |
| 70 | 75 | // We will clean up $_GET shortly. But we want to this ASAP. |
| 71 | 76 | $ts = isset($_GET['ts']) ? (int) $_GET['ts'] : 0; |
| 72 | - if ($ts <= 0 || $ts % 15 != 0 || time() - $ts < 0 || time() - $ts > 20) |
|
| 73 | - obExit_cron(); |
|
| 74 | -} |
|
| 77 | + if ($ts <= 0 || $ts % 15 != 0 || time() - $ts < 0 || time() - $ts > 20) { |
|
| 78 | + obExit_cron(); |
|
| 79 | + } |
|
| 80 | + } |
|
| 75 | 81 | |
| 76 | 82 | // Load the most important includes. In general, a background should be loading its own dependencies. |
| 77 | 83 | require_once($sourcedir . '/Errors.php'); |
@@ -123,8 +129,9 @@ discard block |
||
| 123 | 129 | global $smcFunc; |
| 124 | 130 | |
| 125 | 131 | // Check we haven't run over our time limit. |
| 126 | - if (microtime(true) - TIME_START > MAX_CRON_TIME) |
|
| 127 | - return false; |
|
| 132 | + if (microtime(true) - TIME_START > MAX_CRON_TIME) { |
|
| 133 | + return false; |
|
| 134 | + } |
|
| 128 | 135 | |
| 129 | 136 | // Try to find a task. Specifically, try to find one that hasn't been claimed previously, or failing that, |
| 130 | 137 | // a task that was claimed but failed for whatever reason and failed long enough ago. We should not care |
@@ -159,14 +166,12 @@ discard block |
||
| 159 | 166 | // Update the time and go back. |
| 160 | 167 | $row['claimed_time'] = time(); |
| 161 | 168 | return $row; |
| 162 | - } |
|
| 163 | - else |
|
| 169 | + } else |
|
| 164 | 170 | { |
| 165 | 171 | // Uh oh, we just missed it. Try to claim another one, and let it fall through if there aren't any. |
| 166 | 172 | return fetch_task(); |
| 167 | 173 | } |
| 168 | - } |
|
| 169 | - else |
|
| 174 | + } else |
|
| 170 | 175 | { |
| 171 | 176 | // No dice. Clean up and go home. |
| 172 | 177 | $smcFunc['db_free_result']($request); |
@@ -187,8 +192,9 @@ discard block |
||
| 187 | 192 | if (!empty($task_details['task_file'])) |
| 188 | 193 | { |
| 189 | 194 | $include = strtr(trim($task_details['task_file']), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir)); |
| 190 | - if (file_exists($include)) |
|
| 191 | - require_once($include); |
|
| 195 | + if (file_exists($include)) { |
|
| 196 | + require_once($include); |
|
| 197 | + } |
|
| 192 | 198 | } |
| 193 | 199 | |
| 194 | 200 | if (empty($task_details['task_class'])) |
@@ -204,8 +210,7 @@ discard block |
||
| 204 | 210 | $details = empty($task_details['task_data']) ? array() : $smcFunc['json_decode']($task_details['task_data'], true); |
| 205 | 211 | $bgtask = new $task_details['task_class']($details); |
| 206 | 212 | return $bgtask->execute(); |
| 207 | - } |
|
| 208 | - else |
|
| 213 | + } else |
|
| 209 | 214 | { |
| 210 | 215 | log_error('Invalid background task specified: (class: ' . $task_details['task_class'] . ', ' . (empty($task_details['task_file']) ? ' no file' : ' to load ' . $task_details['task_file']) . ')'); |
| 211 | 216 | return true; // So we clear it from the queue. |
@@ -224,8 +229,9 @@ discard block |
||
| 224 | 229 | $scripturl = $boardurl . '/index.php'; |
| 225 | 230 | |
| 226 | 231 | // These keys shouldn't be set...ever. |
| 227 | - if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) |
|
| 228 | - die('Invalid request variable.'); |
|
| 232 | + if (isset($_REQUEST['GLOBALS']) || isset($_COOKIE['GLOBALS'])) { |
|
| 233 | + die('Invalid request variable.'); |
|
| 234 | + } |
|
| 229 | 235 | |
| 230 | 236 | // Save some memory.. (since we don't use these anyway.) |
| 231 | 237 | unset($GLOBALS['HTTP_POST_VARS'], $GLOBALS['HTTP_POST_VARS']); |
@@ -246,26 +252,28 @@ discard block |
||
| 246 | 252 | global $modSettings; |
| 247 | 253 | |
| 248 | 254 | // Ignore errors if we're ignoring them or they are strict notices from PHP 5 |
| 249 | - if (error_reporting() == 0) |
|
| 250 | - return; |
|
| 255 | + if (error_reporting() == 0) { |
|
| 256 | + return; |
|
| 257 | + } |
|
| 251 | 258 | |
| 252 | 259 | $error_type = 'cron'; |
| 253 | 260 | |
| 254 | 261 | log_error($error_level . ': ' . $error_string, $error_type, $file, $line); |
| 255 | 262 | |
| 256 | 263 | // If this is an E_ERROR or E_USER_ERROR.... die. Violently so. |
| 257 | - if ($error_level % 255 == E_ERROR) |
|
| 258 | - die('No direct access...'); |
|
| 259 | -} |
|
| 264 | + if ($error_level % 255 == E_ERROR) { |
|
| 265 | + die('No direct access...'); |
|
| 266 | + } |
|
| 267 | + } |
|
| 260 | 268 | |
| 261 | 269 | /** |
| 262 | 270 | * The exit function |
| 263 | 271 | */ |
| 264 | 272 | function obExit_cron() |
| 265 | 273 | { |
| 266 | - if (FROM_CLI) |
|
| 267 | - die(0); |
|
| 268 | - else |
|
| 274 | + if (FROM_CLI) { |
|
| 275 | + die(0); |
|
| 276 | + } else |
|
| 269 | 277 | { |
| 270 | 278 | header('content-type: image/gif'); |
| 271 | 279 | die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B"); |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | // Just send a generic message. |
| 77 | 77 | else |
| 78 | 78 | $this->setResponse(array( |
| 79 | - 'text' => $this->_sa == 'add' ? 'attach_error_title' : 'attached_file_deleted_error', |
|
| 79 | + 'text' => $this->_sa == 'add' ? 'attach_error_title' : 'attached_file_deleted_error', |
|
| 80 | 80 | 'type' => 'error', |
| 81 | 81 | 'data' => false, |
| 82 | 82 | )); |
@@ -410,7 +410,7 @@ discard block |
||
| 410 | 410 | // Gotta urlencode the filename. |
| 411 | 411 | if ($this->_attachResults) |
| 412 | 412 | foreach ($this->_attachResults as $k => $v) |
| 413 | - $this->_attachResults[$k]['name'] = urlencode($this->_attachResults[$k]['name']); |
|
| 413 | + $this->_attachResults[$k]['name'] = urlencode($this->_attachResults[$k]['name']); |
|
| 414 | 414 | |
| 415 | 415 | $this->_response = array( |
| 416 | 416 | 'files' => $this->_attachResults ? $this->_attachResults : false, |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | ob_start(); |
| 438 | 438 | |
| 439 | 439 | // Set the header. |
| 440 | - header('content-type: application/json; charset='. $context['character_set'] .''); |
|
| 440 | + header('content-type: application/json; charset=' . $context['character_set'] . ''); |
|
| 441 | 441 | |
| 442 | 442 | echo $smcFunc['json_encode']($this->_response ? $this->_response : array()); |
| 443 | 443 | |
@@ -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 | class Attachments |
| 20 | 21 | { |
@@ -70,16 +71,18 @@ discard block |
||
| 70 | 71 | |
| 71 | 72 | $this->_sa = !empty($_REQUEST['sa']) ? $smcFunc['htmlspecialchars']($smcFunc['htmltrim']($_REQUEST['sa'])) : false; |
| 72 | 73 | |
| 73 | - if ($this->_canPostAttachment && $this->_sa && in_array($this->_sa, $this->_subActions)) |
|
| 74 | - $this->{$this->_sa}(); |
|
| 74 | + if ($this->_canPostAttachment && $this->_sa && in_array($this->_sa, $this->_subActions)) { |
|
| 75 | + $this->{$this->_sa}(); |
|
| 76 | + } |
|
| 75 | 77 | |
| 76 | 78 | // Just send a generic message. |
| 77 | - else |
|
| 78 | - $this->setResponse(array( |
|
| 79 | + else { |
|
| 80 | + $this->setResponse(array( |
|
| 79 | 81 | 'text' => $this->_sa == 'add' ? 'attach_error_title' : 'attached_file_deleted_error', |
| 80 | 82 | 'type' => 'error', |
| 81 | 83 | 'data' => false, |
| 82 | 84 | )); |
| 85 | + } |
|
| 83 | 86 | |
| 84 | 87 | // Back to the future, oh, to the browser! |
| 85 | 88 | $this->sendResponse(); |
@@ -95,12 +98,13 @@ discard block |
||
| 95 | 98 | $attachID = !empty($_REQUEST['attach']) && is_numeric($_REQUEST['attach']) ? (int) $_REQUEST['attach'] : 0; |
| 96 | 99 | |
| 97 | 100 | // Need something to work with. |
| 98 | - if (!$attachID || (!empty($_SESSION['already_attached']) && !isset($_SESSION['already_attached'][$attachID]))) |
|
| 99 | - return $this->setResponse(array( |
|
| 101 | + if (!$attachID || (!empty($_SESSION['already_attached']) && !isset($_SESSION['already_attached'][$attachID]))) { |
|
| 102 | + return $this->setResponse(array( |
|
| 100 | 103 | 'text' => 'attached_file_deleted_error', |
| 101 | 104 | 'type' => 'error', |
| 102 | 105 | 'data' => false, |
| 103 | 106 | )); |
| 107 | + } |
|
| 104 | 108 | |
| 105 | 109 | // Lets pass some params and see what happens :P |
| 106 | 110 | $affectedMessage = removeAttachments(array('id_attach' => $attachID), '', true, true); |
@@ -119,19 +123,21 @@ discard block |
||
| 119 | 123 | public function add() |
| 120 | 124 | { |
| 121 | 125 | // You gotta be able to post attachments. |
| 122 | - if (!$this->_canPostAttachment) |
|
| 123 | - return $this->setResponse(array( |
|
| 126 | + if (!$this->_canPostAttachment) { |
|
| 127 | + return $this->setResponse(array( |
|
| 124 | 128 | 'text' => 'attached_file_cannot', |
| 125 | 129 | 'type' => 'error', |
| 126 | 130 | 'data' => false, |
| 127 | 131 | )); |
| 132 | + } |
|
| 128 | 133 | |
| 129 | 134 | // Process them at once! |
| 130 | 135 | $this->processAttachments(); |
| 131 | 136 | |
| 132 | 137 | // The attachments was created and moved the the right folder, time to update the DB. |
| 133 | - if (!empty($_SESSION['temp_attachments'])) |
|
| 134 | - $this->createAtttach(); |
|
| 138 | + if (!empty($_SESSION['temp_attachments'])) { |
|
| 139 | + $this->createAtttach(); |
|
| 140 | + } |
|
| 135 | 141 | |
| 136 | 142 | // Set the response. |
| 137 | 143 | $this->setResponse(); |
@@ -144,8 +150,9 @@ discard block |
||
| 144 | 150 | { |
| 145 | 151 | global $context, $modSettings, $smcFunc, $user_info, $txt; |
| 146 | 152 | |
| 147 | - if (!isset($_FILES['attachment']['name'])) |
|
| 148 | - $_FILES['attachment']['tmp_name'] = array(); |
|
| 153 | + if (!isset($_FILES['attachment']['name'])) { |
|
| 154 | + $_FILES['attachment']['tmp_name'] = array(); |
|
| 155 | + } |
|
| 149 | 156 | |
| 150 | 157 | // If there are attachments, calculate the total size and how many. |
| 151 | 158 | $context['attachments']['total_size'] = 0; |
@@ -155,25 +162,30 @@ discard block |
||
| 155 | 162 | if (isset($_REQUEST['msg'])) |
| 156 | 163 | { |
| 157 | 164 | $context['attachments']['quantity'] = count($context['current_attachments']); |
| 158 | - foreach ($context['current_attachments'] as $attachment) |
|
| 159 | - $context['attachments']['total_size'] += $attachment['size']; |
|
| 165 | + foreach ($context['current_attachments'] as $attachment) { |
|
| 166 | + $context['attachments']['total_size'] += $attachment['size']; |
|
| 167 | + } |
|
| 160 | 168 | } |
| 161 | 169 | |
| 162 | 170 | // A bit of house keeping first. |
| 163 | - if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) |
|
| 164 | - unset($_SESSION['temp_attachments']); |
|
| 171 | + if (!empty($_SESSION['temp_attachments']) && count($_SESSION['temp_attachments']) == 1) { |
|
| 172 | + unset($_SESSION['temp_attachments']); |
|
| 173 | + } |
|
| 165 | 174 | |
| 166 | 175 | // Our infamous SESSION var, we are gonna have soo much fun with it! |
| 167 | - if (!isset($_SESSION['temp_attachments'])) |
|
| 168 | - $_SESSION['temp_attachments'] = array(); |
|
| 176 | + if (!isset($_SESSION['temp_attachments'])) { |
|
| 177 | + $_SESSION['temp_attachments'] = array(); |
|
| 178 | + } |
|
| 169 | 179 | |
| 170 | 180 | // Make sure we're uploading to the right place. |
| 171 | - if (!empty($modSettings['automanage_attachments'])) |
|
| 172 | - automanage_attachments_check_directory(); |
|
| 181 | + if (!empty($modSettings['automanage_attachments'])) { |
|
| 182 | + automanage_attachments_check_directory(); |
|
| 183 | + } |
|
| 173 | 184 | |
| 174 | 185 | // Is the attachments folder actually there? |
| 175 | - if (!empty($context['dir_creation_error'])) |
|
| 176 | - $this->_generalErrors[] = $context['dir_creation_error']; |
|
| 186 | + if (!empty($context['dir_creation_error'])) { |
|
| 187 | + $this->_generalErrors[] = $context['dir_creation_error']; |
|
| 188 | + } |
|
| 177 | 189 | |
| 178 | 190 | // The current attach folder ha some issues... |
| 179 | 191 | elseif (!is_dir($this->_attchDir)) |
@@ -198,13 +210,12 @@ discard block |
||
| 198 | 210 | ); |
| 199 | 211 | list ($context['attachments']['quantity'], $context['attachments']['total_size']) = $smcFunc['db_fetch_row']($request); |
| 200 | 212 | $smcFunc['db_free_result']($request); |
| 201 | - } |
|
| 202 | - |
|
| 203 | - else |
|
| 204 | - $context['attachments'] = array( |
|
| 213 | + } else { |
|
| 214 | + $context['attachments'] = array( |
|
| 205 | 215 | 'quantity' => 0, |
| 206 | 216 | 'total_size' => 0, |
| 207 | 217 | ); |
| 218 | + } |
|
| 208 | 219 | |
| 209 | 220 | // Check for other general errors here. |
| 210 | 221 | |
@@ -212,9 +223,10 @@ discard block |
||
| 212 | 223 | if (!empty($this->_generalErrors)) |
| 213 | 224 | { |
| 214 | 225 | // And delete the files 'cos they ain't going nowhere. |
| 215 | - foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
|
| 216 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 226 | + foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) { |
|
| 227 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 217 | 228 | unlink($_FILES['attachment']['tmp_name'][$n]); |
| 229 | + } |
|
| 218 | 230 | |
| 219 | 231 | $_FILES['attachment']['tmp_name'] = array(); |
| 220 | 232 | |
@@ -225,26 +237,29 @@ discard block |
||
| 225 | 237 | // Loop through $_FILES['attachment'] array and move each file to the current attachments folder. |
| 226 | 238 | foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy) |
| 227 | 239 | { |
| 228 | - if ($_FILES['attachment']['name'][$n] == '') |
|
| 229 | - continue; |
|
| 240 | + if ($_FILES['attachment']['name'][$n] == '') { |
|
| 241 | + continue; |
|
| 242 | + } |
|
| 230 | 243 | |
| 231 | 244 | // First, let's first check for PHP upload errors. |
| 232 | 245 | $errors = array(); |
| 233 | 246 | if (!empty($_FILES['attachment']['error'][$n])) |
| 234 | 247 | { |
| 235 | - if ($_FILES['attachment']['error'][$n] == 2) |
|
| 236 | - $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
| 237 | - |
|
| 238 | - else |
|
| 239 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
| 248 | + if ($_FILES['attachment']['error'][$n] == 2) { |
|
| 249 | + $errors[] = array('file_too_big', array($modSettings['attachmentSizeLimit'])); |
|
| 250 | + } else { |
|
| 251 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_' . $_FILES['attachment']['error'][$n]]); |
|
| 252 | + } |
|
| 240 | 253 | |
| 241 | 254 | // Log this one, because... |
| 242 | - if ($_FILES['attachment']['error'][$n] == 6) |
|
| 243 | - log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
| 255 | + if ($_FILES['attachment']['error'][$n] == 6) { |
|
| 256 | + log_error($_FILES['attachment']['name'][$n] . ': ' . $txt['php_upload_error_6'], 'critical'); |
|
| 257 | + } |
|
| 244 | 258 | |
| 245 | 259 | // Weird, no errors were cached, still fill out a generic one. |
| 246 | - if (empty($errors)) |
|
| 247 | - $errors[] = 'attach_php_error'; |
|
| 260 | + if (empty($errors)) { |
|
| 261 | + $errors[] = 'attach_php_error'; |
|
| 262 | + } |
|
| 248 | 263 | } |
| 249 | 264 | |
| 250 | 265 | // Try to move and rename the file before doing any more checks on it. |
@@ -256,8 +271,9 @@ discard block |
||
| 256 | 271 | { |
| 257 | 272 | // The reported MIME type of the attachment might not be reliable. |
| 258 | 273 | // Fortunately, PHP 5.3+ lets us easily verify the real MIME type. |
| 259 | - if (function_exists('mime_content_type')) |
|
| 260 | - $_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]); |
|
| 274 | + if (function_exists('mime_content_type')) { |
|
| 275 | + $_FILES['attachment']['type'][$n] = mime_content_type($_FILES['attachment']['tmp_name'][$n]); |
|
| 276 | + } |
|
| 261 | 277 | |
| 262 | 278 | $_SESSION['temp_attachments'][$attachID] = array( |
| 263 | 279 | 'name' => $smcFunc['htmlspecialchars'](basename($_FILES['attachment']['name'][$n])), |
@@ -269,16 +285,18 @@ discard block |
||
| 269 | 285 | ); |
| 270 | 286 | |
| 271 | 287 | // Move the file to the attachments folder with a temp name for now. |
| 272 | - if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) |
|
| 273 | - smf_chmod($destName, 0644); |
|
| 288 | + if (@move_uploaded_file($_FILES['attachment']['tmp_name'][$n], $destName)) { |
|
| 289 | + smf_chmod($destName, 0644); |
|
| 290 | + } |
|
| 274 | 291 | |
| 275 | 292 | // This is madness!! |
| 276 | 293 | else |
| 277 | 294 | { |
| 278 | 295 | // File couldn't be moved. |
| 279 | 296 | $_SESSION['temp_attachments'][$attachID]['errors'][] = 'attach_timeout'; |
| 280 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 281 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 297 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
| 298 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 299 | + } |
|
| 282 | 300 | } |
| 283 | 301 | } |
| 284 | 302 | |
@@ -291,13 +309,15 @@ discard block |
||
| 291 | 309 | 'errors' => $errors, |
| 292 | 310 | ); |
| 293 | 311 | |
| 294 | - if (file_exists($_FILES['attachment']['tmp_name'][$n])) |
|
| 295 | - unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 312 | + if (file_exists($_FILES['attachment']['tmp_name'][$n])) { |
|
| 313 | + unlink($_FILES['attachment']['tmp_name'][$n]); |
|
| 314 | + } |
|
| 296 | 315 | } |
| 297 | 316 | |
| 298 | 317 | // If there's no errors to this point. We still do need to apply some additional checks before we are finished. |
| 299 | - if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) |
|
| 300 | - attachmentChecks($attachID); |
|
| 318 | + if (empty($_SESSION['temp_attachments'][$attachID]['errors'])) { |
|
| 319 | + attachmentChecks($attachID); |
|
| 320 | + } |
|
| 301 | 321 | } |
| 302 | 322 | |
| 303 | 323 | // Mod authors, finally a hook to hang an alternate attachment upload system upon |
@@ -344,14 +364,15 @@ discard block |
||
| 344 | 364 | |
| 345 | 365 | $_SESSION['already_attached'][$attachmentOptions['attachID']] = $attachmentOptions['attachID']; |
| 346 | 366 | |
| 347 | - if (!empty($attachmentOptions['thumb'])) |
|
| 348 | - $_SESSION['already_attached'][$attachmentOptions['thumb']] = $attachmentOptions['thumb']; |
|
| 367 | + if (!empty($attachmentOptions['thumb'])) { |
|
| 368 | + $_SESSION['already_attached'][$attachmentOptions['thumb']] = $attachmentOptions['thumb']; |
|
| 369 | + } |
|
| 349 | 370 | |
| 350 | - if ($this->_msg) |
|
| 351 | - assignAttachments($_SESSION['already_attached'], $this->_msg); |
|
| 371 | + if ($this->_msg) { |
|
| 372 | + assignAttachments($_SESSION['already_attached'], $this->_msg); |
|
| 373 | + } |
|
| 352 | 374 | } |
| 353 | - } |
|
| 354 | - else |
|
| 375 | + } else |
|
| 355 | 376 | { |
| 356 | 377 | // Sort out the errors for display and delete any associated files. |
| 357 | 378 | $log_these = array('attachments_no_create', 'attachments_no_write', 'attach_timeout', 'ran_out_of_space', 'cant_access_upload_path', 'attach_0_byte_file'); |
@@ -363,14 +384,16 @@ discard block |
||
| 363 | 384 | if (!is_array($error)) |
| 364 | 385 | { |
| 365 | 386 | $attachmentOptions['errors'][] = $txt[$error]; |
| 366 | - if (in_array($error, $log_these)) |
|
| 367 | - log_error($attachment['name'] . ': ' . $txt[$error], 'critical'); |
|
| 387 | + if (in_array($error, $log_these)) { |
|
| 388 | + log_error($attachment['name'] . ': ' . $txt[$error], 'critical'); |
|
| 389 | + } |
|
| 390 | + } else { |
|
| 391 | + $attachmentOptions['errors'][] = vsprintf($txt[$error[0]], $error[1]); |
|
| 368 | 392 | } |
| 369 | - else |
|
| 370 | - $attachmentOptions['errors'][] = vsprintf($txt[$error[0]], $error[1]); |
|
| 371 | 393 | } |
| 372 | - if (file_exists($attachment['tmp_name'])) |
|
| 373 | - unlink($attachment['tmp_name']); |
|
| 394 | + if (file_exists($attachment['tmp_name'])) { |
|
| 395 | + unlink($attachment['tmp_name']); |
|
| 396 | + } |
|
| 374 | 397 | } |
| 375 | 398 | |
| 376 | 399 | // You don't need to know. |
@@ -382,8 +405,9 @@ discard block |
||
| 382 | 405 | } |
| 383 | 406 | |
| 384 | 407 | // Temp save this on the db. |
| 385 | - if (!empty($_SESSION['already_attached'])) |
|
| 386 | - $this->_attachSuccess = $_SESSION['already_attached']; |
|
| 408 | + if (!empty($_SESSION['already_attached'])) { |
|
| 409 | + $this->_attachSuccess = $_SESSION['already_attached']; |
|
| 410 | + } |
|
| 387 | 411 | |
| 388 | 412 | unset($_SESSION['temp_attachments']); |
| 389 | 413 | } |
@@ -403,14 +427,16 @@ discard block |
||
| 403 | 427 | if ($this->_sa == 'add') |
| 404 | 428 | { |
| 405 | 429 | // Is there any generic errors? made some sense out of them! |
| 406 | - if ($this->_generalErrors) |
|
| 407 | - foreach ($this->_generalErrors as $k => $v) |
|
| 430 | + if ($this->_generalErrors) { |
|
| 431 | + foreach ($this->_generalErrors as $k => $v) |
|
| 408 | 432 | $this->_generalErrors[$k] = (is_array($v) ? vsprintf($txt[$v[0]], $v[1]) : $txt[$v]); |
| 433 | + } |
|
| 409 | 434 | |
| 410 | 435 | // Gotta urlencode the filename. |
| 411 | - if ($this->_attachResults) |
|
| 412 | - foreach ($this->_attachResults as $k => $v) |
|
| 436 | + if ($this->_attachResults) { |
|
| 437 | + foreach ($this->_attachResults as $k => $v) |
|
| 413 | 438 | $this->_attachResults[$k]['name'] = urlencode($this->_attachResults[$k]['name']); |
| 439 | + } |
|
| 414 | 440 | |
| 415 | 441 | $this->_response = array( |
| 416 | 442 | 'files' => $this->_attachResults ? $this->_attachResults : false, |
@@ -419,9 +445,10 @@ discard block |
||
| 419 | 445 | } |
| 420 | 446 | |
| 421 | 447 | // Rest of us mere mortals gets no special treatment... |
| 422 | - elseif (!empty($data)) |
|
| 423 | - if (!empty($data['text']) && !empty($txt[$data['text']])) |
|
| 448 | + elseif (!empty($data)) { |
|
| 449 | + if (!empty($data['text']) && !empty($txt[$data['text']])) |
|
| 424 | 450 | $this->_response['text'] = $txt[$data['text']]; |
| 451 | + } |
|
| 425 | 452 | } |
| 426 | 453 | |
| 427 | 454 | protected function sendResponse() |
@@ -430,11 +457,11 @@ discard block |
||
| 430 | 457 | |
| 431 | 458 | ob_end_clean(); |
| 432 | 459 | |
| 433 | - if (!empty($modSettings['CompressedOutput'])) |
|
| 434 | - @ob_start('ob_gzhandler'); |
|
| 435 | - |
|
| 436 | - else |
|
| 437 | - ob_start(); |
|
| 460 | + if (!empty($modSettings['CompressedOutput'])) { |
|
| 461 | + @ob_start('ob_gzhandler'); |
|
| 462 | + } else { |
|
| 463 | + ob_start(); |
|
| 464 | + } |
|
| 438 | 465 | |
| 439 | 466 | // Set the header. |
| 440 | 467 | header('content-type: application/json; charset='. $context['character_set'] .''); |
@@ -185,17 +185,21 @@ discard block |
||
| 185 | 185 | $tasksdir = $sourcedir . '/tasks'; |
| 186 | 186 | |
| 187 | 187 | # Make sure the paths are correct... at least try to fix them. |
| 188 | -if (!file_exists($boarddir) && file_exists(dirname(__FILE__) . '/agreement.txt')) |
|
| 188 | +if (!file_exists($boarddir) && file_exists(dirname(__FILE__) . '/agreement.txt')) { |
|
| 189 | 189 | $boarddir = dirname(__FILE__); |
| 190 | -if (!file_exists($sourcedir) && file_exists($boarddir . '/Sources')) |
|
| 190 | +} |
|
| 191 | +if (!file_exists($sourcedir) && file_exists($boarddir . '/Sources')) { |
|
| 191 | 192 | $sourcedir = $boarddir . '/Sources'; |
| 192 | -if (!file_exists($cachedir) && file_exists($boarddir . '/cache')) |
|
| 193 | +} |
|
| 194 | +if (!file_exists($cachedir) && file_exists($boarddir . '/cache')) { |
|
| 193 | 195 | $cachedir = $boarddir . '/cache'; |
| 196 | +} |
|
| 194 | 197 | |
| 195 | 198 | ########## Error-Catching ########## |
| 196 | 199 | # Note: You shouldn't touch these settings. |
| 197 | -if (file_exists((isset($cachedir) ? $cachedir : dirname(__FILE__)) . '/db_last_error.php')) |
|
| 200 | +if (file_exists((isset($cachedir) ? $cachedir : dirname(__FILE__)) . '/db_last_error.php')) { |
|
| 198 | 201 | include((isset($cachedir) ? $cachedir : dirname(__FILE__)) . '/db_last_error.php'); |
| 202 | +} |
|
| 199 | 203 | |
| 200 | 204 | if (!isset($db_last_error)) |
| 201 | 205 | { |
@@ -207,10 +211,11 @@ discard block |
||
| 207 | 211 | if (file_exists(dirname(__FILE__) . '/install.php')) |
| 208 | 212 | { |
| 209 | 213 | $secure = false; |
| 210 | - if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') |
|
| 211 | - $secure = true; |
|
| 212 | - elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') |
|
| 213 | - $secure = true; |
|
| 214 | + if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { |
|
| 215 | + $secure = true; |
|
| 216 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') { |
|
| 217 | + $secure = true; |
|
| 218 | + } |
|
| 214 | 219 | |
| 215 | 220 | header('location: http' . ($secure ? 's' : '') . '://' . (empty($_SERVER['HTTP_HOST']) ? $_SERVER['SERVER_NAME'] . (empty($_SERVER['SERVER_PORT']) || $_SERVER['SERVER_PORT'] == '80' ? '' : ':' . $_SERVER['SERVER_PORT']) : $_SERVER['HTTP_HOST']) . (strtr(dirname($_SERVER['PHP_SELF']), '\\', '/') == '/' ? '' : strtr(dirname($_SERVER['PHP_SELF']), '\\', '/')) . '/install.php'); exit; |
| 216 | 221 | } |
@@ -12,7 +12,8 @@ |
||
| 12 | 12 | header('location: ' . $boardurl); |
| 13 | 13 | } |
| 14 | 14 | // Can't find it... just forget it. |
| 15 | -else |
|
| 15 | +else { |
|
| 16 | 16 | exit; |
| 17 | +} |
|
| 17 | 18 | |
| 18 | 19 | ?> |
| 19 | 20 | \ No newline at end of file |
@@ -12,7 +12,8 @@ |
||
| 12 | 12 | header('location: ' . $boardurl); |
| 13 | 13 | } |
| 14 | 14 | // Can't find it... just forget it. |
| 15 | -else |
|
| 15 | +else { |
|
| 16 | 16 | exit; |
| 17 | +} |
|
| 17 | 18 | |
| 18 | 19 | ?> |
| 19 | 20 | \ No newline at end of file |
@@ -12,7 +12,8 @@ |
||
| 12 | 12 | header('location: ' . $boardurl); |
| 13 | 13 | } |
| 14 | 14 | // Can't find it... just forget it. |
| 15 | -else |
|
| 15 | +else { |
|
| 16 | 16 | exit; |
| 17 | +} |
|
| 17 | 18 | |
| 18 | 19 | ?> |
| 19 | 20 | \ No newline at end of file |
@@ -12,7 +12,8 @@ |
||
| 12 | 12 | header('location: ' . $boardurl); |
| 13 | 13 | } |
| 14 | 14 | // Can't find it... just forget it. |
| 15 | -else |
|
| 15 | +else { |
|
| 16 | 16 | exit; |
| 17 | +} |
|
| 17 | 18 | |
| 18 | 19 | ?> |
| 19 | 20 | \ No newline at end of file |