diff options
author | Andrew Dolgov <[email protected]> | 2015-07-06 21:44:38 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2015-07-06 21:44:38 +0300 |
commit | 3b9ca4e6cc254be9ad724b996340914d24786f48 (patch) | |
tree | 11886973b5125ef783fcad24bf06b454d599f4fe | |
parent | 74c1ff6065a4fc7c58bb453a87dfcf59a14e88f8 (diff) |
af_redditimgur: embed youtube links
-rw-r--r-- | plugins/af_redditimgur/init.php | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/plugins/af_redditimgur/init.php b/plugins/af_redditimgur/init.php index 03418dc85..28e3894d2 100644 --- a/plugins/af_redditimgur/init.php +++ b/plugins/af_redditimgur/init.php @@ -84,6 +84,29 @@ class Af_RedditImgur extends Plugin { $found = true; } + $matches = array(); + if (preg_match("/\/\/www\.youtube\.com\/v\/([\w-]+)/", $entry->getAttribute("href"), $matches) || + preg_match("/\/\/www\.youtube\.com\/watch?v=([\w-]+)/", $entry->getAttribute("href"), $matches) || + preg_match("/\/\/youtu.be\/([\w-]+)/", $entry->getAttribute("href"), $matches)) { + + $vid_id = $matches[1]; + + $iframe = $doc->createElement("iframe"); + $iframe->setAttribute("class", "youtube-player"); + $iframe->setAttribute("type", "text/html"); + $iframe->setAttribute("width", "640"); + $iframe->setAttribute("height", "385"); + $iframe->setAttribute("src", "https://www.youtube.com/embed/$vid_id"); + $iframe->setAttribute("allowfullscreen", "1"); + $iframe->setAttribute("frameborder", "0"); + + $br = $doc->createElement('br'); + $entry->parentNode->insertBefore($iframe, $entry); + $entry->parentNode->insertBefore($br, $entry); + + $found = true; + } + if (preg_match("/\.(jpg|jpeg|gif|png)(\?[0-9][0-9]*)?$/i", $entry->getAttribute("href"))) { $img = $doc->createElement('img'); $img->setAttribute("src", $entry->getAttribute("href")); |