paginate modlog

This commit is contained in:
Michael Save 2012-01-09 10:20:13 +11:00
parent c7d72306ed
commit 9969e37105

69
mod.php
View File

@ -268,41 +268,68 @@
'mod'=>true
)
);
} elseif(preg_match('/^\/log$/', $query)) {
} elseif(preg_match('/^\/log(\/(\d+))?$/', $query, $match)) {
if(!hasPermission($config['mod']['modlog'])) error($config['error']['noaccess']);
$page = isset($match[2]) ? $match[2] : 1;
$boards = Array();
$_boards = listBoards();
foreach($_boards as &$_b) {
$boards[$_b['id']] = $_b['uri'];
}
$body = '<table class="modlog"><tr><th>' . _('User') . '</th><th>' . _('IP address') . '</th><th>' . _('Ago') . '</th><th>' . _('Board') . '</th><th>' . _('Action') . '</th></tr>';
$query = prepare("SELECT `mods`.`id`,`username`,`ip`,`board`,`time`,`text` FROM `modlogs` INNER JOIN `mods` ON `mod` = `mods`.`id` ORDER BY `time` DESC LIMIT :limit");
$query = prepare("SELECT `mods`.`id`,`username`,`ip`,`board`,`time`,`text` FROM `modlogs` LEFT JOIN `mods` ON `mod` = `mods`.`id` ORDER BY `time` DESC LIMIT :offset, :limit");
$query->bindValue(':limit', $config['mod']['modlog_page'], PDO::PARAM_INT);
$query->bindValue(':offset', ($page - 1) * $config['mod']['modlog_page'], PDO::PARAM_INT);
$query->execute() or error(db_error($query));
while($log = $query->fetch()) {
$log['text'] = utf8tohtml($log['text']);
$log['text'] = preg_replace('/(\d+\.\d+\.\d+\.\d+)/', '<a href="?/IP/$1">$1</a>', $log['text']);
if(!$query->rowCount()) {
$body = '<p class="unimportant" style="text-align:center">(Nothing to display.)</p>';
} else {
$body = '<table class="modlog">' .
'<tr>' .
'<th>' . _('User') . '</th>' .
'<th>' . _('IP address') . '</th>' .
'<th>' . _('Ago') . '</th>' .
'<th>' . _('Board') . '</th>' .
'<th>' . _('Action') . '</th>' .
'</tr>';
while($log = $query->fetch()) {
$log['text'] = utf8tohtml($log['text']);
$log['text'] = preg_replace('/(\d+\.\d+\.\d+\.\d+)/', '<a href="?/IP/$1">$1</a>', $log['text']);
$body .= '<tr>' .
'<td class="minimal"><a href="?/users/' . $log['id'] . '">' . $log['username'] . '</a></td>' .
'<td class="minimal"><a href="?/IP/' . $log['ip'] . '">' . $log['ip'] . '</a></td>' .
'<td class="minimal">' . ago($log['time']) . '</td>' .
'<td class="minimal">' .
($log['board'] ?
(isset($boards[$log['board']]) ?
'<a href="?/' . $boards[$log['board']] . '/' . $config['file_index'] . '">' . sprintf($config['board_abbreviation'], $boards[$log['board']]) . '</a></td>'
: '<em>deleted?</em>')
: '-') .
'<td>' . $log['text'] . '</td>' .
'</tr>';
$body .= '<tr>' .
'<td class="minimal">' .
($log['username'] ?
'<a href="?/new_PM/' . $log['id'] . '">' . $log['username'] . '</a>'
: '<em>deleted?</em>') .
'</td>' .
'<td class="minimal"><a href="?/IP/' . $log['ip'] . '">' . $log['ip'] . '</a></td>' .
'<td class="minimal">' . ago($log['time']) . '</td>' .
'<td class="minimal">' .
($log['board'] ?
(isset($boards[$log['board']]) ?
'<a href="?/' . $boards[$log['board']] . '/' . $config['file_index'] . '">' . sprintf($config['board_abbreviation'], $boards[$log['board']]) . '</a></td>'
: '<em>deleted?</em>')
: '-') .
'<td>' . $log['text'] . '</td>' .
'</tr>';
}
$body .= '</table>';
$query = prepare("SELECT COUNT(*) AS `count` FROM `modlogs`");
$query->execute() or error(db_error($query));
$count = $query->fetch();
$body .= '<p class="unimportant" style="text-align:center;word-wrap:break-word">';
for($x = 0; $x < $count['count'] / $config['mod']['modlog_page']; $x ++) {
$body .= '<a href="?/log/' . ($x+1) . '">[' . ($x + 1) . ']</a> ';
}
$body .= '</p>';
}
$body .= '</table>';
echo Element('page.html', Array(
'config'=>$config,
'title'=>_('Moderation log'),