Added YouTube video fetching functionality and update landing page to display videos

This commit is contained in:
2025-07-10 13:59:05 +05:45
parent d85b5a3662
commit 6c2da0d37c
4 changed files with 78 additions and 38 deletions

View File

@ -9,6 +9,7 @@ use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Illuminate\Support\Facades\Http;
function pre($object, $die = false) function pre($object, $die = false)
{ {
@ -581,8 +582,18 @@ if (!function_exists('NepaliMonthNameByNumber')) {
function NepaliMonthNameByNumber($number) function NepaliMonthNameByNumber($number)
{ {
$MonthNames = array( $MonthNames = array(
"Baisakh", "Jestha", "Ashad", "Shrawan", "Bhadra", "Asoj", "Baisakh",
"Kartik", "Mangsir", "Poush", "Magh", "Falgun", "Chaitra" "Jestha",
"Ashad",
"Shrawan",
"Bhadra",
"Asoj",
"Kartik",
"Mangsir",
"Poush",
"Magh",
"Falgun",
"Chaitra"
); );
return $MonthNames[$number - 1]; return $MonthNames[$number - 1];
} }
@ -593,8 +604,18 @@ if (!function_exists('NepaliMonthName')) {
{ {
$Month = NepaliMonth($engDate); $Month = NepaliMonth($engDate);
$MonthNames = array( $MonthNames = array(
"Baisakh", "Jestha", "Ashad", "Shrawan", "Bhadra", "Asoj", "Baisakh",
"Kartik", "Mangsir", "Poush", "Magh", "Falgun", "Chaitra" "Jestha",
"Ashad",
"Shrawan",
"Bhadra",
"Asoj",
"Kartik",
"Mangsir",
"Poush",
"Magh",
"Falgun",
"Chaitra"
); );
return $MonthNames[$Month - 1]; return $MonthNames[$Month - 1];
} }
@ -627,7 +648,7 @@ function pushScriptToFooter($script)
} }
function sectionHeader($text, $sectiontitle = null) function sectionHeader($text, $sectiontitle = null)
{ {
$texts=explode(" ",$text); $texts = explode(" ", $text);
?> ?>
<div class="row text-center intro"> <div class="row text-center intro">
@ -636,7 +657,8 @@ function sectionHeader($text, $sectiontitle = null)
<span class="pre-title"><?php echo $sectiontitle; ?></span> <span class="pre-title"><?php echo $sectiontitle; ?></span>
<?php endif; ?> <?php endif; ?>
<h2 class="ylw-clr"><?php echo $texts[0]; unset($texts[0]); ?> <span class="featured"><span><?php echo implode(" ",$texts); ?></span></span></h2> <h2 class="ylw-clr"><?php echo $texts[0];
unset($texts[0]); ?> <span class="featured"><span><?php echo implode(" ", $texts); ?></span></span></h2>
</div> </div>
@ -648,14 +670,35 @@ if (!function_exists('replace_img_src')) {
{ {
return preg_replace( return preg_replace(
'/src="storage(\/[^"]*)"/', '/src="storage(\/[^"]*)"/',
'src="'.site_url().'storage$1"', 'src="' . site_url() . 'storage$1"',
$content $content
); );
} }
} }
function fetchVideosByChannel($channelId)
{
$url = 'https://www.googleapis.com/youtube/v3/search';
$response = Http::get($url, [
'key' => 'AIzaSyAtDLH9Xzi_Mg-bvz4H27lvqQpT7AR2Bo0',
'channelId' => $channelId,
'part' => 'snippet',
'order' => 'date',
'maxResults' => '8',
'type' => 'video',
]);
if ($response->successful()) {
return $response->json()['items'];
}
return [];
}
function processForShortcode($content) function processForShortcode($content)
{ {
$content=replace_img_src($content); $content = replace_img_src($content);
return preg_replace_callback('/\[([\w_]+)([^]]*)\]/', function ($matches) { return preg_replace_callback('/\[([\w_]+)([^]]*)\]/', function ($matches) {
$shortcodeName = $matches[1]; $shortcodeName = $matches[1];
$shortcodeAttributes = []; $shortcodeAttributes = [];

View File

@ -27,6 +27,7 @@ use Illuminate\Http\Request; // Import the Request class
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\View; use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\Http;
class WebsiteController extends Controller class WebsiteController extends Controller
{ {
@ -43,7 +44,11 @@ class WebsiteController extends Controller
public function home() public function home()
{ {
$channelId = env('CHANNEL_ID');
$videos = fetchVideosByChannel($channelId);
return view('landing.index', [ return view('landing.index', [
'videos' => $videos,
'banners' => Banners::get(), 'banners' => Banners::get(),
'benefits' => Benefits::get(), 'benefits' => Benefits::get(),
'success_stories' => Success_stories::get(), 'success_stories' => Success_stories::get(),

View File

@ -31,4 +31,8 @@ return [
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
], ],
'youtube' => [
'api_key' => 'AIzaSyAtDLH9Xzi_Mg-bvz4H27lvqQpT7AR2Bo0',
],
]; ];

View File

@ -888,39 +888,27 @@
<!-- Successful Visa Grants --> <!-- Successful Visa Grants -->
<section class="section-padding" style="background-color: #aeb5bb"> <section class="section-padding" style="background-color: #aeb5bb">
@foreach ($success_stories as $story) <div class="container">
<div class="container"> <h2 class="section-title text-center" style="color: #fc4e24">
<h2 class="section-title text-center" style="color: #fc4e24"> Trusted by Many Testimonials
Trusted by Many Testimonials </h2>
</h2> <div class="row g-3">
<div class="row g-3"> @foreach ($videos as $video)
@php @php
function convertToEmbedUrl($url) $videoId = $video['id']['videoId'];
{ $embedUrl = "https://www.youtube.com/embed/{$videoId}";
$parsed = parse_url($url);
if (isset($parsed['query'])) {
parse_str($parsed['query'], $queryParams);
if (isset($queryParams['v'])) {
return 'https://www.youtube.com/embed/' . $queryParams['v'];
}
}
return $url; // fallback
}
@endphp @endphp
<div class="col-xl-3 col-lg-4 col-md-6 col-12">
@foreach (json_decode($story->extra_content) as $content) <div class="visa-post">
<div class="col-xl-3 col-lg-4 col-md-6 col-12"> <iframe width="100%" height="350" src="{{ $embedUrl }}" title="YouTube video"
<div class="visa-post"> frameborder="0"
<iframe width="100%" height="350" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
src="{{ convertToEmbedUrl($content->fieldHeader) }}" title="video1" frameborder="0" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div>
</div> </div>
@endforeach </div>
</div> @endforeach
</div> </div>
@endforeach </div>
</section> </section>
<!-- Benefits of choosing TEF --> <!-- Benefits of choosing TEF -->