From ae2ae1ffbf1a8d47a0b92b067fb7c4d89dcc65cd Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Fri, 8 Feb 2019 20:54:28 -0700 Subject: [PATCH] Use SHA1_ prefix, attempt to make thumbnails more reliable --- lib/Thumbnail.lib.php | 5 +++-- pages.php | 4 +++- pages/home.php | 9 +++++---- pages/news.php | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/Thumbnail.lib.php b/lib/Thumbnail.lib.php index 3eb5084..50ec1cd 100644 --- a/lib/Thumbnail.lib.php +++ b/lib/Thumbnail.lib.php @@ -69,10 +69,10 @@ class Thumbnail { * @param type $height * @return type */ - static function addThumbnailToCache(string $url, int $width = 150, $height = true) { + static function addThumbnailToCache(string $url, int $width = 150, $height = true, $forcesha1 = false) { global $database; $encodedfilename = Base64::encode($url); - if (strlen("$encodedfilename.$width.jpg") > 250) { + if ($forcesha1 || strlen("$encodedfilename.$width.jpg") > 250) { // We're too long for common filesystems $encodedfilename = "SHA1_" . sha1($url); if (!$database->has("imagecache", ["url" => $url])) { @@ -82,6 +82,7 @@ class Thumbnail { $path = "cache/thumb/$encodedfilename.$width.jpg"; $image = self::getThumbnailFromUrl($url, $width, $height); file_put_contents(__DIR__ . "/../$path", $image); + echo $path; return $image; } diff --git a/pages.php b/pages.php index e397887..8329676 100644 --- a/pages.php +++ b/pages.php @@ -15,6 +15,7 @@ define("PAGES", [ ], "scripts" => [ "static/Shuffle/dist/shuffle.min.js", + "static/js/newsgrid.js", "static/js/home.js" ] ], @@ -24,10 +25,11 @@ define("PAGES", [ "icon" => "fas fa-newspaper", "scripts" => [ "static/Shuffle/dist/shuffle.min.js", + "static/js/newsgrid.js", "static/js/news.js" ] ], "404" => [ "title" => "404 error" ] -]); \ No newline at end of file +]); diff --git a/pages/home.php b/pages/home.php index df5fa0f..0b83df6 100644 --- a/pages/home.php +++ b/pages/home.php @@ -77,13 +77,14 @@ foreach ($newsitems as $item) {
getImage())) { ?> - getImage(); + $imgurl = $item->getImage(); } else { - echo Thumbnail::getThumbnailCacheURL($item->getImage(), 500); + $imgurl = Thumbnail::getThumbnailCacheURL($item->getImage(), 500); } - ?>" class="card-img-top" alt=""> + ?> +
diff --git a/pages/news.php b/pages/news.php index 364b137..759c10e 100644 --- a/pages/news.php +++ b/pages/news.php @@ -41,7 +41,7 @@ $newsitems = News::getItems(); } else { echo Thumbnail::getThumbnailCacheURL($item->getImage(), 500); } - ?>" class="card-img-top" alt=""> + ?>" class="card-img-top newscard-img" alt="">