forked from leftypol/leftypol
pages.php: refactor mod_ip into mod_user_posts_by_ip
This commit is contained in:
parent
27b7f1c60d
commit
11c5748888
1 changed files with 80 additions and 57 deletions
|
@ -861,9 +861,9 @@ function mod_ip_remove_note(Context $ctx, $ip, $id) {
|
|||
$query->bindValue(':id', $id);
|
||||
$query->execute() or error(db_error($query));
|
||||
|
||||
modLog("Removed a note for <a href=\"?/IP/{$ip}\">{$ip}</a>");
|
||||
modLog("Removed a note for <a href=\"?/user_posts/ip/{$ip}\">{$ip}</a>");
|
||||
|
||||
header('Location: ?/IP/' . $ip . '#notes', true, $config['redirect_http']);
|
||||
\header("Location: ?/user_posts/ip/$ip#notes", true, $config['redirect_http']);
|
||||
}
|
||||
|
||||
function mod_ip(Context $ctx, $ip, string $encoded_cursor = null) {
|
||||
|
@ -879,9 +879,9 @@ function mod_ip(Context $ctx, $ip, string $encoded_cursor = null) {
|
|||
Bans::delete($_POST['ban_id'], true, $mod['boards']);
|
||||
|
||||
if (empty($encoded_cursor)) {
|
||||
header("Location: ?/IP/$ip#bans", true, $config['redirect_http']);
|
||||
\header("Location: ?/user_posts/ip/$ip#bans", true, $config['redirect_http']);
|
||||
} else {
|
||||
header("Location: ?/IP/$ip/cursor/$encoded_cursor#bans", true, $config['redirect_http']);
|
||||
\header("Location: ?/user_posts/ip/$ip/cursor/$encoded_cursor#bans", true, $config['redirect_http']);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -901,64 +901,48 @@ function mod_ip(Context $ctx, $ip, string $encoded_cursor = null) {
|
|||
|
||||
Cache::delete("mod_page_ip_view_notes_$ip");
|
||||
|
||||
modLog("Added a note for <a href=\"?/IP/{$ip}\">{$ip}</a>");
|
||||
modLog("Added a note for <a href=\"?/user_posts/ip/{$ip}\">{$ip}</a>");
|
||||
|
||||
if (empty($encoded_cursor)) {
|
||||
header("Location: ?/IP/$ip#notes", true, $config['redirect_http']);
|
||||
\header("Location: ?/user_posts/ip/$ip#notes", true, $config['redirect_http']);
|
||||
} else {
|
||||
header("Location: ?/IP/$ip/cursor/$encoded_cursor#notes", true, $config['redirect_http']);
|
||||
\header("Location: ?/user_posts/ip/$ip/cursor/$encoded_cursor#notes", true, $config['redirect_http']);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty($encoded_cursor)) {
|
||||
\header("Location: ?/user_posts/ip/$ip", true, 308);
|
||||
} else {
|
||||
\header("Location: ?/user_posts/ip/$ip/cursor/$encoded_cursor", true, 308);
|
||||
}
|
||||
}
|
||||
|
||||
function mod_user_posts_by_ip(Context $ctx, string $ip, string $encoded_cursor = null) {
|
||||
global $mod;
|
||||
|
||||
if (\filter_var($ip, \FILTER_VALIDATE_IP) === false){
|
||||
error("Invalid IP address.");
|
||||
}
|
||||
|
||||
$config = $ctx->get('config');
|
||||
|
||||
$args = [
|
||||
'ip' => $ip,
|
||||
'posts' => []
|
||||
];
|
||||
|
||||
if (isset($config['mod']['ip_recentposts'])) {
|
||||
// TODO log to migrate.
|
||||
$page_size = $config['mod']['ip_recentposts'];
|
||||
} else {
|
||||
$page_size = $config['mod']['recent_user_posts'];
|
||||
}
|
||||
|
||||
if ($config['mod']['dns_lookup']) {
|
||||
$args['hostname'] = rDNS($ip);
|
||||
}
|
||||
|
||||
$boards = listBoards();
|
||||
|
||||
$queryable_uris = [];
|
||||
foreach ($boards as $board) {
|
||||
$uri = $board['uri'];
|
||||
if (hasPermission($config['mod']['show_ip'], $uri)) {
|
||||
$queryable_uris[] = $uri;
|
||||
}
|
||||
}
|
||||
|
||||
$queries = $ctx->get(UserPostQueries::class);
|
||||
$result = $queries->fetchPaginatedByIp($queryable_uris, $ip, $config['mod']['ip_recentposts'], $encoded_cursor);
|
||||
|
||||
$args['cursor_prev'] = $result->cursor_prev;
|
||||
$args['cursor_next'] = $result->cursor_next;
|
||||
|
||||
foreach($boards as $board) {
|
||||
$uri = $board['uri'];
|
||||
// The Thread and Post classes rely on some implicit board parameter set by openBoard.
|
||||
openBoard($uri);
|
||||
|
||||
// Finally load the post contents and build them.
|
||||
foreach ($result->by_uri[$uri] as $post) {
|
||||
if (!$post['thread']) {
|
||||
$po = new Thread($post, '?/', $mod, false);
|
||||
} else {
|
||||
$po = new Post($post, '?/', $mod);
|
||||
}
|
||||
|
||||
if (!isset($args['posts'][$uri])) {
|
||||
$args['posts'][$uri] = [ 'board' => $board, 'posts' => [] ];
|
||||
}
|
||||
$args['posts'][$uri]['posts'][] = $po->build(true);
|
||||
}
|
||||
}
|
||||
|
||||
$args['boards'] = $boards;
|
||||
$args['token'] = make_secure_link_token('ban');
|
||||
|
||||
if (hasPermission($config['mod']['view_ban'])) {
|
||||
$args['bans'] = Bans::find($ip, false, true, $config['auto_maintenance']);
|
||||
}
|
||||
|
@ -989,13 +973,52 @@ function mod_ip(Context $ctx, $ip, string $encoded_cursor = null) {
|
|||
$args['logs'] = [];
|
||||
}
|
||||
|
||||
if (empty($encoded_cursor)) {
|
||||
$args['security_token'] = make_secure_link_token("IP/$ip");
|
||||
} else {
|
||||
$args['security_token'] = make_secure_link_token("IP/$ip/cursor/$encoded_cursor");
|
||||
$boards = listBoards();
|
||||
|
||||
$queryable_uris = [];
|
||||
foreach ($boards as $board) {
|
||||
$uri = $board['uri'];
|
||||
if (hasPermission($config['mod']['show_ip'], $uri)) {
|
||||
$queryable_uris[] = $uri;
|
||||
}
|
||||
}
|
||||
|
||||
mod_page(sprintf('%s: %s', _('IP'), htmlspecialchars($ip)), 'mod/view_ip.html', $args, $args['hostname']);
|
||||
$queries = $ctx->get(UserPostQueries::class);
|
||||
$result = $queries->fetchPaginatedByIp($queryable_uris, $ip, $page_size, $encoded_cursor);
|
||||
|
||||
$args['cursor_prev'] = $result->cursor_prev;
|
||||
$args['cursor_next'] = $result->cursor_next;
|
||||
|
||||
foreach($boards as $board) {
|
||||
$uri = $board['uri'];
|
||||
// The Thread and Post classes rely on some implicit board parameter set by openBoard.
|
||||
openBoard($uri);
|
||||
|
||||
// Finally load the post contents and build them.
|
||||
foreach ($result->by_uri[$uri] as $post) {
|
||||
if (!$post['thread']) {
|
||||
$po = new Thread($post, '?/', $mod, false);
|
||||
} else {
|
||||
$po = new Post($post, '?/', $mod);
|
||||
}
|
||||
|
||||
if (!isset($args['posts'][$uri])) {
|
||||
$args['posts'][$uri] = [ 'board' => $board, 'posts' => [] ];
|
||||
}
|
||||
$args['posts'][$uri]['posts'][] = $po->build(true);
|
||||
}
|
||||
}
|
||||
|
||||
$args['boards'] = $boards;
|
||||
$args['token'] = make_secure_link_token('ban');
|
||||
|
||||
if (empty($encoded_cursor)) {
|
||||
$args['security_token'] = make_secure_link_token("user_posts/ip/$ip");
|
||||
} else {
|
||||
$args['security_token'] = make_secure_link_token("user_posts/ip/$ip/cursor/$encoded_cursor");
|
||||
}
|
||||
|
||||
mod_page(\sprintf('%s: %s', _('IP'), \htmlspecialchars($ip)), 'mod/view_ip.html', $args, $args['hostname']);
|
||||
}
|
||||
|
||||
function mod_ban(Context $ctx) {
|
||||
|
@ -1913,7 +1936,7 @@ function mod_ban_post(Context $ctx, $board, $delete, $post, $token = false) {
|
|||
$query->bindValue(':time', time());
|
||||
$query->bindValue(':body', $autotag);
|
||||
$query->execute() or error(db_error($query));
|
||||
modLog("Added a note for <a href=\"?/IP/{$ip}\">{$ip}</a>");
|
||||
modLog("Added a note for <a href=\"?/user_posts/ip/{$ip}\">{$ip}</a>");
|
||||
}
|
||||
}
|
||||
deletePost($post);
|
||||
|
@ -2024,7 +2047,7 @@ function mod_warning_post(Context $ctx, $board, $post, $token = false) {
|
|||
$query->bindValue(':time', time());
|
||||
$query->bindValue(':body', $autotag);
|
||||
$query->execute() or error(db_error($query));
|
||||
modLog("Added a note for <a href=\"?/IP/{$ip}\">{$ip}</a>");
|
||||
modLog("Added a note for <a href=\"?/user_posts/ip/{$ip}\">{$ip}</a>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2176,7 +2199,7 @@ function mod_delete(Context $ctx, $board, $post) {
|
|||
$query->bindValue(':time', time());
|
||||
$query->bindValue(':body', $autotag);
|
||||
$query->execute() or error(db_error($query));
|
||||
modLog("Added a note for <a href=\"?/IP/{$ip}\">{$ip}</a>");
|
||||
modLog("Added a note for <a href=\"?/user_posts/ip/{$ip}\">{$ip}</a>");
|
||||
}
|
||||
}
|
||||
deletePost($post);
|
||||
|
@ -2347,7 +2370,7 @@ function mod_deletebyip(Context $ctx, $boardName, $post, $global = false) {
|
|||
$query2->bindValue(':time', time());
|
||||
$query2->bindValue(':body', $autotag);
|
||||
$query2->execute() or error(db_error($query2));
|
||||
modLog("Added a note for <a href=\"?/IP/{$ip}\">{$ip}</a>");
|
||||
modLog("Added a note for <a href=\"?/user_posts/ip/{$ip}\">{$ip}</a>");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2378,7 +2401,7 @@ function mod_deletebyip(Context $ctx, $boardName, $post, $global = false) {
|
|||
}
|
||||
|
||||
// Record the action
|
||||
modLog("Deleted all posts by IP address: <a href=\"?/IP/$ip\">$ip</a>");
|
||||
modLog("Deleted all posts by IP address: <a href=\"?/user_posts/ip/$ip\">$ip</a>");
|
||||
|
||||
// Redirect
|
||||
header('Location: ?/' . sprintf($config['board_path'], $boardName) . $config['file_index'], true, $config['redirect_http']);
|
||||
|
@ -2915,7 +2938,7 @@ function mod_report_dismiss(Context $ctx, $id, $all = false) {
|
|||
|
||||
if ($all) {
|
||||
$report_queries->deleteByIp($ip);
|
||||
modLog("Dismissed all reports by <a href=\"?/IP/$ip\">$ip</a>");
|
||||
modLog("Dismissed all reports by <a href=\"?/user_posts/ip/$ip\">$ip</a>");
|
||||
} else {
|
||||
$report_queries->deleteById($id);
|
||||
modLog("Dismissed a report for post #{$id}", $board);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue