From eab68e42c2b79c7f09bcdcee49b55e01cb4e603b Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 23 Jun 2021 08:58:35 +0300 Subject: initial --- README.md | 3 +++ init.php | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 README.md create mode 100644 init.php diff --git a/README.md b/README.md new file mode 100644 index 0000000..13e19b7 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +Provides a filter action to mark old articles as read, based on feed-provided timestamp. + +Git clone to ``(tt-rss-root)/plugins.local/af_catchup_old``. diff --git a/init.php b/init.php new file mode 100644 index 0000000..cb7f49f --- /dev/null +++ b/init.php @@ -0,0 +1,60 @@ +host = $host; + + $this->host->add_filter_action($this, self::ACTION_ONE_DAY, __("Older than 1 day")); + $this->host->add_filter_action($this, self::ACTION_ONE_WEEK, __("Older than 1 week")); + $this->host->add_filter_action($this, self::ACTION_ONE_MONTH, __("Older than 1 month")); + } + + function hook_article_filter_action($article, $action) { + $cutoff_timestamp = 0; + + switch ($action) { + case self::ACTION_ONE_DAY: + $cutoff_timestamp = time() - 86400; + break; + case self::ACTION_ONE_WEEK: + $cutoff_timestamp = time() - 86400 * 7; + break; + case self::ACTION_ONE_MONTH: + $cutoff_timestamp = time() - 86400 * 31; + break; + } + + if ($cutoff_timestamp) { + Debug::log(sprintf("[af_catchup_old] article timestamp: %s, cutoff timestamp: %s ", + date("Y-m-d H:i:s", $article["timestamp"]), + date("Y-m-d H:i:s", $cutoff_timestamp))); + + if ($article["timestamp"] < $cutoff_timestamp) { + Debug::log("[af_catchup_old] article is older than cutoff, marking it as read."); + $article["force_catchup"] = true; + } else { + Debug::log("[af_catchup_old] article is newer than cutoff, ignoring."); + } + } + + return $article; + } + + function api_version() { + return 2; + } +} -- cgit v1.2.3