@php // Whole modal is toggleable from Theme Options. if (theme_option('order_packaging_modal_enabled', 'yes') !== 'yes') { return; } $packagingTitle = theme_option('order_packaging_modal_title') ?: trans('plugins/ecommerce::order.packaging_video_title'); $packagingSubtitle = theme_option('order_packaging_modal_subtitle') ?: trans('plugins/ecommerce::order.how_to_package_order_description'); // Display source: YouTube/Vimeo link, uploaded video file, or an image. $packagingVideoSource = theme_option('order_packaging_video_source', 'youtube'); // --- Uploaded video (validated: must look like a video file) --- $packagingVideoFile = trim((string) theme_option('order_packaging_video_file')); $packagingIsUpload = $packagingVideoSource === 'upload' && $packagingVideoFile !== '' && preg_match('/\.(mp4|webm|ogg|mov|m4v)(\?.*)?$/i', $packagingVideoFile); $packagingUploadUrl = $packagingIsUpload ? (str_starts_with($packagingVideoFile, 'http') ? $packagingVideoFile : RvMedia::getImageUrl($packagingVideoFile)) : null; // --- Image --- $packagingImage = theme_option('order_packaging_image'); $packagingIsImage = $packagingVideoSource === 'image' && ! empty($packagingImage); $packagingImageUrl = $packagingIsImage ? RvMedia::getImageUrl($packagingImage) : null; $defaultVideoUrl = theme_option('order_packaging_video_url', 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'); $videoUrl = $order->packaging_video_url ?? $defaultVideoUrl; if (empty($videoUrl)) { $videoUrl = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'; } // Convert standard YouTube watch URLs, short URLs, and Shorts to embed URLs if (str_contains($videoUrl, 'youtube.com/watch?v=')) { $videoUrl = str_replace('youtube.com/watch?v=', 'youtube.com/embed/', $videoUrl); } elseif (str_contains($videoUrl, 'youtube.com/shorts/')) { $videoUrl = str_replace('youtube.com/shorts/', 'youtube.com/embed/', $videoUrl); } elseif (str_contains($videoUrl, 'youtu.be/')) { $videoUrl = str_replace('youtu.be/', 'youtube.com/embed/', $videoUrl); } elseif (str_contains($videoUrl, 'vimeo.com/') && !str_contains($videoUrl, 'player.vimeo.com')) { $videoUrl = str_replace('vimeo.com/', 'player.vimeo.com/video/', $videoUrl); } // Ensure enablejsapi=1 is present for iframe manipulation if it's YouTube if (str_contains($videoUrl, 'youtube.com') && !str_contains($videoUrl, 'enablejsapi=')) { $separator = str_contains($videoUrl, '?') ? '&' : '?'; $videoUrl .= $separator . 'enablejsapi=1'; } // Only treat as a valid embed when the URL is actually YouTube/Vimeo. $packagingIsYoutube = $packagingVideoSource === 'youtube' && preg_match('/youtube\.com|youtu\.be|vimeo\.com|player\.vimeo/i', (string) $videoUrl); // Feature boxes (each independently toggleable + editable text). $packagingBoxes = []; foreach ([1, 2, 3] as $bi) { if (theme_option("order_packaging_box{$bi}_enabled", 'yes') !== 'yes') { continue; } $packagingBoxes[] = [ 'index' => $bi, 'title' => theme_option("order_packaging_box{$bi}_title", ''), 'desc' => theme_option("order_packaging_box{$bi}_desc", ''), ]; } @endphp