I noticed that images that were loaded within the `format_article_enclosures`function with the plugin enabled were not properly being proxied. To address that I've added support to the plugin for the `HOOK_RENDER_ENCLOSURE` hook to rewrite the image URLs as-needed. Additionally, I've adjusted the regex in `hook_enclosure_entry` hook function as it was not catching any image URLs that had CGI params, e.g. photo.jpg?size=small
Here is the diff:
Code: Select all
diff --git a/plugins/af_zz_imgproxy/init.php b/plugins/af_zz_imgproxy/init.php
index f326b8e..af32419 100644
--- a/plugins/af_zz_imgproxy/init.php
+++ b/plugins/af_zz_imgproxy/init.php
@@ -18,20 +18,47 @@ class Af_Zz_ImgProxy extends Plugin {
$host->add_hook($host::HOOK_RENDER_ARTICLE, $this);
$host->add_hook($host::HOOK_RENDER_ARTICLE_CDM, $this);
$host->add_hook($host::HOOK_ENCLOSURE_ENTRY, $this);
-
+ $host->add_hook($host::HOOK_RENDER_ENCLOSURE, $this);
$host->add_hook($host::HOOK_PREFS_TAB, $this);
}
function hook_enclosure_entry($enc) {
- if (preg_match("/image/", $enc["content_type"]) || preg_match("/\.(jpe?g|png|gif|bmp)$/i", $enc["filename"])) {
+ if (preg_match("/image/", $enc["content_type"]) || preg_match("/\.(jpe?g|png|gif|bmp)/i", $enc["filename"])) {
$proxy_all = $this->host->get($this, "proxy_all");
-
$enc["content_url"] = $this->rewrite_url_if_needed($enc["content_url"], 0, $proxy_all);
}
-
return $enc;
}
+ function hook_render_enclosure($entry) {
+ if (preg_match("/image/", $entry["type"]) || preg_match("/\.(jpe?g|png|gif|bmp)/i", $entry["filename"])) {
+ $proxy_all = $this->host->get($this, "proxy_all");
+ $entry["url"] = $this->rewrite_url_if_needed($entry["url"], 0, $proxy_all);
+
+ if (!$hide_images) {
+ $encsize = '';
+ if ($entry['height'] > 0)
+ $encsize .= ' height="' . intval($entry['height']) . '"';
+ if ($entry['width'] > 0)
+ $encsize .= ' width="' . intval($entry['width']) . '"';
+ $rv = "<p><img
+ alt=\"".htmlspecialchars($entry["filename"])."\"
+ src=\"" .htmlspecialchars($entry["url"]) . "\"
+ " . $encsize . " /></p>";
+ } else {
+ $rv = "<p><a target=\"_blank\" rel=\"noopener noreferrer\"
+ href=\"".htmlspecialchars($entry["url"])."\"
+ >" .htmlspecialchars($entry["url"]) . "</a></p>";
+ }
+
+ if ($entry['title']) {
+ $rv.= "<div class=\"enclosure_title\">${entry['title']}</div>";
+ }
+
+ return $rv;
+ }
+ }
+
function hook_render_article($article) {
return $this->hook_render_article_cdm($article);
}
@@ -230,4 +257,5 @@ class Af_Zz_ImgProxy extends Plugin {
function api_version() {
return 2;
}
-}
\ No newline at end of file
+}
+
If this is good, I'd love to get developer privileges to make the merge request - my gitlab username is the same as here: ErinMorelli
Thanks!
/Erin