2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2019-08-07 19:53:59 +00:00
|
|
|
|
2023-01-10 22:44:09 +00:00
|
|
|
namespace Shimmie2;
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
class LinkImage extends Extension
|
|
|
|
{
|
2020-01-26 13:19:35 +00:00
|
|
|
/** @var LinkImageTheme */
|
2023-06-27 14:56:49 +00:00
|
|
|
protected Themelet $theme;
|
2020-01-26 13:19:35 +00:00
|
|
|
|
2024-01-15 11:52:35 +00:00
|
|
|
public function onDisplayingImage(DisplayingImageEvent $event): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
global $page;
|
|
|
|
$this->theme->links_block($page, $this->data($event->image));
|
|
|
|
}
|
2012-01-27 18:16:46 +00:00
|
|
|
|
2024-01-15 11:52:35 +00:00
|
|
|
public function onSetupBuilding(SetupBuildingEvent $event): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
2020-10-26 15:13:28 +00:00
|
|
|
$sb = $event->panel->create_new_block("Link to Post");
|
2019-05-28 16:59:38 +00:00
|
|
|
$sb->add_text_option("ext_link-img_text-link_format", "Text Link Format: ");
|
|
|
|
}
|
2009-05-11 14:04:33 +00:00
|
|
|
|
2024-01-15 11:52:35 +00:00
|
|
|
public function onInitExt(InitExtEvent $event): void
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
$config->set_default_string("ext_link-img_text-link_format", '$title - $id ($ext $size $filesize)');
|
|
|
|
}
|
2009-07-19 18:35:46 +00:00
|
|
|
|
2024-01-20 14:10:59 +00:00
|
|
|
/**
|
2024-01-20 20:48:47 +00:00
|
|
|
* @return array{thumb_src: string, image_src: string, post_link: string, text_link: string|null}
|
2024-01-20 14:10:59 +00:00
|
|
|
*/
|
2021-03-14 23:43:50 +00:00
|
|
|
private function data(Image $image): array
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
global $config;
|
2009-01-04 19:18:37 +00:00
|
|
|
|
2019-05-28 16:59:38 +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
|
|
|
|
2019-05-28 16:59:38 +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}")),
|
2024-01-20 14:10:59 +00:00
|
|
|
'text_link' => $text_link
|
|
|
|
];
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2007-07-13 19:11:45 +00:00
|
|
|
}
|