mirror of
https://git.tt-rss.org/git/tt-rss.git
synced 2025-12-13 17:45:55 +00:00
diskcache: unify naming
This commit is contained in:
@@ -348,7 +348,7 @@ class API extends Handler {
|
||||
},
|
||||
$hook_object);
|
||||
|
||||
$article['content'] = DiskCache::rewriteUrls($article['content']);
|
||||
$article['content'] = DiskCache::rewrite_urls($article['content']);
|
||||
|
||||
array_push($articles, $article);
|
||||
|
||||
@@ -792,7 +792,7 @@ class API extends Handler {
|
||||
},
|
||||
$hook_object);
|
||||
|
||||
$headline_row["content"] = DiskCache::rewriteUrls($headline_row['content']);
|
||||
$headline_row["content"] = DiskCache::rewrite_urls($headline_row['content']);
|
||||
}
|
||||
|
||||
array_push($headlines, $headline_row);
|
||||
|
||||
@@ -508,7 +508,7 @@ class Article extends Handler_Protected {
|
||||
while ($line = $sth->fetch(PDO::FETCH_ASSOC)) {
|
||||
|
||||
if ($cache->exists(sha1($line["content_url"]))) {
|
||||
$line["content_url"] = $cache->getUrl(sha1($line["content_url"]));
|
||||
$line["content_url"] = $cache->get_url(sha1($line["content_url"]));
|
||||
}
|
||||
|
||||
array_push($rv, $line);
|
||||
@@ -678,10 +678,10 @@ class Article extends Handler_Protected {
|
||||
$cache = new DiskCache("images");
|
||||
|
||||
if ($article_image && $cache->exists(sha1($article_image)))
|
||||
$article_image = $cache->getUrl(sha1($article_image));
|
||||
$article_image = $cache->get_url(sha1($article_image));
|
||||
|
||||
if ($article_stream && $cache->exists(sha1($article_stream)))
|
||||
$article_stream = $cache->getUrl(sha1($article_stream));
|
||||
$article_stream = $cache->get_url(sha1($article_stream));
|
||||
|
||||
return [$article_image, $article_stream, $article_kind];
|
||||
}
|
||||
|
||||
@@ -194,20 +194,20 @@ class DiskCache {
|
||||
$this->dir = CACHE_DIR . "/" . basename(clean($dir));
|
||||
}
|
||||
|
||||
public function getDir() {
|
||||
public function get_dir() {
|
||||
return $this->dir;
|
||||
}
|
||||
|
||||
public function makeDir() {
|
||||
public function make_dir() {
|
||||
if (!is_dir($this->dir)) {
|
||||
return mkdir($this->dir);
|
||||
}
|
||||
}
|
||||
|
||||
public function isWritable($filename = "") {
|
||||
public function is_writable($filename = "") {
|
||||
if ($filename) {
|
||||
if (file_exists($this->getFullPath($filename)))
|
||||
return is_writable($this->getFullPath($filename));
|
||||
if (file_exists($this->get_full_path($filename)))
|
||||
return is_writable($this->get_full_path($filename));
|
||||
else
|
||||
return is_writable($this->dir);
|
||||
} else {
|
||||
@@ -216,44 +216,44 @@ class DiskCache {
|
||||
}
|
||||
|
||||
public function exists($filename) {
|
||||
return file_exists($this->getFullPath($filename));
|
||||
return file_exists($this->get_full_path($filename));
|
||||
}
|
||||
|
||||
public function getSize($filename) {
|
||||
public function get_size($filename) {
|
||||
if ($this->exists($filename))
|
||||
return filesize($this->getFullPath($filename));
|
||||
return filesize($this->get_full_path($filename));
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
public function getFullPath($filename) {
|
||||
public function get_full_path($filename) {
|
||||
return $this->dir . "/" . basename(clean($filename));
|
||||
}
|
||||
|
||||
public function put($filename, $data) {
|
||||
return file_put_contents($this->getFullPath($filename), $data);
|
||||
return file_put_contents($this->get_full_path($filename), $data);
|
||||
}
|
||||
|
||||
public function touch($filename) {
|
||||
return touch($this->getFullPath($filename));
|
||||
return touch($this->get_full_path($filename));
|
||||
}
|
||||
|
||||
public function get($filename) {
|
||||
if ($this->exists($filename))
|
||||
return file_get_contents($this->getFullPath($filename));
|
||||
return file_get_contents($this->get_full_path($filename));
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getMimeType($filename) {
|
||||
public function get_mime_type($filename) {
|
||||
if ($this->exists($filename))
|
||||
return mime_content_type($this->getFullPath($filename));
|
||||
return mime_content_type($this->get_full_path($filename));
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getFakeExtension($filename) {
|
||||
$mimetype = $this->getMimeType($filename);
|
||||
public function get_fake_extension($filename) {
|
||||
$mimetype = $this->get_mime_type($filename);
|
||||
|
||||
if ($mimetype)
|
||||
return isset($this->mimeMap[$mimetype]) ? $this->mimeMap[$mimetype] : "";
|
||||
@@ -262,17 +262,17 @@ class DiskCache {
|
||||
}
|
||||
|
||||
public function send($filename) {
|
||||
$fake_extension = $this->getFakeExtension($filename);
|
||||
$fake_extension = $this->get_fake_extension($filename);
|
||||
|
||||
if ($fake_extension)
|
||||
$fake_extension = ".$fake_extension";
|
||||
|
||||
header("Content-Disposition: inline; filename=\"${filename}${fake_extension}\"");
|
||||
|
||||
return $this->send_local_file($this->getFullPath($filename));
|
||||
return $this->send_local_file($this->get_full_path($filename));
|
||||
}
|
||||
|
||||
public function getUrl($filename) {
|
||||
public function get_url($filename) {
|
||||
return get_self_url_prefix() . "/public.php?op=cached_url&file=" . basename($this->dir) . "/" . basename($filename);
|
||||
}
|
||||
|
||||
@@ -280,7 +280,7 @@ class DiskCache {
|
||||
// this is called separately after sanitize() and plugin render article hooks to allow
|
||||
// plugins work on original source URLs used before caching
|
||||
// NOTE: URLs should be already absolutized because this is called after sanitize()
|
||||
static public function rewriteUrls($str)
|
||||
static public function rewrite_urls($str)
|
||||
{
|
||||
$res = trim($str);
|
||||
if (!$res) return '';
|
||||
@@ -301,7 +301,7 @@ class DiskCache {
|
||||
$cached_filename = sha1($url);
|
||||
|
||||
if ($cache->exists($cached_filename)) {
|
||||
$url = $cache->getUrl($cached_filename);
|
||||
$url = $cache->get_url($cached_filename);
|
||||
|
||||
$entry->setAttribute($attr, $url);
|
||||
$entry->removeAttribute("srcset");
|
||||
@@ -318,7 +318,7 @@ class DiskCache {
|
||||
$cached_filename = sha1($matches[$i]["url"]);
|
||||
|
||||
if ($cache->exists($cached_filename)) {
|
||||
$matches[$i]["url"] = $cache->getUrl($cached_filename);
|
||||
$matches[$i]["url"] = $cache->get_url($cached_filename);
|
||||
|
||||
$need_saving = true;
|
||||
}
|
||||
|
||||
@@ -260,7 +260,7 @@ class Feeds extends Handler_Protected {
|
||||
|
||||
$this->_mark_timestamp(" hook_render_cdm");
|
||||
|
||||
$line['content'] = DiskCache::rewriteUrls($line['content']);
|
||||
$line['content'] = DiskCache::rewrite_urls($line['content']);
|
||||
|
||||
$this->_mark_timestamp(" disk_cache_rewrite");
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ class Handler_Public extends Handler {
|
||||
$content = Sanitizer::sanitize($line["content"], false, $owner_uid,
|
||||
$feed_site_url, false, $line["id"]);
|
||||
|
||||
$content = DiskCache::rewriteUrls($content);
|
||||
$content = DiskCache::rewrite_urls($content);
|
||||
|
||||
if ($line['note']) {
|
||||
$content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" .
|
||||
@@ -354,7 +354,7 @@ class Handler_Public extends Handler {
|
||||
},
|
||||
$line);
|
||||
|
||||
$line['content'] = DiskCache::rewriteUrls($line['content']);
|
||||
$line['content'] = DiskCache::rewrite_urls($line['content']);
|
||||
|
||||
header("Content-Type: text/html");
|
||||
|
||||
|
||||
@@ -1281,7 +1281,7 @@ class RSSUtils {
|
||||
static function cache_enclosures($enclosures, $site_url) {
|
||||
$cache = new DiskCache("images");
|
||||
|
||||
if ($cache->isWritable()) {
|
||||
if ($cache->is_writable()) {
|
||||
foreach ($enclosures as $enc) {
|
||||
|
||||
if (preg_match("/(image|audio|video)/", $enc[1])) {
|
||||
@@ -1335,7 +1335,7 @@ class RSSUtils {
|
||||
} else {
|
||||
Debug::log("cache_media: failed with $fetch_last_error_code: $fetch_last_error");
|
||||
}
|
||||
} else if ($cache->isWritable($local_filename)) {
|
||||
} else if ($cache->is_writable($local_filename)) {
|
||||
$cache->touch($local_filename);
|
||||
}
|
||||
}
|
||||
@@ -1344,7 +1344,7 @@ class RSSUtils {
|
||||
static function cache_media($html, $site_url) {
|
||||
$cache = new DiskCache("images");
|
||||
|
||||
if ($html && $cache->isWritable()) {
|
||||
if ($html && $cache->is_writable()) {
|
||||
$doc = new DOMDocument();
|
||||
if (@$doc->loadHTML($html)) {
|
||||
$xpath = new DOMXPath($doc);
|
||||
|
||||
Reference in New Issue
Block a user