PSR-2. I'm not a huge fan, but ugly consistency beats no consistency...

This commit is contained in:
Shish
2019-05-28 17:59:38 +01:00
parent 5ec3e89884
commit 34b05cca7c
295 changed files with 27094 additions and 24632 deletions

View File

@@ -4,34 +4,38 @@
* 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));
}
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 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)');
}
public function onInitExt(InitExtEvent $event)
{
global $config;
$config->set_default_string("ext_link-img_text-link_format", '$title - $id ($ext $size $filesize)');
}
private function data(Image $image) {
global $config;
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.
$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' => make_http($image->get_thumb_link()),
'image_src' => make_http($image->get_image_link()),
'post_link' => make_http(make_link("post/view/{$image->id}")),
'text_link' => $text_link);
}
return [
'thumb_src' => make_http($image->get_thumb_link()),
'image_src' => make_http($image->get_image_link()),
'post_link' => make_http(make_link("post/view/{$image->id}")),
'text_link' => $text_link];
}
}

View File

@@ -1,24 +1,25 @@
<?php
class LinkImageTest extends ShimmiePHPUnitTestCase {
public function testLinkImage() {
$this->log_in_as_user();
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pie");
class LinkImageTest extends ShimmiePHPUnitTestCase
{
public function testLinkImage()
{
$this->log_in_as_user();
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "pie");
# FIXME
# look in the "plain text link to post" box, follow the link
# in there, see if it takes us to the right page
$this->get_page("post/view/$image_id");
# FIXME
# look in the "plain text link to post" box, follow the link
# in there, see if it takes us to the right page
$this->get_page("post/view/$image_id");
$this->markTestIncomplete();
$this->markTestIncomplete();
// FIXME
$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");
}
}
// FIXME
$matches = [];
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");
}
}
}

View File

@@ -1,25 +1,27 @@
<?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'];
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",
"
$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").
"
$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>
@@ -27,10 +29,10 @@ class LinkImageTheme extends Themelet {
<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").
"
$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>
@@ -38,56 +40,61 @@ class LinkImageTheme extends Themelet {
<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").
"
$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));
}
"main",
50
));
}
protected function url (string $url, string $content, string $type) {
if ($content == NULL) {$content=$url;}
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 = $url." - ".$content;
}
return $text;
}
switch ($type) {
case "html":
$text = "<a href=\"".$url."\">".$content."</a>";
break;
case "ubb":
$text = "[url=".$url."]".$content."[/url]";
break;
default:
$text = $url." - ".$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 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 "
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();' /></td>
</tr>
";
}
}
}