From 41bead9baa6ae6fa84834ec291167fdc780b1e63 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 23 Mar 2017 14:55:40 +0300 Subject: remove local file extensions and generalize some method names for cached media file extensions may still be present in urls, but are ignored by the backend MIGRATION (if you have any cached data worth keeping, not required): in cache/images run "rename 's/\..*$//' *" i.e. strip file extensions --- include/functions2.php | 4 ++-- include/rssfuncs.php | 13 ++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/functions2.php b/include/functions2.php index 34f027a55..39c7f746b 100644 --- a/include/functions2.php +++ b/include/functions2.php @@ -913,11 +913,11 @@ // check cache only for video and images for the time being if ($entry->nodeName == 'img' || ($entry->parentNode && $entry->parentNode->nodeName == "video")) { + $cached_filename = CACHE_DIR . '/images/' . sha1($src); $extension = $entry->tagName == 'source' ? '.mp4' : '.png'; - $cached_filename = CACHE_DIR . '/images/' . sha1($src) . $extension; if (file_exists($cached_filename)) { - $src = get_self_url_prefix() . '/public.php?op=cached_image&hash=' . sha1($src) . $extension; + $src = get_self_url_prefix() . '/public.php?op=cached_url&hash=' . sha1($src) . $extension; if ($entry->hasAttribute('srcset')) { $entry->removeAttribute('srcset'); diff --git a/include/rssfuncs.php b/include/rssfuncs.php index e26fc38be..997ea4594 100644 --- a/include/rssfuncs.php +++ b/include/rssfuncs.php @@ -2,7 +2,7 @@ define_default('DAEMON_UPDATE_LOGIN_LIMIT', 30); define_default('DAEMON_FEED_LIMIT', 500); define_default('DAEMON_SLEEP_INTERVAL', 120); - define_default('_MIN_CACHE_IMAGE_SIZE', 1024); + define_default('_MIN_CACHE_FILE_SIZE', 1024); function calculate_article_hash($article, $pluginhost) { $tmp = ""; @@ -864,7 +864,7 @@ _debug("force catchup: $entry_force_catchup"); if ($cache_images && is_writable(CACHE_DIR . '/images')) - cache_images($entry_content, $site_url, $debug_enabled); + cache_media($entry_content, $site_url, $debug_enabled); $entry_content = db_escape_string($entry_content, false); @@ -1227,7 +1227,7 @@ return $rss; } - function cache_images($html, $site_url, $debug) { + function cache_media($html, $site_url, $debug) { libxml_use_internal_errors(true); $charset_hack = ' @@ -1244,15 +1244,14 @@ if ($entry->hasAttribute('src') && strpos($entry->getAttribute('src'), "data:") !== 0) { $src = rewrite_relative_url($site_url, $entry->getAttribute('src')); - $extension = $entry->tagName == 'source' ? '.mp4' : '.png'; - $local_filename = CACHE_DIR . "/images/" . sha1($src) . $extension; + $local_filename = CACHE_DIR . "/images/" . sha1($src); - if ($debug) _debug("cache_images: downloading: $src to $local_filename"); + if ($debug) _debug("cache_media: downloading: $src to $local_filename"); if (!file_exists($local_filename)) { $file_content = fetch_file_contents($src); - if ($file_content && strlen($file_content) > _MIN_CACHE_IMAGE_SIZE) { + if ($file_content && strlen($file_content) > _MIN_CACHE_FILE_SIZE) { file_put_contents($local_filename, $file_content); } } else { -- cgit v1.2.3-54-g00ecf