mirror of
https://git.tt-rss.org/git/tt-rss.git
synced 2026-01-30 13:57:11 +00:00
* 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
This commit is contained in:
@@ -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"];
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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 (strpos($filename, "/") !== FALSE) {
|
||||
list ($cache_dir, $filename) = explode("/", $filename, 2);
|
||||
} else {
|
||||
$cache_dir = "images";
|
||||
}
|
||||
|
||||
if ($hash) {
|
||||
$cache = new DiskCache($cache_dir);
|
||||
|
||||
$filename = CACHE_DIR . '/images/' . $hash;
|
||||
|
||||
if (file_exists($filename)) {
|
||||
header("Content-Disposition: inline; filename=\"$req_filename\"");
|
||||
|
||||
send_local_file($filename);
|
||||
|
||||
} 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.";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -470,4 +470,8 @@ class PluginHost {
|
||||
function get_filter_actions() {
|
||||
return $this->plugin_actions;
|
||||
}
|
||||
|
||||
function get_owner_uid() {
|
||||
return $this->owner_uid;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user