public function get_logs($mode, $count_logs = true, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $log_time = 0, $sort_by = 'l.log_time DESC', $keywords = '')
{
$this->entry_count = 0;
$this->last_page_offset = $offset;
$topic_id_list = $reportee_id_list = array();
$profile_url = $this->get_is_admin() && $this->phpbb_admin_path ? append_sid("{$this->phpbb_admin_path}index.{$this->php_ext}", 'i=users&mode=overview') : append_sid("{$this->phpbb_root_path}memberlist.{$this->php_ext}", 'mode=viewprofile');
switch ($mode) {
case 'admin':
$log_type = LOG_ADMIN;
$sql_additional = '';
break;
case 'mod':
$log_type = LOG_MOD;
$sql_additional = '';
if ($topic_id) {
$sql_additional = 'AND l.topic_id = ' . (int) $topic_id;
} else {
if (is_array($forum_id)) {
$sql_additional = 'AND ' . $this->db->sql_in_set('l.forum_id', array_map('intval', $forum_id));
} else {
if ($forum_id) {
$sql_additional = 'AND l.forum_id = ' . (int) $forum_id;
}
}
}
break;
case 'user':
$log_type = LOG_USERS;
$sql_additional = 'AND l.reportee_id = ' . (int) $user_id;
break;
case 'users':
$log_type = LOG_USERS;
$sql_additional = '';
break;
case 'critical':
$log_type = LOG_CRITICAL;
$sql_additional = '';
break;
default:
$log_type = false;
$sql_additional = '';
}
/**
* Overwrite log type and limitations before we count and get the logs
*
* NOTE: if log_type is false, no entries will be returned.
*
* @event core.get_logs_modify_type
* @var string mode Mode of the entries we display
* @var bool count_logs Do we count all matching entries?
* @var int limit Limit the number of entries
* @var int offset Offset when fetching the entries
* @var mixed forum_id Limit entries to the forum_id,
* can also be an array of forum_ids
* @var int topic_id Limit entries to the topic_id
* @var int user_id Limit entries to the user_id
* @var int log_time Limit maximum age of log entries
* @var string sort_by SQL order option
* @var string keywords Will only return entries that have the
* keywords in log_operation or log_data
* @var string profile_url URL to the users profile
* @var int log_type Limit logs to a certain type. If log_type
* is false, no entries will be returned.
* @var string sql_additional Additional conditions for the entries,
* e.g.: 'AND l.forum_id = 1'
* @since 3.1.0-a1
*/
$vars = array('mode', 'count_logs', 'limit', 'offset', 'forum_id', 'topic_id', 'user_id', 'log_time', 'sort_by', 'keywords', 'profile_url', 'log_type', 'sql_additional');
extract($this->dispatcher->trigger_event('core.get_logs_modify_type', compact($vars)));
if ($log_type === false) {
$this->last_page_offset = 0;
return array();
}
$sql_keywords = '';
if (!empty($keywords)) {
// Get the SQL condition for our keywords
$sql_keywords = $this->generate_sql_keyword($keywords);
}
$get_logs_sql_ary = array('SELECT' => 'l.*, u.username, u.username_clean, u.user_colour', 'FROM' => array($this->log_table => 'l', USERS_TABLE => 'u'), 'WHERE' => 'l.log_type = ' . (int) $log_type . "\n\t\t\t\t\tAND l.user_id = u.user_id\n\t\t\t\t\t{$sql_keywords}\n\t\t\t\t\t{$sql_additional}", 'ORDER_BY' => $sort_by);
if ($log_time) {
$get_logs_sql_ary['WHERE'] = 'l.log_time >= ' . (int) $log_time . '
AND ' . $get_logs_sql_ary['WHERE'];
}
/**
* Modify the query to obtain the logs data
*
* @event core.get_logs_main_query_before
* @var array get_logs_sql_ary The array in the format of the query builder with the query
* to get the log count and the log list
* @var string mode Mode of the entries we display
* @var bool count_logs Do we count all matching entries?
* @var int limit Limit the number of entries
* @var int offset Offset when fetching the entries
* @var mixed forum_id Limit entries to the forum_id,
* can also be an array of forum_ids
* @var int topic_id Limit entries to the topic_id
* @var int user_id Limit entries to the user_id
* @var int log_time Limit maximum age of log entries
* @var string sort_by SQL order option
* @var string keywords Will only return entries that have the
* keywords in log_operation or log_data
* @var string profile_url URL to the users profile
* @var int log_type Limit logs to a certain type. If log_type
* is false, no entries will be returned.
* @var string sql_additional Additional conditions for the entries,
* e.g.: 'AND l.forum_id = 1'
* @since 3.1.5-RC1
*/
$vars = array('get_logs_sql_ary', 'mode', 'count_logs', 'limit', 'offset', 'forum_id', 'topic_id', 'user_id', 'log_time', 'sort_by', 'keywords', 'profile_url', 'log_type', 'sql_additional');
extract($this->dispatcher->trigger_event('core.get_logs_main_query_before', compact($vars)));
if ($count_logs) {
$count_logs_sql_ary = $get_logs_sql_ary;
$count_logs_sql_ary['SELECT'] = 'COUNT(l.log_id) AS total_entries';
unset($count_logs_sql_ary['ORDER_BY']);
$sql = $this->db->sql_build_query('SELECT', $count_logs_sql_ary);
$result = $this->db->sql_query($sql);
$this->entry_count = (int) $this->db->sql_fetchfield('total_entries');
$this->db->sql_freeresult($result);
if ($this->entry_count == 0) {
// Save the queries, because there are no logs to display
$this->last_page_offset = 0;
return array();
}
// Return the user to the last page that is valid
while ($this->last_page_offset >= $this->entry_count) {
$this->last_page_offset = max(0, $this->last_page_offset - $limit);
}
}
$sql = $this->db->sql_build_query('SELECT', $get_logs_sql_ary);
$result = $this->db->sql_query_limit($sql, $limit, $this->last_page_offset);
$i = 0;
$log = array();
while ($row = $this->db->sql_fetchrow($result)) {
$row['forum_id'] = (int) $row['forum_id'];
if ($row['topic_id']) {
$topic_id_list[] = (int) $row['topic_id'];
}
if ($row['reportee_id']) {
$reportee_id_list[] = (int) $row['reportee_id'];
}
$log_entry_data = array('id' => (int) $row['log_id'], 'reportee_id' => (int) $row['reportee_id'], 'reportee_username' => '', 'reportee_username_full' => '', 'user_id' => (int) $row['user_id'], 'username' => $row['username'], 'username_full' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], false, $profile_url), 'ip' => $row['log_ip'], 'time' => (int) $row['log_time'], 'forum_id' => (int) $row['forum_id'], 'topic_id' => (int) $row['topic_id'], 'viewforum' => $row['forum_id'] && $this->auth->acl_get('f_read', $row['forum_id']) ? append_sid("{$this->phpbb_root_path}viewforum.{$this->php_ext}", 'f=' . $row['forum_id']) : false, 'action' => isset($this->user->lang[$row['log_operation']]) ? $row['log_operation'] : '{' . ucfirst(str_replace('_', ' ', $row['log_operation'])) . '}');
/**
* Modify the entry's data before it is returned
*
* @event core.get_logs_modify_entry_data
* @var array row Entry data from the database
* @var array log_entry_data Entry's data which is returned
* @since 3.1.0-a1
*/
$vars = array('row', 'log_entry_data');
extract($this->dispatcher->trigger_event('core.get_logs_modify_entry_data', compact($vars)));
$log[$i] = $log_entry_data;
if (!empty($row['log_data'])) {
$log_data_ary = unserialize($row['log_data']);
$log_data_ary = $log_data_ary !== false ? $log_data_ary : array();
if (isset($this->user->lang[$row['log_operation']])) {
// Check if there are more occurrences of % than
// arguments, if there are we fill out the arguments
// array. It doesn't matter if we add more arguments than
// placeholders.
$num_args = 0;
if (!is_array($this->user->lang[$row['log_operation']])) {
$num_args = substr_count($this->user->lang[$row['log_operation']], '%');
} else {
foreach ($this->user->lang[$row['log_operation']] as $case => $plural_string) {
$num_args = max($num_args, substr_count($plural_string, '%'));
}
}
if ($num_args - sizeof($log_data_ary) > 0) {
$log_data_ary = array_merge($log_data_ary, array_fill(0, $num_args - sizeof($log_data_ary), ''));
}
$lang_arguments = array_merge(array($log[$i]['action']), $log_data_ary);
$log[$i]['action'] = call_user_func_array(array($this->user, 'lang'), $lang_arguments);
// If within the admin panel we do not censor text out
if ($this->get_is_admin()) {
$log[$i]['action'] = bbcode_nl2br($log[$i]['action']);
} else {
$log[$i]['action'] = bbcode_nl2br(censor_text($log[$i]['action']));
}
} else {
if (!empty($log_data_ary)) {
$log[$i]['action'] .= '<br />' . implode('', $log_data_ary);
}
}
/* Apply make_clickable... has to be seen if it is for good. :/
// Seems to be not for the moment, reconsider later...
$log[$i]['action'] = make_clickable($log[$i]['action']);
*/
} else {
$log[$i]['action'] = $this->user->lang($log[$i]['action']);
}
$i++;
}
$this->db->sql_freeresult($result);
/**
* Get some additional data after we got all log entries
*
* @event core.get_logs_get_additional_data
* @var array log Array with all our log entries
* @var array topic_id_list Array of topic ids, for which we
* get the permission data
* @var array reportee_id_list Array of additional user IDs we
* get the username strings for
* @since 3.1.0-a1
*/
$vars = array('log', 'topic_id_list', 'reportee_id_list');
extract($this->dispatcher->trigger_event('core.get_logs_get_additional_data', compact($vars)));
if (sizeof($topic_id_list)) {
$topic_auth = $this->get_topic_auth($topic_id_list);
foreach ($log as $key => $row) {
$log[$key]['viewtopic'] = isset($topic_auth['f_read'][$row['topic_id']]) ? append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $topic_auth['f_read'][$row['topic_id']] . '&t=' . $row['topic_id']) : false;
$log[$key]['viewlogs'] = isset($topic_auth['m_'][$row['topic_id']]) ? append_sid("{$this->phpbb_root_path}mcp.{$this->php_ext}", 'i=logs&mode=topic_logs&t=' . $row['topic_id'], true, $this->user->session_id) : false;
}
}
if (sizeof($reportee_id_list)) {
$reportee_data_list = $this->get_reportee_data($reportee_id_list);
foreach ($log as $key => $row) {
if (!isset($reportee_data_list[$row['reportee_id']])) {
continue;
}
$log[$key]['reportee_username'] = $reportee_data_list[$row['reportee_id']]['username'];
$log[$key]['reportee_username_full'] = get_username_string('full', $row['reportee_id'], $reportee_data_list[$row['reportee_id']]['username'], $reportee_data_list[$row['reportee_id']]['user_colour'], false, $profile_url);
}
}
/**
* Allow modifying or execute extra final filter on log entries
*
* @event core.get_logs_after
* @var array log Array with all our log entries
* @var array topic_id_list Array of topic ids, for which we
* get the permission data
* @var array reportee_id_list Array of additional user IDs we
* get the username strings for
* @var string mode Mode of the entries we display
* @var bool count_logs Do we count all matching entries?
* @var int limit Limit the number of entries
* @var int offset Offset when fetching the entries
* @var mixed forum_id Limit entries to the forum_id,
* can also be an array of forum_ids
* @var int topic_id Limit entries to the topic_id
* @var int user_id Limit entries to the user_id
* @var int log_time Limit maximum age of log entries
* @var string sort_by SQL order option
* @var string keywords Will only return entries that have the
* keywords in log_operation or log_data
* @var string profile_url URL to the users profile
* @var int log_type The type of logs it was filtered
* @since 3.1.3-RC1
*/
$vars = array('log', 'topic_id_list', 'reportee_id_list', 'mode', 'count_logs', 'limit', 'offset', 'forum_id', 'topic_id', 'user_id', 'log_time', 'sort_by', 'keywords', 'profile_url', 'log_type');
extract($this->dispatcher->trigger_event('core.get_logs_after', compact($vars)));
return $log;
}