| Server IP : 104.21.84.107 / Your IP : 104.23.243.197 Web Server : Apache/2.4.63 (Ubuntu) System : Linux adminpruebas-Virtual-Machine 6.14.0-37-generic #37-Ubuntu SMP PREEMPT_DYNAMIC Fri Nov 14 22:10:32 UTC 2025 x86_64 User : www-data ( 33) PHP Version : 8.4.5 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/biblioteca/includes/ |
Upload File : |
<?php
declare(strict_types=1);
function tutorialSourceType(array $tutorial): string
{
return (string) (($tutorial['source'] ?? [])['type'] ?? 'pending');
}
function tutorialHasMedia(array $tutorial): bool
{
$type = tutorialSourceType($tutorial);
return $type === 'youtube' || $type === 'local';
}
function tutorialEmbedUrl(array $tutorial): string
{
$source = $tutorial['source'] ?? [];
$type = tutorialSourceType($tutorial);
if ($type === 'youtube') {
$src = (string) ($source['src'] ?? '');
$kind = (string) ($source['kind'] ?? 'video');
if ($kind === 'playlist') {
return 'https://www.youtube.com/embed/videoseries?list=' . rawurlencode($src) . '&rel=0&modestbranding=1';
}
return 'https://www.youtube.com/embed/' . rawurlencode($src) . '?rel=0&modestbranding=1';
}
if ($type === 'local') {
return (string) ($source['src'] ?? '');
}
return '';
}
function tutorialOpenUrl(array $tutorial): string
{
$source = $tutorial['source'] ?? [];
$type = tutorialSourceType($tutorial);
if ($type === 'youtube') {
$src = (string) ($source['src'] ?? '');
$kind = (string) ($source['kind'] ?? 'video');
if ($kind === 'playlist') {
return 'https://www.youtube.com/playlist?list=' . rawurlencode($src);
}
return 'https://www.youtube.com/watch?v=' . rawurlencode($src);
}
if ($type === 'local') {
return (string) ($source['src'] ?? '');
}
return '';
}
function tutorialSourceLabel(array $tutorial): string
{
$type = tutorialSourceType($tutorial);
if ($type === 'local') {
return 'Video local';
}
if ($type === 'youtube') {
return 'YouTube';
}
return 'Pendiente';
}
function tutorialFallbackMessage(array $tutorial): string
{
return tutorialHasMedia($tutorial)
? 'No fue posible cargar este video. Revisa la URL o reemplázalo por un archivo local dentro de la carpeta video/.'
: 'Este tutorial fue agregado al listado, pero todavía no tiene un video asociado. Cuando lo tengas, podrás cargarlo desde YouTube o desde la carpeta video/.';
}
function prepareTutorial(array $tutorial): array
{
$tutorial['source_type'] = tutorialSourceType($tutorial);
$tutorial['has_media'] = tutorialHasMedia($tutorial);
$tutorial['embed_url'] = tutorialEmbedUrl($tutorial);
$tutorial['open_url'] = tutorialOpenUrl($tutorial);
$tutorial['source_label'] = tutorialSourceLabel($tutorial);
$tutorial['fallback_message'] = tutorialFallbackMessage($tutorial);
return $tutorial;
}