summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2019-08-13 16:40:21 +0300
committerAndrew Dolgov <[email protected]>2019-08-13 16:40:21 +0300
commitfdb6066bf67751ebb388a3de082d80f5444e3681 (patch)
tree71eaefc6589ef3206c210205144a52a79d7c6953 /classes
parentbed695b127f1bc49103d6112868296f3a9990c2b (diff)
* HOOK_ENCLOSURE_ENTRY: pass article_id to handler
* DiskCache: multiple fixes; support isWritable() for cache entries, set content-disposition for send() * public/cached_url: allow selecting files from sub-caches other than images * plugins/Cache_Starred_Images: rework to use DiskCache, can be enabled per-user, properly handles article enclosures, etc
Diffstat (limited to 'classes')
-rwxr-xr-xclasses/article.php2
-rw-r--r--classes/diskcache.php23
-rwxr-xr-xclasses/handler/public.php27
-rwxr-xr-xclasses/pluginhost.php4
-rwxr-xr-xclasses/rssutils.php2
5 files changed, 37 insertions, 21 deletions
diff --git a/classes/article.php b/classes/article.php
index 2f43b9b07..62ea1f3b9 100755
--- a/classes/article.php
+++ b/classes/article.php
@@ -446,7 +446,7 @@ class Article extends Handler_Protected {
foreach ($result as $line) {
foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ENCLOSURE_ENTRY) as $plugin) {
- $line = $plugin->hook_enclosure_entry($line);
+ $line = $plugin->hook_enclosure_entry($line, $id);
}
$url = $line["content_url"];
diff --git a/classes/diskcache.php b/classes/diskcache.php
index 07643b9be..41609d6b5 100644
--- a/classes/diskcache.php
+++ b/classes/diskcache.php
@@ -3,15 +3,28 @@ class DiskCache {
private $dir;
public function __construct($dir) {
- $this->dir = basename($dir);
+ $this->dir = CACHE_DIR . "/" . basename($dir);
}
public function getDir() {
return $this->dir;
}
- public function isWritable() {
- return is_dir($this->dir) && is_writable($this->dir);
+ public function makeDir() {
+ if (!is_dir($this->dir)) {
+ return mkdir($this->dir);
+ }
+ }
+
+ public function isWritable($filename = "") {
+ if ($filename) {
+ if (file_exists($this->getFullPath($filename)))
+ return is_writable($this->getFullPath($filename));
+ else
+ return is_writable($this->dir);
+ } else {
+ return is_writable($this->dir);
+ }
}
public function exists($filename) {
@@ -28,7 +41,7 @@ class DiskCache {
public function getFullPath($filename) {
$filename = basename($filename);
- return CACHE_DIR . "/" . $this->dir . "/" . $filename;
+ return $this->dir . "/" . $filename;
}
public function put($filename, $data) {
@@ -54,6 +67,8 @@ class DiskCache {
}
public function send($filename) {
+ header("Content-Disposition: inline; filename=\"$filename\"");
+
return send_local_file($this->getFullPath($filename));
}
diff --git a/classes/handler/public.php b/classes/handler/public.php
index 27e984be9..901844e36 100755
--- a/classes/handler/public.php
+++ b/classes/handler/public.php
@@ -1202,24 +1202,21 @@ class Handler_Public extends Handler {
}
function cached_url() {
- @$req_filename = basename($_GET['file']);
+ $filename = $_GET['file'];
- // we don't need an extension to find the file, hash is a complete URL
- $hash = preg_replace("/\.[^\.]*$/", "", $req_filename);
-
- if ($hash) {
-
- $filename = CACHE_DIR . '/images/' . $hash;
-
- if (file_exists($filename)) {
- header("Content-Disposition: inline; filename=\"$req_filename\"");
+ if (strpos($filename, "/") !== FALSE) {
+ list ($cache_dir, $filename) = explode("/", $filename, 2);
+ } else {
+ $cache_dir = "images";
+ }
- send_local_file($filename);
+ $cache = new DiskCache($cache_dir);
- } else {
- header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
- echo "File not found.";
- }
+ if ($cache->exists($filename)) {
+ $cache->send($filename);
+ } else {
+ header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
+ echo "File not found.";
}
}
diff --git a/classes/pluginhost.php b/classes/pluginhost.php
index a3c12ecae..001d5bae2 100755
--- a/classes/pluginhost.php
+++ b/classes/pluginhost.php
@@ -470,4 +470,8 @@ class PluginHost {
function get_filter_actions() {
return $this->plugin_actions;
}
+
+ function get_owner_uid() {
+ return $this->owner_uid;
+ }
}
diff --git a/classes/rssutils.php b/classes/rssutils.php
index 8a8867563..6ba5eaa0b 100755
--- a/classes/rssutils.php
+++ b/classes/rssutils.php
@@ -871,7 +871,7 @@ class RSSUtils {
$entry_ref_id = $ref_id;
if (RSSUtils::find_article_filter($article_filters, "filter")) {
- Debug::log("article is filtered out, nothing to do.");
+ Debug::log("article is filtered out, nothing to do.", Debug::$LOG_VERBOSE);
$pdo->commit();
continue;
}