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

@@ -5,69 +5,73 @@
* Link: http://www.drudexsoftware.com
* License: GPLv2
* Description: Allows displaying a page with random images
* Documentation:
* Documentation:
* Random image list can be accessed through www.yoursite.com/random
* It is recommended that you create a link to this page so users know it exists.
*/
class RandomList extends Extension {
public function onPageRequest(PageRequestEvent $event) {
global $config, $page;
class RandomList extends Extension
{
public function onPageRequest(PageRequestEvent $event)
{
global $config, $page;
if($event->page_matches("random")) {
if(isset($_GET['search'])) {
// implode(explode()) to resolve aliases and sanitise
$search = url_escape(Tag::implode(Tag::explode($_GET['search'], false)));
if(empty($search)) {
$page->set_mode("redirect");
$page->set_redirect(make_link("random"));
}
else {
$page->set_mode("redirect");
$page->set_redirect(make_link('random/'.$search));
}
return;
}
if ($event->page_matches("random")) {
if (isset($_GET['search'])) {
// implode(explode()) to resolve aliases and sanitise
$search = url_escape(Tag::implode(Tag::explode($_GET['search'], false)));
if (empty($search)) {
$page->set_mode("redirect");
$page->set_redirect(make_link("random"));
} else {
$page->set_mode("redirect");
$page->set_redirect(make_link('random/'.$search));
}
return;
}
if($event->count_args() == 0) {
$search_terms = array();
}
else if($event->count_args() == 1) {
$search_terms = explode(' ', $event->get_arg(0));
}
else {
throw new SCoreException("Error: too many arguments.");
}
if ($event->count_args() == 0) {
$search_terms = [];
} elseif ($event->count_args() == 1) {
$search_terms = explode(' ', $event->get_arg(0));
} else {
throw new SCoreException("Error: too many arguments.");
}
// set vars
$images_per_page = $config->get_int("random_images_list_count", 12);
$random_images = array();
// set vars
$images_per_page = $config->get_int("random_images_list_count", 12);
$random_images = [];
// generate random images
for ($i = 0; $i < $images_per_page; $i++) {
$random_image = Image::by_random($search_terms);
if (!$random_image) continue;
array_push($random_images, $random_image);
}
// generate random images
for ($i = 0; $i < $images_per_page; $i++) {
$random_image = Image::by_random($search_terms);
if (!$random_image) {
continue;
}
array_push($random_images, $random_image);
}
$this->theme->set_page($search_terms);
$this->theme->display_page($page, $random_images);
}
}
$this->theme->set_page($search_terms);
$this->theme->display_page($page, $random_images);
}
}
public function onInitExt(InitExtEvent $event) {
global $config;
$config->set_default_int("random_images_list_count", 12);
}
public function onInitExt(InitExtEvent $event)
{
global $config;
$config->set_default_int("random_images_list_count", 12);
}
public function onSetupBuilding(SetupBuildingEvent $event) {
$sb = new SetupBlock("Random Images List");
public function onSetupBuilding(SetupBuildingEvent $event)
{
$sb = new SetupBlock("Random Images List");
// custom headers
$sb->add_int_option("random_images_list_count",
"Amount of Random images to display ");
// custom headers
$sb->add_int_option(
"random_images_list_count",
"Amount of Random images to display "
);
$event->panel->add_block($sb);
}
$event->panel->add_block($sb);
}
}

View File

@@ -1,43 +1,48 @@
<?php
class RandomListTheme extends Themelet {
protected $search_terms;
class RandomListTheme extends Themelet
{
protected $search_terms;
/**
* #param string[] $search_terms
*/
public function set_page(array $search_terms) {
$this->search_terms = $search_terms;
}
/**
* #param string[] $search_terms
*/
public function set_page(array $search_terms)
{
$this->search_terms = $search_terms;
}
/**
* #param Image[] $images
*/
public function display_page(Page $page, array $images) {
$page->title = "Random Images";
/**
* #param Image[] $images
*/
public function display_page(Page $page, array $images)
{
$page->title = "Random Images";
$html = "<b>Refresh the page to view more images</b>";
if (count($images)) {
$html .= "<div class='shm-image-list'>";
$html = "<b>Refresh the page to view more images</b>";
if (count($images)) {
$html .= "<div class='shm-image-list'>";
foreach ($images as $image)
$html .= $this->build_thumb_html($image);
foreach ($images as $image) {
$html .= $this->build_thumb_html($image);
}
$html .= "</div>";
} else {
$html .= "<br/><br/>No images were found to match the search criteria";
}
$html .= "</div>";
} else {
$html .= "<br/><br/>No images were found to match the search criteria";
}
$page->add_block(new Block("Random Images", $html));
$page->add_block(new Block("Random Images", $html));
$nav = $this->build_navigation($this->search_terms);
$page->add_block(new Block("Navigation", $nav, "left", 0));
}
$nav = $this->build_navigation($this->search_terms);
$page->add_block(new Block("Navigation", $nav, "left", 0));
}
protected function build_navigation(array $search_terms): string {
$h_search_string = html_escape(Tag::implode($search_terms));
$h_search_link = make_link("random");
$h_search = "
protected function build_navigation(array $search_terms): string
{
$h_search_string = html_escape(Tag::implode($search_terms));
$h_search_link = make_link("random");
$h_search = "
<p><form action='$h_search_link' method='GET'>
<input type='search' name='search' value='$h_search_string' placeholder='Search random list' class='autocomplete_tags' autocomplete='off' />
<input type='hidden' name='q' value='/random'>
@@ -45,7 +50,6 @@ class RandomListTheme extends Themelet {
</form>
";
return $h_search;
}
return $h_search;
}
}