]> git.wh0rd.org - tt-rss.git/commitdiff
image cache: send files as content-disposition: attachment; add .png suffix to image...
authorAndrew Dolgov <noreply@fakecake.org>
Sat, 4 Feb 2017 08:32:24 +0000 (11:32 +0300)
committerAndrew Dolgov <noreply@fakecake.org>
Sat, 4 Feb 2017 08:32:24 +0000 (11:32 +0300)
classes/handler/public.php
include/functions2.php

index a516b6c5ca2116aa14048fa07a9e161d91319daa..0fc8476c7bd012f01348cb58a5540fa71cd9878d 100644 (file)
@@ -1051,9 +1051,11 @@ class Handler_Public extends Handler {
 
                if ($hash) {
 
-                       $filename = CACHE_DIR . '/images/' . $hash . '.png';
+                       $filename = CACHE_DIR . '/images/' . $hash;
 
                        if (file_exists($filename)) {
+                               header("Content-Disposition: attachment; filename=\"".basename($filename)."\"");
+
                                /* See if we can use X-Sendfile */
                                $xsendfile = false;
                                if (function_exists('apache_get_modules') &&
index b8eff56d2cf6e47e138236c7d18aeb4904ec173d..2b34f287c93e4e2188470bb982439b56983bcfc3 100644 (file)
                                        $entry->setAttribute('rel', 'noopener noreferrer');
                                }
 
-                               if ($entry->hasAttribute('src')) {
-                                       $src = rewrite_relative_url($site_url, $entry->getAttribute('src'));
+                               if ($entry->nodeName == 'img') {
+
+                                       if ($entry->hasAttribute('src')) {
+                                               $src = rewrite_relative_url($site_url, $entry->getAttribute('src'));
 
-                                       $cached_filename = CACHE_DIR . '/images/' . sha1($src) . '.png';
+                                               $cached_filename = CACHE_DIR . '/images/' . sha1($src) . '.png';
 
-                                       if (file_exists($cached_filename)) {
-                                               $src = SELF_URL_PATH . '/public.php?op=cached_image&hash=' . sha1($src);
+                                               if (file_exists($cached_filename)) {
+                                                       $src = SELF_URL_PATH . '/public.php?op=cached_image&hash=' . sha1($src) . '.png';
 
-                                               if ($entry->hasAttribute('srcset')) {
-                                                       $entry->removeAttribute('srcset');
-                                               }
+                                                       if ($entry->hasAttribute('srcset')) {
+                                                               $entry->removeAttribute('srcset');
+                                                       }
 
-                                               if ($entry->hasAttribute('sizes')) {
-                                                       $entry->removeAttribute('sizes');
+                                                       if ($entry->hasAttribute('sizes')) {
+                                                               $entry->removeAttribute('sizes');
+                                                       }
                                                }
-                                       }
 
-                                       $entry->setAttribute('src', $src);
-                               }
+                                               $entry->setAttribute('src', $src);
+                                       }
 
-                               if ($entry->nodeName == 'img') {
                                        if ($entry->hasAttribute('src')) {
                                                $is_https_url = parse_url($entry->getAttribute('src'), PHP_URL_SCHEME) === 'https';