Created
December 29, 2015 19:30
-
-
Save Toyz/230be37ffae401e4ab5a 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 YoutubeEmbed extends JBBCode\CodeDefinition { | |
public function __construct() | |
{ | |
parent::__construct(); | |
$this->setTagName("youtubeEmbed"); | |
} | |
public function asHtml(JBBCode\ElementNode $el) | |
{ | |
$content = ""; | |
foreach($el->getChildren() as $child) | |
$content .= $child->getAsBBCode(); | |
$foundMatch = preg_match('/v=([A-z0-9=\-]+?)(&.*)?$/i', $content, $matches); | |
if(!$foundMatch) | |
return $el->getAsBBCode(); | |
else | |
return "<iframe width=\"640\" height=\"390\" src=\"http://www.youtube.com/embed/".$matches[1]."\" frameborder=\"0\" allowfullscreen></iframe>"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment