* @license https://www.gnu.org/licenses/agpl-3.0.en.html * @version 0.1 */ class PicoVideoEmbed extends AbstractPicoPlugin { /** * API version used by this plugin * * @var int */ const API_VERSION = 3; /** * This plugin depends on ... * * @see AbstractPicoPlugin::$dependsOn * @var string[] */ protected $dependsOn = array(); const SHORTCODE = '#\[video-embed .+?\]#'; /** * Triggered after Pico has prepared the raw file contents for parsing * * @see Pico::parseFileContent() * @see DummyPlugin::onContentParsed() * @param string &$content prepared file contents for parsing * @return void */ public function onContentPrepared(&$content) { if (strpos($content, '[video-embed') !== false) { // Search for Embed shortcodes allover the content preg_match_all(self::SHORTCODE, $content, $matches); // Make sure we found some shortcodes if (count($matches[0]) > 0) { // Walk through shortcodes one by one foreach ($matches[0] as $match) { // First, try youtube // Get youtube like and video ID (Ref:http://stackoverflow.com/questions/3717115/regular-expression-for-youtube-links/3726073#3726073) preg_match(self::YOUTUBE_REGEX, $match, $embed_link); if (count($embed_link) > 1) { $content = preg_replace(self::SHORTCODE, $this->getYoutubeEmbed($embed_link), $content, 1); continue; } // Next, we try vimeo preg_match(self::VIMEO_REGEX, $match, $embed_link); if (count($embed_link) > 1) { $content = preg_replace(self::SHORTCODE, $this->getVimeoEmbed($embed_link), $content, 1); continue; } // Otherwise, it's peertube <3 preg_match(self::PEERTUBE_REGEX, $match, $embed_link); if (count($embed_link) > 1) { $content = preg_replace(self::SHORTCODE, $this->getPeertubeEmbed($embed_link), $content, 1); continue; } } } } } const YOUTUBE_REGEX = '#http(?:s)?\:\/\/(?:www\.)?youtu(?:be\.com/watch\?v=|\.be/|be\.com/embed/)([\w\-]+)(&(amp;)?[\w\?=]*)?#s'; private function getYoutubeEmbed(array $embed_link) { return '
'; } const VIMEO_REGEX = '#http(?:s)?\:\/\/(?:www\.)?(?:player\.)?vimeo\.com/(?:video/)?([0-9]+)(-:\?.+)?#s'; private function getVimeoEmbed(array $embed_link) { return ' '; } const PEERTUBE_REGEX = '#(http(?:s)?)\:\/\/([a-zA-Z0-9](?:(?:[a-zA-Z0-9-]*|(?' . '' . ''; } /** * Triggered after Pico has rendered the page * * @param string &$output contents which will be sent to the user * @return void */ public function onPageRendered(&$output) { // Add embed css $output = str_replace('', ($this->getStyleHeader() . ''), $output); } private function getStyleHeader() { $header = ''; return $header; } }