'<', '>' => '>', '"' => '"'));
$error_message = strtr($error_message, array('<br />' => '
', '<b>' => '', '</b>' => '', "\n" => '
'));
// Add a file and line to the error message?
// Don't use the actual txt entries for file and line but instead use %1$s for file and %2$s for line
if ($file == null)
$file = '';
else
// Window style slashes don't play well, lets convert them to the unix style.
$file = str_replace('\\', '/', $file);
if ($line == null)
$line = 0;
else
$line = (int) $line;
// Just in case there's no id_member or IP set yet.
if (empty($user_info['id']))
$user_info['id'] = 0;
if (empty($user_info['ip']))
$user_info['ip'] = '';
// Find the best query string we can...
$query_string = empty($_SERVER['QUERY_STRING']) ? (empty($_SERVER['REQUEST_URL']) ? '' : str_replace($scripturl, '', $_SERVER['REQUEST_URL'])) : $_SERVER['QUERY_STRING'];
// Don't log the session hash in the url twice, it's a waste.
$query_string = htmlspecialchars((SMF == 'SSI' ? '' : '?') . preg_replace(array('~;sesc=[^&;]+~', '~' . session_name() . '=' . session_id() . '[&;]~'), array(';sesc', ''), $query_string));
// Just so we know what board error messages are from.
if (isset($_POST['board']) && !isset($_GET['board']))
$query_string .= ($query_string == '' ? 'board=' : ';board=') . $_POST['board'];
// What types of categories do we have?
$known_error_types = array(
'general',
'critical',
'database',
'undefined_vars',
'user',
'template',
'debug',
);
// Make sure the category that was specified is a valid one
$error_type = in_array($error_type, $known_error_types) && $error_type !== true ? $error_type : 'general';
// Don't log the same error countless times, as we can get in a cycle of depression...
$error_info = array($user_info['id'], time(), $user_info['ip'], $query_string, $error_message, (string) $sc, $error_type, $file, $line);
if (empty($last_error) || $last_error != $error_info)
{
// Insert the error into the database.
$smcFunc['db_insert']('',
'{db_prefix}log_errors',
array('id_member' => 'int', 'log_time' => 'int', 'ip' => 'string-16', 'url' => 'string-65534', 'message' => 'string-65534', 'session' => 'string', 'error_type' => 'string', 'file' => 'string-255', 'line' => 'int'),
$error_info,
array('id_error')
);
$last_error = $error_info;
}
// Return the message to make things simpler.
return $error_message;
}
/**
* This function logs an action in the respective log. (database log)
* @example logAction('remove', array('starter' => $id_member_started));
*
* @param string $action
* @param array $extra = array()
* @param string $log_type, options 'moderate', 'admin', ...etc.
*/
function logAction($action, $extra = array(), $log_type = 'moderate')
{
global $modSettings, $user_info, $smcFunc, $sourcedir;
$log_types = array(
'moderate' => 1,
'user' => 2,
'admin' => 3,
);
if (!is_array($extra))
trigger_error('logAction(): data is not an array with action \'' . $action . '\'', E_USER_NOTICE);
// Pull out the parts we want to store separately, but also make sure that the data is proper
if (isset($extra['topic']))
{
if (!is_numeric($extra['topic']))
trigger_error('logAction(): data\'s topic is not a number', E_USER_NOTICE);
$topic_id = empty($extra['topic']) ? '0' : (int)$extra['topic'];
unset($extra['topic']);
}
else
$topic_id = '0';
if (isset($extra['message']))
{
if (!is_numeric($extra['message']))
trigger_error('logAction(): data\'s message is not a number', E_USER_NOTICE);
$msg_id = empty($extra['message']) ? '0' : (int)$extra['message'];
unset($extra['message']);
}
else
$msg_id = '0';
// Is there an associated report on this?
if (in_array($action, array('move', 'remove', 'split', 'merge')))
{
$request = $smcFunc['db_query']('', '
SELECT id_report
FROM {db_prefix}log_reported
WHERE {raw:column_name} = {int:reported}
LIMIT 1',
array(
'column_name' => !empty($msg_id) ? 'id_msg' : 'id_topic',
'reported' => !empty($msg_id) ? $msg_id : $topic_id,
));
// Alright, if we get any result back, update open reports.
if ($smcFunc['db_num_rows']($request) > 0)
{
require_once($sourcedir . '/ModerationCenter.php');
updateSettings(array('last_mod_report_action' => time()));
recountOpenReports();
}
$smcFunc['db_free_result']($request);
}
// No point in doing anything else, if the log isn't even enabled.
if (empty($modSettings['modlog_enabled']) || !isset($log_types[$log_type]))
return false;
if (isset($extra['member']) && !is_numeric($extra['member']))
trigger_error('logAction(): data\'s member is not a number', E_USER_NOTICE);
if (isset($extra['board']))
{
if (!is_numeric($extra['board']))
trigger_error('logAction(): data\'s board is not a number', E_USER_NOTICE);
$board_id = empty($extra['board']) ? '0' : (int)$extra['board'];
unset($extra['board']);
}
else
$board_id = '0';
if (isset($extra['board_to']))
{
if (!is_numeric($extra['board_to']))
trigger_error('logAction(): data\'s board_to is not a number', E_USER_NOTICE);
if (empty($board_id))
{
$board_id = empty($extra['board_to']) ? '0' : (int)$extra['board_to'];
unset($extra['board_to']);
}
}
$smcFunc['db_insert']('',
'{db_prefix}log_actions',
array(
'log_time' => 'int', 'id_log' => 'int', 'id_member' => 'int', 'ip' => 'string-16', 'action' => 'string',
'id_board' => 'int', 'id_topic' => 'int', 'id_msg' => 'int', 'extra' => 'string-65534',
),
array(
time(), $log_types[$log_type], $user_info['id'], $user_info['ip'], $action,
$board_id, $topic_id, $msg_id, serialize($extra),
),
array('id_action')
);
return $smcFunc['db_insert_id']('{db_prefix}log_actions', 'id_action');
}
/**
* Debugging.
*/
function db_debug_junk()
{
global $context, $scripturl, $boarddir, $modSettings, $boarddir;
global $db_cache, $db_count, $db_show_debug, $cache_count, $cache_hits, $txt;
// Add to Settings.php if you want to show the debugging information.
if (!isset($db_show_debug) || $db_show_debug !== true || (isset($_GET['action']) && $_GET['action'] == 'viewquery') || WIRELESS)
return;
if (empty($_SESSION['view_queries']))
$_SESSION['view_queries'] = 0;
if (empty($context['debug']['language_files']))
$context['debug']['language_files'] = array();
if (empty($context['debug']['sheets']))
$context['debug']['sheets'] = array();
$files = get_included_files();
$total_size = 0;
for ($i = 0, $n = count($files); $i < $n; $i++)
{
if (file_exists($files[$i]))
$total_size += filesize($files[$i]);
$files[$i] = strtr($files[$i], array($boarddir => '.'));
}
$warnings = 0;
if (!empty($db_cache))
{
foreach ($db_cache as $q => $qq)
{
if (!empty($qq['w']))
$warnings += count($qq['w']);
}
$_SESSION['debug'] = &$db_cache;
}
// Gotta have valid HTML ;).
$temp = ob_get_contents();
if (function_exists('ob_clean'))
ob_clean();
else
{
ob_end_clean();
ob_start('ob_sessrewrite');
}
echo preg_replace('~