From 9875d717924a122614962ecaf2e1ee809c0416d8 Mon Sep 17 00:00:00 2001 From: aliz27 Date: Thu, 14 May 2015 11:03:06 +0200 Subject: [PATCH 1/3] Support .gifv --- plugins/af_redditimgur/init.php | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/plugins/af_redditimgur/init.php b/plugins/af_redditimgur/init.php index a23b3527f..d885ff16d 100644 --- a/plugins/af_redditimgur/init.php +++ b/plugins/af_redditimgur/init.php @@ -28,6 +28,56 @@ class Af_RedditImgur extends Plugin { foreach ($entries as $entry) { if ($entry->hasAttribute("href")) { + + if (preg_match("/\.(gifv)$/i", $entry->getAttribute("href"))) { + + $gifv_meta = fetch_file_contents($entry->getAttribute("href"), + false, false, false, false, 10); + + if ($gifv_meta) { + $adoc = new DOMDocument(); + @$adoc->loadHTML($gifv_meta); + + if ($adoc) { + $axpath = new DOMXPath($adoc); + $aentries = $axpath->query('(//meta)'); + + $width = false; + $height = false; + + foreach ($aentries as $aentry) { + if (strpos($aentry->getAttribute("property"), "og:image:width") !== FALSE) { + $width = $aentry->getAttribute("content"); + } + if (strpos($aentry->getAttribute("property"), "og:image:height") !== FALSE) { + $height = $aentry->getAttribute("content"); + } + } + } + } + + if ($width && $height) { + + $iframe = $doc->createElement('iframe'); + $iframe->setAttribute("src", str_replace("http:", "", $entry->getAttribute("href"))); + $iframe->setAttribute("frameborder", "0"); + $iframe->setAttribute("width", $width); + $iframe->setAttribute("height", $height); + + $br = $doc->createElement('br'); + $entry->parentNode->insertBefore($iframe, $entry); + $entry->parentNode->insertBefore($br, $entry); + + // add empty img tag to disable display of attachment + $img = $doc->createElement('img'); + $img->setAttribute("src", "data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs%3D"); + $img->setAttribute("width", "0"); + $img->setAttribute("height", "0"); + $entry->parentNode->insertBefore($img, $entry); + $found = true; + } + } + if (preg_match("/\.(jpg|jpeg|gif|png)$/i", $entry->getAttribute("href"))) { $img = $doc->createElement('img'); From 7adf95562d924445acfe575f15978e5258efd95f Mon Sep 17 00:00:00 2001 From: aliz27 Date: Thu, 14 May 2015 11:27:09 +0200 Subject: [PATCH 2/3] Sometimes imgur links has ?1 in the url --- plugins/af_redditimgur/init.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/af_redditimgur/init.php b/plugins/af_redditimgur/init.php index d885ff16d..889e2bcd6 100644 --- a/plugins/af_redditimgur/init.php +++ b/plugins/af_redditimgur/init.php @@ -78,7 +78,7 @@ class Af_RedditImgur extends Plugin { } } - if (preg_match("/\.(jpg|jpeg|gif|png)$/i", $entry->getAttribute("href"))) { + if (preg_match("/\.(jpg|jpeg|gif|png)(\?[0-9])?$/i", $entry->getAttribute("href"))) { $img = $doc->createElement('img'); $img->setAttribute("src", $entry->getAttribute("href")); From 248c5a6ab1a3817d32b205c4a8a3351f8e9574d9 Mon Sep 17 00:00:00 2001 From: aliz27 Date: Thu, 14 May 2015 11:52:44 +0200 Subject: [PATCH 3/3] Allow links to m.imgur.com pages --- plugins/af_redditimgur/init.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/af_redditimgur/init.php b/plugins/af_redditimgur/init.php index 889e2bcd6..1bf91e88a 100644 --- a/plugins/af_redditimgur/init.php +++ b/plugins/af_redditimgur/init.php @@ -92,7 +92,7 @@ class Af_RedditImgur extends Plugin { // links to imgur pages $matches = array(); - if (preg_match("/^https?:\/\/imgur.com\/([^\.\/]+$)/", $entry->getAttribute("href"), $matches)) { + if (preg_match("/^https?:\/\/(m\.)?imgur.com\/([^\.\/]+$)/", $entry->getAttribute("href"), $matches)) { $token = $matches[1];