Last active
November 2, 2015 18:10
-
-
Save xhezairbey/f12721fef50a40a42bbd to your computer and use it in GitHub Desktop.
Simple Statamic Plugin to embed YouTube videos from a given link.
This file contains hidden or 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 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