]> git.wh0rd.org - tt-rss.git/blame - backend.php
mark headlines page as read now works (via rpc)
[tt-rss.git] / backend.php
CommitLineData
1cd17194
AD
1<?
2 header("Content-Type: application/xml");
3
82baad4a
AD
4 require_once "config.php";
5 require_once "functions.php";
6 require_once "magpierss/rss_fetch.inc";
1cd17194 7
d76a3b03
AD
8
9 $link = pg_connect(DB_CONN);
10
11 pg_query("set client_encoding = 'utf-8'");
12
6f428bc5 13 $op = $_GET["op"];
331900c6 14 $fetch = $_GET["fetch"];
175847de
AD
15
16 if ($op == "rpc") {
17
18 $subop = $_GET["subop"];
82baad4a 19
175847de
AD
20 if ($subop == "catchupPage") {
21
22 $ids = split(",", $_GET["ids"]);
23
24 foreach ($ids as $id) {
25
26 pg_query("UPDATE ttrss_entries SET unread=false,last_read = NOW()
27 WHERE id = '$id'");
28
29 }
30
31 print "Marked active page as read.";
32 }
33
34 }
35
1cd17194
AD
36 if ($op == "feeds") {
37
476cac42
AD
38 $subop = $_GET["subop"];
39
40 if ($subop == "catchupAll") {
41 pg_query("UPDATE ttrss_entries SET last_read = NOW(),unread = false");
42 }
43
9c9c7e6b 44 if ($fetch) update_all_feeds($link, $fetch);
476cac42 45
82baad4a 46
d76a3b03
AD
47 $result = pg_query("SELECT *,
48 (SELECT count(id) FROM ttrss_entries
49 WHERE feed_id = ttrss_feeds.id) AS total,
50 (SELECT count(id) FROM ttrss_entries
51 WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
52 FROM ttrss_feeds ORDER BY title");
1cd17194 53
82baad4a 54 print "<table width=\"100%\" class=\"feeds\">";
1cd17194
AD
55
56 $lnum = 0;
57
76798ff3
AD
58 $total_unread = 0;
59
6f428bc5 60 while ($line = pg_fetch_assoc($result)) {
a1a8a2be 61
6f428bc5 62 $feed = $line["title"];
2c1dd701
AD
63 $feed_id = $line["id"];
64
d76a3b03
AD
65 $total = $line["total"];
66 $unread = $line["unread"];
67
1cd17194 68 $class = ($lnum % 2) ? "even" : "odd";
a1a8a2be
AD
69
70 if ($unread > 0) $class .= "Unread";
71
76798ff3
AD
72 $total_unread += $unread;
73
a1a8a2be
AD
74 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
75
76 $feed = "<a href=\"javascript:viewfeed($feed_id, 0);\">$feed</a>";
77 print "<td id=\"FEEDN-$feed_id\">$feed</td>";
c442fb6e
AD
78 print "<td>";
79 print "<span id=\"FEEDU-$feed_id\">$unread</span>&nbsp;/&nbsp;";
80 print "<span id=\"FEEDT-$feed_id\">$total</span>";
81 print "</td>";
a1a8a2be
AD
82
83 print "</tr>";
1cd17194
AD
84 ++$lnum;
85 }
86
476cac42
AD
87// print "<tr><td class=\"footer\" colspan=\"3\">
88// <a href=\"javascript:update_feed_list(false,true)\">Update all feeds</a></td></tr>";
89
90// print "<tr><td class=\"footer\" colspan=\"2\">&nbsp;";
91// print "</td></tr>";
82baad4a 92
a1a8a2be 93 print "</table>";
1cd17194 94
476cac42
AD
95 print "<p align=\"center\">All feeds:
96 <a class=\"button\"
97 href=\"javascript:updateFeedList(false,true)\">Update</a>";
98
99 print "&nbsp;<a class=\"button\"
100 href=\"javascript:catchupAllFeeds()\">Mark as read</a></p>";
101
76798ff3
AD
102 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
103
1cd17194
AD
104 }
105
106 if ($op == "view") {
107
d76a3b03
AD
108 $id = $_GET["id"];
109
b197f117 110 $result = pg_query("UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'");
a1a8a2be 111
d76a3b03
AD
112 $result = pg_query("SELECT title,link,content FROM ttrss_entries
113 WHERE id = '$id'");
1cd17194 114
d76a3b03 115 if ($result) {
1cd17194 116
d76a3b03 117 $line = pg_fetch_assoc($result);
1cd17194 118
d76a3b03
AD
119 print "<table class=\"feedOverview\">";
120 print "<tr><td><b>Title:</b></td><td>".$line["title"]."</td></tr>";
121 print "<tr><td><b>Link:</b></td><td><a href=\"".$line["link"]."\">".$line["link"]."</a></td></tr>";
122
123 print "</table>";
124
125 print $line["content"];
126
127
128 }
1cd17194
AD
129 }
130
131 if ($op == "viewfeed") {
132
133 $feed = $_GET["feed"];
d76a3b03 134 $skip = $_GET["skip"];
476cac42 135 $subop = $_GET["subop"];
a1a8a2be 136
ac53063a
AD
137 if (!$skip) $skip = 0;
138
476cac42 139 if ($subop == "undefined") $subop = "";
1cd17194 140
ac53063a
AD
141 // FIXME: check for null value here
142
82baad4a
AD
143 $result = pg_query("SELECT *,
144 EXTRACT(EPOCH FROM NOW()) - EXTRACT(EPOCH FROM last_updated) as update_timeout
145 FROM ttrss_feeds WHERE id = '$feed'");
1cd17194 146
d76a3b03 147 if ($result) {
1cd17194 148
d76a3b03 149 $line = pg_fetch_assoc($result);
1cd17194 150
476cac42
AD
151 if ($subop == "ForceUpdate" ||
152 (!$subop && $line["update_timeout"] > MIN_UPDATE_TIME)) {
82baad4a
AD
153
154 update_rss_feed($link, $line["feed_url"], $feed);
d76a3b03 155
a1a8a2be 156 } else {
d76a3b03 157
476cac42 158 if ($subop == "MarkAllRead") {
d76a3b03 159
b197f117 160 pg_query("UPDATE ttrss_entries SET unread = false,last_read = NOW()
a1a8a2be
AD
161 WHERE feed_id = '$feed'");
162 }
83fe4d6d 163
476cac42 164 if ($subop == "MarkPageRead") {
83fe4d6d
AD
165
166// pg_query("UPDATE ttrss_entries SET unread = false
167// WHERE feed_id = '$feed' ORDER BY updated OFFSET $skip LIMIT 1");
168 }
169
a1a8a2be
AD
170 }
171 }
d76a3b03 172
175847de 173 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
ac53063a 174
1c37c607 175 print "<tr><td class=\"search\" colspan=\"3\">
83fe4d6d 176 Search: <input onchange=\"javascript:search($feed,this);\"></td></tr>";
b197f117 177 print "<tr><td colspan=\"3\" class=\"title\">" . $line["title"] . "</td></tr>";
d76a3b03 178
ac53063a
AD
179 if ($ext == "SEARCH") {
180 $search = $_GET["search"];
181 $search_query_part = "(upper(title) LIKE upper('%$search%')
182 OR content LIKE '%$search%') AND";
183 }
184
e6d1c0a0
AD
185 $result = pg_query("SELECT count(id) AS total_entries
186 FROM ttrss_entries WHERE feed_id = '$feed'");
187
188 $total_entries = pg_fetch_result($result, 0, "total_entries");
189
b197f117
AD
190 $result = pg_query("SELECT
191 id,title,updated,unread,feed_id,
192 EXTRACT(EPOCH FROM last_read) AS last_read_ts,
193 EXTRACT(EPOCH FROM updated) AS updated_ts
194 FROM
195 ttrss_entries
196 WHERE
ac53063a
AD
197 $search_query_part
198 feed_id = '$feed' ORDER BY updated DESC LIMIT ".HEADLINES_PER_PAGE." OFFSET $skip");
d76a3b03 199
a1a8a2be 200 $lnum = 0;
d76a3b03 201
a1a8a2be 202 while ($line = pg_fetch_assoc($result)) {
d76a3b03 203
a1a8a2be 204 $class = ($lnum % 2) ? "even" : "odd";
d76a3b03 205
b197f117
AD
206 if ($line["last_read_ts"] < $line["updated_ts"] && $line["unread"] == "f") {
207 $update_pic = "<img src=\"updated.png\" alt=\"Updated\">";
208 } else {
209 $update_pic = "&nbsp;";
210 }
211
a1a8a2be
AD
212 if ($line["unread"] == "t")
213 $class .= "Unread";
d76a3b03 214
b197f117
AD
215 $id = $line["id"];
216 $feed_id = $line["feed_id"];
217
218 $content_link = "<a href=\"javascript:view($id,$feed_id);\">" .
219 $line["title"] . "</a>";
220
221 print "<tr class='$class' id='RROW-$id'>";
222
223 print "<td id='FUPDPIC-$id' valign='center' class='headlineUpdateMark'>$update_pic</td>";
224
a1a8a2be
AD
225 print "<td class='headlineUpdated'>".$line["updated"]."</td>";
226 print "<td class='headlineTitle'>$content_link</td>";
d76a3b03 227
a1a8a2be 228 print "</tr>";
d76a3b03 229
a1a8a2be
AD
230 ++$lnum;
231 }
d76a3b03 232
ac53063a
AD
233 if ($lnum == 0) {
234 print "<tr><td align='center'>No entries found.</td></tr>";
235
236 }
237
b197f117 238 print "<tr><td colspan=\"3\" class=\"headlineToolbar\">";
d76a3b03 239
a1a8a2be
AD
240 $next_skip = $skip + HEADLINES_PER_PAGE;
241 $prev_skip = $skip - HEADLINES_PER_PAGE;
83fe4d6d
AD
242
243 print "Navigate: ";
e6d1c0a0
AD
244
245 if ($prev_skip >= 0) {
246 print "<a class=\"button\"
247 href=\"javascript:viewfeed($feed, $prev_skip);\">Previous Page</a>";
248 } else {
249 print "<a class=\"disabledButton\">Previous Page</a>";
250 }
a1a8a2be 251 print "&nbsp;";
e6d1c0a0
AD
252
253 if ($next_skip < $total_entries) {
254 print "<a class=\"button\"
255 href=\"javascript:viewfeed($feed, $next_skip);\">Next Page</a>";
256 } else {
257 print "<a class=\"disabledButton\">Next Page</a>";
258 }
83fe4d6d 259 print "&nbsp;";
b197f117
AD
260 print "<a class=\"button\"
261 href=\"javascript:viewfeed($feed, $skip, '');\">Refresh Page</a>";
262 print "&nbsp;";
ac53063a 263 print "<a class=\"button\"
4fa3573e 264 href=\"javascript:viewfeed($feed, 0, 'ForceUpdate');\">Update</a>";
175847de 265
83fe4d6d 266 print "&nbsp;&nbsp;Mark as read: ";
175847de 267
83fe4d6d 268 print "<a class=\"button\"
175847de 269 href=\"javascript:catchupPage($feed);\">This Page</a>";
83fe4d6d 270 print "&nbsp;";
a1a8a2be 271 print "<a class=\"button\"
83fe4d6d 272 href=\"javascript:viewfeed($feed, $skip, 'MarkAllRead');\">All Posts</a>";
d76a3b03 273
a1a8a2be
AD
274 print "</td></tr>";
275 print "</table>";
d76a3b03 276
a1a8a2be
AD
277 $result = pg_query("SELECT id, (SELECT count(id) FROM ttrss_entries
278 WHERE feed_id = ttrss_feeds.id) AS total,
279 (SELECT count(id) FROM ttrss_entries
280 WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
281 FROM ttrss_feeds WHERE id = '$feed'");
d76a3b03 282
a1a8a2be
AD
283 $total = pg_fetch_result($result, 0, "total");
284 $unread = pg_fetch_result($result, 0, "unread");
d76a3b03 285
a1a8a2be
AD
286 print "<div class=\"invisible\" id=\"FACTIVE\">$feed</div>";
287 print "<div class=\"invisible\" id=\"FTOTAL\">$total</div>";
288 print "<div class=\"invisible\" id=\"FUNREAD\">$unread</div>";
d76a3b03 289
1cd17194
AD
290 }
291
0e091d38 292 if ($op == "pref-rpc") {
331900c6 293
0e091d38 294 $subop = $_GET["subop"];
331900c6 295
83fe4d6d
AD
296 if ($subop == "unread") {
297 $ids = split(",", $_GET["ids"]);
298 foreach ($ids as $id) {
299 pg_query("UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'");
300 }
0e091d38
AD
301
302 print "Marked selected feeds as read.";
83fe4d6d
AD
303 }
304
305 if ($subop == "read") {
306 $ids = split(",", $_GET["ids"]);
307 foreach ($ids as $id) {
b197f117
AD
308 pg_query("UPDATE ttrss_entries
309 SET unread = false,last_read = NOW() WHERE feed_id = '$id'");
83fe4d6d 310 }
0e091d38
AD
311
312 print "Marked selected feeds as unread.";
313
314 }
315
316 }
317
318 if ($op == "pref-feeds") {
319
320 $subop = $_GET["subop"];
321
322 if ($subop == "edit") {
323 print "<p>[Edit feed placeholder]</p>";
83fe4d6d
AD
324 }
325
331900c6
AD
326 if ($subop == "remove") {
327 $ids = split(",", $_GET["ids"]);
328
329 foreach ($ids as $id) {
330 pg_query("BEGIN");
331 pg_query("DELETE FROM ttrss_entries WHERE feed_id = '$id'");
332 pg_query("DELETE FROM ttrss_feeds WHERE id = '$id'");
333 pg_query("COMMIT");
334
335 }
336 }
337
338 if ($subop == "add") {
339 $feed_link = pg_escape_string($_GET["link"]);
340
341 $result = pg_query(
342 "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')");
343
344 $result = pg_query("SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'");
345
346 $feed_id = pg_fetch_result($result, 0, "id");
347
348 if ($feed_id) {
349 update_rss_feed($link, $feed_link, $feed_id);
350 }
351
352 }
353
007bda35 354 $result = pg_query("SELECT * FROM ttrss_feeds ORDER by title");
1cd17194 355
331900c6 356 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
007bda35
AD
357 print "<tr class=\"title\">
358 <td>Select</td><td>Title</td><td>Link</td><td>Last Updated</td></tr>";
359
360 $lnum = 0;
361
362 while ($line = pg_fetch_assoc($result)) {
363
364 $class = ($lnum % 2) ? "even" : "odd";
331900c6
AD
365
366 $feed_id = $line["id"];
367
368 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
007bda35
AD
369
370 print "<td><input onclick='toggleSelectRow(this);'
331900c6
AD
371 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
372 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
373 $line["title"] . "</td>";
374 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
375 $line["feed_url"] . "</td>";
376
007bda35
AD
377 print "<td>" . $line["last_updated"] . "</td>";
378 print "</tr>";
379
380 ++$lnum;
381 }
382
383 print "</table>";
384
385 }
386
387 pg_close($link);
1cd17194 388?>