1
0
mirror of https://git.tt-rss.org/git/tt-rss.git synced 2025-12-23 00:01:29 +00:00

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
This commit is contained in:
Andrew Dolgov
2017-03-23 14:55:40 +03:00
parent 63f0ed3d9c
commit 41bead9baa
4 changed files with 19 additions and 19 deletions

View File

@@ -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 = '<head>
@@ -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 {