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/contrib/link_image/main.php
green-ponies (jgen) 30eb5ddd8b More type hints!
2012-02-09 23:04:37 -05:00

47 lines
1.4 KiB
PHP

<?php
/*
* Name: Link to Image
* Author: Artanis <artanis.00@gmail.com>
* Description: Show various forms of link to each image, for copy & paste
*/
class LinkImage extends Extension {
public function onDisplayingImage(DisplayingImageEvent $event) {
global $page;
$this->theme->links_block($page, $this->data($event->image));
}
public function onSetupBuildingEvent(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 onInitExtEvent(InitExtEvent $event) {
global $config;
$config->set_default_string("ext_link-img_text-link_format", '$title - $id ($ext $size $filesize)');
}
private function hostify(/*string*/ $str) {
$str = str_replace(" ", "%20", $str);
if(strpos($str, "ttp://") > 0) {
return $str;
}
else {
return "http://" . $_SERVER["HTTP_HOST"] . $str;
}
}
private function data(Image $image) {
global $config;
$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.
return array(
'thumb_src' => $this->hostify($image->get_thumb_link()),
'image_src' => $this->hostify($image->get_image_link()),
'post_link' => $this->hostify($_SERVER["REQUEST_URI"]),
'text_link' => $text_link);
}
}
?>