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

@ -3,39 +3,39 @@
**/
/* * * Link to Image * * */
#link_to_image {
#Link_to_Image {
/* allows borders to encompass the content; */
overflow:hidden;
}
#link_to_image fieldset {
#Link_to_Image fieldset {
width: 32%;
float:left;
min-width:25em;
}
#link_to_image input, #link_to_image label {
#Link_to_Image input, #Link_to_Image label {
display:block;
width:66%;
float:left;
margin-bottom:2.5px;
}
#link_to_image label {
#Link_to_Image label {
width:30%;
text-align:left;
padding-right:2%;
cursor:pointer;
}
#link_to_image input {
#Link_to_Image input {
font-size:0.7em;
font-family:courier, fixed, monospace;
}
#link_to_image br {
#Link_to_Image br {
clear:both;
}
#link_to_image label:hover {
#Link_to_Image label:hover {
border-bottom:1px dashed;
}

View file

@ -1,83 +0,0 @@
<?php
class LinkImageHTML {
var $post_link;
var $image_src;
var $thumb_src;
var $text_link;
function __construct ($post, $img, $thumb, $text) {
$this->post_link = $post;
$this->image_src = $img;
$this->thumb_src = $thumb;
$this->text_link = $text;
}
public function getHTML () {
$html = "";
/* Rearrange or add to the code sections here. (BEGINNER) *
* Please do not edit anything outside the following section. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
$html .= "<div id='link_to_image'>";
$html .= $this->BBCode();
$html .= $this->HTML();
$html .= $this->PlainText();
$html .= "</div>";
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
return $html;
}
/* Section Construction (INTERMEDIATE) *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
private function BBCode() {
return $this->section("<a href='http://en.wikipedia.org/wiki/Bbcode' target='_blank'>BBCode</a></legend>",
$this->link_code("Text Link", $this->ubb_url($this->post_link, $this->text_link), "ubb_text-link").
$this->link_code("Thumbnail Link",$this->ubb_url($this->post_link, $this->ubb_img($this->thumb_src)),"ubb_thumb-link").
$this->link_code("Inline Image", $this->ubb_img($this->image_src), "ubb_full-img"));
}
private function HTML() {
return $this->section("<a href='http://en.wikipedia.org/wiki/Html' target='_blank'>HTML</a>",
$this->link_code("Text Link", $this->html_url($this->post_link, $this->text_link), "html_text-link").
$this->link_code("Thumbnail Link", $this->html_url($this->post_link,$this->html_img($this->thumb_src)), "html_thumb-link").
$this->link_code("Inline Image", $this->html_img($this->image_src), "html_full-image"));
}
private function PlainText() {
return $this->section("Plain Text",
$this->link_code("Post URL",$this->post_link,"text_post-link").
$this->link_code("Thumbnail URL",$this->thumb_src,"text_thumb-url").
$this->link_code("Image URL",$this->image_src,"text_image-src"));
}
private function section ($legend, $content) {
return "<fieldset><legend>$legend</legend>$content</fieldset>\n\n";
}
/* Text and Textbox Construction (ADVANCED) *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
private function ubb_url($link,$content) {
if ($content == NULL) { $content=$link; }
return "[url=".$link."]".$content."[/url]";
}
private function ubb_img($src) {
return "[img]".$src."[/img]";
}
private function html_url($link,$content) {
if ($content == NULL) { $content=$link; }
return "<a href=\"".$link."\">".$content."</a>";
}
private function html_img($src) {
return "<img src=\"".$src."\" />";
}
private function link_code($label,$content,$id=NULL) {
$control = "<label for='".$id."' title='Click to select the textbox'>$label</label>\n";
$control .= "<input type='text' readonly='readonly' id='".$id."' name='".$id."' value='".$content."' onfocus='this.select();'></input>\n";
$control .= "<br/>\n";
return $control;
}
}
?>

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());
?>

View file

@ -25,23 +25,20 @@ To reset to the default, simply clear the current setting. Link to Image will th
To leave the setting blank for any reason, leave a space (' ') in it.
= Theming =
Link to Image now has a prototype theme engine built into it. All HTML generation has been moved to a seperate file.
To use this, copy link_image.html.php from {{{ext/link_image/}}} to {{{themes/$theme/}}}. You may then change the html output of Link to Image by editing this copy as it will be used in preference of the default.
= Install =
1. Copy the folder {{{contrib/link_image/}}} to {{{ext/}}}.
2. In the Config panel, make sure Base URL is set (you may as well set Data URL while you're there, if you haven't already.)
3. Make sure Image Link, Thumb Link, and Short Link all contain the full path ("http://" and onward,) either by using $base or plain text. Link to Image will not be able to retrieve the correct paths without these variables.
4. If you use .htaccess to make NiceURLs, make sure that a it allows access to the {{{ext/ folder}}}, or else Link to Image will not be able to access {{{ext/link_image/style.css}}}.
* http://trac.shishnet.org/shimmie2/wiki/NiceURLs - Nice URLs
* Recent changes to .htaccess (with its addition to the SVN) may make this step unnessasary.
= Change Log =
= Change Log =
== Version 0.3.0 ==
* Moved Link to Image over to the official theme engine. This functions basically the same as what the prototype was, but it's more thought out and nicer.
* Cleaned up the insides a bit.
== Version 0.2.0 ==
* Changed the HTML generation to use a prototype theme engine. All HTML generation is now contained within {{{link_image.html.php}}}, which may be copied to the current theme folder and edited from there.
== Version 0.1.4 - 20071510 ==
== Version 0.1.4 - 20070510 ==
* Style changes.
* Added output containing only the locations of the thumb, image and post.
* Added a link to wikipedia's HTML page, just as BBCode has a wikipedia link.

View file

@ -0,0 +1,71 @@
<?php
class LinkImageTheme extends Themelet {
public function links_block($page,$data) {
$thumb_src = $data['thumb_src'];
$image_src = $data['image_src'];
$post_link = $data['post_link'];
$text_link = $data['text_link'];
$page->add_block( new Block(
"Link to Image",
"<fieldset>".
"<legend><a href='http://en.wikipedia.org/wiki/Bbcode' target='_blank'>BBCode</a></legend>".
$this->link_code("Text Link",$this->url($post_link, $text_link,"ubb"),"ubb_text-link").
$this->link_code("Thumbnail Link",$this->url($post_link, $this->img($thumb_src,"ubb"),"ubb"),"ubb_thumb-link").
$this->link_code("Inline Image", $this->img($image_src,"ubb"), "ubb_full-img").
"</fieldset>".
"<fieldset>".
"<legend><a href='http://en.wikipedia.org/wiki/Html' target='_blank'>HTML</a></legend>".
$this->link_code("Text Link", $this->url($post_link, $text_link,"html"), "html_text-link").
$this->link_code("Thumbnail Link", $this->url($post_link,$this->img($thumb_src,"html"),"html"), "html_thumb-link").
$this->link_code("Inline Image", $this->img($image_src,"html"), "html_full-image").
"</fieldset>".
"<fieldset>".
"<legend>Plain Text</legend>".
$this->link_code("Post URL",$post_link,"text_post-link").
$this->link_code("Thumbnail URL",$thumb_src,"text_thumb-url").
$this->link_code("Image URL",$image_src,"text_image-src").
"</fieldset>",
"main",
50));
}
private function url ($url,$content,$type) {
if ($content == NULL) {$content=$url;}
switch ($type) {
case "html":
$text = "<a href=\"".$url."\">".$content."</a>";
break;
case "ubb":
$text = "[url=".$url."]".$content."[/url]";
break;
default:
$text = $link." - ".$content;
}
return $text;
}
private function img ($src,$type) {
switch ($type) {
case "html":
$text = "<img src=\"$src\" />";
break;
case "ubb":
$text = "[img]".$src."[/img]";
break;
default:
$text = $src;
}
return $text;
}
private function link_code($label,$content,$id=NULL) {
return "<label for='".$id."' title='Click to select the textbox'>$label</label>\n".
"<input type='text' readonly='readonly' id='".$id."' name='".$id."' value='".$content."' onfocus='this.select();'></input>\n<br/>\n";
}
}
?>