diff options
author | Andrew Dolgov <[email protected]> | 2019-08-13 12:39:21 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2019-08-13 12:39:21 +0300 |
commit | b1dd38f880d843dad92f0d76838edd40f1bf687b (patch) | |
tree | 5a765e132ce74911e0b68596fa51118e4ee0f7a0 | |
parent | 7602819b9825ffe2013e214b6d072ae798d5541a (diff) |
add DiskCache.getUrl() and use it in a bunch of places
-rwxr-xr-x | classes/article.php | 2 | ||||
-rw-r--r-- | classes/diskcache.php | 4 | ||||
-rwxr-xr-x | classes/handler/public.php | 2 | ||||
-rw-r--r-- | include/functions.php | 15 |
4 files changed, 7 insertions, 16 deletions
diff --git a/classes/article.php b/classes/article.php index 43b25f94f..2f43b9b07 100755 --- a/classes/article.php +++ b/classes/article.php @@ -676,7 +676,7 @@ class Article extends Handler_Protected { while ($line = $sth->fetch()) { if (file_exists(CACHE_DIR . '/images/' . sha1($line["content_url"]))) { - $line["content_url"] = get_self_url_prefix() . '/public.php?op=cached_url&hash=' . sha1($line["content_url"]); + $line["content_url"] = DiskCache::getUrl(sha1($line["content_url"])); } array_push($rv, $line); diff --git a/classes/diskcache.php b/classes/diskcache.php index d21148041..9dbc010c6 100644 --- a/classes/diskcache.php +++ b/classes/diskcache.php @@ -56,4 +56,8 @@ class DiskCache { public function send($filename) { return send_local_file($this->getFullPath($filename)); } + + static public function getUrl($filename) { + return get_self_url_prefix() . "/public.php?op=cached_url&file=" . $filename; + } } diff --git a/classes/handler/public.php b/classes/handler/public.php index 0e990bec7..97c61cfd3 100755 --- a/classes/handler/public.php +++ b/classes/handler/public.php @@ -1202,7 +1202,7 @@ class Handler_Public extends Handler { } function cached_url() { - @$req_filename = basename($_GET['hash']); + @$req_filename = basename($_GET['file']); // we don't need an extension to find the file, hash is a complete URL $hash = preg_replace("/\.[^\.]*$/", "", $req_filename); diff --git a/include/functions.php b/include/functions.php index 80ae3fe7e..b63f8725e 100644 --- a/include/functions.php +++ b/include/functions.php @@ -1258,20 +1258,7 @@ if (file_exists($cached_filename)) { - // this is strictly cosmetic - if ($entry->tagName == 'img') { - $suffix = ".png"; - } else if ($entry->parentNode && $entry->parentNode->tagName == "picture") { - $suffix = ".png"; - } else if ($entry->parentNode && $entry->parentNode->tagName == "video") { - $suffix = ".mp4"; - } else if ($entry->parentNode && $entry->parentNode->tagName == "audio") { - $suffix = ".ogg"; - } else { - $suffix = ""; - } - - $src = get_self_url_prefix() . '/public.php?op=cached_url&hash=' . sha1($src) . $suffix; + $src = DiskCache::getUrl(sha1($src)); if ($entry->hasAttribute('poster')) $entry->setAttribute('poster', $src); |