summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-02-15 16:11:30 +0300
committerAndrew Dolgov <[email protected]>2021-02-15 16:11:30 +0300
commit166f2d46666bb872a1f30a5ab23b113f2f481640 (patch)
treeaba3be014a77a930e067864ce36b72e962100e3a
parent8e79f1717d5270558ffd30c20cc75840b0ecc955 (diff)
diskcache: unify naming
-rwxr-xr-xclasses/api.php4
-rwxr-xr-xclasses/article.php6
-rw-r--r--classes/diskcache.php44
-rwxr-xr-xclasses/feeds.php2
-rwxr-xr-xclasses/handler/public.php4
-rwxr-xr-xclasses/rssutils.php6
-rw-r--r--plugins/af_proxy_http/init.php4
-rwxr-xr-xplugins/cache_starred_images/init.php18
8 files changed, 44 insertions, 44 deletions
diff --git a/classes/api.php b/classes/api.php
index 62ce1764c..ec51c70a6 100755
--- a/classes/api.php
+++ b/classes/api.php
@@ -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);
diff --git a/classes/article.php b/classes/article.php
index d177a8d6d..5800af2b7 100755
--- a/classes/article.php
+++ b/classes/article.php
@@ -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];
}
diff --git a/classes/diskcache.php b/classes/diskcache.php
index 3fd099d3c..bad2ee0da 100644
--- a/classes/diskcache.php
+++ b/classes/diskcache.php
@@ -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;
}
diff --git a/classes/feeds.php b/classes/feeds.php
index 10873d8ca..07e3aa455 100755
--- a/classes/feeds.php
+++ b/classes/feeds.php
@@ -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");
diff --git a/classes/handler/public.php b/classes/handler/public.php
index ea2a0c5ef..6ea02c361 100755
--- a/classes/handler/public.php
+++ b/classes/handler/public.php
@@ -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");
diff --git a/classes/rssutils.php b/classes/rssutils.php
index cd6f90859..751cae58e 100755
--- a/classes/rssutils.php
+++ b/classes/rssutils.php
@@ -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);
diff --git a/plugins/af_proxy_http/init.php b/plugins/af_proxy_http/init.php
index 3bde08fdb..3f26ca900 100644
--- a/plugins/af_proxy_http/init.php
+++ b/plugins/af_proxy_http/init.php
@@ -59,14 +59,14 @@ class Af_Proxy_Http extends Plugin {
$local_filename = sha1($url);
if ($this->cache->exists($local_filename)) {
- header("Location: " . $this->cache->getUrl($local_filename));
+ header("Location: " . $this->cache->get_url($local_filename));
return;
} else {
$data = UrlHelper::fetch(["url" => $url, "max_size" => MAX_CACHE_FILE_SIZE]);
if ($data) {
if ($this->cache->put($local_filename, $data)) {
- header("Location: " . $this->cache->getUrl($local_filename));
+ header("Location: " . $this->cache->get_url($local_filename));
return;
}
} else {
diff --git a/plugins/cache_starred_images/init.php b/plugins/cache_starred_images/init.php
index 9dd4cd49d..9c2d4cb7e 100755
--- a/plugins/cache_starred_images/init.php
+++ b/plugins/cache_starred_images/init.php
@@ -17,18 +17,18 @@ class Cache_Starred_Images extends Plugin {
$this->host = $host;
$this->cache = new DiskCache("starred-images");
- if ($this->cache->makeDir())
- chmod($this->cache->getDir(), 0777);
+ if ($this->cache->make_dir())
+ chmod($this->cache->get_dir(), 0777);
if (!$this->cache->exists(".no-auto-expiry"))
$this->cache->touch(".no-auto-expiry");
- if ($this->cache->isWritable()) {
+ if ($this->cache->is_writable()) {
$host->add_hook($host::HOOK_HOUSE_KEEPING, $this);
$host->add_hook($host::HOOK_ENCLOSURE_ENTRY, $this);
$host->add_hook($host::HOOK_SANITIZE, $this);
} else {
- user_error("Starred cache directory ".$this->cache->getDir()." is not writable.", E_USER_WARNING);
+ user_error("Starred cache directory ".$this->cache->get_dir()." is not writable.", E_USER_WARNING);
}
}
@@ -69,9 +69,9 @@ class Cache_Starred_Images extends Plugin {
/* actual housekeeping */
- Debug::log("expiring " . $this->cache->getDir() . "...");
+ Debug::log("expiring " . $this->cache->get_dir() . "...");
- $files = glob($this->cache->getDir() . "/*.{png,mp4,status}", GLOB_BRACE);
+ $files = glob($this->cache->get_dir() . "/*.{png,mp4,status}", GLOB_BRACE);
$last_article_id = 0;
$article_exists = 1;
@@ -98,7 +98,7 @@ class Cache_Starred_Images extends Plugin {
$local_filename = $article_id . "-" . sha1($enc["content_url"]);
if ($this->cache->exists($local_filename)) {
- $enc["content_url"] = $this->cache->getUrl($local_filename);
+ $enc["content_url"] = $this->cache->get_url($local_filename);
}
return $enc;
@@ -117,7 +117,7 @@ class Cache_Starred_Images extends Plugin {
$local_filename = $article_id . "-" . sha1($src);
if ($this->cache->exists($local_filename)) {
- $entry->setAttribute("src", $this->cache->getUrl($local_filename));
+ $entry->setAttribute("src", $this->cache->get_url($local_filename));
$entry->removeAttribute("srcset");
}
}
@@ -151,7 +151,7 @@ class Cache_Starred_Images extends Plugin {
$status_filename = $article_id . "-" . sha1($site_url) . ".status";
/* housekeeping might run as a separate user, in this case status/media might not be writable */
- if (!$this->cache->isWritable($status_filename)) {
+ if (!$this->cache->is_writable($status_filename)) {
Debug::log("status not writable: $status_filename", Debug::$LOG_VERBOSE);
return false;
}