@@ -19,7 +19,7 @@ |
||
| 19 | 19 | /** |
| 20 | 20 | * Truncate the GET array to a specified length |
| 21 | 21 | * @param array $arr The array to truncate |
| 22 | - * @param max_length $max_length The upperbound on the length |
|
| 22 | + * @param integer $max_length The upperbound on the length |
|
| 23 | 23 | * |
| 24 | 24 | * @return array The truncated array |
| 25 | 25 | */ |
@@ -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 3 |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -if (!defined('SMF')) |
|
| 16 | +if (!defined('SMF')) { |
|
| 17 | 17 | die('No direct access...'); |
| 18 | +} |
|
| 18 | 19 | |
| 19 | 20 | /** |
| 20 | 21 | * 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 | $serialized = 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($serialized['sesc'], $serialized[$context['session_var']]); |
| 84 | 89 | $serialized = json_encode($serialized); |
| 90 | + } else { |
|
| 91 | + $serialized = ''; |
|
| 85 | 92 | } |
| 86 | - else |
|
| 87 | - $serialized = ''; |
|
| 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" class="new_win">', $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" class="new_win" 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'], |