diff options
author | Andrew Dolgov <[email protected]> | 2019-08-14 08:25:09 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2019-08-14 08:25:09 +0300 |
commit | 65450f8a2bbf325d26177c2589c3a9bbe67d8f80 (patch) | |
tree | 932b65b145294955ac4628cd9b0536c83c392ce6 /plugins/af_zz_imgproxy | |
parent | b0fbae938dbc7c66c7829a86f7dd0fe6fb689908 (diff) | |
parent | fdb6066bf67751ebb388a3de082d80f5444e3681 (diff) |
Merge branch 'master' of git.tt-rss.org:fox/tt-rss
Diffstat (limited to 'plugins/af_zz_imgproxy')
-rwxr-xr-x | plugins/af_zz_imgproxy/init.php | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/plugins/af_zz_imgproxy/init.php b/plugins/af_zz_imgproxy/init.php index b172d4563..b1281dff0 100755 --- a/plugins/af_zz_imgproxy/init.php +++ b/plugins/af_zz_imgproxy/init.php @@ -4,6 +4,9 @@ class Af_Zz_ImgProxy extends Plugin { /* @var PluginHost $host */ private $host; + /* @var DiskCache $cache */ + private $cache; + function about() { return array(1.0, "Load insecure images via built-in proxy", @@ -18,6 +21,7 @@ class Af_Zz_ImgProxy extends Plugin { function init($host) { $this->host = $host; + $this->cache = new DiskCache("images"); $host->add_hook($host::HOOK_RENDER_ARTICLE, $this); $host->add_hook($host::HOOK_RENDER_ARTICLE_CDM, $this); @@ -50,16 +54,10 @@ class Af_Zz_ImgProxy extends Plugin { return; } - $local_filename = CACHE_DIR . "/images/" . sha1($url); - - if ($_REQUEST["debug"] == "1") { print $url . "\n" . $local_filename; die; } - - header("Content-Disposition: inline; filename=\"".basename($local_filename)."\""); - - if (file_exists($local_filename)) { - - send_local_file($local_filename); + $local_filename = sha1($url); + if ($this->cache->exists($local_filename)) { + $this->cache->send($local_filename); } else { $data = fetch_file_contents(["url" => $url, "max_size" => MAX_CACHE_FILE_SIZE]); @@ -68,8 +66,8 @@ class Af_Zz_ImgProxy extends Plugin { $disable_cache = $this->host->get($this, "disable_cache"); if (!$disable_cache && strlen($data) > MIN_CACHE_FILE_SIZE) { - if (file_put_contents($local_filename, $data)) { - $mimetype = mime_content_type($local_filename); + if ($this->cache->put($local_filename, $data)) { + $mimetype = $this->cache->getMimeType($local_filename); header("Content-type: $mimetype"); } } @@ -110,7 +108,7 @@ class Af_Zz_ImgProxy extends Plugin { } } - function rewrite_url_if_needed($url, $all_remote = false) { + private function rewrite_url_if_needed($url, $all_remote = false) { $scheme = parse_url($url, PHP_URL_SCHEME); if ($all_remote) { |