]> git.wh0rd.org - tt-rss.git/blobdiff - plugins/cache_starred_images/init.php
remove apache-specific x-sendfile stuff
[tt-rss.git] / plugins / cache_starred_images / init.php
index f1341a35078d884267c131beb59e4f0779eb46a5..82e7d1fbd6b46a0a675d51cf06a9122794da4172 100644 (file)
@@ -11,10 +11,16 @@ class Cache_Starred_Images extends Plugin implements IHandler {
                        true);
        }
 
+       /**
+        * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+        */
        function csrf_ignore($method) {
                return false;
        }
 
+       /**
+        * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+        */
        function before($method) {
                return true;
        }
@@ -59,26 +65,12 @@ class Cache_Starred_Images extends Plugin implements IHandler {
 
                if ($hash) {
 
-                       $filename = $this->cache_dir . "/" . $hash;
-                       $is_video = strpos($filename, ".mp4") !== FALSE;
+                       $filename = $this->cache_dir . "/" . basename($hash);
 
                        if (file_exists($filename)) {
-                               /* See if we can use X-Sendfile */
-                               $xsendfile = false;
-                               if (function_exists('apache_get_modules') &&
-                                   array_search('mod_xsendfile', apache_get_modules()))
-                                       $xsendfile = true;
-
-                               if ($xsendfile) {
-                                       header("X-Sendfile: $filename");
-                                       header("Content-type: application/octet-stream");
-                                       header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
-                               } else {
-                                       header("Content-type: " . ($is_video ? "video/mp4" : "image/png"));
-                                       $stamp = gmdate("D, d M Y H:i:s", filemtime($filename)). " GMT";
-                                       header("Last-Modified: $stamp", true);
-                                       readfile($filename);
-                               }
+                               header("Content-Disposition: attachment; filename=\"$hash\"");
+
+                               send_local_file($filename);
                        } else {
                                header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
                                echo "File not found.";
@@ -86,6 +78,9 @@ class Cache_Starred_Images extends Plugin implements IHandler {
                }
        }
 
+       /**
+        * @SuppressWarnings(PHPMD.UnusedLocalVariable)
+        */
        function hook_house_keeping() {
                $files = glob($this->cache_dir . "/*.{png,mp4}", GLOB_BRACE);
 
@@ -110,6 +105,9 @@ class Cache_Starred_Images extends Plugin implements IHandler {
                }
        }
 
+       /**
+        * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+        */
        function hook_sanitize($doc, $site_url, $allowed_elements, $disallowed_attributes, $article_id) {
                $xpath = new DOMXpath($doc);
 
@@ -160,6 +158,9 @@ class Cache_Starred_Images extends Plugin implements IHandler {
                }
        }
 
+       /**
+        * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+        */
        function cache_article_images($content, $site_url, $owner_uid, $article_id) {
                libxml_use_internal_errors(true);
 
@@ -178,7 +179,8 @@ class Cache_Starred_Images extends Plugin implements IHandler {
 
                foreach ($entries as $entry) {
 
-                       if ($entry->hasAttribute('src')) {
+                       if ($entry->hasAttribute('src') && strpos($entry->getAttribute('src'), "data:") !== 0) {
+
                                $has_images = true;
                                $src = rewrite_relative_url($site_url, $entry->getAttribute('src'));
 
@@ -191,7 +193,7 @@ class Cache_Starred_Images extends Plugin implements IHandler {
                                if (!file_exists($local_filename)) {
                                        $file_content = fetch_file_contents($src);
 
-                                       if ($file_content && strlen($file_content) > 0) {
+                                       if ($file_content && strlen($file_content) > MIN_CACHE_FILE_SIZE) {
                                                file_put_contents($local_filename, $file_content);
                                                $success = true;
                                        }
@@ -208,4 +210,3 @@ class Cache_Starred_Images extends Plugin implements IHandler {
                return 2;
        }
 }
-?>