Spaces:
Running
Running
File size: 6,829 Bytes
7731906 6d8cf3e 7731906 282827b 7731906 282827b 7731906 282827b 7731906 282827b 7731906 282827b 7731906 282827b 7731906 282827b 7731906 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | <?php
namespace App\Controllers;
use App\Models\Video;
class VideoController {
public function index() {
$videos = Video::getAll();
$jsonLd = [
'@context' => 'https://schema.org',
'@type' => 'CollectionPage',
'name' => 'ວິດີໂອ - ຄຳສອນພຸດທະ',
'description' => 'ລວມວິດີໂອທັມມະ ແລະ ຄຳສອນຂອງພຣະພຸດທະເຈົ້າ',
'url' => canonicalUrl(),
'inLanguage' => 'lo',
];
return view('pages.video.index', [
'videos' => $videos,
'seo' => [
'title' => 'ວິດີໂອ - ຄຳສອນພຸດທະ',
'description' => 'ລວມວິດີໂອທັມມະ ແລະ ຄຳສອນຂອງພຣະພຸດທະເຈົ້າ',
'keywords' => 'ວິດີໂອ, ທັມມະ, ຄຳສອນພຸດທະ, ພຸດທະສາສະໜາ',
'json_ld' => $jsonLd,
]
]);
}
public function show($id) {
$videos = Video::getAll();
$video = null;
$ytId = null;
foreach ($videos as $item) {
$itemKey = $item['_key'] ?? ($item['_ytId'] ?? '');
if ($itemKey === '' || $itemKey === null) {
$itemKey = (string) ($item['ID'] ?? '');
}
if ((string) $itemKey === (string) $id || (string) ($item['ID'] ?? '') === (string) $id) {
$video = $item;
$ytId = $item['_ytId'] ?? '';
break;
}
}
if (!$video) {
http_response_code(404);
return view('pages.video.404', [
'videoId' => $id,
'seo' => [
'title' => 'ວິດີໂອບໍ່ພົບ - ຄຳສອນພຸດທະ',
'description' => 'ວິດີໂອທີ່ທ່ານຄົ້ນຫາບໍ່ພົບໃນລະບົບ',
]
]);
}
$currentKey = $video['_key'] ?? ($ytId ?: (string) ($video['ID'] ?? ''));
$provider = $video['_provider'] ?? 'youtube';
$videoId = $video['_videoId'] ?? $ytId;
$sourceUrl = $video['link'] ?? '';
$isReel = !empty($video['_isReel']);
$embedUrl = '';
$watchUrl = $sourceUrl;
$sourceLabel = 'ວິດີໂອ';
if ($provider === 'youtube' && $videoId) {
$embedUrl = 'https://www.youtube.com/embed/' . rawurlencode($videoId) . '?autoplay=1&rel=0';
$watchUrl = 'https://www.youtube.com/watch?v=' . rawurlencode($videoId);
$sourceLabel = 'YouTube';
} elseif ($provider === 'facebook' && $sourceUrl) {
/* Official plugin embed: works for public reels/watch/share links
without any app token or session cookie. */
$embedUrl = 'https://www.facebook.com/plugins/video.php?href=' . rawurlencode($sourceUrl)
. '&show_text=false&autoplay=true&width=720';
$watchUrl = $sourceUrl;
$sourceLabel = 'Facebook';
} elseif ($provider === 'drive' && $videoId) {
$embedUrl = 'https://drive.google.com/file/d/' . rawurlencode($videoId) . '/preview';
$watchUrl = 'https://drive.google.com/file/d/' . rawurlencode($videoId) . '/view';
$sourceLabel = 'Google Drive';
} elseif ($provider === 'vimeo' && $videoId) {
$embedUrl = 'https://player.vimeo.com/video/' . rawurlencode($videoId) . '?autoplay=1';
$watchUrl = 'https://vimeo.com/' . rawurlencode($videoId);
$sourceLabel = 'Vimeo';
} elseif ($provider === 'file') {
$embedUrl = $sourceUrl;
$sourceLabel = 'ວິດີໂອ';
}
$otherVideos = array_filter($videos, function($item) use ($currentKey) {
$key = $item['_key'] ?? ($item['_ytId'] ?? '');
return $key !== '' && $key !== $currentKey;
});
$canonicalUrl = canonicalUrl();
$videoTitle = $video['ຊື່ພຣະສູດ'] ?? 'Video';
$thumbnailUrl = $video['_thumbnail'] ?? '';
if ($thumbnailUrl === '' && $ytId) {
// Use default thumbnail for YouTube videos
$thumbnailUrl = 'https://img.youtube.com/vi/' . $ytId . '/hqdefault.jpg';
}
if ($thumbnailUrl === '') {
$thumbnailUrl = absoluteUrl('/assets/images/logo.png');
}
$jsonLd = [
'@context' => 'https://schema.org',
'@type' => 'VideoObject',
'name' => $videoTitle,
'description' => 'ວິດີໂອ: ' . $videoTitle,
'url' => $canonicalUrl,
'inLanguage' => 'lo',
'embedUrl' => $embedUrl !== '' ? $embedUrl : $watchUrl,
'thumbnailUrl' => $thumbnailUrl,
'isPartOf' => [
'@type' => 'Collection',
'name' => 'ຄຳສອນພຸດທະ',
],
'breadcrumb' => [
'@type' => 'BreadcrumbList',
'itemListElement' => [
['@type' => 'ListItem', 'position' => 1, 'name' => 'ໜ້າຫຼັກ', 'item' => absoluteUrl('')],
['@type' => 'ListItem', 'position' => 2, 'name' => 'ວິດີໂອ', 'item' => absoluteUrl('/video')],
['@type' => 'ListItem', 'position' => 3, 'name' => $videoTitle],
],
],
];
$videoDescription = strip_tags($video['description'] ?? $video['detail'] ?? '');
$videoDescription = !empty($videoDescription)
? (mb_strlen($videoDescription) > 160 ? mb_substr($videoDescription, 0, 157) . '...' : $videoDescription)
: 'ວິດີໂອ: ' . $videoTitle;
return view('pages.video.show', [
'video' => $video,
'ytId' => $ytId,
'provider' => $provider,
'sourceLabel' => $sourceLabel,
'embedUrl' => $embedUrl,
'watchUrl' => $watchUrl,
'isReel' => $isReel,
'otherVideos' => array_values($otherVideos),
'seo' => [
'title' => $videoTitle . ' - ຄຳສອນພຸດທະ',
'description' => $videoDescription,
'keywords' => ($video['ໝວດທັມ'] ?? '') . ', ວິດີໂອ, ທັມມະ, ຄຳສອນພຸດທະ',
'image' => $thumbnailUrl,
'json_ld' => $jsonLd,
'og_type' => 'video.other',
'video_published_time' => $video['datePublished'] ?? date('Y-m-d'),
]
]);
}
}
|