2020-02-01 18:22:08 +00:00
|
|
|
<?php
|
2021-12-14 18:32:47 +00:00
|
|
|
|
2023-01-10 21:21:26 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2023-01-10 22:44:09 +00:00
|
|
|
namespace Shimmie2;
|
|
|
|
|
2023-06-27 13:10:53 +00:00
|
|
|
use MicroHTML\HTMLElement;
|
|
|
|
|
|
|
|
use function MicroHTML\{A,BR,DIV,IMG,SPAN,rawHTML};
|
|
|
|
|
2020-02-01 18:22:08 +00:00
|
|
|
class Themelet extends BaseThemelet
|
|
|
|
{
|
2023-06-27 13:10:53 +00:00
|
|
|
public function build_thumb_html(Image $image): HTMLElement
|
2020-02-01 18:22:08 +00:00
|
|
|
{
|
2020-03-13 09:23:54 +00:00
|
|
|
global $cache, $config;
|
2020-02-01 18:22:08 +00:00
|
|
|
|
|
|
|
$cached = $cache->get("thumb-block:{$image->id}");
|
2023-02-02 16:50:09 +00:00
|
|
|
if (!is_null($cached)) {
|
2023-06-27 13:10:53 +00:00
|
|
|
return rawHTML($cached);
|
2020-02-01 18:22:08 +00:00
|
|
|
}
|
|
|
|
|
2023-06-27 13:10:53 +00:00
|
|
|
$id = $image->id;
|
|
|
|
$view_link = make_link('post/view/'.$id);
|
|
|
|
$image_link = $image->get_image_link();
|
|
|
|
$thumb_link = $image->get_thumb_link();
|
|
|
|
$tip = $image->get_tooltip();
|
|
|
|
$tags = strtolower($image->get_tag_list());
|
|
|
|
$ext = strtolower($image->get_ext());
|
2020-03-13 09:23:54 +00:00
|
|
|
|
2020-02-01 18:22:08 +00:00
|
|
|
// If file is flash or svg then sets thumbnail to max size.
|
2020-06-14 16:05:55 +00:00
|
|
|
if ($image->get_mime() === MimeType::FLASH || $image->get_mime() === MimeType::SVG) {
|
2020-02-01 18:22:08 +00:00
|
|
|
$tsize = get_thumbnail_size($config->get_int('thumb_width'), $config->get_int('thumb_height'));
|
|
|
|
} else {
|
|
|
|
$tsize = get_thumbnail_size($image->width, $image->height);
|
|
|
|
}
|
|
|
|
|
2023-06-27 13:10:53 +00:00
|
|
|
$html = DIV(
|
2023-11-11 21:49:12 +00:00
|
|
|
['class' => 'shm-thumb thumb', 'data-ext' => $ext, 'data-tags' => $tags, 'data-post-id' => $id],
|
2023-06-27 13:10:53 +00:00
|
|
|
A(
|
2023-11-11 21:49:12 +00:00
|
|
|
['class' => 'shm-thumb-link', 'href' => $view_link],
|
|
|
|
IMG(['id' => "thumb_$id", 'title' => $tip, 'alt' => $tip, 'height' => $tsize[1], 'width' => $tsize[0], 'src' => $thumb_link, 'loading' => 'lazy'])
|
2023-06-27 13:10:53 +00:00
|
|
|
),
|
|
|
|
BR(),
|
2023-11-11 21:49:12 +00:00
|
|
|
A(['href' => $image_link], 'File Only'),
|
|
|
|
SPAN(['class' => 'need-del'], ' - ', A(['href' => '#', 'onclick' => "image_hash_ban($id); return false;"], 'Ban'))
|
2023-06-27 13:10:53 +00:00
|
|
|
);
|
2020-02-01 18:22:08 +00:00
|
|
|
|
|
|
|
// cache for ages; will be cleared in ext/index:onImageInfoSet
|
2023-06-27 13:10:53 +00:00
|
|
|
$cache->set("thumb-block:{$image->id}", (string)$html, rand(43200, 86400));
|
2020-02-01 18:22:08 +00:00
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
}
|