-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.php
60 lines (48 loc) · 1.6 KB
/
init.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
class Af_Catchup_Old extends Plugin {
/** @var PluginHost $host */
private $host;
const ACTION_ONE_DAY = "action_force_catchup_1day";
const ACTION_ONE_WEEK = "action_force_catchup_1week";
const ACTION_ONE_MONTH = "action_force_catchup_1month";
function about() {
return [1.0,
"Provides a filter action to mark old articles as read, based on feed-provided timestamp",
"fox"];
}
function init($host) {
$this->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;
}
}