leilukin-tumbleblog/modules/easy_embed/easy_embed.php

35 lines
1.3 KiB
PHP
Raw Normal View History

2024-06-20 14:10:42 +00:00
<?php
class EasyEmbed extends Modules {
public function __init(): void {
# Replace comment codes before Markdown filtering (priority 5).
$this->setPriority("markup_text", 4);
}
public function markup_text($text): string {
$urls = array(
'|<!--[^>]*youtube.com/watch\?v=([a-z0-9_\-]{11})[^>]*-->|i'
=> 'https://www.youtube.com/embed/$1',
'|<!--[^>]*youtu.be/([a-z0-9_\-]{11})[^>]*-->|i'
=> 'https://www.youtube.com/embed/$1',
'|<!--[^>]*vimeo.com/([0-9]{9})[^>]*-->|i'
=> 'https://player.vimeo.com/video/$1',
'|<!--[^>]*twitch.tv/[^/]+/v/([0-9]{9})[^>]*-->|i'
=> 'https://player.twitch.tv/?video=v$1',
'|<!--[^>]*archive.org/details/([a-z0-9_\-]+)[^>]*-->|i'
=> 'https://archive.org/embed/$1'
);
2024-09-05 17:51:48 +00:00
foreach ($urls as $view => &$embed) {
2024-06-20 14:10:42 +00:00
$embed = '<iframe class="video_embed" src="'.
fix($embed, true).
'" allowfullscreen></iframe>';
2024-09-05 17:51:48 +00:00
}
2024-06-20 14:10:42 +00:00
return preg_replace(array_keys($urls), array_values($urls), $text);
}
}