Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 41 additions & 22 deletions resources/views/public/blogs/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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://')) {
Expand All @@ -104,8 +123,8 @@ function verifyImage($url) {
<!-- Favicon -->
<link rel="icon" type="image/x-icon" href="{{ $meetMytechFavicon }}">
<link rel="shortcut icon" type="image/x-icon" href="{{ $meetMytechFavicon }}">
<link rel="apple-touch-icon" href="{{ $meetMytechLogo }}">
<meta name="msapplication-TileImage" content="{{ $meetMytechLogo }}">
<link rel="apple-touch-icon" href="{{ $defaultLogo }}">
<meta name="msapplication-TileImage" content="{{ $defaultLogo }}">

<!-- Generic Social Media Meta Tags with Version -->
<meta property="og:type" content="article">
Expand Down