From a59a830f5e0c6a7be854ff9c64ce82be3fe0f03e Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Sat, 9 Feb 2019 17:40:30 -0700 Subject: [PATCH] Add generateGridCard(), add placeholder thumbnail --- lib/NewsItem.lib.php | 43 +++++++++++++++++++++++++++++++++ static/img/news-placeholder.svg | 2 ++ 2 files changed, 45 insertions(+) create mode 100644 static/img/news-placeholder.svg diff --git a/lib/NewsItem.lib.php b/lib/NewsItem.lib.php index ba39699..50872ed 100644 --- a/lib/NewsItem.lib.php +++ b/lib/NewsItem.lib.php @@ -58,4 +58,47 @@ class NewsItem { return $this->category; } + /** + * Generate a HTML card for a grid layout + * @return string + */ + function generateGridCard(bool $lazyload = false): string { + $category = $this->getCategory()->toString(); + $url = $this->getURL(); + $headline = htmlentities($this->getHeadline()); + $source = $this->getSource(); + $imghtml = ""; + if (!empty($this->getImage())) { + $imghtml = ''; + if (strpos($this->getImage(), "preview.redd.it") !== false) { + $imgurl = $this->getImage(); + } else { + $imgurl = Thumbnail::getThumbnailCacheURL($this->getImage(), 500); + } + if ($lazyload) { + $imghtml .= ''; + $imghtml .= ''; + } else { + $imghtml .= ''; + } + $imghtml .= ''; + } + $html = << +
+ $imghtml +
+ +

+ $headline +

+
+

$source

+
+
+ +END; + return $html; + } + } diff --git a/static/img/news-placeholder.svg b/static/img/news-placeholder.svg new file mode 100644 index 0000000..2437b2e --- /dev/null +++ b/static/img/news-placeholder.svg @@ -0,0 +1,2 @@ + +