[file handlers] separate out display_image and display_metadata

This commit is contained in:
Shish 2024-01-01 20:21:51 +00:00
parent 8755298ee9
commit aea533b345
7 changed files with 36 additions and 16 deletions

View file

@ -374,10 +374,13 @@ abstract class DataHandlerExtension extends Extension
public function onDisplayingImage(DisplayingImageEvent $event)
{
global $page;
global $config, $page;
if ($this->supported_mime($event->image->get_mime())) {
// @phpstan-ignore-next-line
$this->theme->display_image($page, $event->image);
$this->theme->display_image($event->image);
if ($config->get_bool(ImageConfig::SHOW_META) && method_exists($this->theme, "display_metadata")) {
$this->theme->display_metadata($event->image);
}
}
}

View file

@ -6,8 +6,9 @@ namespace Shimmie2;
class CBZFileHandlerTheme extends Themelet
{
public function display_image(Page $page, Image $image)
public function display_image(Image $image)
{
global $page;
$data_href = get_base_href();
$ilink = $image->get_image_link();
$html = "

View file

@ -6,8 +6,9 @@ namespace Shimmie2;
class IcoFileHandlerTheme extends Themelet
{
public function display_image(Page $page, Image $image)
public function display_image(Image $image)
{
global $page;
$ilink = $image->get_image_link();
$html = "
<img id='main_image' class='shm-main-image' alt='main image' src='$ilink'

View file

@ -6,8 +6,9 @@ namespace Shimmie2;
class MP3FileHandlerTheme extends Themelet
{
public function display_image(Page $page, Image $image)
public function display_image(Image $image)
{
global $page;
$data_href = get_base_href();
$ilink = $image->get_image_link();
$html = "

View file

@ -4,14 +4,31 @@ declare(strict_types=1);
namespace Shimmie2;
use function MicroHTML\IMG;
class PixelFileHandlerTheme extends Themelet
{
public function display_image(Page $page, Image $image)
public function display_image(Image $image)
{
global $config;
global $config, $page;
$u_ilink = $image->get_image_link();
if ($config->get_bool(ImageConfig::SHOW_META) && function_exists(ImageIO::EXIF_READ_FUNCTION)) {
$html = IMG([
'alt' => 'main image',
'class' => 'shm-main-image',
'id' => 'main_image',
'src' => $image->get_image_link(),
'data-width' => $image->width,
'data-height' => $image->height,
'data-mime' => $image->get_mime(),
]);
$page->add_block(new Block("Image", $html, "main", 10));
}
public function display_metadata(Image $image)
{
global $page;
if (function_exists(ImageIO::EXIF_READ_FUNCTION)) {
# FIXME: only read from jpegs?
$exif = @exif_read_data($image->get_image_filename(), "IFD0", true);
if ($exif) {
@ -32,9 +49,5 @@ class PixelFileHandlerTheme extends Themelet
}
}
}
$html = "<img alt='main image' class='shm-main-image' id='main_image' src='$u_ilink' ".
"data-width='{$image->width}' data-height='{$image->height}' data-mime='{$image->get_mime()}'>";
$page->add_block(new Block("Image", $html, "main", 10));
}
}

View file

@ -6,8 +6,9 @@ namespace Shimmie2;
class SVGFileHandlerTheme extends Themelet
{
public function display_image(Page $page, Image $image)
public function display_image(Image $image)
{
global $page;
$ilink = make_link("get_svg/{$image->id}/{$image->id}.svg");
// $ilink = $image->get_image_link();
$html = "

View file

@ -8,9 +8,9 @@ use function MicroHTML\{A, BR, VIDEO, SOURCE, emptyHTML};
class VideoFileHandlerTheme extends Themelet
{
public function display_image(Page $page, Image $image)
public function display_image(Image $image)
{
global $config;
global $config, $page;
$width = "auto";
if ($image->width > 1) {