-
Notifications
You must be signed in to change notification settings - Fork 4
/
init.php
159 lines (138 loc) · 6.07 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
class FeedStatistics extends Plugin {
function about() {
return array(1.10,
"Generates simple statistics for your feeds",
"jsoares",
false,
"");
}
function init($host) {
$this->host = $host;
$host->add_hook($host::HOOK_PREFS_TAB, $this);
}
function hook_prefs_tab($args) {
if ($args != "prefFeeds") return;
print "<div dojoType=\"dijit.layout.AccordionPane\"
title=\"<i class='material-icons'>extension</i> ".__('Feed stats (feedstatistics)')."\">";
$owner_uid = $_SESSION["uid"] ? $_SESSION["uid"] : "NULL";
// By default, use previous 30 days for statistics.
$interval = 30;
// However, if the purge limit is lower, adjust accordingly
$sth = $this->pdo->prepare("SELECT value FROM ttrss_user_prefs
WHERE pref_name = 'PURGE_OLD_DAYS' AND owner_uid = :owner AND profile IS NULL");
$sth->execute(['owner'=>$owner_uid]);
$result = $sth->fetch(PDO::FETCH_OBJ);
$purge_text = "Your default configuration is to never purge items.";
if (isset($result->value)) {
$purge_limit = $result->value;
if ($purge_limit > 0) {
$purge_text = "Your default configuration is to purge items after {$purge_limit} days.";
$interval = min($interval,$purge_limit);
}
}
$date = new DateTime();
$date->sub(new DateInterval("P{$interval}D"));
$datestr = $date->format("Y-m-d");
// Google Reader-like one-line summary for recently read items
$sth = $this->pdo->prepare("SELECT
COUNT(DISTINCT ttrss_feeds.id) AS feeds,
COUNT(NULLIF(last_read > :date, false)) AS items,
COUNT(NULLIF(last_marked > :date, false)) AS starred,
COUNT(NULLIF(last_published > :date, false)) AS published
FROM ttrss_feeds
LEFT JOIN ttrss_user_entries ON ttrss_feeds.id = ttrss_user_entries.feed_id
WHERE ttrss_feeds.owner_uid = :owner");
$sth->execute(['date'=>$datestr, 'owner'=>$owner_uid]);
$result = $sth->fetch(PDO::FETCH_OBJ);
print "<h2>Recent items</h2>";
if (isset($result->feeds)) {
print_notice("From your {$result->feeds} subscriptions, over the last {$interval} days you read {$result->items} items, starred {$result->starred} items, and published {$result->published} items.");
}
// Per-feed reading statistics
$sth = $this->pdo->prepare("SELECT
ttrss_feeds.id AS id,
ttrss_feeds.title AS title,
ttrss_feed_categories.title AS category,
COUNT(NULLIF(ttrss_user_entries.last_read > :date, false)) AS items,
COUNT(NULLIF(ttrss_user_entries.last_marked > :date, false)) AS starred,
COUNT(NULLIF(ttrss_user_entries.last_published > :date, false)) AS published,
ROUND(CAST(COUNT(NULLIF(last_read > :date, false)) AS DECIMAL) / :interval, 2) AS items_day
FROM ttrss_feeds
LEFT JOIN ttrss_user_entries ON ttrss_feeds.id = ttrss_user_entries.feed_id
LEFT JOIN ttrss_entries ON ttrss_user_entries.ref_id = ttrss_entries.id
LEFT JOIN ttrss_feed_categories ON ttrss_feeds.cat_id = ttrss_feed_categories.id
WHERE ttrss_feeds.owner_uid = :owner
GROUP BY ttrss_feeds.id, ttrss_feeds.title, ttrss_feed_categories.title
ORDER BY items_day DESC");
$sth->execute(['date'=>$datestr, 'interval'=>$interval, 'owner'=>$owner_uid]);
$result = $sth->fetchAll(PDO::FETCH_ASSOC);
if (count($result) > 0) {
print "<details><summary>Details</summary>";
print "<table cellpadding=\"5\" class=\"feed-table\" style=\"text-align: left;\">";
print "<tr class=\"title\"><th>Feed</th><th>Category</th><th>Read</th><th>Starred</th><th>Published</th><th>Items/day</th></tr>";
foreach ($result as $row) {
array_shift($row);
print "<tr>";
foreach ($row as $key=>$value) {
print "<td>{$value}</td>";
}
print "</tr>";
}
print "</table></details>";
}
// One-line summary for all items
$sth = $this->pdo->prepare("SELECT
COUNT(DISTINCT ttrss_feeds.id) AS feeds,
COUNT(ttrss_user_entries.int_id) AS items,
COUNT(ttrss_user_entries.last_read) AS read_items,
COUNT(ttrss_user_entries.last_marked) AS starred_items,
COUNT(ttrss_user_entries.last_published) AS published_items
FROM ttrss_feeds
LEFT JOIN ttrss_user_entries ON ttrss_feeds.id = ttrss_user_entries.feed_id
WHERE ttrss_feeds.owner_uid = :owner");
$sth->execute(['owner'=>$owner_uid]);
$result = $sth->fetch(PDO::FETCH_OBJ);
print "<h2>All items</h2>";
if (isset($result->feeds)) {
print_notice("From your {$result->feeds} subscriptions, there are {$result->items} total items and you read {$result->read_items} items, starred {$result->starred_items} items, and published {$result->published_items} items. " . $purge_text);
}
// All items statistics
$sth = $this->pdo->prepare("SELECT
ttrss_feeds.id AS id,
ttrss_feeds.title AS title,
ttrss_feed_categories.title AS category,
COUNT(ttrss_user_entries.int_id) AS items,
COUNT(ttrss_user_entries.last_read) AS read_items,
COUNT(ttrss_user_entries.last_marked) AS starred_items,
COUNT(ttrss_user_entries.last_published) AS published_items
FROM ttrss_feeds
LEFT JOIN ttrss_user_entries ON ttrss_feeds.id = ttrss_user_entries.feed_id
LEFT JOIN ttrss_entries ON ttrss_user_entries.ref_id = ttrss_entries.id
LEFT JOIN ttrss_feed_categories ON ttrss_feeds.cat_id = ttrss_feed_categories.id
WHERE ttrss_feeds.owner_uid = :owner
GROUP BY ttrss_feeds.id, ttrss_feeds.title, ttrss_feed_categories.title
ORDER BY items DESC");
$sth->execute(['owner'=>$owner_uid]);
$result = $sth->fetchAll(PDO::FETCH_ASSOC);
if (count($result) > 0) {
print "<details><summary>Details</summary>";
print "<table cellpadding=\"5\" class=\"feed-table\" style=\"text-align: left;\">";
print "<thead><tr class=\"title\"><th>Feed</th><th>Category</th><th>Total</th><th>Read</th><th>Starred</th><th>Published</th></tr></thead>";
foreach ($result as $row) {
array_shift($row);
print "<tr>";
foreach ($row as $key=>$value) {
print "<td>{$value}</td>";
}
print "</tr>";
}
print "</table></details>";
}
print "</div>"; #pane
}
function api_version() {
return 2;
}
}
?>