Last active
August 29, 2015 13:56
-
-
Save tgloeggl/8976256 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class YouTubePlugin extends StudipPlugin implements SystemPlugin | |
{ | |
function __construct() | |
{ | |
parent::__construct(); | |
StudipFormat::addStudipMarkup('youtube1', '\[youtube\]', '\[\/youtube\]', 'YouTubePlugin::markupYouTube'); | |
StudipFormat::addStudipMarkup('youtube2','\[(you)\](.*?)(?=\s|$)', null, 'YouTubePlugin::markupYouTube', 'links'); | |
} | |
static function markupYouTube($markup, $matches, $contents) | |
{ | |
$input = parse_url(isset($matches[2]) ? $matches[2] : $contents); | |
if (isset($input['query'])) { | |
parse_str(urldecode(html_entity_decode($input['query'])), $params); | |
} else { | |
$params['v'] = $input['path']; | |
} | |
$video = $params['v']; | |
unset($params['v']); | |
return sprintf('<iframe width="480" height="360" src="//www.youtube-nocookie.com/embed/%s?%s" frameborder="0" allowfullscreen></iframe>', | |
htmlReady($video), htmlReady(http_build_query($params))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment