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/link_image/main.php

41 lines
1.3 KiB
PHP
Raw Normal View History

2020-01-26 13:19:35 +00:00
<?php declare(strict_types=1);
class LinkImage extends Extension
{
2020-01-26 13:19:35 +00:00
/** @var LinkImageTheme */
protected $theme;
public function onDisplayingImage(DisplayingImageEvent $event)
{
global $page;
$this->theme->links_block($page, $this->data($event->image));
}
public function onSetupBuilding(SetupBuildingEvent $event)
{
$sb = new SetupBlock("Link to Image");
$sb->add_text_option("ext_link-img_text-link_format", "Text Link Format: ");
$event->panel->add_block($sb);
}
public function onInitExt(InitExtEvent $event)
{
global $config;
$config->set_default_string("ext_link-img_text-link_format", '$title - $id ($ext $size $filesize)');
}
private function data(Image $image)
{
global $config;
2009-01-04 19:18:37 +00:00
$text_link = $image->parse_link_template($config->get_string("ext_link-img_text-link_format"));
$text_link = trim($text_link) == "" ? null : $text_link; // null blank setting so the url gets filled in on the text links.
2009-01-04 19:18:37 +00:00
return [
'thumb_src' => make_http($image->get_thumb_link()),
'image_src' => make_http($image->get_image_link()),
'post_link' => make_http(make_link("post/view/{$image->id}")),
'text_link' => $text_link];
}
}