From 390915a88498235ae6dadee691d09c89b386e8ad Mon Sep 17 00:00:00 2001 From: grandeljay Date: Wed, 8 Jun 2022 16:02:20 +0200 Subject: [PATCH] Use original image as preview --- src/classes/blog.php | 22 ---------------------- src/pages/post.php | 6 +++--- 2 files changed, 3 insertions(+), 25 deletions(-) diff --git a/src/classes/blog.php b/src/classes/blog.php index 06c988e8..f2bfa9ec 100644 --- a/src/classes/blog.php +++ b/src/classes/blog.php @@ -89,28 +89,6 @@ class Blog return $htmlPicture; } - public static function getMediaPreviewURL(int $mediaID): string - { - $url = ''; - - $media = self::getMedia($mediaID); - $mediaSizes = (array) $media->media_details->sizes; - uasort( - $mediaSizes, - function ($a, $b) { - $sizeA = $a->width + $a->height; - $sizeB = $b->width + $b->height; - - return $sizeA <=> $sizeB; - } - ); - $mediaSmallest = (object) reset($mediaSizes); - - $url = $mediaSmallest->source_url; - - return $url; - } - public static function getCategory(int $categoryID): \stdClass { $category = self::get(sprintf(self::ENDPOINT_CATEGORIES, $categoryID)); diff --git a/src/pages/post.php b/src/pages/post.php index 74626209..42628e9b 100644 --- a/src/pages/post.php +++ b/src/pages/post.php @@ -11,12 +11,12 @@ namespace wishthis; $postSlug = $_SESSION['_GET']['slug']; $post = Blog::getPostBySlug($postSlug); $postMediaHTML = isset($post->featured_media) ? Blog::getMediaHTML($post->featured_media) : ''; -$postMediaURL = isset($post->featured_media) ? Blog::getMediaPreviewURL($post->featured_media) : ''; +$postMedia = isset($post->featured_media) ? Blog::getMedia($post->featured_media) : new \stdClss(); $page = new Page(__FILE__, $post->title->rendered); -if ('' !== $postMediaURL) { - $page->link_preview = $postMediaURL; +if (isset($postMedia->source_url)) { + $page->link_preview = $postMedia->source_url; } $page->header();