Merge branch 'master' of https://github.com/shish/shimmie2
This commit is contained in:
commit
4e03d3cce3
6 changed files with 95 additions and 196 deletions
|
@ -1,5 +1,31 @@
|
|||
<?php
|
||||
|
||||
use MicroCRUD\StringColumn;
|
||||
use MicroCRUD\DateColumn;
|
||||
use MicroCRUD\TextColumn;
|
||||
use MicroCRUD\Table;
|
||||
|
||||
class HashBanTable extends Table
|
||||
{
|
||||
public function __construct(\FFSPHP\PDO $db)
|
||||
{
|
||||
parent::__construct($db);
|
||||
$this->table = "image_bans";
|
||||
$this->base_query = "SELECT * FROM image_bans";
|
||||
$this->size = 100;
|
||||
$this->limit = 1000000;
|
||||
$this->columns = [
|
||||
new StringColumn("hash", "Hash"),
|
||||
new TextColumn("reason", "Reason"),
|
||||
new DateColumn("date", "Date"),
|
||||
];
|
||||
$this->order_by = ["date DESC", "id"];
|
||||
$this->create_url = make_link("image_hash_ban/add");
|
||||
$this->delete_url = make_link("image_hash_ban/remove");
|
||||
$this->table_attrs = ["class" => "zebra"];
|
||||
}
|
||||
}
|
||||
|
||||
class RemoveImageHashBanEvent extends Event
|
||||
{
|
||||
public $hash;
|
||||
|
@ -55,9 +81,11 @@ class ImageBan extends Extension
|
|||
if ($event->page_matches("image_hash_ban")) {
|
||||
if ($user->can(Permissions::BAN_IMAGE)) {
|
||||
if ($event->get_arg(0) == "add") {
|
||||
$image = isset($_POST['image_id']) ? Image::by_id(int_escape($_POST['image_id'])) : null;
|
||||
$hash = isset($_POST["hash"]) ? $_POST["hash"] : $image->hash;
|
||||
$reason = isset($_POST['reason']) ? $_POST['reason'] : "DNP";
|
||||
$user->ensure_authed();
|
||||
$input = validate_input(["c_hash"=>"optional,string", "c_reason"=>"string", "c_image_id"=>"optional,int"]);
|
||||
$image = isset($input['c_image_id']) ? Image::by_id($input['c_image_id']) : null;
|
||||
$hash = isset($input["c_hash"]) ? $input["c_hash"] : $image->hash;
|
||||
$reason = isset($input['c_reason']) ? $input['c_reason'] : "DNP";
|
||||
|
||||
if ($hash) {
|
||||
send_event(new AddImageHashBanEvent($hash, $reason));
|
||||
|
@ -72,21 +100,17 @@ class ImageBan extends Extension
|
|||
$page->set_redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
} elseif ($event->get_arg(0) == "remove") {
|
||||
if (isset($_POST['hash'])) {
|
||||
send_event(new RemoveImageHashBanEvent($_POST['hash']));
|
||||
|
||||
flash_message("Image ban removed");
|
||||
$page->set_mode(PageMode::REDIRECT);
|
||||
$page->set_redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
$user->ensure_authed();
|
||||
$input = validate_input(["d_hash"=>"string"]);
|
||||
send_event(new RemoveImageHashBanEvent($input['hash']));
|
||||
flash_message("Image ban removed");
|
||||
$page->set_mode(PageMode::REDIRECT);
|
||||
$page->set_redirect($_SERVER['HTTP_REFERER']);
|
||||
} elseif ($event->get_arg(0) == "list") {
|
||||
$page_num = 0;
|
||||
if ($event->count_args() == 2) {
|
||||
$page_num = int_escape($event->get_arg(1));
|
||||
}
|
||||
$page_size = 100;
|
||||
$page_count = ceil($database->get_one("SELECT COUNT(id) FROM image_bans")/$page_size);
|
||||
$this->theme->display_Image_hash_Bans($page, $page_num, $page_count, $this->get_image_hash_bans($page_num, $page_size));
|
||||
$t = new HashBanTable($database->raw_db());
|
||||
$t->token = $user->get_auth_token();
|
||||
$t->inputs = $_GET;
|
||||
$this->theme->display_bans($page, $t->table($t->query()), $t->paginator());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -102,7 +126,6 @@ class ImageBan extends Extension
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public function onUserBlockBuilding(UserBlockBuildingEvent $event)
|
||||
{
|
||||
global $user;
|
||||
|
@ -114,7 +137,7 @@ class ImageBan extends Extension
|
|||
public function onAddImageHashBan(AddImageHashBanEvent $event)
|
||||
{
|
||||
global $database;
|
||||
$database->Execute(
|
||||
$database->execute(
|
||||
"INSERT INTO image_bans (hash, reason, date) VALUES (:hash, :reason, now())",
|
||||
["hash"=>$event->hash, "reason"=>$event->reason]
|
||||
);
|
||||
|
@ -124,7 +147,7 @@ class ImageBan extends Extension
|
|||
public function onRemoveImageHashBan(RemoveImageHashBanEvent $event)
|
||||
{
|
||||
global $database;
|
||||
$database->Execute("DELETE FROM image_bans WHERE hash = :hash", ["hash"=>$event->hash]);
|
||||
$database->execute("DELETE FROM image_bans WHERE hash = :hash", ["hash"=>$event->hash]);
|
||||
}
|
||||
|
||||
public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event)
|
||||
|
@ -135,41 +158,6 @@ class ImageBan extends Extension
|
|||
}
|
||||
}
|
||||
|
||||
// DB funness
|
||||
|
||||
public function get_image_hash_bans(int $page, int $size=100): array
|
||||
{
|
||||
global $database;
|
||||
|
||||
// FIXME: many
|
||||
$size_i = int_escape($size);
|
||||
$offset_i = int_escape($page-1)*$size_i;
|
||||
$where = ["(1=1)"];
|
||||
$args = [];
|
||||
if (!empty($_GET['hash'])) {
|
||||
$where[] = 'hash = :hash';
|
||||
$args['hash'] = $_GET['hash'];
|
||||
}
|
||||
if (!empty($_GET['reason'])) {
|
||||
$where[] = 'reason SCORE_ILIKE :reason';
|
||||
$args['reason'] = "%".$_GET['reason']."%";
|
||||
}
|
||||
$where = implode(" AND ", $where);
|
||||
$bans = $database->get_all($database->scoreql_to_sql("
|
||||
SELECT *
|
||||
FROM image_bans
|
||||
WHERE $where
|
||||
ORDER BY id DESC
|
||||
LIMIT $size_i
|
||||
OFFSET $offset_i
|
||||
"), $args);
|
||||
if ($bans) {
|
||||
return $bans;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
// in before resolution limit plugin
|
||||
public function get_priority(): int
|
||||
{
|
||||
|
|
|
@ -4,81 +4,25 @@ class ImageBanTheme extends Themelet
|
|||
{
|
||||
/*
|
||||
* Show all the bans
|
||||
*
|
||||
* $bans = an array of (
|
||||
* 'hash' => the banned hash
|
||||
* 'reason' => why the hash was banned
|
||||
* 'date' => when the ban started
|
||||
* )
|
||||
*/
|
||||
public function display_image_hash_bans(Page $page, $page_number, $page_count, $bans)
|
||||
public function display_bans(Page $page, $table, $paginator)
|
||||
{
|
||||
$h_bans = "";
|
||||
foreach ($bans as $ban) {
|
||||
$h_bans .= "
|
||||
<tr>
|
||||
".make_form(make_link("image_hash_ban/remove"))."
|
||||
<td width='30%'>{$ban['hash']}</td>
|
||||
<td>{$ban['reason']}</td>
|
||||
<td width='10%'>
|
||||
<input type='hidden' name='hash' value='{$ban['hash']}'>
|
||||
<input type='submit' value='Remove'>
|
||||
</td>
|
||||
</form>
|
||||
</tr>
|
||||
";
|
||||
}
|
||||
$html = "
|
||||
<table id='image_bans' class='zebra sortable'>
|
||||
<thead>
|
||||
<th>Hash</th><th>Reason</th><th>Action</th>
|
||||
<tr>
|
||||
<form action='".make_link("image_hash_ban/list/1")."' method='GET'>
|
||||
<td><input type='text' name='hash'></td>
|
||||
<td><input type='text' name='reason'></td>
|
||||
<td><input type='submit' value='Search'></td>
|
||||
</form>
|
||||
</tr>
|
||||
</thead>
|
||||
$h_bans
|
||||
<tfoot><tr>
|
||||
".make_form(make_link("image_hash_ban/add"))."
|
||||
<td><input type='text' name='hash'></td>
|
||||
<td><input type='text' name='reason'></td>
|
||||
<td><input type='submit' value='Ban'></td>
|
||||
</form>
|
||||
</tr></tfoot>
|
||||
</table>
|
||||
";
|
||||
|
||||
$prev = $page_number - 1;
|
||||
$next = $page_number + 1;
|
||||
|
||||
$h_prev = ($page_number <= 1) ? "Prev" : "<a href='".make_link("image_hash_ban/list/$prev")."'>Prev</a>";
|
||||
$h_index = "<a href='".make_link()."'>Index</a>";
|
||||
$h_next = ($page_number >= $page_count) ? "Next" : "<a href='".make_link("image_hash_ban/list/$next")."'>Next</a>";
|
||||
|
||||
$nav = "$h_prev | $h_index | $h_next";
|
||||
|
||||
$page->set_title("Image Bans");
|
||||
$page->set_heading("Image Bans");
|
||||
$page->add_block(new Block("Edit Image Bans", $html));
|
||||
$page->add_block(new Block("Navigation", $nav, "left", 0));
|
||||
$this->display_paginator($page, "image_hash_ban/list", null, $page_number, $page_count);
|
||||
$page->add_block(new NavBlock());
|
||||
$page->add_block(new Block("Edit Image Bans", $table . $paginator));
|
||||
}
|
||||
|
||||
/*
|
||||
* Display a link to delete an image
|
||||
*
|
||||
* $image_id = the image to delete
|
||||
*/
|
||||
public function get_buttons_html(Image $image)
|
||||
{
|
||||
$html = "
|
||||
".make_form(make_link("image_hash_ban/add"))."
|
||||
<input type='hidden' name='hash' value='{$image->hash}'>
|
||||
<input type='hidden' name='image_id' value='{$image->id}'>
|
||||
<input type='text' name='reason'>
|
||||
<input type='hidden' name='c_hash' value='{$image->hash}'>
|
||||
<input type='hidden' name='c_image_id' value='{$image->id}'>
|
||||
<input type='text' name='c_reason'>
|
||||
<input type='submit' value='Ban Hash and Delete Image'>
|
||||
</form>
|
||||
";
|
||||
|
|
|
@ -9,10 +9,9 @@ use MicroCRUD\Table;
|
|||
|
||||
class IPBanTable extends Table
|
||||
{
|
||||
public function __construct(\PDO $db, $token=null)
|
||||
public function __construct(\FFSPHP\PDO $db)
|
||||
{
|
||||
parent::__construct($db, $token);
|
||||
|
||||
parent::__construct($db);
|
||||
$this->table = "bans";
|
||||
$this->base_query = "
|
||||
SELECT * FROM (
|
||||
|
@ -20,7 +19,6 @@ class IPBanTable extends Table
|
|||
FROM bans JOIN users ON banner_id=users.id
|
||||
) AS tbl1
|
||||
";
|
||||
|
||||
$this->size = 100;
|
||||
$this->limit = 1000000;
|
||||
$this->columns = [
|
||||
|
@ -42,7 +40,6 @@ class IPBanTable extends Table
|
|||
];
|
||||
$this->create_url = make_link("ip_ban/create");
|
||||
$this->delete_url = make_link("ip_ban/delete");
|
||||
|
||||
$this->table_attrs = ["class" => "zebra"];
|
||||
}
|
||||
}
|
||||
|
@ -200,8 +197,7 @@ class IPBan extends Extension
|
|||
$t = new IPBanTable($database->raw_db());
|
||||
$t->token = $user->get_auth_token();
|
||||
$t->inputs = $_GET;
|
||||
$table = $t->table($t->query());
|
||||
$this->theme->display_bans($page, $table, $t->paginator());
|
||||
$this->theme->display_bans($page, $t->table($t->query()), $t->paginator());
|
||||
}
|
||||
} else {
|
||||
$this->theme->display_permission_denied();
|
||||
|
|
|
@ -4,7 +4,6 @@ class IPBanTheme extends Themelet
|
|||
{
|
||||
public function display_bans(Page $page, $table, $paginator)
|
||||
{
|
||||
$today = date('Y-m-d');
|
||||
$html = "
|
||||
<a href='".make_link("ip_ban/list", "r__size=1000000")."'>Show All Active</a> /
|
||||
<a href='".make_link("ip_ban/list", "r_all=on&r__size=1000000")."'>Show EVERYTHING</a>
|
||||
|
|
|
@ -1,5 +1,28 @@
|
|||
<?php
|
||||
|
||||
use MicroCRUD\TextColumn;
|
||||
use MicroCRUD\Table;
|
||||
|
||||
class NotATagTable extends Table
|
||||
{
|
||||
public function __construct(\FFSPHP\PDO $db)
|
||||
{
|
||||
parent::__construct($db);
|
||||
$this->table = "untags";
|
||||
$this->base_query = "SELECT * FROM untags";
|
||||
$this->size = 100;
|
||||
$this->limit = 1000000;
|
||||
$this->columns = [
|
||||
new TextColumn("tag", "Tag"),
|
||||
new TextColumn("redirect", "Redirect"),
|
||||
];
|
||||
$this->order_by = ["tag", "redirect"];
|
||||
$this->create_url = make_link("untag/add");
|
||||
$this->delete_url = make_link("untag/remove");
|
||||
$this->table_attrs = ["class" => "zebra"];
|
||||
}
|
||||
}
|
||||
|
||||
class NotATag extends Extension
|
||||
{
|
||||
public function get_priority(): int
|
||||
|
@ -77,32 +100,29 @@ class NotATag extends Extension
|
|||
if ($event->page_matches("untag")) {
|
||||
if ($user->can(Permissions::BAN_IMAGE)) {
|
||||
if ($event->get_arg(0) == "add") {
|
||||
$tag = $_POST["tag"];
|
||||
$redirect = isset($_POST['redirect']) ? $_POST['redirect'] : "DNP";
|
||||
|
||||
$database->Execute(
|
||||
$user->ensure_authed();
|
||||
$input = validate_input(["c_tag"=>"string", "c_redirect"=>"string"]);
|
||||
$database->execute(
|
||||
"INSERT INTO untags(tag, redirect) VALUES (:tag, :redirect)",
|
||||
["tag"=>$tag, "redirect"=>$redirect]
|
||||
["tag"=>$input['c_tag'], "redirect"=>$input['c_redirect']]
|
||||
);
|
||||
|
||||
$page->set_mode(PageMode::REDIRECT);
|
||||
$page->set_redirect($_SERVER['HTTP_REFERER']);
|
||||
} elseif ($event->get_arg(0) == "remove") {
|
||||
if (isset($_POST['tag'])) {
|
||||
$database->Execute($database->scoreql_to_sql("DELETE FROM untags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)"), ["tag"=>$_POST['tag']]);
|
||||
|
||||
flash_message("Image ban removed");
|
||||
$page->set_mode(PageMode::REDIRECT);
|
||||
$page->set_redirect($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
$user->ensure_authed();
|
||||
$input = validate_input(["d_tag"=>"string"]);
|
||||
$database->execute($database->scoreql_to_sql(
|
||||
"DELETE FROM untags WHERE SCORE_STRNORM(tag) = SCORE_STRNORM(:tag)"),
|
||||
["tag"=>$input['d_tag']]
|
||||
);
|
||||
flash_message("Image ban removed");
|
||||
$page->set_mode(PageMode::REDIRECT);
|
||||
$page->set_redirect($_SERVER['HTTP_REFERER']);
|
||||
} elseif ($event->get_arg(0) == "list") {
|
||||
$page_num = 0;
|
||||
if ($event->count_args() == 2) {
|
||||
$page_num = int_escape($event->get_arg(1));
|
||||
}
|
||||
$page_size = 100;
|
||||
$page_count = ceil($database->get_one("SELECT COUNT(tag) FROM untags")/$page_size);
|
||||
$this->theme->display_untags($page, $page_num, $page_count, $this->get_untags($page_num, $page_size));
|
||||
$t = new NotATagTable($database->raw_db());
|
||||
$t->token = $user->get_auth_token();
|
||||
$t->inputs = $_GET;
|
||||
$this->theme->display_bans($page, $t->table($t->query()), $t->paginator());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,59 +1,11 @@
|
|||
<?php
|
||||
class NotATagTheme extends Themelet
|
||||
{
|
||||
public function display_untags(Page $page, $page_number, $page_count, $bans)
|
||||
public function display_untags(Page $page, $table, $paginator)
|
||||
{
|
||||
$h_bans = "";
|
||||
foreach ($bans as $ban) {
|
||||
$h_bans .= "
|
||||
<tr>
|
||||
".make_form(make_link("untag/remove"))."
|
||||
<td width='30%'>{$ban['tag']}</td>
|
||||
<td>{$ban['redirect']}</td>
|
||||
<td width='10%'>
|
||||
<input type='hidden' name='tag' value='{$ban['tag']}'>
|
||||
<input type='submit' value='Remove'>
|
||||
</td>
|
||||
</form>
|
||||
</tr>
|
||||
";
|
||||
}
|
||||
$html = "
|
||||
<table id='image_bans' class='zebra sortable'>
|
||||
<thead>
|
||||
<th>Tag</th><th>Redirect</th><th>Action</th>
|
||||
<tr>
|
||||
<form action='".make_link("untag/list/1")."' method='GET'>
|
||||
<td><input type='text' name='tag' class='autocomplete_tags' autocomplete='off'></td>
|
||||
<td><input type='text' name='redirect'></td>
|
||||
<td><input type='submit' value='Search'></td>
|
||||
</form>
|
||||
</tr>
|
||||
</thead>
|
||||
$h_bans
|
||||
<tfoot><tr>
|
||||
".make_form(make_link("untag/add"))."
|
||||
<td><input type='text' name='tag' class='autocomplete_tags' autocomplete='off'></td>
|
||||
<td><input type='text' name='redirect'></td>
|
||||
<td><input type='submit' value='Ban'></td>
|
||||
</form>
|
||||
</tr></tfoot>
|
||||
</table>
|
||||
";
|
||||
|
||||
$prev = $page_number - 1;
|
||||
$next = $page_number + 1;
|
||||
|
||||
$h_prev = ($page_number <= 1) ? "Prev" : "<a href='".make_link("untag/list/$prev")."'>Prev</a>";
|
||||
$h_index = "<a href='".make_link()."'>Index</a>";
|
||||
$h_next = ($page_number >= $page_count) ? "Next" : "<a href='".make_link("untag/list/$next")."'>Next</a>";
|
||||
|
||||
$nav = "$h_prev | $h_index | $h_next";
|
||||
|
||||
$page->set_title("UnTags");
|
||||
$page->set_heading("UnTags");
|
||||
$page->add_block(new Block("Edit UnTags", $html));
|
||||
$page->add_block(new Block("Navigation", $nav, "left", 0));
|
||||
$this->display_paginator($page, "untag/list", null, $page_number, $page_count);
|
||||
$page->add_block(new NavBlock());
|
||||
$page->add_block(new Block("Edit UnTags", $table . $paginator));
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue