From 97e020a77f89c8ea847f70bbda6db0a8c3792cc7 Mon Sep 17 00:00:00 2001 From: B Vikas Chandra <48272577+vikaschandrab@users.noreply.github.com> Date: Tue, 30 Sep 2025 21:39:11 +0530 Subject: [PATCH] issue fixes --- resources/views/public/blogs/show.blade.php | 63 ++++++++++++++------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/resources/views/public/blogs/show.blade.php b/resources/views/public/blogs/show.blade.php index dfd1a3e..c9a7f79 100644 --- a/resources/views/public/blogs/show.blade.php +++ b/resources/views/public/blogs/show.blade.php @@ -43,47 +43,66 @@ ]); // Get the absolute URL for images with strict checking - $baseUrl = config('app.url'); + $baseUrl = rtrim(config('app.url'), '/'); $imageUrl = ''; $defaultLogo = $baseUrl . '/meetmytech_logo.jpg'; + $meetMytechFavicon = $baseUrl . '/favicon.ico'; // Function to verify image existence and accessibility function verifyImage($url) { if (empty($url)) return false; - // URL encode spaces and special characters - $encodedUrl = str_replace(' ', '%20', $url); + try { + // URL encode spaces and special characters + $encodedUrl = str_replace(' ', '%20', $url); + + // Handle both HTTP and HTTPS + if (!preg_match('~^(?:f|ht)tps?://~i', $encodedUrl)) { + $encodedUrl = 'https://' . ltrim($encodedUrl, '/'); + } - // For absolute URLs - $headers = @get_headers($encodedUrl); - return $headers && strpos($headers[0], '200') !== false; + // For absolute URLs + $headers = @get_headers($encodedUrl); + $isAccessible = $headers && strpos($headers[0], '200') !== false; + + Log::info('Image verification', [ + 'url' => $url, + 'encoded_url' => $encodedUrl, + 'accessible' => $isAccessible + ]); + + return $isAccessible; + } catch (\Exception $e) { + Log::error('Image verification failed', [ + 'url' => $url, + 'error' => $e->getMessage() + ]); + return false; + } } - // Check featured image + // First try the blog's featured image if ($blog->featured_image) { - $featuredImageUrl = url(Storage::url($blog->featured_image)); - // URL encode spaces and special characters - $featuredImageUrl = str_replace(' ', '%20', $featuredImageUrl); - - if (verifyImage($featuredImageUrl)) { - $imageUrl = $featuredImageUrl; - Log::info('Using featured image: ' . $imageUrl); + $featuredImagePath = $blog->featured_image; + if (Storage::disk('public')->exists($featuredImagePath)) { + $imageUrl = $baseUrl . Storage::url($featuredImagePath); + Log::info('Using blog featured image', ['url' => $imageUrl]); } } - // If featured image fails or doesn't exist, use default logo + // If featured image is not available or accessible, use default logo if (empty($imageUrl) || !verifyImage($imageUrl)) { $imageUrl = $defaultLogo; - Log::info('Using default logo: ' . $imageUrl); + Log::info('Using default MeetMyTech logo', ['url' => $imageUrl]); } - // Force HTTPS for production + // Ensure HTTPS for production if (app()->environment('production')) { - $imageUrl = str_replace('http://', 'https://', $imageUrl); + $imageUrl = preg_replace('/^http:/', 'https:', $imageUrl); } - // Set favicon - $meetMytechFavicon = $baseUrl . '/favicon.ico'; + // URL encode the final image URL + $imageUrl = str_replace(' ', '%20', $imageUrl); // Force HTTPS for production if (app()->environment('production') && !str_starts_with($imageUrl, 'https://')) { @@ -104,8 +123,8 @@ function verifyImage($url) { - - + +