94 lines
2.9 KiB
PHP
94 lines
2.9 KiB
PHP
<?php
|
|
/*
|
|
* Name: Regen Thumb
|
|
* Author: Shish <webmaster@shishnet.org>
|
|
* Link: http://code.shishnet.org/shimmie2/
|
|
* License: GPLv2
|
|
* Description: Regenerate a thumbnail image
|
|
* Documentation:
|
|
* This adds a button in the image control section on an
|
|
* image's view page, which allows an admin to regenerate
|
|
* an image's thumbnail; useful for instance if the first
|
|
* attempt failed due to lack of memory, and memory has
|
|
* since been increased.
|
|
*/
|
|
|
|
class RegenThumb extends Extension
|
|
{
|
|
public function regenerate_thumbnail($image)
|
|
{
|
|
global $database;
|
|
|
|
send_event(new ThumbnailGenerationEvent($image->hash, $image->ext, true));
|
|
$database->cache->delete("thumb-block:{$image->id}");
|
|
}
|
|
|
|
public function onPageRequest(PageRequestEvent $event)
|
|
{
|
|
global $database, $page, $user;
|
|
|
|
if ($event->page_matches("regen_thumb/one") && $user->can("delete_image") && isset($_POST['image_id'])) {
|
|
$image = Image::by_id(int_escape($_POST['image_id']));
|
|
|
|
$this->regenerate_thumbnail($image);
|
|
|
|
$this->theme->display_results($page, $image);
|
|
}
|
|
if ($event->page_matches("regen_thumb/mass") && $user->can("delete_image") && isset($_POST['tags'])) {
|
|
$tags = Tag::explode(strtolower($_POST['tags']), false);
|
|
$images = Image::find_images(0, 10000, $tags);
|
|
|
|
foreach ($images as $image) {
|
|
$this->regenerate_thumbnail($image);
|
|
}
|
|
|
|
$page->set_mode("redirect");
|
|
$page->set_redirect(make_link("post/list"));
|
|
}
|
|
}
|
|
|
|
public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event)
|
|
{
|
|
global $user;
|
|
if ($user->can("delete_image")) {
|
|
$event->add_part($this->theme->get_buttons_html($event->image->id));
|
|
}
|
|
}
|
|
|
|
// public function onPostListBuilding(PostListBuildingEvent $event)
|
|
// {
|
|
// global $user;
|
|
// if ($user->can("delete_image") && !empty($event->search_terms)) {
|
|
// $event->add_control($this->theme->mtr_html(Tag::implode($event->search_terms)));
|
|
// }
|
|
// }
|
|
|
|
public function onBulkActionBlockBuilding(BulkActionBlockBuildingEvent $event)
|
|
{
|
|
global $user;
|
|
|
|
if ($user->can("delete_image")) {
|
|
$event->add_action("Regen Thumbnails");
|
|
}
|
|
|
|
}
|
|
|
|
public function onBulkAction(BulkActionEvent $event)
|
|
{
|
|
global $user;
|
|
|
|
switch($event->action) {
|
|
case "Regen Thumbnails":
|
|
if ($user->can("delete_image")) {
|
|
$total = 0;
|
|
foreach ($event->items as $image) {
|
|
$this->regenerate_thumbnail($image);
|
|
$total++;
|
|
}
|
|
flash_message("Regenerated thumbnails for $total items");
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|