forked from leftypol/leftypol
pages.php: use IpNoteQueries
This commit is contained in:
parent
583b50af56
commit
5d52f6b32a
1 changed files with 44 additions and 55 deletions
|
@ -3,7 +3,7 @@
|
|||
* Copyright (c) 2010-2013 Tinyboard Development Group
|
||||
*/
|
||||
use Vichan\Context;
|
||||
use Vichan\Data\{UserPostQueries, ReportQueries};
|
||||
use Vichan\Data\{IpNoteQueries, UserPostQueries, ReportQueries};
|
||||
use Vichan\Functions\Net;
|
||||
|
||||
defined('TINYBOARD') or exit;
|
||||
|
@ -851,18 +851,26 @@ function mod_view_thread50(Context $ctx, $boardName, $thread) {
|
|||
}
|
||||
|
||||
function mod_ip_remove_note(Context $ctx, $ip, $id) {
|
||||
global $config;
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (!hasPermission($config['mod']['remove_notes']))
|
||||
error($config['error']['noaccess']);
|
||||
if (!hasPermission($config['mod']['remove_notes'])) {
|
||||
error($config['error']['noaccess']);
|
||||
}
|
||||
|
||||
if (filter_var($ip, FILTER_VALIDATE_IP) === false)
|
||||
if (filter_var($ip, \FILTER_VALIDATE_IP) === false) {
|
||||
error('Invalid IP address');
|
||||
}
|
||||
|
||||
$query = prepare('DELETE FROM ``ip_notes`` WHERE `ip` = :ip AND `id` = :id');
|
||||
$query->bindValue(':ip', $ip);
|
||||
$query->bindValue(':id', $id);
|
||||
$query->execute() or error(db_error($query));
|
||||
if (!is_numeric($id)) {
|
||||
error('Invalid note ID');
|
||||
}
|
||||
|
||||
$queries = $ctx->get(IpNoteQueries::class);
|
||||
$deleted = $queries->deleteWhereIp((int)$id, $ip);
|
||||
|
||||
if (!$deleted) {
|
||||
error("Note $id does not exist for $ip");
|
||||
}
|
||||
|
||||
modLog("Removed a note for <a href=\"?/user_posts/ip/{$ip}\">{$ip}</a>");
|
||||
|
||||
|
@ -870,14 +878,17 @@ function mod_ip_remove_note(Context $ctx, $ip, $id) {
|
|||
}
|
||||
|
||||
function mod_ip(Context $ctx, $ip, string $encoded_cursor = null) {
|
||||
global $config, $mod;
|
||||
global $mod;
|
||||
$config = $ctx->get('config');
|
||||
|
||||
if (filter_var($ip, FILTER_VALIDATE_IP) === false)
|
||||
if (filter_var($ip, FILTER_VALIDATE_IP) === false) {
|
||||
error('Invalid IP address');
|
||||
}
|
||||
|
||||
if (isset($_POST['ban_id'], $_POST['unban'])) {
|
||||
if (!hasPermission($config['mod']['unban']))
|
||||
if (!hasPermission($config['mod']['unban'])) {
|
||||
error($config['error']['noaccess']);
|
||||
}
|
||||
|
||||
Bans::delete($_POST['ban_id'], true, $mod['boards']);
|
||||
|
||||
|
@ -890,17 +901,15 @@ function mod_ip(Context $ctx, $ip, string $encoded_cursor = null) {
|
|||
}
|
||||
|
||||
if (isset($_POST['note'])) {
|
||||
if (!hasPermission($config['mod']['create_notes']))
|
||||
if (!hasPermission($config['mod']['create_notes'])) {
|
||||
error($config['error']['noaccess']);
|
||||
}
|
||||
|
||||
$_POST['note'] = escape_markup_modifiers($_POST['note']);
|
||||
markup($_POST['note']);
|
||||
$query = prepare('INSERT INTO ``ip_notes`` VALUES (NULL, :ip, :mod, :time, :body)');
|
||||
$query->bindValue(':ip', $ip);
|
||||
$query->bindValue(':mod', $mod['id']);
|
||||
$query->bindValue(':time', time());
|
||||
$query->bindValue(':body', $_POST['note']);
|
||||
$query->execute() or error(db_error($query));
|
||||
|
||||
$note_queries = $ctx->get(IpNoteQueries::class);
|
||||
$note_queries->add($ip, $mod['id'], $_POST['note']);
|
||||
|
||||
Cache::delete("mod_page_ip_view_notes_$ip");
|
||||
|
||||
|
@ -952,15 +961,8 @@ function mod_user_posts_by_ip(Context $ctx, string $ip, string $encoded_cursor =
|
|||
}
|
||||
|
||||
if (hasPermission($config['mod']['view_notes'])) {
|
||||
$ret = Cache::get("mod_page_ip_view_notes_$ip");
|
||||
if (!$ret) {
|
||||
$query = prepare("SELECT ``ip_notes``.*, `username` FROM ``ip_notes`` LEFT JOIN ``mods`` ON `mod` = ``mods``.`id` WHERE `ip` = :ip ORDER BY `time` DESC");
|
||||
$query->bindValue(':ip', $ip);
|
||||
$query->execute() or error(db_error($query));
|
||||
$ret = $query->fetchAll(PDO::FETCH_ASSOC);
|
||||
Cache::set("mod_page_ip_view_notes_$ip", $ret, 900);
|
||||
}
|
||||
$args['notes'] = $ret;
|
||||
$note_queries = $ctx->get(IpNoteQueries::class);
|
||||
$args['notes'] = $note_queries->getByIp($ip);
|
||||
}
|
||||
|
||||
if (hasPermission($config['mod']['modlog_ip'])) {
|
||||
|
@ -1998,13 +2000,9 @@ function mod_ban_post(Context $ctx, $board, $delete, $post, $token = false) {
|
|||
$autotag .= "/${board}/" . " " . $filehash . " " . $filename ."\r\n";
|
||||
$autotag .= $body . "\r\n";
|
||||
$autotag = escape_markup_modifiers($autotag);
|
||||
markup($autotag);
|
||||
$query = prepare('INSERT INTO ``ip_notes`` VALUES (NULL, :ip, :mod, :time, :body)');
|
||||
$query->bindValue(':ip', $ip);
|
||||
$query->bindValue(':mod', $mod['id']);
|
||||
$query->bindValue(':time', time());
|
||||
$query->bindValue(':body', $autotag);
|
||||
$query->execute() or error(db_error($query));
|
||||
|
||||
$note_queries = $ctx->get(IpNoteQueries::class);
|
||||
$note_queries->add($ip, $mod['id'], $autotag);
|
||||
modLog("Added a note for <a href=\"?/user_posts/ip/{$ip}\">{$ip}</a>");
|
||||
}
|
||||
}
|
||||
|
@ -2110,12 +2108,9 @@ function mod_warning_post(Context $ctx, $board, $post, $token = false) {
|
|||
$autotag .= $body . "\r\n";
|
||||
$autotag = escape_markup_modifiers($autotag);
|
||||
markup($autotag);
|
||||
$query = prepare('INSERT INTO ``ip_notes`` VALUES (NULL, :ip, :mod, :time, :body)');
|
||||
$query->bindValue(':ip', $ip);
|
||||
$query->bindValue(':mod', $mod['id']);
|
||||
$query->bindValue(':time', time());
|
||||
$query->bindValue(':body', $autotag);
|
||||
$query->execute() or error(db_error($query));
|
||||
|
||||
$note_queries = $ctx->get(IpNoteQueries::class);
|
||||
$note_queries->add($ip, $mod['id'], $autotag);
|
||||
modLog("Added a note for <a href=\"?/user_posts/ip/{$ip}\">{$ip}</a>");
|
||||
}
|
||||
}
|
||||
|
@ -2221,7 +2216,7 @@ function mod_edit_post(Context $ctx, $board, $edit_raw_html, $postID) {
|
|||
}
|
||||
|
||||
function mod_delete(Context $ctx, $board, $post) {
|
||||
global $config;
|
||||
global $config, $mod;
|
||||
|
||||
if (!openBoard($board))
|
||||
error($config['error']['noboard']);
|
||||
|
@ -2262,12 +2257,9 @@ function mod_delete(Context $ctx, $board, $post) {
|
|||
$autotag .= $body . "\r\n";
|
||||
$autotag = escape_markup_modifiers($autotag);
|
||||
markup($autotag);
|
||||
$query = prepare('INSERT INTO ``ip_notes`` VALUES (NULL, :ip, :mod, :time, :body)');
|
||||
$query->bindValue(':ip', $ip);
|
||||
$query->bindValue(':mod', $mod['id']);
|
||||
$query->bindValue(':time', time());
|
||||
$query->bindValue(':body', $autotag);
|
||||
$query->execute() or error(db_error($query));
|
||||
|
||||
$note_queries = $ctx->get(IpNoteQueries::class);
|
||||
$note_queries->add($ip, $mod['id'], $autotag);
|
||||
modLog("Added a note for <a href=\"?/user_posts/ip/{$ip}\">{$ip}</a>");
|
||||
}
|
||||
}
|
||||
|
@ -2355,7 +2347,7 @@ function mod_spoiler_image(Context $ctx, $board, $post, $file) {
|
|||
}
|
||||
|
||||
function mod_deletebyip(Context $ctx, $boardName, $post, $global = false) {
|
||||
global $config, $board;
|
||||
global $config, $board, $mod;
|
||||
|
||||
$global = (bool)$global;
|
||||
|
||||
|
@ -2433,12 +2425,9 @@ function mod_deletebyip(Context $ctx, $boardName, $post, $global = false) {
|
|||
$autotag .= $body . "\r\n";
|
||||
$autotag = escape_markup_modifiers($autotag);
|
||||
markup($autotag);
|
||||
$query2 = prepare('INSERT INTO ``ip_notes`` VALUES (NULL, :ip, :mod, :time, :body)');
|
||||
$query2->bindValue(':ip', $ip);
|
||||
$query2->bindValue(':mod', $mod['id']);
|
||||
$query2->bindValue(':time', time());
|
||||
$query2->bindValue(':body', $autotag);
|
||||
$query2->execute() or error(db_error($query2));
|
||||
|
||||
$note_queries = $ctx->get(IpNoteQueries::class);
|
||||
$note_queries->add($ip, $mod['id'], $autotag);
|
||||
modLog("Added a note for <a href=\"?/user_posts/ip/{$ip}\">{$ip}</a>");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue