Added YouTube video fetching functionality and update landing page to display videos
This commit is contained in:
@ -9,6 +9,7 @@ use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
function pre($object, $die = false)
|
||||
{
|
||||
@ -581,8 +582,18 @@ if (!function_exists('NepaliMonthNameByNumber')) {
|
||||
function NepaliMonthNameByNumber($number)
|
||||
{
|
||||
$MonthNames = array(
|
||||
"Baisakh", "Jestha", "Ashad", "Shrawan", "Bhadra", "Asoj",
|
||||
"Kartik", "Mangsir", "Poush", "Magh", "Falgun", "Chaitra"
|
||||
"Baisakh",
|
||||
"Jestha",
|
||||
"Ashad",
|
||||
"Shrawan",
|
||||
"Bhadra",
|
||||
"Asoj",
|
||||
"Kartik",
|
||||
"Mangsir",
|
||||
"Poush",
|
||||
"Magh",
|
||||
"Falgun",
|
||||
"Chaitra"
|
||||
);
|
||||
return $MonthNames[$number - 1];
|
||||
}
|
||||
@ -593,8 +604,18 @@ if (!function_exists('NepaliMonthName')) {
|
||||
{
|
||||
$Month = NepaliMonth($engDate);
|
||||
$MonthNames = array(
|
||||
"Baisakh", "Jestha", "Ashad", "Shrawan", "Bhadra", "Asoj",
|
||||
"Kartik", "Mangsir", "Poush", "Magh", "Falgun", "Chaitra"
|
||||
"Baisakh",
|
||||
"Jestha",
|
||||
"Ashad",
|
||||
"Shrawan",
|
||||
"Bhadra",
|
||||
"Asoj",
|
||||
"Kartik",
|
||||
"Mangsir",
|
||||
"Poush",
|
||||
"Magh",
|
||||
"Falgun",
|
||||
"Chaitra"
|
||||
);
|
||||
return $MonthNames[$Month - 1];
|
||||
}
|
||||
@ -627,7 +648,7 @@ function pushScriptToFooter($script)
|
||||
}
|
||||
function sectionHeader($text, $sectiontitle = null)
|
||||
{
|
||||
$texts=explode(" ",$text);
|
||||
$texts = explode(" ", $text);
|
||||
?>
|
||||
<div class="row text-center intro">
|
||||
|
||||
@ -636,7 +657,8 @@ function sectionHeader($text, $sectiontitle = null)
|
||||
<span class="pre-title"><?php echo $sectiontitle; ?></span>
|
||||
<?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>
|
||||
|
||||
@ -648,14 +670,35 @@ if (!function_exists('replace_img_src')) {
|
||||
{
|
||||
return preg_replace(
|
||||
'/src="storage(\/[^"]*)"/',
|
||||
'src="'.site_url().'storage$1"',
|
||||
'src="' . site_url() . 'storage$1"',
|
||||
$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)
|
||||
{
|
||||
$content=replace_img_src($content);
|
||||
$content = replace_img_src($content);
|
||||
return preg_replace_callback('/\[([\w_]+)([^]]*)\]/', function ($matches) {
|
||||
$shortcodeName = $matches[1];
|
||||
$shortcodeAttributes = [];
|
||||
@ -687,4 +730,4 @@ if (!function_exists('uploadImage')) {
|
||||
$filePath = Storage::disk('public')->putFileAs($path, $file, $fileName);
|
||||
return $filePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ use Illuminate\Http\Request; // Import the Request class
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class WebsiteController extends Controller
|
||||
{
|
||||
@ -43,7 +44,11 @@ class WebsiteController extends Controller
|
||||
|
||||
public function home()
|
||||
{
|
||||
$channelId = env('CHANNEL_ID');
|
||||
$videos = fetchVideosByChannel($channelId);
|
||||
|
||||
return view('landing.index', [
|
||||
'videos' => $videos,
|
||||
'banners' => Banners::get(),
|
||||
'benefits' => Benefits::get(),
|
||||
'success_stories' => Success_stories::get(),
|
||||
|
@ -31,4 +31,8 @@ return [
|
||||
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
||||
],
|
||||
|
||||
'youtube' => [
|
||||
'api_key' => 'AIzaSyAtDLH9Xzi_Mg-bvz4H27lvqQpT7AR2Bo0',
|
||||
],
|
||||
|
||||
];
|
||||
|
@ -888,39 +888,27 @@
|
||||
|
||||
<!-- Successful Visa Grants -->
|
||||
<section class="section-padding" style="background-color: #aeb5bb">
|
||||
@foreach ($success_stories as $story)
|
||||
<div class="container">
|
||||
<h2 class="section-title text-center" style="color: #fc4e24">
|
||||
Trusted by Many — Testimonials
|
||||
</h2>
|
||||
<div class="row g-3">
|
||||
<div class="container">
|
||||
<h2 class="section-title text-center" style="color: #fc4e24">
|
||||
Trusted by Many — Testimonials
|
||||
</h2>
|
||||
<div class="row g-3">
|
||||
@foreach ($videos as $video)
|
||||
@php
|
||||
function convertToEmbedUrl($url)
|
||||
{
|
||||
$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
|
||||
}
|
||||
$videoId = $video['id']['videoId'];
|
||||
$embedUrl = "https://www.youtube.com/embed/{$videoId}";
|
||||
@endphp
|
||||
|
||||
@foreach (json_decode($story->extra_content) as $content)
|
||||
<div class="col-xl-3 col-lg-4 col-md-6 col-12">
|
||||
<div class="visa-post">
|
||||
<iframe width="100%" height="350"
|
||||
src="{{ convertToEmbedUrl($content->fieldHeader) }}" title="video1" frameborder="0"
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
|
||||
referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
|
||||
</div>
|
||||
<div class="col-xl-3 col-lg-4 col-md-6 col-12">
|
||||
<div class="visa-post">
|
||||
<iframe width="100%" height="350" src="{{ $embedUrl }}" title="YouTube video"
|
||||
frameborder="0"
|
||||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
|
||||
referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Benefits of choosing TEF -->
|
||||
|
Reference in New Issue
Block a user