Skip to content

Instantly share code, notes, and snippets.

@tgloeggl
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tgloeggl/8976256 to your computer and use it in GitHub Desktop.
Save tgloeggl/8976256 to your computer and use it in GitHub Desktop.
<?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