]> git.wh0rd.org Git - tt-rss.git/commitdiff
image cache: do not try to cache data: schema urls; add caching of html5 video conten...
authorAndrew Dolgov <noreply@fakecake.org>
Sat, 4 Feb 2017 08:50:01 +0000 (11:50 +0300)
committerAndrew Dolgov <noreply@fakecake.org>
Sat, 4 Feb 2017 08:50:01 +0000 (11:50 +0300)
include/functions2.php
include/rssfuncs.php
plugins/cache_starred_images/init.php

index 2b34f287c93e4e2188470bb982439b56983bcfc3..6017a78f84d66226face64666d02cb0875b6d7eb 100644 (file)
                $doc->loadHTML($charset_hack . $res);
                $xpath = new DOMXPath($doc);
 
-               $entries = $xpath->query('(//a[@href]|//img[@src])');
+               $entries = $xpath->query('(//a[@href]|//img[@src]|//video/source[@src])');
 
                $ttrss_uses_https = parse_url(get_self_url_prefix(), PHP_URL_SCHEME) === 'https';
 
                                        $entry->setAttribute('rel', 'noopener noreferrer');
                                }
 
-                               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';
+                               if ($entry->hasAttribute('src')) {
+                                       $src = rewrite_relative_url($site_url, $entry->getAttribute('src'));
 
-                                               if (file_exists($cached_filename)) {
-                                                       $src = SELF_URL_PATH . '/public.php?op=cached_image&hash=' . sha1($src) . '.png';
+                                       $extension = $entry->tagName == 'source' ? '.mp4' : '.png';
+                                       $cached_filename = CACHE_DIR . '/images/' . sha1($src) . $extension;
 
-                                                       if ($entry->hasAttribute('srcset')) {
-                                                               $entry->removeAttribute('srcset');
-                                                       }
+                                       if (file_exists($cached_filename)) {
+                                               $src = SELF_URL_PATH . '/public.php?op=cached_image&hash=' . sha1($src) . $extension;
 
-                                                       if ($entry->hasAttribute('sizes')) {
-                                                               $entry->removeAttribute('sizes');
-                                                       }
+                                               if ($entry->hasAttribute('srcset')) {
+                                                       $entry->removeAttribute('srcset');
                                                }
 
-                                               $entry->setAttribute('src', $src);
+                                               if ($entry->hasAttribute('sizes')) {
+                                                       $entry->removeAttribute('sizes');
+                                               }
                                        }
 
+                                       $entry->setAttribute('src', $src);
+                               }
+                               
+                               if ($entry->nodeName == 'img') {
+
                                        if ($entry->hasAttribute('src')) {
                                                $is_https_url = parse_url($entry->getAttribute('src'), PHP_URL_SCHEME) === 'https';
 
index fd4a10f13fea21171c8f01c72b3415c92860529b..1f38091b6126dc64c84d1aa7dfd37e4f75bb0ea0 100644 (file)
                $doc->loadHTML($charset_hack . $html);
                $xpath = new DOMXPath($doc);
 
-               $entries = $xpath->query('(//img[@src])');
+               $entries = $xpath->query('(//img[@src])|(//video/source[@src])');
 
                foreach ($entries as $entry) {
-                       if ($entry->hasAttribute('src')) {
+                       if ($entry->hasAttribute('src') && strpos($entry->getAttribute('src'), "data:") !== 0) {
                                $src = rewrite_relative_url($site_url, $entry->getAttribute('src'));
 
-                               $local_filename = CACHE_DIR . "/images/" . sha1($src) . ".png";
+                               $extension = $entry->tagName == 'source' ? '.mp4' : '.png';
+                               $local_filename = CACHE_DIR . "/images/" . sha1($src) . $extension;
 
                                if ($debug) _debug("cache_images: downloading: $src to $local_filename");
 
index 63637bfd8743820e6cb829d320635d394a94cd73..de627fc7722946f63b503f187b5a532455cb1cd5 100644 (file)
@@ -180,7 +180,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'));