mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
add embeded audio
This commit is contained in:
parent
171413c108
commit
fa3d48bc24
|
|
@ -513,7 +513,7 @@ class Markdown
|
||||||
}
|
}
|
||||||
|
|
||||||
// Embedding
|
// Embedding
|
||||||
$state = $this->options['embedding'] ?? false;
|
$state = $this->options['embeding'] ?? false;
|
||||||
if ($state !== false) {
|
if ($state !== false) {
|
||||||
$this->inlineTypes['['][] = 'Embeding';
|
$this->inlineTypes['['][] = 'Embeding';
|
||||||
$this->inlineMarkerList .= '[';
|
$this->inlineMarkerList .= '[';
|
||||||
|
|
@ -1251,65 +1251,89 @@ class Markdown
|
||||||
*/
|
*/
|
||||||
protected function inlineEmbeding(array $excerpt) : ?array
|
protected function inlineEmbeding(array $excerpt) : ?array
|
||||||
{
|
{
|
||||||
if (!($this->options['embedding'] ?? false)
|
if (!($this->options['embeding'] ?? false)
|
||||||
|| \preg_match('/\[video.*src="([^"]*)".*\]/', $excerpt['text'], $matches) !== 1
|
|| (($video = (\preg_match('/\[video.*src="([^"]*)".*\]/', $excerpt['text'], $matches) !== 1))
|
||||||
|
&& ($audio = (\preg_match('/\[audio.*src="([^"]*)".*\]/', $excerpt['text'], $matches) !== 1)))
|
||||||
) {
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$video = !$video;
|
||||||
|
$audio = !$audio;
|
||||||
|
|
||||||
$url = $matches[1];
|
$url = $matches[1];
|
||||||
$type = '';
|
if ($video) {
|
||||||
|
$type = '';
|
||||||
|
|
||||||
$needles = ['youtube', 'vimeo', 'dailymotion'];
|
$needles = ['youtube', 'vimeo', 'dailymotion'];
|
||||||
foreach ($needles as $needle) {
|
foreach ($needles as $needle) {
|
||||||
if (\strpos($url, $needle) !== false) {
|
if (\strpos($url, $needle) !== false) {
|
||||||
$type = $needle;
|
$type = $needle;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch ($type) {
|
||||||
|
case 'youtube':
|
||||||
|
$element = 'iframe';
|
||||||
|
$attributes = [
|
||||||
|
'src' => preg_replace('/.*\?v=([^\&\]]*).*/', 'https://www.youtube.com/embed/$1', $url),
|
||||||
|
'frameborder' => '0',
|
||||||
|
'allow' => 'autoplay',
|
||||||
|
'allowfullscreen' => '',
|
||||||
|
'sandbox' => 'allow-same-origin allow-scripts allow-forms'
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case 'vimeo':
|
||||||
|
$element = 'iframe';
|
||||||
|
$attributes = [
|
||||||
|
'src' => preg_replace('/(?:https?:\/\/(?:[\w]{3}\.|player\.)*vimeo\.com(?:[\/\w:]*(?:\/videos)?)?\/([0-9]+)[^\s]*)/', 'https://player.vimeo.com/video/$1', $url),
|
||||||
|
'frameborder' => '0',
|
||||||
|
'allow' => 'autoplay',
|
||||||
|
'allowfullscreen' => '',
|
||||||
|
'sandbox' => 'allow-same-origin allow-scripts allow-forms'
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case 'dailymotion':
|
||||||
|
$element = 'iframe';
|
||||||
|
$attributes = [
|
||||||
|
'src' => $url,
|
||||||
|
'frameborder' => '0',
|
||||||
|
'allow' => 'autoplay',
|
||||||
|
'allowfullscreen' => '',
|
||||||
|
'sandbox' => 'allow-same-origin allow-scripts allow-forms'
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$element = 'video';
|
||||||
|
$attributes = [
|
||||||
|
'src' => UriFactory::build($url),
|
||||||
|
'controls' => ''
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'extent' => \strlen($matches[0]),
|
||||||
|
'element' => [
|
||||||
|
'name' => $element,
|
||||||
|
'text' => $matches[1],
|
||||||
|
'attributes' => $attributes
|
||||||
|
],
|
||||||
|
];
|
||||||
|
} elseif ($audio) {
|
||||||
|
return [
|
||||||
|
'extent' => \strlen($matches[0]),
|
||||||
|
'element' => [
|
||||||
|
'name' => 'audio',
|
||||||
|
'text' => $matches[1],
|
||||||
|
'attributes' => [
|
||||||
|
'src' => UriFactory::build($url),
|
||||||
|
'controls' => ''
|
||||||
|
]
|
||||||
|
],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($type) {
|
return null;
|
||||||
case 'youtube':
|
|
||||||
$element = 'iframe';
|
|
||||||
$attributes = [
|
|
||||||
'src' => preg_replace('/.*\?v=([^\&\]]*).*/', 'https://www.youtube.com/embed/$1', $url),
|
|
||||||
'frameborder' => '0',
|
|
||||||
'allow' => 'autoplay',
|
|
||||||
'allowfullscreen' => '',
|
|
||||||
'sandbox' => 'allow-same-origin allow-scripts allow-forms'
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
case 'vimeo':
|
|
||||||
$element = 'iframe';
|
|
||||||
$attributes = [
|
|
||||||
'src' => preg_replace('/(?:https?:\/\/(?:[\w]{3}\.|player\.)*vimeo\.com(?:[\/\w:]*(?:\/videos)?)?\/([0-9]+)[^\s]*)/', 'https://player.vimeo.com/video/$1', $url),
|
|
||||||
'frameborder' => '0',
|
|
||||||
'allow' => 'autoplay',
|
|
||||||
'allowfullscreen' => '',
|
|
||||||
'sandbox' => 'allow-same-origin allow-scripts allow-forms'
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
case 'dailymotion':
|
|
||||||
$element = 'iframe';
|
|
||||||
$attributes = [
|
|
||||||
'src' => $url,
|
|
||||||
'frameborder' => '0',
|
|
||||||
'allow' => 'autoplay',
|
|
||||||
'allowfullscreen' => '',
|
|
||||||
'sandbox' => 'allow-same-origin allow-scripts allow-forms'
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$element = 'video';
|
|
||||||
}
|
|
||||||
|
|
||||||
return [
|
|
||||||
'extent' => strlen($matches[0]),
|
|
||||||
'element' => [
|
|
||||||
'name' => $element,
|
|
||||||
'text' => $matches[1],
|
|
||||||
'attributes' => $attributes
|
|
||||||
],
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user