2 // header("Content-Type: application/xml");
4 require_once "config.php";
5 require_once "functions.php";
6 require_once "magpierss/rss_fetch.inc";
10 $link = pg_connect(DB_CONN
);
12 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
15 print "Could not connect to database. Please check local configuration.";
19 pg_query("set client_encoding = 'utf-8'");
22 $fetch = $_GET["fetch"];
24 function outputFeedList($link) {
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");
33 print "<table width=\"100%\" class=\"feeds\" id=\"feedsList\">";
39 while ($line = pg_fetch_assoc($result)) {
41 $feed = $line["title"];
42 $feed_id = $line["id"];
44 $subop = $_GET["subop"];
46 $total = $line["total"];
47 $unread = $line["unread"];
49 $class = ($lnum %
2) ?
"even" : "odd";
51 if ($unread > 0) $class .= "Unread";
53 $total_unread +
= $unread;
55 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
57 $icon_file = ICONS_DIR
. "/$feed_id.ico";
59 if ($subop != "piggie") {
61 if (file_exists($icon_file) && filesize($icon_file) > 0) {
62 $feed_icon = "<img width=\"16\" height=\"16\"
63 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
65 $feed_icon = " ";
68 $feed_icon = "<img width=\"16\" height=\"16\"
69 src=\"http://madoka.spb.ru/stuff/fox/tiny_piggie.png\">";
72 $feed = "<a href=\"javascript:viewfeed($feed_id, 0);\">$feed</a>";
73 if (ENABLE_FEED_ICONS
) {
74 print "<td>$feed_icon</td>";
76 print "<td id=\"FEEDN-$feed_id\">$feed</td>";
78 print "<span id=\"FEEDU-$feed_id\">$unread</span> / ";
79 print "<span id=\"FEEDT-$feed_id\">$total</span>";
86 // print "<tr><td class=\"footer\" colspan=\"3\">
87 // <a href=\"javascript:update_feed_list(false,true)\">Update all feeds</a></td></tr>";
89 // print "<tr><td class=\"footer\" colspan=\"2\"> ";
90 // print "</td></tr>";
94 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
97 print "<p align=\"center\">All feeds:
99 href=\"javascript:scheduleFeedUpdate(true)\">Update</a>";
101 print " <a class=\"button\"
102 href=\"javascript:catchupAllFeeds()\">Mark as read</a></p>";
104 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
113 $subop = $_GET["subop"];
115 if ($subop == "updateFeed") {
116 $feed_id = $_GET["feed"];
118 $result = pg_query($link,
119 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'");
121 if (pg_num_rows($result) > 0) {
122 $feed_url = pg_fetch_result($result, 0, "feed_url");
123 // update_rss_feed($link, $feed_url, $feed_id);
126 print "DONE-$feed_id";
131 if ($subop == "forceUpdateAllFeeds") {
132 update_all_feeds($link, true);
133 outputFeedList($link);
136 if ($subop == "updateAllFeeds") {
137 update_all_feeds($link, false);
138 outputFeedList($link);
141 if ($subop == "catchupPage") {
143 $ids = split(",", $_GET["ids"]);
145 foreach ($ids as $id) {
147 pg_query("UPDATE ttrss_entries SET unread=false,last_read = NOW()
152 print "Marked active page as read.";
157 if ($op == "feeds") {
159 $subop = $_GET["subop"];
161 if ($subop == "catchupAll") {
162 pg_query("UPDATE ttrss_entries SET last_read = NOW(),unread = false");
165 outputFeedList($link);
173 $result = pg_query("UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'");
175 $result = pg_query("SELECT title,link,content,feed_id,comments,
176 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
182 $line = pg_fetch_assoc($result);
184 if ($line["icon_url"]) {
185 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
187 $feed_icon = " ";
190 print "<table class=\"postTable\" width=\"100%\" cellspacing=\"0\"
193 print "<tr class=\"titleTop\"><td align=\"right\"><b>Title:</b></td>
194 <td width=\"100%\">".$line["title"]."</td>
195 <td> </td></tr>";
197 if ($line["comments"] && $line["comments"] != $line["link"]) {
198 // print "<tr class=\"titleInner\"><td align=\"right\"><b>Comments:</b></td>
199 // <td><a href=\"".$line["comments"]."\">".$line["comments"]."</a></td>
200 // <td> </td> </tr>";
202 $comments_prompt = "(<a href=\"".$line["comments"]."\">Comments</a>)";
205 print "<tr class=\"titleBottom\"><td align=\"right\"><b>Link:</b></td>
206 <td><a href=\"".$line["link"]."\">".$line["link"]."</a> $comments_prompt</td>
207 <td> </td></tr>";
208 print "<tr><td valign=\"top\" class=\"post\"
209 colspan=\"2\">" . $line["content"] . "</td>
210 <td valign=\"top\">$feed_icon</td>
217 if ($op == "viewfeed") {
219 $feed = $_GET["feed"];
220 $skip = $_GET["skip"];
221 $subop = $_GET["subop"];
223 if (!$skip) $skip = 0;
225 if ($subop == "undefined") $subop = "";
227 // FIXME: check for null value here
229 $result = pg_query("SELECT *,SUBSTRING(last_updated,1,16) as last_updated,
230 EXTRACT(EPOCH FROM NOW()) - EXTRACT(EPOCH FROM last_updated) as update_timeout
231 FROM ttrss_feeds WHERE id = '$feed'");
235 $line = pg_fetch_assoc($result);
237 if ($subop == "ForceUpdate" ||
238 (!$subop && $line["update_timeout"] > MIN_UPDATE_TIME
)) {
240 update_rss_feed($link, $line["feed_url"], $feed);
244 if ($subop == "MarkAllRead") {
246 pg_query("UPDATE ttrss_entries SET unread = false,last_read = NOW()
247 WHERE feed_id = '$feed'");
252 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
254 $feed_last_updated = "Updated: " . $line["last_updated"];
256 print "<tr><td class=\"search\" colspan=\"3\">
257 Search: <input id=\"searchbox\"
258 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
259 onchange=\"javascript:search($feed);\">
260 <a class=\"button\" href=\"javascript:resetSearch()\">Reset</a>
263 <td colspan=\"3\" class=\"title\">" . $line["title"] . "</td></tr>";
265 $search = $_GET["search"];
268 $search_query_part = "(upper(title) LIKE upper('%$search%')
269 OR content LIKE '%$search%') AND";
272 $result = pg_query("SELECT count(id) AS total_entries
273 FROM ttrss_entries WHERE
277 $total_entries = pg_fetch_result($result, 0, "total_entries");
279 $result = pg_query("SELECT
280 id,title,updated,unread,feed_id,
281 EXTRACT(EPOCH FROM last_read) AS last_read_ts,
282 EXTRACT(EPOCH FROM updated) AS updated_ts
287 feed_id = '$feed' ORDER BY updated DESC LIMIT ".HEADLINES_PER_PAGE
." OFFSET $skip");
293 while ($line = pg_fetch_assoc($result)) {
295 $class = ($lnum %
2) ?
"even" : "odd";
297 if ($line["last_read_ts"] < $line["updated_ts"] && $line["unread"] == "f") {
298 $update_pic = "<img src=\"images/updated.png\" alt=\"Updated\">";
301 $update_pic = " ";
304 if ($line["unread"] == "t") {
310 $feed_id = $line["feed_id"];
312 $content_link = "<a href=\"javascript:view($id,$feed_id);\">" .
313 $line["title"] . "</a>";
315 print "<tr class='$class' id='RROW-$id'>";
317 print "<td id='FUPDPIC-$id' valign='center' class='headlineUpdateMark'>$update_pic</td>";
319 print "<td class='headlineUpdated'>
320 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
321 print "<td class='headlineTitle'>$content_link</td>";
329 print "<tr><td align='center'>No entries found.</td></tr>";
332 while ($lnum < HEADLINES_PER_PAGE
) {
334 print "<tr><td> </td></tr>";
337 // start unholy navbar block
339 print "<tr><td colspan=\"3\" class=\"headlineToolbar\">";
341 $next_skip = $skip + HEADLINES_PER_PAGE
;
342 $prev_skip = $skip - HEADLINES_PER_PAGE
;
346 if ($prev_skip >= 0) {
347 print "<a class=\"button\"
348 href=\"javascript:viewfeed($feed, $prev_skip);\">Previous Page</a>";
350 print "<a class=\"disabledButton\">Previous Page</a>";
354 if ($next_skip < $total_entries) {
355 print "<a class=\"button\"
356 href=\"javascript:viewfeed($feed, $next_skip);\">Next Page</a>";
358 print "<a class=\"disabledButton\">Next Page</a>";
360 print " Feed: ";
362 print "<a class=\"button\"
363 href=\"javascript:viewfeed($feed, 0, 'ForceUpdate');\">Update</a>";
365 print " Mark as read: ";
367 if ($num_unread > 0) {
368 print "<a class=\"button\" id=\"btnCatchupPage\"
369 href=\"javascript:catchupPage($feed);\">This Page</a>";
372 print "<a class=\"disabledButton\">This Page</a>";
376 print "<a class=\"button\"
377 href=\"javascript:viewfeed($feed, $skip, 'MarkAllRead');\">All Posts</a>";
381 // end unholy navbar block
385 $result = pg_query("SELECT id, (SELECT count(id) FROM ttrss_entries
386 WHERE feed_id = ttrss_feeds.id) AS total,
387 (SELECT count(id) FROM ttrss_entries
388 WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
389 FROM ttrss_feeds WHERE id = '$feed'");
391 $total = pg_fetch_result($result, 0, "total");
392 $unread = pg_fetch_result($result, 0, "unread");
394 print "<div class=\"invisible\" id=\"FACTIVE\">$feed</div>";
395 print "<div class=\"invisible\" id=\"FTOTAL\">$total</div>";
396 print "<div class=\"invisible\" id=\"FUNREAD\">$unread</div>";
400 if ($op == "pref-rpc") {
402 $subop = $_GET["subop"];
404 if ($subop == "unread") {
405 $ids = split(",", $_GET["ids"]);
406 foreach ($ids as $id) {
407 pg_query("UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'");
410 print "Marked selected feeds as read.";
413 if ($subop == "read") {
414 $ids = split(",", $_GET["ids"]);
415 foreach ($ids as $id) {
416 pg_query("UPDATE ttrss_entries
417 SET unread = false,last_read = NOW() WHERE feed_id = '$id'");
420 print "Marked selected feeds as unread.";
426 if ($op == "pref-feeds") {
428 $subop = $_GET["subop"];
430 if ($subop == "editSave") {
431 $feed_title = pg_escape_string($_GET["t"]);
432 $feed_link = pg_escape_string($_GET["l"]);
433 $feed_id = $_GET["id"];
435 $result = pg_query("UPDATE ttrss_feeds SET
436 title = '$feed_title', feed_url = '$feed_link' WHERE id = '$feed_id'");
440 if ($subop == "remove") {
442 if (!WEB_DEMO_MODE
) {
444 $ids = split(",", $_GET["ids"]);
446 foreach ($ids as $id) {
448 pg_query("DELETE FROM ttrss_entries WHERE feed_id = '$id'");
449 pg_query("DELETE FROM ttrss_feeds WHERE id = '$id'");
452 if (file_exists(ICONS_DIR
. "/$id.ico")) {
453 unlink(ICONS_DIR
. "/$id.ico");
459 if ($subop == "add") {
461 if (!WEB_DEMO_MODE
) {
463 $feed_link = pg_escape_string($_GET["link"]);
466 "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')");
469 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'");
471 $feed_id = pg_fetch_result($result, 0, "id");
474 update_rss_feed($link, $feed_link, $feed_id);
479 $result = pg_query("SELECT
480 id,title,feed_url,substring(last_updated,1,16) as last_updated
482 ttrss_feeds ORDER by title");
484 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
485 print "<tr class=\"title\">
486 <td> </td><td>Select</td><td width=\"40%\">Title</td>
487 <td width=\"40%\">Link</td><td>Last Updated</td></tr>";
491 while ($line = pg_fetch_assoc($result)) {
493 $class = ($lnum %
2) ?
"even" : "odd";
495 $feed_id = $line["id"];
497 $edit_feed_id = $_GET["id"];
499 if ($subop == "edit" && $feed_id != $edit_feed_id) {
503 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
505 $icon_file = ICONS_DIR
. "/$feed_id.ico";
507 if (file_exists($icon_file) && filesize($icon_file) > 0) {
508 $feed_icon = "<img width=\"16\" height=\"16\"
509 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
511 $feed_icon = " ";
513 print "<td align='center'>$feed_icon</td>";
515 if (!$edit_feed_id ||
$subop != "edit") {
517 print "<td><input onclick='toggleSelectRow(this);'
518 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
520 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
521 $line["title"] . "</td>";
522 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
523 $line["feed_url"] . "</td>";
526 } else if ($feed_id != $edit_feed_id) {
528 print "<td><input disabled=\"true\" type=\"checkbox\"
529 id=\"FRCHK-".$line["id"]."\"></td>";
531 print "<td>".$line["title"]."</td>";
532 print "<td>".$line["feed_url"]."</td>";
536 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
538 print "<td><input id=\"iedit_title\" value=\"".$line["title"]."\"></td>";
539 print "<td><input id=\"iedit_link\" value=\"".$line["feed_url"]."\"></td>";
543 print "<td>" . $line["last_updated"] . "</td>";
554 if ($subop == "edit") {
555 print "Edit feed:
556 <a class=\"button\" href=\"javascript:feedEditCancel()\">Cancel</a>
557 <a class=\"button\" href=\"javascript:feedEditSave()\">Save</a>";
563 href=\"javascript:editSelectedFeed()\">Edit</a>
564 <a class=\"buttonWarn\"
565 href=\"javascript:removeSelectedFeeds()\">Remove</a> ";
566 if (ENABLE_PREFS_CATCHUP_UNCATCHUP
) {
569 href=\"javascript:readSelectedFeeds()\">Mark as read</a>
571 href=\"javascript:unreadSelectedFeeds()\">Mark as unread</a> ";
575 <a class=\"button\" href=\"opml.php?op=Export\">Export OPML</a>";