summaryrefslogtreecommitdiff
path: root/plugins/af_redditimgur
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2019-02-06 16:24:31 +0300
committerAndrew Dolgov <[email protected]>2019-02-06 16:24:31 +0300
commit1d2da64572ed592dfd78bebd95cb67f7be8512d2 (patch)
treefd14b7724b41827cfd115a9588efab4cc0fd89f2 /plugins/af_redditimgur
parent856e0c32eb9f60ab505de0cc92406cc5bb2a1668 (diff)
af_redditimgur: apparently imgur has link rel='image_src' now, let's use it
Diffstat (limited to 'plugins/af_redditimgur')
-rwxr-xr-xplugins/af_redditimgur/init.php31
1 files changed, 31 insertions, 0 deletions
diff --git a/plugins/af_redditimgur/init.php b/plugins/af_redditimgur/init.php
index 36f31a031..17ba432fd 100755
--- a/plugins/af_redditimgur/init.php
+++ b/plugins/af_redditimgur/init.php
@@ -278,6 +278,37 @@ class Af_RedditImgur extends Plugin {
$found = true;
}
+ // imgur via link rel="image_src" href="..."
+ if (!$found && preg_match("/imgur/", $entry->getAttribute("href"))) {
+
+ Debug::log("handling as imgur page/whatever", Debug::$LOG_VERBOSE);
+
+ $content = fetch_file_contents(["url" => $entry->getAttribute("href"),
+ "http_accept" => "text/*"]);
+
+ if ($content) {
+ $cdoc = new DOMDocument();
+
+ if (@$cdoc->loadHTML($content)) {
+ $cxpath = new DOMXPath($cdoc);
+
+ $rel_image = $cxpath->query("//link[@rel='image_src']")->item(0);
+
+ if ($rel_image) {
+
+ $img = $doc->createElement('img');
+ $img->setAttribute("src", $rel_image->getAttribute("href"));
+
+ $br = $doc->createElement('br');
+ $entry->parentNode->insertBefore($img, $entry);
+ $entry->parentNode->insertBefore($br, $entry);
+
+ $found = true;
+ }
+ }
+ }
+ }
+
// wtf is this even
if (!$found && preg_match("/^https?:\/\/gyazo\.com\/([^\.\/]+$)/", $entry->getAttribute("href"), $matches)) {
$img_id = $matches[1];