Image to Post - random
This commit is contained in:
parent
bfe95a09e7
commit
0db32f2ccc
4 changed files with 18 additions and 18 deletions
|
@ -5,22 +5,22 @@ class RandomImageInfo extends ExtensionInfo
|
|||
public const KEY = "random_image";
|
||||
|
||||
public $key = self::KEY;
|
||||
public $name = "Random Image";
|
||||
public $name = "Random Post";
|
||||
public $url = self::SHIMMIE_URL;
|
||||
public $authors = self::SHISH_AUTHOR;
|
||||
public $license = self::LICENSE_GPLV2;
|
||||
public $description = "Do things with a random image";
|
||||
public $description = "Do things with a random post";
|
||||
public $documentation =
|
||||
"<b>Viewing a random image</b>
|
||||
"<b>Viewing a random post</b>
|
||||
<br>Visit <code>/random_image/view</code>
|
||||
<p><b>Downloading a random image</b>
|
||||
<p><b>Downloading a random post</b>
|
||||
<br>Link to <code>/random_image/download</code>. This will give
|
||||
the raw data for an image (no HTML). This is useful so that you
|
||||
the raw data for a post (no HTML). This is useful so that you
|
||||
can set your desktop wallpaper to be the download URL, refreshed
|
||||
every couple of hours.
|
||||
<p><b>Getting a random image from a subset</b>
|
||||
<br>Adding a slash and some search terms will get a random image
|
||||
<p><b>Getting a random post from a subset</b>
|
||||
<br>Adding a slash and some search terms will get a random post
|
||||
from those results. This can be useful if you want a specific size
|
||||
of random image, or from a category. You could link to
|
||||
of random post, or from a category. You could link to
|
||||
<code>/random_image/download/size=1024x768+cute</code>";
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ class RandomImage extends Extension
|
|||
$image = Image::by_random($search_terms);
|
||||
if (!$image) {
|
||||
throw new SCoreException(
|
||||
"Couldn't find any images randomly",
|
||||
"Couldn't find any posts randomly",
|
||||
Tag::implode($search_terms)
|
||||
);
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ class RandomImage extends Extension
|
|||
|
||||
public function onSetupBuilding(SetupBuildingEvent $event)
|
||||
{
|
||||
$sb = new SetupBlock("Random Image");
|
||||
$sb = new SetupBlock("Random Post");
|
||||
$sb->add_bool_option("show_random_block", "Show Random Block: ");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ class RandomImage extends Extension
|
|||
public function onPageSubNavBuilding(PageSubNavBuildingEvent $event)
|
||||
{
|
||||
if ($event->parent=="posts") {
|
||||
$event->add_nav_link("posts_random", new Link('random_image/view'), "Random Image");
|
||||
$event->add_nav_link("posts_random", new Link('random_image/view'), "Random Post");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,10 +8,10 @@ class RandomImageTest extends ShimmiePHPUnitTestCase
|
|||
$this->log_out();
|
||||
|
||||
$page = $this->get_page("random_image/view");
|
||||
$this->assertEquals("Image $image_id: test", $page->title);
|
||||
$this->assertEquals("Post $image_id: test", $page->title);
|
||||
|
||||
$page = $this->get_page("random_image/view/test");
|
||||
$this->assertEquals("Image $image_id: test", $page->title);
|
||||
$this->assertEquals("Post $image_id: test", $page->title);
|
||||
|
||||
$page = $this->get_page("random_image/download");
|
||||
$this->assertNotNull($page->data);
|
||||
|
@ -27,21 +27,21 @@ class RandomImageTest extends ShimmiePHPUnitTestCase
|
|||
# enabled, no image = no text
|
||||
$config->set_bool("show_random_block", true);
|
||||
$page = $this->get_page("post/list");
|
||||
$this->assertNull($page->find_block("Random Image"));
|
||||
$this->assertNull($page->find_block("Random Post"));
|
||||
|
||||
# enabled, image = text
|
||||
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "test");
|
||||
$page = $this->get_page("post/list");
|
||||
$this->assertNotNull($page->find_block("Random Image"));
|
||||
$this->assertNotNull($page->find_block("Random Post"));
|
||||
|
||||
# disabled, image = no text
|
||||
$config->set_bool("show_random_block", false);
|
||||
$page = $this->get_page("post/list");
|
||||
$this->assertNull($page->find_block("Random Image"));
|
||||
$this->assertNull($page->find_block("Random Post"));
|
||||
|
||||
# disabled, no image = no image
|
||||
$this->delete_image($image_id);
|
||||
$page = $this->get_page("post/list");
|
||||
$this->assertNull($page->find_block("Random Image"));
|
||||
$this->assertNull($page->find_block("Random Post"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ class RandomImageTheme extends Themelet
|
|||
{
|
||||
public function display_random(Page $page, Image $image)
|
||||
{
|
||||
$page->add_block(new Block("Random Image", $this->build_random_html($image), "left", 8));
|
||||
$page->add_block(new Block("Random Post", $this->build_random_html($image), "left", 8));
|
||||
}
|
||||
|
||||
public function build_random_html(Image $image, ?string $query = null): string
|
||||
|
|
Reference in a new issue