diff options
Diffstat (limited to 'plugins/af_redditimgur/init.php')
-rwxr-xr-x | plugins/af_redditimgur/init.php | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/plugins/af_redditimgur/init.php b/plugins/af_redditimgur/init.php index d28e072f4..d3e91f383 100755 --- a/plugins/af_redditimgur/init.php +++ b/plugins/af_redditimgur/init.php @@ -24,7 +24,7 @@ class Af_RedditImgur extends Plugin { function hook_prefs_tab($args) { if ($args != "prefFeeds") return; - print "<div dojoType=\"dijit.layout.AccordionPane\" + print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"<i class='material-icons'>extension</i> ".__('Reddit content settings (af_redditimgur)')."\">"; $enable_readability = $this->host->get($this, "enable_readability"); @@ -94,7 +94,7 @@ class Af_RedditImgur extends Plugin { //$debug = 1; foreach ($entries as $entry) { - if ($entry->hasAttribute("href") && strpos($entry->getAttribute("href"), "reddit.com") === FALSE) { + if ($entry->hasAttribute("href") && strpos($entry->getAttribute("href"), "reddit.com") === false) { Debug::log("processing href: " . $entry->getAttribute("href"), Debug::$LOG_VERBOSE); @@ -103,7 +103,7 @@ class Af_RedditImgur extends Plugin { if (!$found && preg_match("/^https?:\/\/twitter.com\/(.*?)\/status\/(.*)/", $entry->getAttribute("href"), $matches)) { Debug::log("handling as twitter: " . $matches[1] . " " . $matches[2], Debug::$LOG_VERBOSE); - $oembed_result = fetch_file_contents("https://publish.twitter.com/oembed?url=" . urlencode($entry->getAttribute("href"))); + $oembed_result = UrlHelper::fetch("https://publish.twitter.com/oembed?url=" . urlencode($entry->getAttribute("href"))); if ($oembed_result) { $oembed_result = json_decode($oembed_result, true); @@ -111,7 +111,7 @@ class Af_RedditImgur extends Plugin { if ($oembed_result && isset($oembed_result["html"])) { $tmp = new DOMDocument(); - if ($tmp->loadHTML('<?xml encoding="utf-8" ?>' . $oembed_result["html"])) { + if (@$tmp->loadHTML('<?xml encoding="utf-8" ?>' . $oembed_result["html"])) { $p = $doc->createElement("p"); $p->appendChild($doc->importNode( @@ -140,7 +140,7 @@ class Af_RedditImgur extends Plugin { $content_type = $this->get_content_type($source_stream); - if (strpos($content_type, "video/") !== FALSE) { + if (strpos($content_type, "video/") !== false) { $this->handle_as_video($doc, $entry, $source_stream, $poster_url); $found = 1; } @@ -165,7 +165,7 @@ class Af_RedditImgur extends Plugin { $source_stream = false; if ($source_article_url) { - $j = json_decode(fetch_file_contents($source_article_url.".json"), true); + $j = json_decode(UrlHelper::fetch($source_article_url.".json"), true); if ($j) { foreach ($j as $listing) { @@ -195,7 +195,7 @@ class Af_RedditImgur extends Plugin { Debug::log("Handling as Streamable", Debug::$LOG_VERBOSE); - $tmp = fetch_file_contents($entry->getAttribute("href")); + $tmp = UrlHelper::fetch($entry->getAttribute("href")); if ($tmp) { $tmpdoc = new DOMDocument(); @@ -230,7 +230,7 @@ class Af_RedditImgur extends Plugin { $source_stream = str_replace(".gifv", ".mp4", $entry->getAttribute("href")); - if (strpos($source_stream, "imgur.com") !== FALSE) + if (strpos($source_stream, "imgur.com") !== false) $poster_url = str_replace(".mp4", "h.jpg", $source_stream); $this->handle_as_video($doc, $entry, $source_stream, $poster_url); @@ -265,8 +265,8 @@ class Af_RedditImgur extends Plugin { } if (!$found && (preg_match("/\.(jpg|jpeg|gif|png)(\?[0-9][0-9]*)?[$\?]/i", $entry->getAttribute("href")) || - mb_strpos($entry->getAttribute("href"), "i.reddituploads.com") !== FALSE || - mb_strpos($this->get_content_type($entry->getAttribute("href")), "image/") !== FALSE)) { + mb_strpos($entry->getAttribute("href"), "i.reddituploads.com") !== false || + mb_strpos($this->get_content_type($entry->getAttribute("href")), "image/") !== false)) { Debug::log("Handling as a picture", Debug::$LOG_VERBOSE); @@ -285,7 +285,7 @@ class Af_RedditImgur extends Plugin { Debug::log("handling as imgur page/whatever", Debug::$LOG_VERBOSE); - $content = fetch_file_contents(["url" => $entry->getAttribute("href"), + $content = UrlHelper::fetch(["url" => $entry->getAttribute("href"), "http_accept" => "text/*"]); if ($content) { @@ -331,7 +331,7 @@ class Af_RedditImgur extends Plugin { if (!$found) { Debug::log("looking for meta og:image", Debug::$LOG_VERBOSE); - $content = fetch_file_contents(["url" => $entry->getAttribute("href"), + $content = UrlHelper::fetch(["url" => $entry->getAttribute("href"), "http_accept" => "text/*"]); if ($content) { @@ -393,7 +393,7 @@ class Af_RedditImgur extends Plugin { function hook_article_filter($article) { - if (strpos($article["link"], "reddit.com/r/") !== FALSE) { + if (strpos($article["link"], "reddit.com/r/") !== false) { $doc = new DOMDocument(); @$doc->loadHTML($article["content"]); $xpath = new DOMXPath($doc); @@ -437,6 +437,7 @@ class Af_RedditImgur extends Plugin { if ($node && $found) { $article["content"] = $doc->saveHTML($node); + $article["enclosures"] = []; } else if ($content_link) { $article = $this->readability($article, $content_link->getAttribute("href"), $doc, $xpath); } @@ -470,11 +471,11 @@ class Af_RedditImgur extends Plugin { $entry->parentNode->insertBefore($video, $entry); $entry->parentNode->insertBefore($br, $entry); - $img = $doc->createElement('img'); + /*$img = $doc->createElement('img'); $img->setAttribute("src", "data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs%3D"); - $entry->parentNode->insertBefore($img, $entry); + $entry->parentNode->insertBefore($img, $entry);*/ } function testurl() { @@ -542,7 +543,7 @@ class Af_RedditImgur extends Plugin { // do not try to embed posts linking back to other reddit posts // readability.php requires PHP 5.6 - if ($url && strpos($url, "reddit.com") === FALSE && version_compare(PHP_VERSION, '5.6.0', '>=')) { + if ($url && strpos($url, "reddit.com") === false && version_compare(PHP_VERSION, '5.6.0', '>=')) { /* link may lead to a huge video file or whatever, we need to check content type before trying to parse it which p much requires curl */ @@ -550,7 +551,7 @@ class Af_RedditImgur extends Plugin { $useragent_compat = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)"; $content_type = $this->get_content_type($url, $useragent_compat); - if ($content_type && strpos($content_type, "text/html") !== FALSE) { + if ($content_type && strpos($content_type, "text/html") !== false) { foreach ($this->host->get_hooks(PluginHost::HOOK_GET_FULL_TEXT) as $p) { $extracted_content = $p->hook_get_full_text($url); |