2007-07-13 19:11:45 +00:00
|
|
|
<?php
|
2009-08-20 22:37:17 +00:00
|
|
|
/*
|
2007-12-04 18:20:46 +00:00
|
|
|
* Name: Link to Image
|
|
|
|
* Author: Artanis <artanis.00@gmail.com>
|
|
|
|
* Description: Show various forms of link to each image, for copy & paste
|
|
|
|
*/
|
2012-02-08 12:07:01 +00:00
|
|
|
class LinkImage extends Extension {
|
2012-02-08 11:24:25 +00:00
|
|
|
public function onDisplayingImage(DisplayingImageEvent $event) {
|
|
|
|
global $page;
|
|
|
|
$this->theme->links_block($page, $this->data($event->image));
|
|
|
|
}
|
2012-01-27 18:16:46 +00:00
|
|
|
|
2012-02-08 11:24:25 +00:00
|
|
|
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);
|
|
|
|
}
|
2009-05-11 14:04:33 +00:00
|
|
|
|
2012-02-08 11:24:25 +00:00
|
|
|
public function onInitExtEvent(InitExtEvent $event) {
|
|
|
|
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
|
|
|
|
|
|
|
private function hostify($str) {
|
|
|
|
$str = str_replace(" ", "%20", $str);
|
|
|
|
if(strpos($str, "ttp://") > 0) {
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return "http://" . $_SERVER["HTTP_HOST"] . $str;
|
|
|
|
}
|
|
|
|
}
|
2012-02-08 11:24:25 +00:00
|
|
|
|
|
|
|
private function data(Image $image) {
|
2007-07-13 19:11:45 +00:00
|
|
|
global $config;
|
2009-01-04 19:18:37 +00:00
|
|
|
|
2007-07-16 06:52:31 +00:00
|
|
|
$text_link = $image->parse_link_template($config->get_string("ext_link-img_text-link_format"));
|
2009-07-19 18:35:46 +00:00
|
|
|
$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
|
|
|
|
2007-07-13 19:11:45 +00:00
|
|
|
return array(
|
2009-07-19 18:35:46 +00:00
|
|
|
'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);
|
2007-07-13 19:11:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|