Initial commit
This commit is contained in:
commit
c909d539bc
7178 files changed
+756624
No files matched your search
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Illuminate\View\Component;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class AppLayout extends Component
|
||||
{
|
||||
/**
|
||||
* Get the view / contents that represents the component.
|
||||
*/
|
||||
public function render(): View
|
||||
{
|
||||
return view('layouts.app');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\View\Component;
|
||||
use App\Models\Course;
|
||||
|
||||
class CourseCard extends Component
|
||||
{
|
||||
public Course $course;
|
||||
|
||||
public function __construct(Course $course)
|
||||
{
|
||||
$this->course = $course;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('components.course-card');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Illuminate\View\Component;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class GuestLayout extends Component
|
||||
{
|
||||
/**
|
||||
* Get the view / contents that represents the component.
|
||||
*/
|
||||
public function render(): View
|
||||
{
|
||||
return view('layouts.guest');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\View\Component;
|
||||
|
||||
class VideoPlayer extends Component
|
||||
{
|
||||
public string $url;
|
||||
public ?string $title;
|
||||
|
||||
public function __construct(?string $url = null, ?string $title = null)
|
||||
{
|
||||
// Coerce null → "" then trim so downstream code is safe
|
||||
$this->url = trim((string) $url);
|
||||
$this->title = $title ?: 'Video';
|
||||
}
|
||||
|
||||
public function provider(): ?string
|
||||
{
|
||||
if ($this->url === '') return null;
|
||||
$u = $this->url;
|
||||
|
||||
if (stripos($u, '<iframe') !== false && preg_match('/src=["\']([^"\']+)["\']/', $u, $m)) {
|
||||
$u = $m[1];
|
||||
}
|
||||
if (preg_match('~(youtube\.com|youtu\.be)~i', $u)) return 'youtube';
|
||||
if (preg_match('~vimeo\.com~i', $u)) return 'vimeo';
|
||||
return null;
|
||||
}
|
||||
|
||||
public function videoId(): ?string
|
||||
{
|
||||
if ($this->url === '') return null;
|
||||
$u = $this->url;
|
||||
|
||||
if (stripos($u, '<iframe') !== false && preg_match('/src=["\']([^"\']+)["\']/', $u, $m)) {
|
||||
$u = $m[1];
|
||||
}
|
||||
if (preg_match('~(youtube\.com|youtu\.be)~i', $u) &&
|
||||
preg_match('~(?:v=|/embed/|youtu\.be/)([0-9A-Za-z_-]{11})~', $u, $m)) {
|
||||
return $m[1];
|
||||
}
|
||||
if (preg_match('~vimeo\.com~i', $u)) {
|
||||
if (preg_match('~vimeo\.com/(?:video/)?(\d+)~', $u, $m)) return $m[1];
|
||||
if (preg_match('~player\.vimeo\.com/video/(\d+)~', $u, $m)) return $m[1];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function embedSrc(): ?string
|
||||
{
|
||||
$provider = $this->provider();
|
||||
$id = $this->videoId();
|
||||
if (!$provider || !$id) return null;
|
||||
|
||||
return match ($provider) {
|
||||
'youtube' => "https://www.youtube.com/embed/{$id}",
|
||||
'vimeo' => "https://player.vimeo.com/video/{$id}?title=0&byline=0&portrait=0",
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
|
||||
public function render(): View|Closure|string
|
||||
{
|
||||
return view('components.video-player', [
|
||||
'embedSrc' => $this->embedSrc(),
|
||||
'provider' => $this->provider(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user