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 == "mark") {
116 $mark = $_GET["mark"];
117 $id = pg_escape_string($_GET["id"]);
125 $result = pg_query("UPDATE ttrss_entries SET marked = $mark
129 if ($subop == "updateFeed") {
130 $feed_id = pg_escape_string($_GET["feed"]);
132 $result = pg_query($link,
133 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'");
135 if (pg_num_rows($result) > 0) {
136 $feed_url = pg_fetch_result($result, 0, "feed_url");
137 // update_rss_feed($link, $feed_url, $feed_id);
140 print "DONE-$feed_id";
145 if ($subop == "forceUpdateAllFeeds") {
146 update_all_feeds($link, true);
147 outputFeedList($link);
150 if ($subop == "updateAllFeeds") {
151 update_all_feeds($link, false);
152 outputFeedList($link);
155 if ($subop == "catchupPage") {
157 $ids = split(",", $_GET["ids"]);
159 foreach ($ids as $id) {
161 pg_query("UPDATE ttrss_entries SET unread=false,last_read = NOW()
166 print "Marked active page as read.";
171 if ($op == "feeds") {
173 $subop = $_GET["subop"];
175 if ($subop == "catchupAll") {
176 pg_query("UPDATE ttrss_entries SET last_read = NOW(),unread = false");
179 outputFeedList($link);
187 $result = pg_query("UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'");
189 $addheader = $_GET["addheader"];
191 $result = pg_query("SELECT title,link,content,feed_id,comments,
192 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
198 <title>Tiny Tiny RSS : Article $id</title>
199 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
200 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
206 $line = pg_fetch_assoc($result);
208 if ($line["icon_url"]) {
209 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
211 $feed_icon = " ";
214 print "<table class=\"postTable\" width=\"100%\" cellspacing=\"0\"
217 print "<tr class=\"titleTop\"><td align=\"right\"><b>Title:</b></td>
218 <td width=\"100%\">".$line["title"]."</td>
219 <td> </td></tr>";
221 if ($line["comments"] && $line["comments"] != $line["link"]) {
222 // print "<tr class=\"titleInner\"><td align=\"right\"><b>Comments:</b></td>
223 // <td><a href=\"".$line["comments"]."\">".$line["comments"]."</a></td>
224 // <td> </td> </tr>";
226 $comments_prompt = "(<a href=\"".$line["comments"]."\">Comments</a>)";
229 print "<tr class=\"titleBottom\"><td align=\"right\"><b>Link:</b></td>
230 <td><a href=\"".$line["link"]."\">".$line["link"]."</a> $comments_prompt</td>
231 <td> </td></tr>";
232 print "<tr><td valign=\"top\" class=\"post\"
233 colspan=\"2\">" . $line["content"] . "</td>
234 <td valign=\"top\">$feed_icon</td>
241 print "</body></html>";
245 if ($op == "viewfeed") {
247 $feed = $_GET["feed"];
248 $skip = $_GET["skip"];
249 $subop = $_GET["subop"];
250 $view_mode = $_GET["view"];
251 $addheader = $_GET["addheader"];
253 if (!$skip) $skip = 0;
255 if ($subop == "undefined") $subop = "";
259 <title>Tiny Tiny RSS : Article $id</title>
260 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
261 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
262 <script type=\"text/javascript\" src=\"functions.js\"></script>
263 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
267 // FIXME: check for null value here
269 $result = pg_query("SELECT *,SUBSTRING(last_updated,1,16) as last_updated,
270 EXTRACT(EPOCH FROM NOW()) - EXTRACT(EPOCH FROM last_updated) as update_timeout
271 FROM ttrss_feeds WHERE id = '$feed'");
275 $line = pg_fetch_assoc($result);
277 if ($subop == "ForceUpdate") {
278 // (!$subop && $line["update_timeout"] > MIN_UPDATE_TIME)) {
280 update_rss_feed($link, $line["feed_url"], $feed);
284 if ($subop == "MarkAllRead") {
286 pg_query("UPDATE ttrss_entries SET unread = false,last_read = NOW()
287 WHERE feed_id = '$feed'");
292 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
294 $feed_last_updated = "Updated: " . $line["last_updated"];
298 print "<tr><td class=\"search\" colspan=\"4\">
299 Search: <input id=\"searchbox\"
300 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
301 onchange=\"javascript:search($feed);\"> ";
303 print " <a class=\"button\" href=\"javascript:resetSearch()\">Reset</a>";
305 print " View: ";
307 print_select("viewbox", $view_mode, array("All Posts", "Starred"),
308 "onchange=\"javascript:viewfeed('$feed', '0', '');\"");
313 <td colspan=\"4\" class=\"title\">" . $line["title"] . "</td></tr>";
317 $search = $_GET["search"];
320 $search_query_part = "(upper(title) LIKE upper('%$search%')
321 OR content LIKE '%$search%') AND";
323 $search_query_part = "";
326 $view_query_part = "";
328 if ($view_mode == "Starred") {
329 $view_query_part = " marked = true AND ";
332 $result = pg_query("SELECT count(id) AS total_entries
333 FROM ttrss_entries WHERE
337 $total_entries = pg_fetch_result($result, 0, "total_entries");
340 $limit_query_part = "LIMIT ".HEADLINES_PER_PAGE
." OFFSET $skip";
343 $result = pg_query("SELECT
344 id,title,updated,unread,feed_id,marked,
345 EXTRACT(EPOCH FROM last_read) AS last_read_ts,
346 EXTRACT(EPOCH FROM updated) AS updated_ts
352 feed_id = '$feed' ORDER BY updated DESC
359 while ($line = pg_fetch_assoc($result)) {
361 $class = ($lnum %
2) ?
"even" : "odd";
363 if ($line["last_read_ts"] < $line["updated_ts"] && $line["unread"] == "f") {
364 $update_pic = "<img src=\"images/updated.png\" alt=\"Updated\">";
367 $update_pic = " ";
370 if ($line["unread"] == "t") {
376 $feed_id = $line["feed_id"];
378 if ($line["marked"] == "t") {
379 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
380 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
382 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
383 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
386 $content_link = "<a href=\"javascript:view($id,$feed_id);\">" .
387 $line["title"] . "</a>";
389 print "<tr class='$class' id='RROW-$id'>";
391 print "<td id='FUPDPIC-$id' valign='center'
392 class='headlineUpdateMark'>$update_pic</td>";
394 print "<td valign='center'
395 class='headlineUpdateMark'>$marked_pic</td>";
397 print "<td class='headlineUpdated'>
398 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
399 print "<td class='headlineTitle'>$content_link</td>";
407 print "<tr><td align='center'>No entries found.</td></tr>";
410 while ($lnum < HEADLINES_PER_PAGE
) {
412 print "<tr><td> </td></tr>";
415 // start unholy navbar block
419 print "<tr><td colspan=\"4\" class=\"headlineToolbar\">";
421 $next_skip = $skip + HEADLINES_PER_PAGE
;
422 $prev_skip = $skip - HEADLINES_PER_PAGE
;
426 if ($prev_skip >= 0) {
427 print "<a class=\"button\"
428 href=\"javascript:viewfeed($feed, $prev_skip);\">Previous Page</a>";
430 print "<a class=\"disabledButton\">Previous Page</a>";
434 if ($next_skip < $total_entries) {
435 print "<a class=\"button\"
436 href=\"javascript:viewfeed($feed, $next_skip);\">Next Page</a>";
438 print "<a class=\"disabledButton\">Next Page</a>";
440 print " Feed: ";
442 print "<a class=\"button\"
443 href=\"javascript:viewfeed($feed, 0, 'ForceUpdate');\">Update</a>";
445 print " Mark as read: ";
447 if ($num_unread > 0) {
448 print "<a class=\"button\" id=\"btnCatchupPage\"
449 href=\"javascript:catchupPage($feed);\">This Page</a>";
452 print "<a class=\"disabledButton\">This Page</a>";
456 print "<a class=\"button\"
457 href=\"javascript:viewfeed($feed, $skip, 'MarkAllRead');\">All Posts</a>";
461 /* print " Unmark: ";
463 print "<a class=\"button\"
464 href=\"javascript:unmarkPosts(false);\">This Page</a>";
467 print "<a class=\"button\"
468 href=\"javascript:unmarkPosts(true);\">All Posts</a>"; */
472 // end unholy navbar block
476 $result = pg_query("SELECT id, (SELECT count(id) FROM ttrss_entries
477 WHERE feed_id = ttrss_feeds.id) AS total,
478 (SELECT count(id) FROM ttrss_entries
479 WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
480 FROM ttrss_feeds WHERE id = '$feed'");
482 $total = pg_fetch_result($result, 0, "total");
483 $unread = pg_fetch_result($result, 0, "unread");
485 print "<div class=\"invisible\" id=\"FACTIVE\">$feed</div>";
486 print "<div class=\"invisible\" id=\"FTOTAL\">$total</div>";
487 print "<div class=\"invisible\" id=\"FUNREAD\">$unread</div>";
490 print "</body></html>";
495 if ($op == "pref-rpc") {
497 $subop = $_GET["subop"];
499 if ($subop == "unread") {
500 $ids = split(",", $_GET["ids"]);
501 foreach ($ids as $id) {
502 pg_query("UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'");
505 print "Marked selected feeds as read.";
508 if ($subop == "read") {
509 $ids = split(",", $_GET["ids"]);
510 foreach ($ids as $id) {
511 pg_query("UPDATE ttrss_entries
512 SET unread = false,last_read = NOW() WHERE feed_id = '$id'");
515 print "Marked selected feeds as unread.";
521 if ($op == "pref-feeds") {
523 $subop = $_GET["subop"];
525 if ($subop == "editSave") {
526 $feed_title = pg_escape_string($_GET["t"]);
527 $feed_link = pg_escape_string($_GET["l"]);
528 $feed_id = $_GET["id"];
530 $result = pg_query("UPDATE ttrss_feeds SET
531 title = '$feed_title', feed_url = '$feed_link' WHERE id = '$feed_id'");
535 if ($subop == "remove") {
537 if (!WEB_DEMO_MODE
) {
539 $ids = split(",", $_GET["ids"]);
541 foreach ($ids as $id) {
543 pg_query("DELETE FROM ttrss_entries WHERE feed_id = '$id'");
544 pg_query("DELETE FROM ttrss_feeds WHERE id = '$id'");
547 if (file_exists(ICONS_DIR
. "/$id.ico")) {
548 unlink(ICONS_DIR
. "/$id.ico");
554 if ($subop == "add") {
556 if (!WEB_DEMO_MODE
) {
558 $feed_link = pg_escape_string($_GET["link"]);
561 "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')");
564 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'");
566 $feed_id = pg_fetch_result($result, 0, "id");
569 update_rss_feed($link, $feed_link, $feed_id);
574 print "<table class=\"prefAddFeed\"><tr>
575 <td><input id=\"fadd_link\"></td>
576 <td colspan=\"4\" align=\"right\">
577 <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr>
580 $result = pg_query("SELECT
581 id,title,feed_url,substring(last_updated,1,16) as last_updated
583 ttrss_feeds ORDER by title");
585 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
586 print "<tr class=\"title\">
587 <td> </td><td>Select</td><td width=\"40%\">Title</td>
588 <td width=\"40%\">Link</td><td>Last updated</td></tr>";
592 while ($line = pg_fetch_assoc($result)) {
594 $class = ($lnum %
2) ?
"even" : "odd";
596 $feed_id = $line["id"];
598 $edit_feed_id = $_GET["id"];
600 if ($subop == "edit" && $feed_id != $edit_feed_id) {
604 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
606 $icon_file = ICONS_DIR
. "/$feed_id.ico";
608 if (file_exists($icon_file) && filesize($icon_file) > 0) {
609 $feed_icon = "<img width=\"16\" height=\"16\"
610 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
612 $feed_icon = " ";
614 print "<td align='center'>$feed_icon</td>";
616 if (!$edit_feed_id ||
$subop != "edit") {
618 print "<td><input onclick='toggleSelectRow(this);'
619 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
621 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
622 $line["title"] . "</td>";
623 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
624 $line["feed_url"] . "</td>";
627 } else if ($feed_id != $edit_feed_id) {
629 print "<td><input disabled=\"true\" type=\"checkbox\"
630 id=\"FRCHK-".$line["id"]."\"></td>";
632 print "<td>".$line["title"]."</td>";
633 print "<td>".$line["feed_url"]."</td>";
637 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
639 print "<td><input id=\"iedit_title\" value=\"".$line["title"]."\"></td>";
640 print "<td><input id=\"iedit_link\" value=\"".$line["feed_url"]."\"></td>";
644 if (!$line["last_updated"]) $line["last_updated"] = "Never";
646 print "<td>" . $line["last_updated"] . "</td>";
654 print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>";
661 if ($subop == "edit") {
662 print "Edit feed:
663 <a class=\"button\" href=\"javascript:feedEditCancel()\">Cancel</a>
664 <a class=\"button\" href=\"javascript:feedEditSave()\">Save</a>";
670 href=\"javascript:editSelectedFeed()\">Edit</a>
671 <a class=\"buttonWarn\"
672 href=\"javascript:removeSelectedFeeds()\">Remove</a> ";
673 if (ENABLE_PREFS_CATCHUP_UNCATCHUP
) {
676 href=\"javascript:readSelectedFeeds()\">Mark as read</a>
678 href=\"javascript:unreadSelectedFeeds()\">Mark as unread</a> ";
682 <a class=\"button\" href=\"opml.php?op=Export\">Export OPML</a>";
688 if ($op == "pref-filters") {
690 $subop = $_GET["subop"];
692 if ($subop == "editSave") {
694 $regexp = pg_escape_string($_GET["r"]);
695 $descr = pg_escape_string($_GET["d"]);
696 $match = pg_escape_string($_GET["m"]);
697 $filter_id = pg_escape_string($_GET["id"]);
699 $result = pg_query("UPDATE ttrss_filters SET
701 description = '$descr',
702 filter_type = (SELECT id FROM ttrss_filter_types WHERE
703 description = '$match')
704 WHERE id = '$filter_id'");
707 if ($subop == "remove") {
709 if (!WEB_DEMO_MODE
) {
711 $ids = split(",", $_GET["ids"]);
713 foreach ($ids as $id) {
714 pg_query("DELETE FROM ttrss_filters WHERE id = '$id'");
720 if ($subop == "add") {
722 if (!WEB_DEMO_MODE
) {
724 $regexp = pg_escape_string($_GET["regexp"]);
725 $match = pg_escape_string($_GET["match"]);
728 "INSERT INTO ttrss_filters (regexp,filter_type) VALUES
729 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
730 description = '$match'))");
734 $result = pg_query("SELECT description
735 FROM ttrss_filter_types ORDER BY description");
737 $filter_types = array();
739 while ($line = pg_fetch_assoc($result)) {
740 array_push($filter_types, $line["description"]);
743 print "<table class=\"prefAddFeed\"><tr>
744 <td><input id=\"fadd_regexp\"></td>
746 print_select("fadd_match", "Title", $filter_types);
748 print"</td><td colspan=\"4\" align=\"right\">
749 <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr>
752 $result = pg_query("SELECT
753 id,regexp,description,
754 (SELECT name FROM ttrss_filter_types WHERE
755 id = filter_type) as filter_type_name,
756 (SELECT description FROM ttrss_filter_types
757 WHERE id = filter_type) as filter_type_descr
759 ttrss_filters ORDER by regexp");
761 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
763 print "<tr class=\"title\">
764 <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td>
765 <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>";
769 while ($line = pg_fetch_assoc($result)) {
771 $class = ($lnum %
2) ?
"even" : "odd";
773 $filter_id = $line["id"];
774 $edit_filter_id = $_GET["id"];
776 if ($subop == "edit" && $filter_id != $edit_filter_id) {
780 print "<tr class=\"$class\" id=\"FILRR-$filter_id\">";
782 $line["regexp"] = htmlspecialchars($line["regexp"]);
783 $line["description"] = htmlspecialchars($line["description"]);
785 if (!$edit_filter_id ||
$subop != "edit") {
787 if (!$line["description"]) $line["description"] = "[No description]";
789 print "<td><input onclick='toggleSelectRow(this);'
790 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
792 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
793 $line["regexp"] . "</td>";
795 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
796 $line["description"] . "</td>";
798 print "<td>".$line["filter_type_descr"]."</td>";
800 } else if ($filter_id != $edit_filter_id) {
802 if (!$line["description"]) $line["description"] = "[No description]";
804 print "<td><input disabled=\"true\" type=\"checkbox\"
805 id=\"FICHK-".$line["id"]."\"></td>";
807 print "<td>".$line["regexp"]."</td>";
808 print "<td>".$line["description"]."</td>";
809 print "<td>".$line["filter_type_descr"]."</td>";
813 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
815 print "<td><input id=\"iedit_regexp\" value=\"".$line["regexp"].
818 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
822 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
834 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
841 if ($subop == "edit") {
842 print "Edit feed:
843 <a class=\"button\" href=\"javascript:filterEditCancel()\">Cancel</a>
844 <a class=\"button\" href=\"javascript:filterEditSave()\">Save</a>";
851 href=\"javascript:editSelectedFilter()\">Edit</a>
852 <a class=\"buttonWarn\"
853 href=\"javascript:removeSelectedFilters()\">Remove</a> ";