Compare commits

...
Sign in to create a new pull request.

1 commit

View file

@ -4,7 +4,7 @@
*/
use Vichan\Context;
use Vichan\Data\ReportQueries;
use Vichan\Functions\Format;
use Vichan\Data\Driver\CacheDriver;
use Vichan\Functions\Net;
use function Vichan\Functions\Net\decode_cursor;
@ -860,11 +860,15 @@ function mod_ip_remove_note(Context $ctx, $ip, $id) {
if (filter_var($ip, FILTER_VALIDATE_IP) === false)
error("Invalid IP address.");
$cache = $ctx->get(CacheDriver::class);
$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));
$cache->delete("mod_page_ip_view_notes_$ip");
modLog("Removed a note for <a href=\"?/IP/{$ip}\">{$ip}</a>");
header('Location: ?/IP/' . $ip . '#notes', true, $config['redirect_http']);
@ -903,7 +907,8 @@ function mod_ip(Context $ctx, $ip, string $encoded_cursor = '') {
$query->bindValue(':body', $_POST['note']);
$query->execute() or error(db_error($query));
Cache::delete("mod_page_ip_view_notes_$ip");
$cache = $ctx->get(CacheDriver::class);
$cache->delete("mod_page_ip_view_notes_$ip");
modLog("Added a note for <a href=\"?/IP/{$ip}\">{$ip}</a>");
@ -1025,25 +1030,27 @@ function mod_ip(Context $ctx, $ip, string $encoded_cursor = '') {
}
if (hasPermission($config['mod']['view_notes'])) {
$ret = Cache::get("mod_page_ip_view_notes_$ip");
if (!$ret) {
$cache = $ctx->get(CacheDriver::class);
$ret = $cache->get("mod_page_ip_view_notes_$ip");
if ($ret === null) {
$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);
$cache->set("mod_page_ip_view_notes_$ip", $ret, 900);
}
$args['notes'] = $ret;
}
if (hasPermission($config['mod']['modlog_ip'])) {
$ret = Cache::get("mod_page_ip_modlog_ip_$ip");
if (!$ret) {
$cache = $ctx->get(CacheDriver::class);
$ret = $cache->get("mod_page_ip_modlog_ip_$ip");
if ($ret === null) {
$query = prepare("SELECT `username`, `mod`, `ip`, `board`, `time`, `text` FROM ``modlogs`` LEFT JOIN ``mods`` ON `mod` = ``mods``.`id` WHERE `text` LIKE :search ORDER BY `time` DESC LIMIT 50");
$query->bindValue(':search', '%' . $ip . '%');
$query->execute() or error(db_error($query));
$ret = $query->fetchAll(PDO::FETCH_ASSOC);
Cache::set("mod_page_ip_modlog_ip_$ip", $ret, 900);
$cache->set("mod_page_ip_modlog_ip_$ip", $ret, 900);
}
$args['logs'] = $ret;
} else {