public function add($mode, $user_id, $log_ip, $log_operation, $log_time = false, $additional_data = array())
{
if (!$this->is_enabled($mode)) {
return false;
}
if ($log_time === false) {
$log_time = time();
}
$sql_ary = array('user_id' => $user_id ? (int) $user_id : ANONYMOUS, 'log_ip' => empty($log_ip) ? '' : $log_ip, 'log_time' => $log_time, 'log_operation' => $log_operation);
switch ($mode) {
case 'admin':
$sql_ary += array('log_type' => LOG_ADMIN, 'log_data' => !empty($additional_data) ? serialize($additional_data) : '');
break;
case 'mod':
$forum_id = isset($additional_data['forum_id']) ? (int) $additional_data['forum_id'] : 0;
unset($additional_data['forum_id']);
$topic_id = isset($additional_data['topic_id']) ? (int) $additional_data['topic_id'] : 0;
unset($additional_data['topic_id']);
$sql_ary += array('log_type' => LOG_MOD, 'forum_id' => $forum_id, 'topic_id' => $topic_id, 'log_data' => !empty($additional_data) ? serialize($additional_data) : '');
break;
case 'user':
$reportee_id = (int) $additional_data['reportee_id'];
unset($additional_data['reportee_id']);
$sql_ary += array('log_type' => LOG_USERS, 'reportee_id' => $reportee_id, 'log_data' => !empty($additional_data) ? serialize($additional_data) : '');
break;
case 'critical':
$sql_ary += array('log_type' => LOG_CRITICAL, 'log_data' => !empty($additional_data) ? serialize($additional_data) : '');
break;
}
/**
* Allows to modify log data before we add it to the database
*
* NOTE: if sql_ary does not contain a log_type value, the entry will
* not be stored in the database. So ensure to set it, if needed.
*
* @event core.add_log
* @var string mode Mode of the entry we log
* @var int user_id ID of the user who triggered the log
* @var string log_ip IP of the user who triggered the log
* @var string log_operation Language key of the log operation
* @var int log_time Timestamp, when the log was added
* @var array additional_data Array with additional log data
* @var array sql_ary Array with log data we insert into the
* database. If sql_ary[log_type] is not set,
* we won't add the entry to the database.
* @since 3.1.0-a1
*/
$vars = array('mode', 'user_id', 'log_ip', 'log_operation', 'log_time', 'additional_data', 'sql_ary');
extract($this->dispatcher->trigger_event('core.add_log', compact($vars)));
// We didn't find a log_type, so we don't save it in the database.
if (!isset($sql_ary['log_type'])) {
return false;
}
$this->db->sql_query('INSERT INTO ' . $this->log_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary));
return $this->db->sql_nextid();
}