Skip to content

Instantly share code, notes, and snippets.

@xhezairbey
Last active November 2, 2015 18:10
Show Gist options
  • Save xhezairbey/f12721fef50a40a42bbd to your computer and use it in GitHub Desktop.
Save xhezairbey/f12721fef50a40a42bbd to your computer and use it in GitHub Desktop.
Simple Statamic Plugin to embed YouTube videos from a given link.
<?php
class Plugin_youtube extends Plugin
{
var $meta = array(
'name' => 'Youtube',
'version' => '0.0.1',
'author' => 'Arian Xhezairi',
'author_url' => 'http://xhezairi.com'
);
function __call($method, $args)
{
$embed = $this->getEmbed();
return $embed;
}
/**
* Return an embeded YouTube video.
* @return String YouTube embeded iframe element.
*/
private function getEmbed() {
$link = $this->fetchParam('link', '');
preg_match(
'/[\\?\\&]v=([^\\?\\&]+)/',
$link,
$matches
);
return '<iframe width="560" height="315" src="http://www.youtube.com/embed/{$matches[1]}?rel=0" frameborder="0" allowfullscreen></iframe>';
}
}
// Usage: Place this somewhere in the templates.
// {{ youtube link="https://www.youtube.com/watch?v=KKtaVfS3ygU" }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment