summaryrefslogtreecommitdiff
path: root/plugins/af_redditimgur/init.php
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/af_redditimgur/init.php')
-rwxr-xr-xplugins/af_redditimgur/init.php38
1 files changed, 19 insertions, 19 deletions
diff --git a/plugins/af_redditimgur/init.php b/plugins/af_redditimgur/init.php
index be3a5108e..2b8415dd0 100755
--- a/plugins/af_redditimgur/init.php
+++ b/plugins/af_redditimgur/init.php
@@ -82,7 +82,7 @@ class Af_RedditImgur extends Plugin {
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
- private function inline_stuff($article, &$doc, $xpath, $debug = false) {
+ private function inline_stuff($article, &$doc, $xpath) {
$entries = $xpath->query('(//a[@href]|//img[@src])');
$img_entries = $xpath->query("(//img[@src])");
@@ -93,12 +93,12 @@ class Af_RedditImgur extends Plugin {
foreach ($entries as $entry) {
if ($entry->hasAttribute("href") && strpos($entry->getAttribute("href"), "reddit.com") === FALSE) {
- _debug("processing href: " . $entry->getAttribute("href"), $debug);
+ Debug::log("processing href: " . $entry->getAttribute("href"), Debug::$LOG_VERBOSE);
$matches = array();
if (!$found && preg_match("/^https?:\/\/twitter.com\/(.*?)\/status\/(.*)/", $entry->getAttribute("href"), $matches)) {
- _debug("handling as twitter: " . $matches[1] . " " . $matches[2], $debug);
+ 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")));
@@ -130,7 +130,7 @@ class Af_RedditImgur extends Plugin {
if (!$found && preg_match("/https?:\/\/(www\.)?gfycat.com\/([a-z]+)$/i", $entry->getAttribute("href"), $matches)) {
- _debug("Handling as Gfycat", $debug);
+ Debug::log("Handling as Gfycat", Debug::$LOG_VERBOSE);
$source_stream = 'https://giant.gfycat.com/' . $matches[2] . '.mp4';
$poster_url = 'https://thumbs.gfycat.com/' . $matches[2] . '-mobile.jpg';
@@ -145,7 +145,7 @@ class Af_RedditImgur extends Plugin {
if (!$found && preg_match("/https?:\/\/v\.redd\.it\/(.*)$/i", $entry->getAttribute("href"), $matches)) {
- _debug("Handling as reddit inline video", $debug);
+ Debug::log("Handling as reddit inline video", Debug::$LOG_VERBOSE);
$img = $img_entries->item(0);
@@ -157,7 +157,7 @@ class Af_RedditImgur extends Plugin {
// Get original article URL from v.redd.it redirects
$source_article_url = $this->get_location($matches[0]);
- _debug("Resolved ".$matches[0]." to ".$source_article_url, $debug);
+ Debug::log("Resolved ".$matches[0]." to ".$source_article_url, Debug::$LOG_VERBOSE);
$source_stream = false;
@@ -190,7 +190,7 @@ class Af_RedditImgur extends Plugin {
if (!$found && preg_match("/https?:\/\/(www\.)?streamable.com\//i", $entry->getAttribute("href"))) {
- _debug("Handling as Streamable", $debug);
+ Debug::log("Handling as Streamable", Debug::$LOG_VERBOSE);
$tmp = fetch_file_contents($entry->getAttribute("href"));
@@ -216,21 +216,21 @@ class Af_RedditImgur extends Plugin {
// imgur .gif -> .gifv
if (!$found && preg_match("/i\.imgur\.com\/(.*?)\.gif$/i", $entry->getAttribute("href"))) {
- _debug("Handling as imgur gif (->gifv)", $debug);
+ Debug::log("Handling as imgur gif (->gifv)", Debug::$LOG_VERBOSE);
$entry->setAttribute("href",
str_replace(".gif", ".gifv", $entry->getAttribute("href")));
}
if (!$found && preg_match("/\.(gifv|mp4)$/i", $entry->getAttribute("href"))) {
- _debug("Handling as imgur gifv", $debug);
+ Debug::log("Handling as imgur gifv", Debug::$LOG_VERBOSE);
$source_stream = str_replace(".gifv", ".mp4", $entry->getAttribute("href"));
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, $debug);
+ $this->handle_as_video($doc, $entry, $source_stream, $poster_url);
$found = true;
}
@@ -243,7 +243,7 @@ class Af_RedditImgur extends Plugin {
$vid_id = $matches[1];
- _debug("Handling as youtube: $vid_id", $debug);
+ Debug::log("Handling as youtube: $vid_id", Debug::$LOG_VERBOSE);
$iframe = $doc->createElement("iframe");
$iframe->setAttribute("class", "youtube-player");
@@ -265,7 +265,7 @@ class Af_RedditImgur extends Plugin {
mb_strpos($entry->getAttribute("href"), "i.reddituploads.com") !== FALSE ||
mb_strpos($this->get_content_type($entry->getAttribute("href")), "image/") !== FALSE) {
- _debug("Handling as a picture", $debug);
+ Debug::log("Handling as a picture", Debug::$LOG_VERBOSE);
$img = $doc->createElement('img');
$img->setAttribute("src", $entry->getAttribute("href"));
@@ -281,7 +281,7 @@ class Af_RedditImgur extends Plugin {
if (!$found && preg_match("/^https?:\/\/gyazo\.com\/([^\.\/]+$)/", $entry->getAttribute("href"), $matches)) {
$img_id = $matches[1];
- _debug("handling as gyazo: $img_id", $debug);
+ Debug::log("handling as gyazo: $img_id", Debug::$LOG_VERBOSE);
$img = $doc->createElement('img');
$img->setAttribute("src", "https://i.gyazo.com/$img_id.jpg");
@@ -295,7 +295,7 @@ class Af_RedditImgur extends Plugin {
// let's try meta properties
if (!$found) {
- _debug("looking for meta og:image", $debug);
+ Debug::log("looking for meta og:image", Debug::$LOG_VERBOSE);
$content = fetch_file_contents(["url" => $entry->getAttribute("href"),
"http_accept" => "text/*"]);
@@ -415,9 +415,9 @@ class Af_RedditImgur extends Plugin {
return 2;
}
- private function handle_as_video($doc, $entry, $source_stream, $poster_url = false, $debug = false) {
+ private function handle_as_video($doc, $entry, $source_stream, $poster_url = false) {
- _debug("handle_as_video: $source_stream", $debug);
+ Debug::log("handle_as_video: $source_stream", Debug::$LOG_VERBOSE);
$video = $doc->createElement('video');
$video->setAttribute("autoplay", "1");
@@ -454,14 +454,14 @@ class Af_RedditImgur extends Plugin {
@$doc->loadHTML("<html><body><a href=\"$url\">[link]</a></body>");
$xpath = new DOMXPath($doc);
- $found = $this->inline_stuff([], $doc, $xpath, true);
+ $found = $this->inline_stuff([], $doc, $xpath);
print "Inline result: $found\n";
if (!$found) {
print "\nReadability result:\n";
- $article = $this->readability([], $url, $doc, $xpath, true);
+ $article = $this->readability([], $url, $doc, $xpath);
print_r($article);
} else {
@@ -523,7 +523,7 @@ class Af_RedditImgur extends Plugin {
"useragent" => $useragent_compat,
"http_accept" => "text/html"]);
- if ($debug) _debug("tmplen: " . mb_strlen($tmp));
+ Debug::log("tmplen: " . mb_strlen($tmp), Debug::$LOG_VERBOSE);
if ($tmp && mb_strlen($tmp) < 1024 * 500) {