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