forked from Cavemanon/cavepaintings
store enabled exts in a config file, rather than moving directories around
This commit is contained in:
47
ext/link_image/main.php
Normal file
47
ext/link_image/main.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?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 onSetupBuilding(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 onInitExt(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);
|
||||
}
|
||||
}
|
||||
?>
|
82
ext/link_image/readme.txt
Normal file
82
ext/link_image/readme.txt
Normal file
@@ -0,0 +1,82 @@
|
||||
Link to Image adds BBCode and HTML link codes to the image view. Offers code for a customizable text link, thumbnail links, and full image inline.
|
||||
|
||||
Author: Erik Youngren <artanis.00@gmail.com>
|
||||
|
||||
License: GPLv2
|
||||
|
||||
Submit a Bug Report or Suggestion for Link to Image:
|
||||
* http://trac.shishnet.org/shimmie2/newticket?owner=artanis.00@gmail.com&component=third%20party%20extensions&keywords=link_to_image
|
||||
|
||||
= Use =
|
||||
There is one option in Board Config: Text Link Format.
|
||||
It takes the following arguments as well as plain text.
|
||||
|| arguments || replacement ||
|
||||
|| $id || The image ID. ||
|
||||
|| $hash || The MD5 hash of the image. ||
|
||||
|| $tags || The image's tag list. ||
|
||||
|| $base || The base HREF as set in Config. ||
|
||||
|| $ext || The image's extension. ||
|
||||
|| $size || The image's display size. ||
|
||||
|| $filesize || The image's size in KB. ||
|
||||
|| $filename || The image's original filename. ||
|
||||
|| $title || The site title as set in Config. ||
|
||||
Link to Image will default this option to '$title - $id ($ext $size $filesize)'.
|
||||
To reset to the default, simply clear the current setting. Link to Image will then fill in the default value after the save.
|
||||
|
||||
To leave the setting blank for any reason, leave a space (' ') in it.
|
||||
|
||||
= 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.
|
||||
|
||||
= 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 - 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.
|
||||
|
||||
== Version 0.1.3b - 20070509 ==
|
||||
* Renamed style.css to _style.css to avoid the auto loader.
|
||||
|
||||
== Version 0.1.3 - 20070508 ==
|
||||
* Created Readme.txt
|
||||
* Merged 0.1.2 into 0.1.2b
|
||||
* Removed uneeded documentation from main.php
|
||||
* Rewrote the css to be unique. Previously used CSS I wrote for elsewhere. Styled to reduce space consumption.
|
||||
* Added code to insert the CSS import.
|
||||
* Updated Nice URLs to allow access to the /ext/ folder. (Why is my stylesheet returning HTML instead of CSS?)
|
||||
* First SVN update.
|
||||
|
||||
== Version 0.1.2b - 20070507 ==
|
||||
(fairly simultaneous with 0.1.2)
|
||||
* shish:
|
||||
* Updated to new extension format
|
||||
* Created folder link_image in trunk/contrib
|
||||
* Renamed link_image.ext.php to main.php and moved to /link_image/
|
||||
* Created style.css {{{ /* 404'd :|*/ }}}.
|
||||
* Documentation (different from mine.)
|
||||
* Changed add_text_option() and added add_label() in SetupBuildingEvent because I was using an edited version of the function that shish didn't know about. It was a wonder that didn't throw massive errors.
|
||||
* Published on SVN.
|
||||
|
||||
== Version 0.1.2 - 20070506 ==
|
||||
* Textboxes now select-all when they gain focus.
|
||||
* Commenting and documentation.
|
||||
|
||||
== Version 0.1.1 - 20070506 ==
|
||||
* Fixed HTML thumbnail link code. (image tag was being html_escaped twice, resulting in "$gt;" and "<" from the first escape becoming "&gt;" and "&lt;") It turns out that html_escape was completely unnecessary, all I had to do was replace the single-quotes around the attributes with escaped double-quotes ('\"'.)
|
||||
|
||||
== Version 0.1.0 - 20070506 ==
|
||||
* Release.
|
||||
|
||||
= Links =
|
||||
* http://trac.shishnet.org/shimmie2/wiki/Contrib/Extensions/LinkToImage - Home
|
||||
* http://forum.shishnet.org/viewtopic.php?p=153 - Discussion
|
||||
* http://trac.shishnet.org/shimmie2/browser/trunk/contrib/link_image - Shimmie2 Trac SVN
|
25
ext/link_image/test.php
Normal file
25
ext/link_image/test.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
class LinkImageTest extends ShimmieWebTestCase {
|
||||
function testLinkImage() {
|
||||
$this->log_in_as_user();
|
||||
$image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pie");
|
||||
|
||||
# look in the "plain text link to post" box, follow the link
|
||||
# in there, see if it takes us to the right page
|
||||
$raw = $this->get_page("post/view/$image_id");
|
||||
$matches = array();
|
||||
preg_match("#value='(http://.*(/|%2F)post(/|%2F)view(/|%2F)[0-9]+)'#", $raw, $matches);
|
||||
$this->assertTrue(count($matches) > 0);
|
||||
if($matches) {
|
||||
$this->get($matches[1]);
|
||||
$this->assert_title("Image $image_id: pie");
|
||||
}
|
||||
|
||||
$this->log_out();
|
||||
|
||||
$this->log_in_as_admin();
|
||||
$this->delete_image($image_id);
|
||||
$this->log_out();
|
||||
}
|
||||
}
|
||||
?>
|
94
ext/link_image/theme.php
Normal file
94
ext/link_image/theme.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
class LinkImageTheme extends Themelet {
|
||||
public function links_block(Page $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",
|
||||
"
|
||||
<table><tr>
|
||||
|
||||
<td><fieldset>
|
||||
<legend><a href='http://en.wikipedia.org/wiki/Bbcode' target='_blank'>BBCode</a></legend>
|
||||
<table>
|
||||
".
|
||||
$this->link_code("Link",$this->url($post_link, $text_link,"ubb"),"ubb_text-link").
|
||||
$this->link_code("Thumb",$this->url($post_link, $this->img($thumb_src,"ubb"),"ubb"),"ubb_thumb-link").
|
||||
$this->link_code("Image", $this->img($image_src,"ubb"), "ubb_full-img").
|
||||
"
|
||||
</table>
|
||||
</fieldset></td>
|
||||
|
||||
<td><fieldset>
|
||||
<legend><a href='http://en.wikipedia.org/wiki/Html' target='_blank'>HTML</a></legend>
|
||||
<table>
|
||||
".
|
||||
$this->link_code("Link", $this->url($post_link, $text_link,"html"), "html_text-link").
|
||||
$this->link_code("Thumb", $this->url($post_link,$this->img($thumb_src,"html"),"html"), "html_thumb-link").
|
||||
$this->link_code("Image", $this->img($image_src,"html"), "html_full-image").
|
||||
"
|
||||
</table>
|
||||
</fieldset></td>
|
||||
|
||||
<td><fieldset>
|
||||
<legend>Plain Text</legend>
|
||||
<table>
|
||||
".
|
||||
$this->link_code("Link",$post_link,"text_post-link").
|
||||
$this->link_code("Thumb",$thumb_src,"text_thumb-url").
|
||||
$this->link_code("Image",$image_src,"text_image-src").
|
||||
"
|
||||
</table>
|
||||
</fieldset></td>
|
||||
|
||||
</tr></table>
|
||||
",
|
||||
"main",
|
||||
50));
|
||||
}
|
||||
|
||||
protected function url (/*string*/ $url, /*string*/ $content, /*string*/ $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;
|
||||
}
|
||||
|
||||
protected function img (/*string*/ $src, /*string*/ $type) {
|
||||
switch ($type) {
|
||||
case "html":
|
||||
$text = "<img src=\"$src\" />";
|
||||
break;
|
||||
case "ubb":
|
||||
$text = "[img]".$src."[/img]";
|
||||
break;
|
||||
default:
|
||||
$text = $src;
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
protected function link_code(/*string*/ $label, /*string*/ $content, $id=NULL) {
|
||||
return "
|
||||
<tr>
|
||||
<td><label for='".$id."' title='Click to select the textbox'>$label</label></td>
|
||||
<td><input type='text' readonly='readonly' id='".$id."' name='".$id."'
|
||||
value='".html_escape($content)."' onfocus='this.select();'></input></td>
|
||||
</tr>
|
||||
";
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user