diff --git a/classes/urlhelper.php b/classes/urlhelper.php index 55d5d1e6a..46d80a0e6 100644 --- a/classes/urlhelper.php +++ b/classes/urlhelper.php @@ -271,10 +271,15 @@ class UrlHelper { // holy shit closures in php // download & upload are *expected* sizes respectively, could be zero - curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function($curl_handle, $download_size, $downloaded, $upload_size, $uploaded) use( &$max_size) { - Debug::log("[curl progressfunction] $downloaded $max_size", Debug::$LOG_EXTENDED); + curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function($curl_handle, $download_size, $downloaded, $upload_size, $uploaded) use(&$max_size, $url) { + //Debug::log("[curl progressfunction] $downloaded $max_size", Debug::$LOG_EXTENDED); - return ($downloaded > $max_size) ? 1 : 0; // if max size is set, abort when exceeding it + if ($downloaded > $max_size) { + Debug::log("curl: reached max size of $max_size bytes requesting $url, aborting.", Debug::LOG_VERBOSE); + return 1; + } + + return 0; }); } diff --git a/plugins/af_redditimgur/init.php b/plugins/af_redditimgur/init.php index 32970fb99..35eb40950 100755 --- a/plugins/af_redditimgur/init.php +++ b/plugins/af_redditimgur/init.php @@ -132,7 +132,7 @@ class Af_RedditImgur extends Plugin { if (!empty($media["s"]["u"])) { $media_url = htmlspecialchars_decode($media["s"]["u"]); - Debug::log("found media_metadata (gallery): $media_url", Debug::$LOG_VERBOSE); + Debug::log("found media_metadata (gallery): $media_url", Debug::LOG_VERBOSE); if ($media_url) { $this->handle_as_image($doc, $anchor, $media_url); @@ -153,7 +153,7 @@ class Af_RedditImgur extends Plugin { else $poster_url = ""; - Debug::log("found stream fallback_url: $stream_url / poster $poster_url", Debug::$LOG_VERBOSE); + Debug::log("found stream fallback_url: $stream_url / poster $poster_url", Debug::LOG_VERBOSE); $this->handle_as_video($doc, $anchor, $stream_url, $poster_url); } @@ -172,12 +172,12 @@ class Af_RedditImgur extends Plugin { else $poster_url = ""; - Debug::log("found hosted video url: $media_url / poster $poster_url, looking up fallback url...", Debug::$LOG_VERBOSE); + Debug::log("found hosted video url: $media_url / poster $poster_url, looking up fallback url...", Debug::LOG_VERBOSE); $fallback_url = $data["media"]["reddit_video"]["fallback_url"]; if ($fallback_url) { - Debug::log("found video fallback_url: $fallback_url", Debug::$LOG_VERBOSE); + Debug::log("found video fallback_url: $fallback_url", Debug::LOG_VERBOSE); $this->handle_as_video($doc, $anchor, $fallback_url, $poster_url); $found = 1; @@ -192,7 +192,7 @@ class Af_RedditImgur extends Plugin { else $poster_url = ""; - Debug::log("found video url: $media_url / poster $poster_url", Debug::$LOG_VERBOSE); + Debug::log("found video url: $media_url / poster $poster_url", Debug::LOG_VERBOSE); $this->handle_as_video($doc, $anchor, $media_url, $poster_url); $found = 1; @@ -201,7 +201,7 @@ class Af_RedditImgur extends Plugin { if (!$found && $post_hint == "image") { $media_url = $data["url"]; - Debug::log("found image url: $media_url", Debug::$LOG_VERBOSE); + Debug::log("found image url: $media_url", Debug::LOG_VERBOSE); $this->handle_as_image($doc, $anchor, $media_url); $found = 1; @@ -215,12 +215,12 @@ class Af_RedditImgur extends Plugin { if ($media_url) { if ($post_hint == "self") { - Debug::log("found preview image url: $media_url (link: $target_url)", Debug::$LOG_VERBOSE); + Debug::log("found preview image url: $media_url (link: $target_url)", Debug::LOG_VERBOSE); $this->handle_as_image($doc, $anchor, $media_url, $target_url); $found = 1; } else { // gonna use this later if nothing is found using generic link processing - Debug::log("found fallback preview image url: $media_url (link: $target_url);", Debug::$LOG_VERBOSE); + Debug::log("found fallback preview image url: $media_url (link: $target_url);", Debug::LOG_VERBOSE); array_push($this->fallback_preview_urls, $media_url); } } @@ -247,12 +247,12 @@ class Af_RedditImgur extends Plugin { $link_flairs = []; $apply_nsfw_tags = FeedItem_Common::normalize_categories($this->host->get_array($this, "apply_nsfw_tags", [])); - // embed before reddit
+ if ($anchor) + $anchor->parentNode->insertBefore($iframe, $anchor); + else + $entry->parentNode->insertBefore($iframe, $entry); $found = true; } @@ -452,7 +458,7 @@ class Af_RedditImgur extends Plugin { /* mb_strpos($entry_href, "i.reddituploads.com") !== false || */ mb_strpos($this->get_content_type($entry_href), "image/") !== false)) { - Debug::log("Handling as a picture", Debug::$LOG_VERBOSE); + Debug::log("Handling as a picture", Debug::LOG_VERBOSE); $img = $doc->createElement('img'); $img->setAttribute("src", $entry_href); @@ -467,7 +473,7 @@ class Af_RedditImgur extends Plugin { // imgur via link rel="image_src" href="..." if (!$found && preg_match("/imgur/", $entry_href)) { - Debug::log("handling as imgur page/whatever", Debug::$LOG_VERBOSE); + Debug::log("handling as imgur page/whatever", Debug::LOG_VERBOSE); $content = UrlHelper::fetch(["url" => $entry_href, "http_accept" => "text/*"]); @@ -499,7 +505,7 @@ class Af_RedditImgur extends Plugin { if (!$found && preg_match("/^https?:\/\/gyazo\.com\/([^\.\/]+$)/", $entry_href, $matches)) { $img_id = $matches[1]; - Debug::log("handling as gyazo: $img_id", Debug::$LOG_VERBOSE); + Debug::log("handling as gyazo: $img_id", Debug::LOG_VERBOSE); $img = $doc->createElement('img'); $img->setAttribute("src", "https://i.gyazo.com/$img_id.jpg"); @@ -513,7 +519,7 @@ class Af_RedditImgur extends Plugin { // let's try meta properties if (!$found) { - Debug::log("looking for meta og:image", Debug::$LOG_VERBOSE); + Debug::log("looking for meta og:image", Debug::LOG_VERBOSE); $content = UrlHelper::fetch(["url" => $entry_href, "http_accept" => "text/*"]); @@ -564,7 +570,7 @@ class Af_RedditImgur extends Plugin { } if (!$found && $anchor && count($this->fallback_preview_urls) > 0) { - Debug::log("JSON: processing fallback preview urls...", Debug::$LOG_VERBOSE); + Debug::log("JSON: processing fallback preview urls...", Debug::LOG_VERBOSE); foreach ($this->fallback_preview_urls as $media_url) { $this->handle_as_image($doc, $anchor, $media_url); @@ -671,7 +677,7 @@ class Af_RedditImgur extends Plugin { private function handle_as_video($doc, $entry, $source_stream, $poster_url = false) { - Debug::log("handle_as_video: $source_stream", Debug::$LOG_VERBOSE); + Debug::log("handle_as_video: $source_stream", Debug::LOG_VERBOSE); $video = $doc->createElement('video'); $video->setAttribute("autoplay", "1"); @@ -705,10 +711,11 @@ class Af_RedditImgur extends Plugin { $url = clean($_POST["url"] ?? ""); $article_url = clean($_POST["article_url"] ?? ""); + $article_id = clean($_POST["article_id"] ?? ""); $this->dump_json_data = true; - if (!$url && !$article_url) { + if (!$url && !$article_url && !$article_id) { header("Content-type: text/html"); ?> |