git-svn-id: file:///home/shish/svn/shimmie2/trunk@274 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
Artanis
2007-07-13 19:11:45 +00:00
parent 8a2c7283a9
commit b010709e2d
5 changed files with 129 additions and 172 deletions

View File

@@ -1,72 +1,44 @@
<?php
/*
* This file may not be distributed without its readme.txt
**/
class LinkImage extends Extension {
//event handler
public function receive_event($event) {
if(is_a($event, 'DisplayingImageEvent')) {
global $page;
global $config;
$data_href = $config->get_string("data_href");
$page->add_header("<link rel='stylesheet' href='$data_href/ext/link_image/_style.css' type='text/css'>",0);
$page->add_block(new Block("Link to Image", $this->get_html($event->image)));
}
if(is_a($event, 'SetupBuildingEvent')) {
$sb = new SetupBlock("Link to Image");
$sb->add_text_option("ext_link-img_text-link_format","Text Link Format:");
$event->panel->add_block($sb);
}
if(is_a($event, 'InitExtEvent')) {
global $config;
//just set default if empty.
if ($config->get_string("ext_link-img_text-link_format") == "") {
$config->set_string("ext_link-img_text-link_format", '$title - $id ($ext $size $filesize)');
}
}
}
private function get_html($image) {
global $config;
$thumb_src = $image->get_thumb_link();
$image_src = $image->get_image_link();
$post_link = $image->get_short_link();
$text_link = $this->parse_link_template($config->get_string("ext_link-img_text-link_format"),$image);
$html = "";
if($this->get_HTML_PHP()) {
$html_gen = new LinkImageHTML($post_link, $image_src, $thumb_src, $text_link);
$html = $html_gen->getHTML();
}
return $html;
}
/* This function would do better generalized in the Extension class instead *
* of repeated in every extension. And probaly renamed, too... *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
private function get_HTML_PHP() {
global $config;
$theme = $config->get_string("theme");
if(file_exists("themes/$theme/link_image.html.php")) {
//$html .= "Using theme version";
include "themes/$theme/link_image.html.php";
} else if(file_exists("ext/link_image/link_image.html.php")) {
include "ext/link_image/link_image.html.php";
//$html .= "Using default generation in absense of themed generation.";
} else {
echo "<b>[Link to Image]<b> Error: <b>link_image.html.php</b> not found at either <b>ext/link_image/link_image.html.php</b> nor <b>themes/$theme/link_image.html.php</b>.<br/>".
"Please restore the default file to the former location, and copy it over to the latter if you wish to edit the html output of this extension.";
return false;
}
return true;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
<?php
class LinkImage extends Extension {
var $theme;
public function receive_event($event) {
if(is_null($this->theme)) $this->theme = get_theme_object("link_image", "LinkImageTheme");
if(is_a($event, 'DisplayingImageEvent')) {
global $page;
global $config;
$data_href = $config->get_string("data_href");
$page->add_header("<link rel='stylesheet' href='$data_href/ext/link_image/_style.css' type='text/css'>",0);
$this->theme->links_block($page,$this->data($event->image));
}
if(is_a($event, 'SetupBuildingEvent')) {
$sb = new SetupBlock("Link to Image");
$sb->add_text_option("ext_link-img_text-link_format", "Text Link Format");
$event->panel->add_block($sb);
}
if(is_a($event, 'InitExtEvent')) {
global $config;
//just set default if empty.
if ($config->get_string("ext_link-img_text-link_format") == "") {
$config->set_string("ext_link-img_text-link_format",
'$title - $id ($ext $size $filesize)');
}
}
}
private function data($image) {
global $config;
$text_link = $this->parse_link_template($config->get_string("ext_link-img_text-link_format"),$image);
$text_link = $text_link==" "? null : $text_link; // null blank setting so the url gets filled in on the text links.
return array(
'thumb_src' => $image->get_thumb_link(),
'image_src' => $image->get_image_link(),
'post_link' => $image->get_short_link(),
'text_link' => $text_link);
}
private function parse_link_template($tmpl, $img) { //shamelessly copied from image.class.php
global $config;
@@ -93,7 +65,7 @@ class LinkImage extends Extension {
$tmpl = str_replace('$title', $config->get_string("title"), $tmpl);
return $tmpl;
}
}
add_event_listener(new LinkImage());
?>
}
}
add_event_listener(new LinkImage());
?>