ImageAction->add_button + display_crud
This commit is contained in:
parent
7da79fe2a9
commit
81a8587543
39 changed files with 139 additions and 336 deletions
|
@ -183,4 +183,13 @@ class BaseThemelet
|
|||
' >>'
|
||||
);
|
||||
}
|
||||
|
||||
public function display_crud(string $title, HTMLElement $table, HTMLElement $paginator): void
|
||||
{
|
||||
global $page;
|
||||
$page->set_title($title);
|
||||
$page->set_heading($title);
|
||||
$page->add_block(new NavBlock());
|
||||
$page->add_block(new Block("$title Table", emptyHTML($table, $paginator)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -181,6 +181,12 @@ class PageRequestEvent extends Event
|
|||
return true;
|
||||
}
|
||||
|
||||
public function authed_page_matches(string $name): bool
|
||||
{
|
||||
global $user;
|
||||
return $this->page_matches($name) && $user->check_auth_token();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the n th argument of the page request (if it exists.)
|
||||
*/
|
||||
|
|
|
@ -217,7 +217,12 @@ class Approval extends Extension
|
|||
{
|
||||
global $user, $config;
|
||||
if ($user->can(Permissions::APPROVE_IMAGE) && $config->get_bool(ApprovalConfig::IMAGES)) {
|
||||
$event->add_part($this->theme->get_image_admin_html($event->image));
|
||||
if ($event->image['approved'] === true) {
|
||||
$event->add_button("Disapprove", "disapprove_image/".$event->image->id);
|
||||
} else {
|
||||
$event->add_button("Approve", "approve_image/".$event->image->id);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,23 +12,6 @@ use function MicroHTML\{BUTTON,INPUT,P};
|
|||
|
||||
class ApprovalTheme extends Themelet
|
||||
{
|
||||
public function get_image_admin_html(Image $image): HTMLElement
|
||||
{
|
||||
if ($image['approved'] === true) {
|
||||
$form = SHM_SIMPLE_FORM(
|
||||
'disapprove_image/'.$image->id,
|
||||
SHM_SUBMIT("Disapprove")
|
||||
);
|
||||
} else {
|
||||
$form = SHM_SIMPLE_FORM(
|
||||
'approve_image/'.$image->id,
|
||||
SHM_SUBMIT("Approve")
|
||||
);
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
public function get_help_html(): HTMLElement
|
||||
{
|
||||
return emptyHTML(
|
||||
|
|
|
@ -44,7 +44,11 @@ class Favorites extends Extension
|
|||
["user_id" => $user_id, "image_id" => $image_id]
|
||||
) > 0;
|
||||
|
||||
$event->add_part($this->theme->get_voter_html($event->image, $is_favorited));
|
||||
if($is_favorited) {
|
||||
$event->add_button("Un-Favorite", "favourite/remove/{$event->image->id}");
|
||||
} else {
|
||||
$event->add_button("Favorite", "favourite/add/{$event->image->id}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,18 +63,19 @@ class Favorites extends Extension
|
|||
public function onPageRequest(PageRequestEvent $event): void
|
||||
{
|
||||
global $page, $user;
|
||||
if ($event->page_matches("change_favorite") && !$user->is_anonymous() && $user->check_auth_token()) {
|
||||
$image_id = int_escape($event->req_POST('image_id'));
|
||||
$action = $event->req_POST('favorite_action');
|
||||
if ((($action == "set") || ($action == "unset")) && ($image_id > 0)) {
|
||||
if ($action == "set") {
|
||||
send_event(new FavoriteSetEvent($image_id, $user, true));
|
||||
log_debug("favourite", "Favourite set for $image_id", "Favourite added");
|
||||
} else {
|
||||
send_event(new FavoriteSetEvent($image_id, $user, false));
|
||||
log_debug("favourite", "Favourite removed for $image_id", "Favourite removed");
|
||||
}
|
||||
}
|
||||
if ($user->is_anonymous()) {
|
||||
return;
|
||||
} // FIXME: proper permissions
|
||||
|
||||
if ($event->authed_page_matches("favourite/add")) {
|
||||
$image_id = int_escape($event->get_arg(0));
|
||||
send_event(new FavoriteSetEvent($image_id, $user, true));
|
||||
$page->set_mode(PageMode::REDIRECT);
|
||||
$page->set_redirect(make_link("post/view/$image_id"));
|
||||
}
|
||||
if ($event->authed_page_matches("favourite/remove")) {
|
||||
$image_id = int_escape($event->get_arg(0));
|
||||
send_event(new FavoriteSetEvent($image_id, $user, false));
|
||||
$page->set_mode(PageMode::REDIRECT);
|
||||
$page->set_redirect(make_link("post/view/$image_id"));
|
||||
}
|
||||
|
|
|
@ -10,18 +10,6 @@ use function MicroHTML\INPUT;
|
|||
|
||||
class FavoritesTheme extends Themelet
|
||||
{
|
||||
public function get_voter_html(Image $image, bool $is_favorited): HTMLElement
|
||||
{
|
||||
$name = $is_favorited ? "unset" : "set";
|
||||
$label = $is_favorited ? "Un-Favorite" : "Favorite";
|
||||
return SHM_SIMPLE_FORM(
|
||||
"change_favorite",
|
||||
INPUT(["type" => "hidden", "name" => "image_id", "value" => $image->id]),
|
||||
INPUT(["type" => "hidden", "name" => "favorite_action", "value" => $name]),
|
||||
INPUT(["type" => "submit", "value" => $label]),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $username_array
|
||||
*/
|
||||
|
|
|
@ -85,7 +85,7 @@ class Featured extends Extension
|
|||
{
|
||||
global $user;
|
||||
if ($user->can(Permissions::EDIT_FEATURE) && $event->context == "view") {
|
||||
$event->add_part($this->theme->get_buttons_html($event->image->id));
|
||||
$event->add_button("Feature This", "featured_image/set/{$event->image->id}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,15 +16,6 @@ class FeaturedTheme extends Themelet
|
|||
$page->add_block(new Block("Featured Post", $this->build_featured_html($image), "left", 3));
|
||||
}
|
||||
|
||||
public function get_buttons_html(int $image_id): \MicroHTML\HTMLElement
|
||||
{
|
||||
return SHM_SIMPLE_FORM(
|
||||
"featured_image/set",
|
||||
INPUT(["type" => 'hidden', "name" => 'image_id', "value" => $image_id]),
|
||||
INPUT(["type" => 'submit', "value" => 'Feature This']),
|
||||
);
|
||||
}
|
||||
|
||||
public function build_featured_html(Image $image, ?string $query = null): \MicroHTML\HTMLElement
|
||||
{
|
||||
$tsize = get_thumbnail_size($image->width, $image->height);
|
||||
|
|
|
@ -8,6 +8,8 @@ use Symfony\Component\Console\Command\Command;
|
|||
use Symfony\Component\Console\Input\{InputInterface,InputArgument};
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use function MicroHTML\{INPUT, emptyHTML};
|
||||
|
||||
require_once "config.php";
|
||||
|
||||
/**
|
||||
|
@ -15,9 +17,6 @@ require_once "config.php";
|
|||
*/
|
||||
class ImageIO extends Extension
|
||||
{
|
||||
/** @var ImageIOTheme */
|
||||
protected Themelet $theme;
|
||||
|
||||
public const COLLISION_OPTIONS = [
|
||||
'Error' => ImageConfig::COLLISION_ERROR,
|
||||
'Merge' => ImageConfig::COLLISION_MERGE
|
||||
|
@ -118,7 +117,12 @@ class ImageIO extends Extension
|
|||
global $user;
|
||||
|
||||
if ($user->can(Permissions::DELETE_IMAGE)) {
|
||||
$event->add_part($this->theme->get_deleter_html($event->image->id));
|
||||
$form = SHM_FORM("image/delete", form_id: "image_delete_form");
|
||||
$form->appendChild(emptyHTML(
|
||||
INPUT(["type" => 'hidden', "name" => 'image_id', "value" => $event->image->id]),
|
||||
INPUT(["type" => 'submit', "value" => 'Delete', "onclick" => 'return confirm("Delete the image?");', "id" => "image_delete_button"]),
|
||||
));
|
||||
$event->add_part($form);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shimmie2;
|
||||
|
||||
use function MicroHTML\{INPUT, emptyHTML};
|
||||
|
||||
class ImageIOTheme extends Themelet
|
||||
{
|
||||
/**
|
||||
* Display a link to delete an image
|
||||
* (Added inline Javascript to confirm the deletion)
|
||||
*/
|
||||
public function get_deleter_html(int $image_id): \MicroHTML\HTMLElement
|
||||
{
|
||||
$form = SHM_FORM("image/delete", form_id: "image_delete_form");
|
||||
$form->appendChild(emptyHTML(
|
||||
INPUT(["type" => 'hidden', "name" => 'image_id', "value" => $image_id]),
|
||||
INPUT(["type" => 'submit', "value" => 'Delete', "onclick" => 'return confirm("Delete the image?");', "id" => "image_delete_button"]),
|
||||
));
|
||||
return $form;
|
||||
}
|
||||
}
|
|
@ -10,6 +10,8 @@ use MicroCRUD\DateColumn;
|
|||
use MicroCRUD\TextColumn;
|
||||
use MicroCRUD\Table;
|
||||
|
||||
use function MicroHTML\{INPUT,emptyHTML};
|
||||
|
||||
class HashBanTable extends Table
|
||||
{
|
||||
public function __construct(\FFSPHP\PDO $db)
|
||||
|
@ -59,9 +61,6 @@ class AddImageHashBanEvent extends Event
|
|||
|
||||
class ImageBan extends Extension
|
||||
{
|
||||
/** @var ImageBanTheme */
|
||||
protected Themelet $theme;
|
||||
|
||||
public function onDatabaseUpgrade(DatabaseUpgradeEvent $event): void
|
||||
{
|
||||
global $database;
|
||||
|
@ -122,7 +121,7 @@ class ImageBan extends Extension
|
|||
$t = new HashBanTable($database->raw_db());
|
||||
$t->token = $user->get_auth_token();
|
||||
$t->inputs = $event->GET;
|
||||
$this->theme->display_bans($page, $t->table($t->query()), $t->paginator());
|
||||
$this->theme->display_crud("Post Bans", $t->table($t->query()), $t->paginator());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -166,7 +165,13 @@ class ImageBan extends Extension
|
|||
{
|
||||
global $user;
|
||||
if ($user->can(Permissions::BAN_IMAGE)) {
|
||||
$event->add_part($this->theme->get_buttons_html($event->image));
|
||||
$event->add_part(SHM_SIMPLE_FORM(
|
||||
"image_hash_ban/add",
|
||||
INPUT(["type" => 'hidden', "name" => 'c_hash', "value" => $event->image->hash]),
|
||||
INPUT(["type" => 'hidden', "name" => 'c_image_id', "value" => $event->image->id]),
|
||||
INPUT(["type" => 'text', "name" => 'c_reason']),
|
||||
INPUT(["type" => 'submit', "value" => 'Ban Hash and Delete Post']),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shimmie2;
|
||||
|
||||
use MicroHTML\HTMLElement;
|
||||
|
||||
use function MicroHTML\{INPUT,emptyHTML};
|
||||
|
||||
class ImageBanTheme extends Themelet
|
||||
{
|
||||
/*
|
||||
* Show all the bans
|
||||
*/
|
||||
public function display_bans(Page $page, HTMLElement $table, HTMLElement $paginator): void
|
||||
{
|
||||
$page->set_title("Post Bans");
|
||||
$page->set_heading("Post Bans");
|
||||
$page->add_block(new NavBlock());
|
||||
$page->add_block(new Block("Edit Post Bans", emptyHTML($table, $paginator)));
|
||||
}
|
||||
|
||||
/*
|
||||
* Display a link to delete an image
|
||||
*/
|
||||
public function get_buttons_html(Image $image): HTMLElement
|
||||
{
|
||||
return SHM_SIMPLE_FORM(
|
||||
"image_hash_ban/add",
|
||||
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 Post']),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -238,9 +238,6 @@ class LogTable extends Table
|
|||
|
||||
class LogDatabase extends Extension
|
||||
{
|
||||
/** @var LogDatabaseTheme */
|
||||
protected Themelet $theme;
|
||||
|
||||
public function onInitExt(InitExtEvent $event): void
|
||||
{
|
||||
global $config;
|
||||
|
@ -285,7 +282,7 @@ class LogDatabase extends Extension
|
|||
if ($user->can(Permissions::VIEW_EVENTLOG)) {
|
||||
$t = new LogTable($database->raw_db());
|
||||
$t->inputs = $event->GET;
|
||||
$this->theme->display_events($t->table($t->query()), $t->paginator());
|
||||
$this->theme->display_crud("Event Log", $t->table($t->query()), $t->paginator());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shimmie2;
|
||||
|
||||
use MicroHTML\HTMLElement;
|
||||
|
||||
use function MicroHTML\emptyHTML;
|
||||
|
||||
class LogDatabaseTheme extends Themelet
|
||||
{
|
||||
public function display_events(HTMLElement $table, HTMLElement $paginator): void
|
||||
{
|
||||
global $page;
|
||||
$page->set_title("Event Log");
|
||||
$page->set_heading("Event Log");
|
||||
$page->add_block(new NavBlock());
|
||||
$page->add_block(new Block("Events", emptyHTML($table, $paginator)));
|
||||
}
|
||||
}
|
|
@ -75,11 +75,10 @@ class Media extends Extension
|
|||
global $page, $user;
|
||||
|
||||
if (
|
||||
$event->page_matches("media_rescan/") &&
|
||||
$user->can(Permissions::RESCAN_MEDIA) &&
|
||||
$event->get_POST('image_id')
|
||||
$event->authed_page_matches("media_rescan") &&
|
||||
$user->can(Permissions::RESCAN_MEDIA)
|
||||
) {
|
||||
$image = Image::by_id(int_escape($event->get_POST('image_id')));
|
||||
$image = Image::by_id(int_escape($event->get_arg(0)));
|
||||
|
||||
send_event(new MediaCheckPropertiesEvent($image));
|
||||
$image->save_to_db();
|
||||
|
@ -118,7 +117,7 @@ class Media extends Extension
|
|||
{
|
||||
global $user;
|
||||
if ($user->can(Permissions::DELETE_IMAGE)) {
|
||||
$event->add_part($this->theme->get_buttons_html($event->image->id));
|
||||
$event->add_button("Scan Media Properties", "media_rescan/{$event->image->id}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,19 +4,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace Shimmie2;
|
||||
|
||||
use function MicroHTML\INPUT;
|
||||
|
||||
class MediaTheme extends Themelet
|
||||
{
|
||||
public function get_buttons_html(int $image_id): \MicroHTML\HTMLElement
|
||||
{
|
||||
return SHM_SIMPLE_FORM(
|
||||
"media_rescan/",
|
||||
INPUT(["type" => 'hidden', "name" => 'image_id', "value" => $image_id]),
|
||||
SHM_SUBMIT('Scan Media Properties'),
|
||||
);
|
||||
}
|
||||
|
||||
public function get_help_html(): string
|
||||
{
|
||||
return '<p>Search for posts based on the type of media.</p>
|
||||
|
|
|
@ -32,9 +32,6 @@ class NotATagTable extends Table
|
|||
|
||||
class NotATag extends Extension
|
||||
{
|
||||
/** @var NotATagTheme */
|
||||
protected Themelet $theme;
|
||||
|
||||
public function get_priority(): int
|
||||
{
|
||||
return 30;
|
||||
|
@ -154,7 +151,7 @@ class NotATag extends Extension
|
|||
$t = new NotATagTable($database->raw_db());
|
||||
$t->token = $user->get_auth_token();
|
||||
$t->inputs = $event->GET;
|
||||
$this->theme->display_untags($page, $t->table($t->query()), $t->paginator());
|
||||
$this->theme->display_crud("UnTags", $t->table($t->query()), $t->paginator());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shimmie2;
|
||||
|
||||
use MicroHTML\HTMLElement;
|
||||
|
||||
use function MicroHTML\emptyHTML;
|
||||
|
||||
class NotATagTheme extends Themelet
|
||||
{
|
||||
public function display_untags(Page $page, HTMLElement $table, HTMLElement $paginator): void
|
||||
{
|
||||
$page->set_title("UnTags");
|
||||
$page->set_heading("UnTags");
|
||||
$page->add_block(new NavBlock());
|
||||
$page->add_block(new Block("Edit UnTags", emptyHTML($table, $paginator)));
|
||||
}
|
||||
}
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace Shimmie2;
|
||||
|
||||
use function MicroHTML\{INPUT};
|
||||
|
||||
abstract class PoolsConfig
|
||||
{
|
||||
public const MAX_IMPORT_RESULTS = "poolsMaxImportResults";
|
||||
|
@ -523,7 +525,13 @@ class Pools extends Extension
|
|||
$pools = $database->get_pairs("SELECT id,title FROM pools WHERE user_id=:id ORDER BY title", ["id" => $user->id]);
|
||||
}
|
||||
if (count($pools) > 0) {
|
||||
$event->add_part($this->theme->get_adder_html($event->image, $pools));
|
||||
$html = SHM_SIMPLE_FORM(
|
||||
"pool/add_post",
|
||||
SHM_SELECT("pool_id", $pools),
|
||||
INPUT(["type" => "hidden", "name" => "image_id", "value" => $event->image->id]),
|
||||
SHM_SUBMIT("Add Post to Pool")
|
||||
);
|
||||
$event->add_part($html);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,19 +47,6 @@ class PoolsTheme extends Themelet
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, string> $pools
|
||||
*/
|
||||
public function get_adder_html(Image $image, array $pools): HTMLElement
|
||||
{
|
||||
return SHM_SIMPLE_FORM(
|
||||
"pool/add_post",
|
||||
SHM_SELECT("pool_id", $pools),
|
||||
INPUT(["type" => "hidden", "name" => "image_id", "value" => $image->id]),
|
||||
SHM_SUBMIT("Add Post to Pool")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* HERE WE SHOWS THE LIST OF POOLS.
|
||||
*
|
||||
|
|
|
@ -212,7 +212,11 @@ class PrivateImage extends Extension
|
|||
{
|
||||
global $user;
|
||||
if (($user->can(Permissions::SET_PRIVATE_IMAGE) && $user->id == $event->image->owner_id) || $user->can(Permissions::SET_OTHERS_PRIVATE_IMAGES)) {
|
||||
$event->add_part($this->theme->get_image_admin_html($event->image));
|
||||
if ($event->image['private'] === false) {
|
||||
$event->add_button("Make Private", "privatize_image/".$event->image->id);
|
||||
} else {
|
||||
$event->add_button("Make Public", "publicize_image/".$event->image->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,23 +8,6 @@ use function MicroHTML\INPUT;
|
|||
|
||||
class PrivateImageTheme extends Themelet
|
||||
{
|
||||
public function get_image_admin_html(Image $image): \MicroHTML\HTMLElement
|
||||
{
|
||||
if ($image['private'] === false) {
|
||||
$html = SHM_SIMPLE_FORM(
|
||||
'privatize_image/'.$image->id,
|
||||
SHM_SUBMIT("Make Private")
|
||||
);
|
||||
} else {
|
||||
$html = SHM_SIMPLE_FORM(
|
||||
'publicize_image/'.$image->id,
|
||||
SHM_SUBMIT("Make Public")
|
||||
);
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function get_help_html(): string
|
||||
{
|
||||
return '<p>Search for posts that are private/public.</p>
|
||||
|
|
|
@ -22,8 +22,8 @@ class RegenThumb extends Extension
|
|||
global $page, $user;
|
||||
|
||||
if ($event->page_matches("regen_thumb") && $user->can(Permissions::DELETE_IMAGE)) {
|
||||
if ($event->page_matches("regen_thumb/one")) {
|
||||
$image = Image::by_id(int_escape($event->req_POST('image_id')));
|
||||
if ($event->authed_page_matches("regen_thumb/one")) {
|
||||
$image = Image::by_id(int_escape($event->get_arg(0)));
|
||||
|
||||
$this->regenerate_thumbnail($image);
|
||||
|
||||
|
@ -47,7 +47,7 @@ class RegenThumb extends Extension
|
|||
{
|
||||
global $user;
|
||||
if ($user->can(Permissions::DELETE_IMAGE)) {
|
||||
$event->add_part($this->theme->get_buttons_html($event->image->id));
|
||||
$event->add_button("Regenerate Thumbnail", "regen_thumb/one/{$event->image->id}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ class RegenThumbTest extends ShimmiePHPUnitTestCase
|
|||
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pbx computer screenshot");
|
||||
$this->get_page("post/view/$image_id");
|
||||
|
||||
$this->post_page("regen_thumb/one", ['image_id' => $image_id]);
|
||||
$this->post_page("regen_thumb/one/$image_id");
|
||||
$this->assert_title("Thumbnail Regenerated");
|
||||
|
||||
# FIXME: test that the thumb's modified time has been updated
|
||||
|
|
|
@ -8,18 +8,6 @@ use function MicroHTML\INPUT;
|
|||
|
||||
class RegenThumbTheme extends Themelet
|
||||
{
|
||||
/**
|
||||
* Show a form which offers to regenerate the thumb of an image with ID #$image_id
|
||||
*/
|
||||
public function get_buttons_html(int $image_id): \MicroHTML\HTMLElement
|
||||
{
|
||||
return SHM_SIMPLE_FORM(
|
||||
"regen_thumb/one",
|
||||
INPUT(["type" => 'hidden', "name" => 'image_id', "value" => $image_id]),
|
||||
SHM_SUBMIT('Regenerate Thumbnail')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a link to the new thumbnail.
|
||||
*/
|
||||
|
|
|
@ -51,7 +51,7 @@ class ReplaceFile extends Extension
|
|||
|
||||
/* In the future, could perhaps allow users to replace images that they own as well... */
|
||||
if ($user->can(Permissions::REPLACE_IMAGE)) {
|
||||
$event->add_part($this->theme->get_replace_html($event->image->id));
|
||||
$event->add_button("Replace", "replace/{$event->image->id}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -63,16 +63,6 @@ class ReplaceFileTheme extends Themelet
|
|||
$page->add_block(new Block("Upload Replacement File", $html, "main", 20));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display link to replace the image
|
||||
*/
|
||||
public function get_replace_html(int $image_id): \MicroHTML\HTMLElement
|
||||
{
|
||||
$form = SHM_FORM("replace/$image_id", "GET");
|
||||
$form->appendChild(INPUT(["type" => 'submit', "value" => 'Replace']));
|
||||
return $form;
|
||||
}
|
||||
|
||||
protected function get_accept(): string
|
||||
{
|
||||
return ".".join(",.", DataHandlerExtension::get_all_supported_exts());
|
||||
|
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace Shimmie2;
|
||||
|
||||
use function MicroHTML\{rawHTML};
|
||||
|
||||
abstract class ResizeConfig
|
||||
{
|
||||
public const ENABLED = 'resize_enabled';
|
||||
|
@ -45,10 +47,28 @@ class ResizeImage extends Extension
|
|||
public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event): void
|
||||
{
|
||||
global $user, $config;
|
||||
if ($user->can(Permissions::EDIT_FILES) && $config->get_bool(ResizeConfig::ENABLED)
|
||||
&& $this->can_resize_mime($event->image->get_mime())) {
|
||||
if (
|
||||
$user->can(Permissions::EDIT_FILES) &&
|
||||
$config->get_bool(ResizeConfig::ENABLED) &&
|
||||
$this->can_resize_mime($event->image->get_mime())
|
||||
) {
|
||||
/* Add a link to resize the image */
|
||||
$event->add_part($this->theme->get_resize_html($event->image));
|
||||
global $config;
|
||||
|
||||
$default_width = $config->get_int(ResizeConfig::DEFAULT_WIDTH, $event->image->width);
|
||||
$default_height = $config->get_int(ResizeConfig::DEFAULT_HEIGHT, $event->image->height);
|
||||
|
||||
$event->add_part(SHM_SIMPLE_FORM(
|
||||
"resize/{$event->image->id}",
|
||||
rawHTML("
|
||||
<input id='original_width' name='original_width' type='hidden' value='{$event->image->width}'>
|
||||
<input id='original_height' name='original_height' type='hidden' value='{$event->image->height}'>
|
||||
<input id='resize_width' style='width: 70px;' name='resize_width' type='number' min='1' value='".$default_width."'> x
|
||||
<input id='resize_height' style='width: 70px;' name='resize_height' type='number' min='1' value='".$default_height."'>
|
||||
<br><label><input type='checkbox' id='resize_aspect' name='resize_aspect' style='max-width: 20px;' checked='checked'> Keep Aspect</label>
|
||||
<br><input id='resizebutton' type='submit' value='Resize'>
|
||||
")
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,7 +141,7 @@ class ResizeImage extends Extension
|
|||
{
|
||||
global $page, $user;
|
||||
|
||||
if ($event->page_matches("resize") && $user->can(Permissions::EDIT_FILES)) {
|
||||
if ($event->authed_page_matches("resize") && $user->can(Permissions::EDIT_FILES)) {
|
||||
// Try to get the image ID
|
||||
$image_id = int_escape(null_throws($event->get_arg(0)));
|
||||
$image = Image::by_id($image_id);
|
||||
|
|
|
@ -8,37 +8,6 @@ use function MicroHTML\{rawHTML};
|
|||
|
||||
class ResizeImageTheme extends Themelet
|
||||
{
|
||||
/*
|
||||
* Display a link to resize an image
|
||||
*/
|
||||
public function get_resize_html(Image $image): \MicroHTML\HTMLElement
|
||||
{
|
||||
global $config;
|
||||
|
||||
$default_width = $config->get_int(ResizeConfig::DEFAULT_WIDTH);
|
||||
$default_height = $config->get_int(ResizeConfig::DEFAULT_HEIGHT);
|
||||
|
||||
if (!$default_width) {
|
||||
$default_width = $image->width;
|
||||
}
|
||||
if (!$default_height) {
|
||||
$default_height = $image->height;
|
||||
}
|
||||
|
||||
$html = rawHTML("
|
||||
".make_form(make_link("resize/{$image->id}"))."
|
||||
<input id='original_width' name='original_width' type='hidden' value='{$image->width}'>
|
||||
<input id='original_height' name='original_height' type='hidden' value='{$image->height}'>
|
||||
<input id='resize_width' style='width: 70px;' name='resize_width' type='number' min='1' value='".$default_width."'> x
|
||||
<input id='resize_height' style='width: 70px;' name='resize_height' type='number' min='1' value='".$default_height."'>
|
||||
<br><label><input type='checkbox' id='resize_aspect' name='resize_aspect' style='max-width: 20px;' checked='checked'> Keep Aspect</label>
|
||||
<br><input id='resizebutton' type='submit' value='Resize'>
|
||||
</form>
|
||||
");
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function display_resize_error(Page $page, string $title, string $message): void
|
||||
{
|
||||
$page->set_title("Resize Image");
|
||||
|
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace Shimmie2;
|
||||
|
||||
use function MicroHTML\{INPUT};
|
||||
|
||||
// TODO Add warning that rotate doesn't support lossless webp output
|
||||
|
||||
/**
|
||||
|
@ -36,7 +38,11 @@ class RotateImage extends Extension
|
|||
if ($user->can(Permissions::EDIT_FILES) && $config->get_bool("rotate_enabled")
|
||||
&& MimeType::matches_array($event->image->get_mime(), self::SUPPORTED_MIME)) {
|
||||
/* Add a link to rotate the image */
|
||||
$event->add_part($this->theme->get_rotate_html($event->image->id));
|
||||
$event->add_part(SHM_SIMPLE_FORM(
|
||||
'rotate/'.$event->image->id,
|
||||
INPUT(["type" => 'number', "name" => 'rotate_deg', "id" => "rotate_deg", "placeholder" => "Rotation degrees"]),
|
||||
INPUT(["type" => 'submit', "value" => 'Rotate', "id" => "rotatebutton"]),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,7 +59,7 @@ class RotateImage extends Extension
|
|||
{
|
||||
global $page, $user;
|
||||
|
||||
if ($event->page_matches("rotate") && $user->can(Permissions::EDIT_FILES)) {
|
||||
if ($event->authed_page_matches("rotate") && $user->can(Permissions::EDIT_FILES)) {
|
||||
// Try to get the image ID
|
||||
$image_id = int_escape(null_throws($event->get_arg(0)));
|
||||
$image = Image::by_id($image_id);
|
||||
|
|
|
@ -4,22 +4,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace Shimmie2;
|
||||
|
||||
use function MicroHTML\INPUT;
|
||||
|
||||
class RotateImageTheme extends Themelet
|
||||
{
|
||||
/**
|
||||
* Display a link to rotate an image.
|
||||
*/
|
||||
public function get_rotate_html(int $image_id): \MicroHTML\HTMLElement
|
||||
{
|
||||
return SHM_SIMPLE_FORM(
|
||||
'rotate/'.$image_id,
|
||||
INPUT(["type" => 'number', "name" => 'rotate_deg', "id" => "rotate_deg", "placeholder" => "Rotation degrees"]),
|
||||
INPUT(["type" => 'submit', "value" => 'Rotate', "id" => "rotatebutton"]),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the error.
|
||||
*/
|
||||
|
|
|
@ -130,11 +130,10 @@ class S3 extends Extension
|
|||
{
|
||||
global $config, $page, $user;
|
||||
if (
|
||||
$event->page_matches("s3/sync") &&
|
||||
$user->can(Permissions::DELETE_IMAGE) &&
|
||||
$user->check_auth_token()
|
||||
$event->authed_page_matches("s3/sync") &&
|
||||
$user->can(Permissions::DELETE_IMAGE)
|
||||
) {
|
||||
$id = int_escape($event->req_POST('image_id'));
|
||||
$id = int_escape($event->get_arg(0));
|
||||
$this->sync_post(Image::by_id($id));
|
||||
log_info("s3", "Manual resync for >>$id", "File re-sync'ed");
|
||||
$page->set_mode(PageMode::REDIRECT);
|
||||
|
@ -146,11 +145,7 @@ class S3 extends Extension
|
|||
{
|
||||
global $user;
|
||||
if ($user->can(Permissions::DELETE_IMAGE)) {
|
||||
$event->add_part(SHM_SIMPLE_FORM(
|
||||
"s3/sync",
|
||||
INPUT(["type" => 'hidden', "name" => 'image_id', "value" => $event->image->id]),
|
||||
INPUT(["type" => 'submit', "value" => 'CDN Re-Sync']),
|
||||
));
|
||||
$event->add_button("CDN Re-Sync", "s3/sync/{$event->image->id}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -58,11 +58,7 @@ class SourceHistory extends Extension
|
|||
|
||||
public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event): void
|
||||
{
|
||||
$event->add_part(rawHTML("
|
||||
<form action='".make_link("source_history/{$event->image->id}")."' method='GET'>
|
||||
<input type='submit' value='View Source History'>
|
||||
</form>
|
||||
"), 20);
|
||||
$event->add_button("View Source History", "source_history/{$event->image->id}", 20);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -52,11 +52,7 @@ class TagHistory extends Extension
|
|||
|
||||
public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event): void
|
||||
{
|
||||
$event->add_part(rawHTML("
|
||||
<form action='".make_link("tag_history/{$event->image->id}")."' method='GET'>
|
||||
<input type='submit' value='View Tag History'>
|
||||
</form>
|
||||
"), 20);
|
||||
$event->add_button("View Tag History", "tag_history/{$event->image->id}", 20);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -153,7 +153,7 @@ class Trash extends Extension
|
|||
{
|
||||
global $user;
|
||||
if ($event->image['trash'] === true && $user->can(Permissions::VIEW_TRASH)) {
|
||||
$event->add_part($this->theme->get_image_admin_html($event->image->id));
|
||||
$event->add_button("Restore From Trash", "trash_restore/".$event->image->id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,15 +8,6 @@ use function MicroHTML\INPUT;
|
|||
|
||||
class TrashTheme extends Themelet
|
||||
{
|
||||
public function get_image_admin_html(int $image_id): \MicroHTML\HTMLElement
|
||||
{
|
||||
return SHM_SIMPLE_FORM(
|
||||
'trash_restore/'.$image_id,
|
||||
INPUT(["type" => 'submit', "value" => 'Restore From Trash']),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function get_help_html(): string
|
||||
{
|
||||
return '<p>Search for posts in the trash.</p>
|
||||
|
|
|
@ -200,7 +200,7 @@ class UserPage extends Extension
|
|||
// $t->columns[] = $col;
|
||||
array_splice($t->columns, 2, 0, [$col]);
|
||||
}
|
||||
$this->theme->display_user_list($page, $t->table($t->query()), $t->paginator());
|
||||
$this->theme->display_crud("Users", $t->table($t->query()), $t->paginator());
|
||||
} elseif ($event->get_arg(0) == "classes") {
|
||||
$this->theme->display_user_classes(
|
||||
$page,
|
||||
|
|
|
@ -36,14 +36,6 @@ class UserPageTheme extends Themelet
|
|||
));
|
||||
}
|
||||
|
||||
public function display_user_list(Page $page, HTMLElement $table, HTMLElement $paginator): void
|
||||
{
|
||||
$page->set_title("User List");
|
||||
$page->set_heading("User List");
|
||||
$page->add_block(new NavBlock());
|
||||
$page->add_block(new Block("Users", emptyHTML($table, $paginator)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, array{name: string|HTMLElement, link: string}> $parts
|
||||
*/
|
||||
|
|
|
@ -6,6 +6,8 @@ namespace Shimmie2;
|
|||
|
||||
use MicroHTML\HTMLElement;
|
||||
|
||||
use function MicroHTML\{FORM,INPUT};
|
||||
|
||||
class ImageAdminBlockBuildingEvent extends Event
|
||||
{
|
||||
/** @var HTMLElement[] */
|
||||
|
@ -29,4 +31,18 @@ class ImageAdminBlockBuildingEvent extends Event
|
|||
}
|
||||
$this->parts[$position] = $html;
|
||||
}
|
||||
|
||||
public function add_button(string $name, string $path, int $position = 50): void
|
||||
{
|
||||
$this->add_part(
|
||||
SHM_SIMPLE_FORM(
|
||||
make_link($path),
|
||||
INPUT([
|
||||
"type" => "submit",
|
||||
"value" => $name,
|
||||
])
|
||||
),
|
||||
$position
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue