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/themes/rule34v2/themelet.class.php

54 lines
1.8 KiB
PHP
Raw Normal View History

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);
namespace Shimmie2;
use MicroHTML\HTMLElement;
use function MicroHTML\{A,BR,DIV,IMG,SPAN,rawHTML};
2020-02-01 18:22:08 +00:00
class Themelet extends BaseThemelet
{
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)) {
return rawHTML($cached);
2020-02-01 18:22:08 +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);
}
$html = DIV(
2023-11-11 21:49:12 +00:00
['class' => 'shm-thumb thumb', 'data-ext' => $ext, 'data-tags' => $tags, 'data-post-id' => $id],
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'])
),
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'))
);
2020-02-01 18:22:08 +00:00
// cache for ages; will be cleared in ext/index:onImageInfoSet
$cache->set("thumb-block:{$image->id}", (string)$html, rand(43200, 86400));
2020-02-01 18:22:08 +00:00
return $html;
}
}