This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/ext/regen_thumb/main.php

55 lines
1.8 KiB
PHP
Raw Normal View History

<?php
2009-08-20 22:37:17 +00:00
/*
* Name: Regen Thumb
* Author: Shish <webmaster@shishnet.org>
* Link: http://code.shishnet.org/shimmie2/
* License: GPLv2
* Description: Regenerate a thumbnail image
2009-01-16 08:18:41 +00:00
* 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 onPageRequest(PageRequestEvent $event) {
2017-06-01 19:44:17 +00:00
global $database, $page, $user;
2017-06-01 19:44:17 +00:00
if($event->page_matches("regen_thumb/one") && $user->can("delete_image") && isset($_POST['image_id'])) {
2009-07-01 23:52:24 +00:00
$image = Image::by_id(int_escape($_POST['image_id']));
send_event(new ThumbnailGenerationEvent($image->hash, $image->ext, true));
$database->cache->delete("thumb-block:{$image->id}");
2009-07-01 23:52:24 +00:00
$this->theme->display_results($page, $image);
}
2017-06-01 19:44:17 +00:00
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) {
send_event(new ThumbnailGenerationEvent($image->hash, $image->ext, true));
$database->cache->delete("thumb-block:{$image->id}");
2017-06-01 19:44:17 +00:00
}
$page->set_mode("redirect");
$page->set_redirect(make_link("post/list"));
}
2009-07-01 23:52:24 +00:00
}
public function onImageAdminBlockBuilding(ImageAdminBlockBuildingEvent $event) {
2009-07-01 23:52:24 +00:00
global $user;
2012-08-25 19:28:34 +00:00
if($user->can("delete_image")) {
2009-07-01 23:52:24 +00:00
$event->add_part($this->theme->get_buttons_html($event->image->id));
}
}
2017-06-01 19:44:17 +00:00
public function onPostListBuilding(PostListBuildingEvent $event) {
global $user;
if($user->can("delete_image") && !empty($event->search_terms)) {
$event->add_control($this->theme->mtr_html(implode(" ", $event->search_terms)));
}
}
}