Модификатор для проигрывания VK видео на сайте
<?php
$input = trim($input); // Ссылка или iframe из TV-поля
$width = $modx->getOption('width', $scriptProperties, '100%');
$height = $modx->getOption('height', $scriptProperties, '360');
$responsive = $modx->getOption('responsive', $scriptProperties, true); // Адаптивность по умолчанию
if (empty($input)) return '';
// ─────────────────────────────────────────────
// ВАРИАНТ 1: Пользователь вставил готовый <iframe>
// ─────────────────────────────────────────────
if (stripos($input, '<iframe') !== false) {
// Если включена адаптивность — заменяем width/height на 100%
if ($responsive) {
$input = preg_replace('/width="\d+"/i', 'width="100%"', $input);
$input = preg_replace('/height="\d+"/i', 'height="100%"', $input);
$input = preg_replace("/width='\d+'/i", "width='100%'", $input);
$input = preg_replace("/height='\d+'/i", "height='100%'", $input);
}
return $input;
}
// ─────────────────────────────────────────────
// ВАРИАНТ 2: Пользователь вставил обычную ссылку
// ─────────────────────────────────────────────
if (preg_match('/video(-?\d+)_(\d+)/i', $input, $matches)) {
$oid = $matches[1];
$vid = $matches[2];
$src = "https://vk.com/video_ext.php?oid={$oid}&id={$vid}&hd=2";
$w = $responsive ? '100%' : $width;
$h = $responsive ? '100%' : $height;
return "<iframe src=\"{$src}\" width=\"{$w}\" height=\"{$h}\" " .
"frameborder=\"0\" allowfullscreen " .
"allow=\"autoplay; encrypted-media; fullscreen; picture-in-picture; screen-wake-lock\">" .
"</iframe>";
}
return '<!-- VkVideo: не распознан формат -->';
Готовы обсудить проект?
Опишите задачу в двух словах — за редким исключением отвечаю моментально.