- Added standard Laravel directory structure and configuration. - Included Svelte and Tailwind configuration for the admin interface. - Added core PHPUnit and testing scripts.
160 lines
4.9 KiB
PHP
160 lines
4.9 KiB
PHP
<?php
|
|
|
|
use App\Support\ThemeManager;
|
|
use App\Models\Media;
|
|
use Illuminate\Support\Facades\File;
|
|
use Illuminate\Support\HtmlString;
|
|
|
|
if (! function_exists('theme_asset')) {
|
|
function theme_asset(string $path): string
|
|
{
|
|
$themeManager = new ThemeManager();
|
|
$activeTheme = $themeManager->getActiveTheme();
|
|
|
|
// Use our new theme asset route
|
|
return route('theme.asset', [
|
|
'theme' => $activeTheme,
|
|
'path' => $path,
|
|
]);
|
|
}
|
|
}
|
|
|
|
if (! function_exists('css')) {
|
|
function css(string $path, array $attributes = []): HtmlString
|
|
{
|
|
$push = $attributes['push'] ?? false;
|
|
unset($attributes['push']);
|
|
|
|
$url = theme_asset($path);
|
|
$attrString = '';
|
|
foreach ($attributes as $key => $value) {
|
|
$attrString .= is_bool($value) ? ($value ? " {$key}" : '') : " {$key}=\"$value\"";
|
|
}
|
|
|
|
$tag = "<link rel=\"stylesheet\" href=\"$url\"$attrString>";
|
|
|
|
if ($push) {
|
|
view()->startPush('styles', $tag);
|
|
return new HtmlString('');
|
|
}
|
|
|
|
return new HtmlString($tag);
|
|
}
|
|
}
|
|
|
|
if (! function_exists('js')) {
|
|
function js(string $path, array $attributes = []): HtmlString
|
|
{
|
|
$push = $attributes['push'] ?? false;
|
|
unset($attributes['push']);
|
|
|
|
$url = theme_asset($path);
|
|
$attrString = '';
|
|
foreach ($attributes as $key => $value) {
|
|
$attrString .= is_bool($value) ? ($value ? " {$key}" : '') : " {$key}=\"$value\"";
|
|
}
|
|
|
|
$tag = "<script src=\"$url\"$attrString></script>";
|
|
|
|
if ($push) {
|
|
view()->startPush('scripts', $tag);
|
|
return new HtmlString('');
|
|
}
|
|
|
|
return new HtmlString($tag);
|
|
}
|
|
}
|
|
|
|
if (! function_exists('sw_media')) {
|
|
/**
|
|
* Helper to render a file (image, audio, video, or link).
|
|
*/
|
|
function sw_media(string|int|Media $file, array $attributes = []): HtmlString
|
|
{
|
|
return sw_file($file, $attributes);
|
|
}
|
|
}
|
|
|
|
if (! function_exists('sw_file')) {
|
|
function sw_file(string|int|Media $file, array $attributes = []): HtmlString
|
|
{
|
|
$path = '';
|
|
$url = '';
|
|
|
|
if ($file instanceof Media) {
|
|
$path = $file->filename;
|
|
$url = route('media.jit', ['path' => $file->filename]);
|
|
} elseif (is_int($file) || (is_string($file) && is_numeric($file))) {
|
|
$media = Media::find($file);
|
|
if ($media) {
|
|
$path = $media->filename;
|
|
$url = route('media.jit', ['path' => $media->filename]);
|
|
} else {
|
|
return new HtmlString('');
|
|
}
|
|
} else {
|
|
$path = $file;
|
|
// Detect if the path is a theme asset or a media file
|
|
if (str_starts_with($path, 'media/')) {
|
|
$mediaPath = str_replace('media/', '', $path);
|
|
$url = route('media.jit', ['path' => $mediaPath]);
|
|
} else {
|
|
$url = theme_asset($path);
|
|
}
|
|
}
|
|
|
|
$extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));
|
|
|
|
// Handle Image sizing via JIT if it's an image
|
|
if (in_array($extension, ['jpg', 'jpeg', 'png', 'gif', 'webp', 'avif'])) {
|
|
$jitParams = ['w', 'h', 'fit', 'q', 'fm', 'fp-x', 'fp-y'];
|
|
$query = [];
|
|
foreach ($jitParams as $param) {
|
|
if (isset($attributes[$param])) {
|
|
$query[$param] = $attributes[$param];
|
|
unset($attributes[$param]);
|
|
}
|
|
}
|
|
|
|
if (! empty($query)) {
|
|
$url .= (str_contains($url, '?') ? '&' : '?') . http_build_query($query);
|
|
}
|
|
|
|
$attrString = '';
|
|
foreach ($attributes as $key => $value) {
|
|
$attrString .= " {$key}=\"$value\"";
|
|
}
|
|
|
|
return new HtmlString("<img src=\"$url\"$attrString>");
|
|
}
|
|
|
|
// Audio
|
|
if (in_array($extension, ['mp3', 'wav', 'ogg'])) {
|
|
$attrString = '';
|
|
foreach ($attributes as $key => $value) {
|
|
$attrString .= is_bool($value) ? ($value ? " {$key}" : '') : " {$key}=\"$value\"";
|
|
}
|
|
return new HtmlString("<audio src=\"$url\"$attrString></audio>");
|
|
}
|
|
|
|
// Video
|
|
if (in_array($extension, ['mp4', 'webm', 'ogv'])) {
|
|
$attrString = '';
|
|
foreach ($attributes as $key => $value) {
|
|
$attrString .= is_bool($value) ? ($value ? " {$key}" : '') : " {$key}=\"$value\"";
|
|
}
|
|
return new HtmlString("<video src=\"$url\"$attrString></video>");
|
|
}
|
|
|
|
// Default (Link)
|
|
$attrString = '';
|
|
$text = $attributes['text'] ?? basename($path);
|
|
unset($attributes['text']);
|
|
foreach ($attributes as $key => $value) {
|
|
$attrString .= " {$key}=\"$value\"";
|
|
}
|
|
|
|
return new HtmlString("<a href=\"$url\"$attrString>$text</a>");
|
|
}
|
|
}
|