From f763fc13565a8cc04bb4a13ae7dd9cb407565477 Mon Sep 17 00:00:00 2001 From: im-mi Date: Fri, 23 Sep 2016 12:31:02 -0400 Subject: [PATCH] React appropriately when there are no random list search results --- ext/random_list/main.php | 7 +++++-- ext/random_list/theme.php | 15 ++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ext/random_list/main.php b/ext/random_list/main.php index 267c971a..46c49801 100644 --- a/ext/random_list/main.php +++ b/ext/random_list/main.php @@ -44,8 +44,11 @@ class RandomList extends Extension { $random_images = array(); // generate random images - for ($i = 0; $i < $images_per_page; $i++) - array_push($random_images, Image::by_random($search_terms)); + 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); diff --git a/ext/random_list/theme.php b/ext/random_list/theme.php index c092b086..dd0f1d25 100644 --- a/ext/random_list/theme.php +++ b/ext/random_list/theme.php @@ -17,13 +17,18 @@ class RandomListTheme extends Themelet { public function display_page(Page $page, $images) { $page->title = "Random Images"; - $html = "Refresh the page to view more images -
"; + $html = "Refresh the page to view more images"; + if (count($images)) { + $html .= "
"; - foreach ($images as $image) - $html .= $this->build_thumb_html($image); + foreach ($images as $image) + $html .= $this->build_thumb_html($image); + + $html .= "
"; + } else { + $html .= "

No images were found to match the search criteria"; + } - $html .= "
"; $page->add_block(new Block("Random Images", $html)); $nav = $this->build_navigation($this->search_terms);