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) {
27 <title>Tiny Tiny RSS : Feedlist</title>
28 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
29 <script type=\"text/javascript\" src=\"functions.js\"></script>
30 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
31 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
34 $result = pg_query($link, "SELECT *,
35 (SELECT count(id) FROM ttrss_entries
36 WHERE feed_id = ttrss_feeds.id) AS total,
37 (SELECT count(id) FROM ttrss_entries
38 WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
39 FROM ttrss_feeds ORDER BY title");
41 $actid = $_GET["actid"];
43 // print "<table width=\"100%\" class=\"feedsList\" id=\"feedsList\">";
45 print "<ul class=\"feedList\" id=\"feedList\">";
51 while ($line = pg_fetch_assoc($result)) {
53 $feed = $line["title"];
54 $feed_id = $line["id"];
56 $subop = $_GET["subop"];
58 $total = $line["total"];
59 $unread = $line["unread"];
61 // $class = ($lnum % 2) ? "even" : "odd";
65 if ($unread > 0) $class .= "Unread";
67 if ($actid == $feed_id) {
71 $total_unread +
= $unread;
73 // print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
75 $icon_file = ICONS_DIR
. "/$feed_id.ico";
77 if ($subop != "piggie") {
79 if (file_exists($icon_file) && filesize($icon_file) > 0) {
80 $feed_icon = "<img src=\"" . ICONS_URL
. "/$feed_id.ico\">";
82 $feed_icon = "<img src=\"images/blank_icon.png\">";
85 $feed_icon = "<img width=\"16\" height=\"16\"
86 src=\"http://madoka.spb.ru/stuff/fox/tiny_piggie.png\">";
89 $feed = "<a href=\"javascript:viewfeed($feed_id, 0);\">$feed</a>";
91 /* if (ENABLE_FEED_ICONS) {
92 print "<td>$feed_icon</td>";
95 print "<td id=\"FEEDN-$feed_id\">$feed</td>";
97 print "<span id=\"FEEDU-$feed_id\">$unread</span> / ";
98 print "<span id=\"FEEDT-$feed_id\">$total</span>";
103 print "<li id=\"FEEDR-$feed_id\" class=\"$class\">";
104 if (ENABLE_FEED_ICONS
) {
107 print "<span id=\"FEEDN-$feed_id\">$feed</span>";
112 $fctr_class = "class=\"invisible\"";
115 print "<span $fctr_class id=\"FEEDCTR-$feed_id\">
116 (<span id=\"FEEDU-$feed_id\">$unread</span>)</span>";
125 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
126 print "<div class=\"invisible\" id=\"ACTFEEDID\">$actid</div>";
133 $subop = $_GET["subop"];
135 if ($subop == "mark") {
136 $mark = $_GET["mark"];
137 $id = pg_escape_string($_GET["id"]);
145 $result = pg_query("UPDATE ttrss_entries SET marked = $mark
149 if ($subop == "updateFeed") {
150 $feed_id = pg_escape_string($_GET["feed"]);
152 $result = pg_query($link,
153 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'");
155 if (pg_num_rows($result) > 0) {
156 $feed_url = pg_fetch_result($result, 0, "feed_url");
157 // update_rss_feed($link, $feed_url, $feed_id);
160 print "DONE-$feed_id";
165 if ($subop == "forceUpdateAllFeeds") {
166 update_all_feeds($link, true);
169 if ($subop == "updateAllFeeds") {
170 update_all_feeds($link, false);
173 if ($subop == "catchupPage") {
175 $ids = split(",", $_GET["ids"]);
177 foreach ($ids as $id) {
179 pg_query("UPDATE ttrss_entries SET unread=false,last_read = NOW()
184 print "Marked active page as read.";
189 if ($op == "feeds") {
191 $subop = $_GET["subop"];
193 if ($subop == "catchupAll") {
194 pg_query("UPDATE ttrss_entries SET last_read = NOW(),unread = false");
197 outputFeedList($link);
205 $result = pg_query("UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'");
207 $addheader = $_GET["addheader"];
209 $result = pg_query("SELECT title,link,content,feed_id,comments,
210 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
216 <title>Tiny Tiny RSS : Article $id</title>
217 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
218 <script type=\"text/javascript\" src=\"functions.js\"></script>
219 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
225 $line = pg_fetch_assoc($result);
227 if ($line["icon_url"]) {
228 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
230 $feed_icon = " ";
233 if ($line["comments"] && $line["link"] != $line["comments"]) {
234 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
236 $entry_comments = "";
239 print "<div class=\"postReply\">";
241 print "<div class=\"postHeader\"><table>";
243 print "<tr><td><b>Title:</b></td>
244 <td width='100%'>" . $line["title"] . "</td></tr>";
246 print "<tr><td><b>Link:</b></td>
248 <a href=\"" . $line["link"] . "\">".$line["link"]."</a>
249 $entry_comments</td></tr>";
251 print "</table></div>";
253 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
254 print "<div class=\"postContent\">" . $line["content"] . "</div>";
261 print "</body></html>";
265 if ($op == "viewfeed") {
267 $feed = $_GET["feed"];
268 $skip = $_GET["skip"];
269 $subop = $_GET["subop"];
270 $view_mode = $_GET["view"];
271 $addheader = $_GET["addheader"];
272 $limit = $_GET["limit"];
274 if (!$skip) $skip = 0;
276 if ($subop == "undefined") $subop = "";
280 <title>Tiny Tiny RSS : Feed $feed</title>
281 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
282 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
283 <script type=\"text/javascript\" src=\"functions.js\"></script>
284 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
288 // FIXME: check for null value here
290 $result = pg_query("SELECT *,SUBSTRING(last_updated,1,16) as last_updated_s,
291 EXTRACT(EPOCH FROM NOW()) - EXTRACT(EPOCH FROM last_updated) as update_timeout
292 FROM ttrss_feeds WHERE id = '$feed'");
296 $line = pg_fetch_assoc($result);
298 if ($subop == "ForceUpdate" ||
299 $line["last_updated"] == "" ||
300 $line["update_timeout"] > MIN_UPDATE_TIME
) {
302 update_rss_feed($link, $line["feed_url"], $feed);
306 if ($subop == "MarkAllRead") {
308 pg_query("UPDATE ttrss_entries SET unread = false,last_read = NOW()
309 WHERE feed_id = '$feed'");
314 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
316 $feed_last_updated = "Updated: " . $line["last_updated"];
318 $search = $_GET["search"];
321 $search_query_part = "(upper(title) LIKE upper('%$search%')
322 OR content LIKE '%$search%') AND";
324 $search_query_part = "";
327 $view_query_part = "";
329 if ($view_mode == "Starred") {
330 $view_query_part = " marked = true AND ";
333 if ($view_mode == "Unread") {
334 $view_query_part = " unread = true AND ";
337 $result = pg_query("SELECT count(id) AS total_entries
338 FROM ttrss_entries WHERE
342 $total_entries = pg_fetch_result($result, 0, "total_entries");
344 /* $result = pg_query("SELECT count(id) AS unread_entries
345 FROM ttrss_entries WHERE
350 $unread_entries = pg_fetch_result($result, 0, "unread_entries"); */
352 if ($limit != "All") {
353 $limit_query_part = "LIMIT " . $limit;
356 $result = pg_query("SELECT
357 id,title,updated,unread,feed_id,marked,link,
358 EXTRACT(EPOCH FROM last_read) AS last_read_ts,
359 EXTRACT(EPOCH FROM updated) AS updated_ts
365 feed_id = '$feed' ORDER BY updated DESC
372 while ($line = pg_fetch_assoc($result)) {
374 $class = ($lnum %
2) ?
"even" : "odd";
377 $feed_id = $line["feed_id"];
379 if ($line["last_read_ts"] < $line["updated_ts"] && $line["unread"] == "f") {
380 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
384 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.png\"
388 if ($line["unread"] == "t") {
393 if ($line["marked"] == "t") {
394 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
395 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
397 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
398 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
401 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
402 $line["title"] . "</a>";
404 print "<tr class='$class' id='RROW-$id'";
405 // onclick=\"javascript:view($id,$feed_id)\">
407 print "<td valign='center' align='center'
408 class='headlineUpdateMark'>$update_pic</td>";
410 print "<td valign='center' align='center'
411 class='headlineUpdateMark'>$marked_pic</td>";
413 print "<td class='headlineUpdated' width='25%'>
414 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
415 print "<td width='70%' class='headlineTitle'>$content_link</td>";
423 print "<tr><td align='center'>No entries found.</td></tr>";
426 while ($lnum < HEADLINES_PER_PAGE
) {
428 print "<tr><td> </td></tr>";
433 $result = pg_query("SELECT id, (SELECT count(id) FROM ttrss_entries
434 WHERE feed_id = ttrss_feeds.id) AS total,
435 (SELECT count(id) FROM ttrss_entries
436 WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
437 FROM ttrss_feeds WHERE id = '$feed'");
439 $total = pg_fetch_result($result, 0, "total");
440 $unread = pg_fetch_result($result, 0, "unread");
442 // update unread/total counters and status for active feed in the feedlist
443 // kludge, because iframe doesn't seem to support onload()
445 print "<script type=\"text/javascript\">
446 document.onkeydown = hotkey_handler;
448 var p_document = parent.frames['feeds-frame'].document;
450 var feedr = p_document.getElementById(\"FEEDR-\" + $feed);
451 var feedu = p_document.getElementById(\"FEEDU-\" + $feed);
454 feedu.innerHTML = \"$unread\";
457 var feedctr = p_document.getElementById(\"FEEDCTR-\" + $feed);
459 if ($unread > 0 && !feedr.className.match(\"Unread\")) {
460 feedr.className = feedr.className + \"Unread\";
461 feedctr.className = '';
462 } else if ($unread <= 0) {
463 feedr.className = feedr.className.replace(\"Unread\", \"\");
464 feedctr.className = 'invisible';
472 print "</body></html>";
477 if ($op == "pref-rpc") {
479 $subop = $_GET["subop"];
481 if ($subop == "unread") {
482 $ids = split(",", $_GET["ids"]);
483 foreach ($ids as $id) {
484 pg_query("UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'");
487 print "Marked selected feeds as read.";
490 if ($subop == "read") {
491 $ids = split(",", $_GET["ids"]);
492 foreach ($ids as $id) {
493 pg_query("UPDATE ttrss_entries
494 SET unread = false,last_read = NOW() WHERE feed_id = '$id'");
497 print "Marked selected feeds as unread.";
503 if ($op == "pref-feeds") {
505 $subop = $_GET["subop"];
507 if ($subop == "editSave") {
508 $feed_title = pg_escape_string($_GET["t"]);
509 $feed_link = pg_escape_string($_GET["l"]);
510 $feed_id = $_GET["id"];
512 $result = pg_query("UPDATE ttrss_feeds SET
513 title = '$feed_title', feed_url = '$feed_link' WHERE id = '$feed_id'");
517 if ($subop == "remove") {
519 if (!WEB_DEMO_MODE
) {
521 $ids = split(",", $_GET["ids"]);
523 foreach ($ids as $id) {
525 pg_query("DELETE FROM ttrss_entries WHERE feed_id = '$id'");
526 pg_query("DELETE FROM ttrss_feeds WHERE id = '$id'");
529 if (file_exists(ICONS_DIR
. "/$id.ico")) {
530 unlink(ICONS_DIR
. "/$id.ico");
536 if ($subop == "add") {
538 if (!WEB_DEMO_MODE
) {
540 $feed_link = pg_escape_string($_GET["link"]);
543 "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')");
546 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'");
548 $feed_id = pg_fetch_result($result, 0, "id");
551 update_rss_feed($link, $feed_link, $feed_id);
556 print "<table class=\"prefAddFeed\"><tr>
557 <td><input id=\"fadd_link\"></td>
558 <td colspan=\"4\" align=\"right\">
559 <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr>
562 $result = pg_query("SELECT
563 id,title,feed_url,substring(last_updated,1,16) as last_updated
565 ttrss_feeds ORDER by title");
567 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
568 print "<tr class=\"title\">
569 <td> </td><td>Select</td><td width=\"40%\">Title</td>
570 <td width=\"40%\">Link</td><td>Last updated</td></tr>";
574 while ($line = pg_fetch_assoc($result)) {
576 $class = ($lnum %
2) ?
"even" : "odd";
578 $feed_id = $line["id"];
580 $edit_feed_id = $_GET["id"];
582 if ($subop == "edit" && $feed_id != $edit_feed_id) {
586 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
588 $icon_file = ICONS_DIR
. "/$feed_id.ico";
590 if (file_exists($icon_file) && filesize($icon_file) > 0) {
591 $feed_icon = "<img width=\"16\" height=\"16\"
592 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
594 $feed_icon = " ";
596 print "<td align='center'>$feed_icon</td>";
598 if (!$edit_feed_id ||
$subop != "edit") {
600 print "<td><input onclick='toggleSelectRow(this);'
601 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
603 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
604 $line["title"] . "</td>";
605 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
606 $line["feed_url"] . "</td>";
609 } else if ($feed_id != $edit_feed_id) {
611 print "<td><input disabled=\"true\" type=\"checkbox\"
612 id=\"FRCHK-".$line["id"]."\"></td>";
614 print "<td>".$line["title"]."</td>";
615 print "<td>".$line["feed_url"]."</td>";
619 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
621 print "<td><input id=\"iedit_title\" value=\"".$line["title"]."\"></td>";
622 print "<td><input id=\"iedit_link\" value=\"".$line["feed_url"]."\"></td>";
626 if (!$line["last_updated"]) $line["last_updated"] = "Never";
628 print "<td>" . $line["last_updated"] . "</td>";
636 print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>";
643 if ($subop == "edit") {
644 print "Edit feed:
645 <input type=\"submit\" class=\"button\"
646 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
647 <input type=\"submit\" class=\"button\"
648 onclickf=\"javascript:feedEditSave()\" value=\"Save\">";
653 <input type=\"submit\" class=\"button\"
654 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
655 <input type=\"submit\" class=\"button\"
656 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
658 if (ENABLE_PREFS_CATCHUP_UNCATCHUP
) {
660 <input type=\"submit\" class=\"button\"
661 onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\">
662 <input type=\"submit\" class=\"button\"
663 onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\"> ";
667 <input type=\"submit\"
668 class=\"button\" onclick=\"opml.php?op=Export\" value=\"Export OPML\">";
674 if ($op == "pref-filters") {
676 $subop = $_GET["subop"];
678 if ($subop == "editSave") {
680 $regexp = pg_escape_string($_GET["r"]);
681 $descr = pg_escape_string($_GET["d"]);
682 $match = pg_escape_string($_GET["m"]);
683 $filter_id = pg_escape_string($_GET["id"]);
685 $result = pg_query("UPDATE ttrss_filters SET
687 description = '$descr',
688 filter_type = (SELECT id FROM ttrss_filter_types WHERE
689 description = '$match')
690 WHERE id = '$filter_id'");
693 if ($subop == "remove") {
695 if (!WEB_DEMO_MODE
) {
697 $ids = split(",", $_GET["ids"]);
699 foreach ($ids as $id) {
700 pg_query("DELETE FROM ttrss_filters WHERE id = '$id'");
706 if ($subop == "add") {
708 if (!WEB_DEMO_MODE
) {
710 $regexp = pg_escape_string($_GET["regexp"]);
711 $match = pg_escape_string($_GET["match"]);
714 "INSERT INTO ttrss_filters (regexp,filter_type) VALUES
715 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
716 description = '$match'))");
720 $result = pg_query("SELECT description
721 FROM ttrss_filter_types ORDER BY description");
723 $filter_types = array();
725 while ($line = pg_fetch_assoc($result)) {
726 array_push($filter_types, $line["description"]);
729 print "<table class=\"prefAddFeed\"><tr>
730 <td><input id=\"fadd_regexp\"></td>
732 print_select("fadd_match", "Title", $filter_types);
734 print"</td><td colspan=\"4\" align=\"right\">
735 <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr>
738 $result = pg_query("SELECT
739 id,regexp,description,
740 (SELECT name FROM ttrss_filter_types WHERE
741 id = filter_type) as filter_type_name,
742 (SELECT description FROM ttrss_filter_types
743 WHERE id = filter_type) as filter_type_descr
745 ttrss_filters ORDER by regexp");
747 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
749 print "<tr class=\"title\">
750 <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td>
751 <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>";
755 while ($line = pg_fetch_assoc($result)) {
757 $class = ($lnum %
2) ?
"even" : "odd";
759 $filter_id = $line["id"];
760 $edit_filter_id = $_GET["id"];
762 if ($subop == "edit" && $filter_id != $edit_filter_id) {
766 print "<tr class=\"$class\" id=\"FILRR-$filter_id\">";
768 $line["regexp"] = htmlspecialchars($line["regexp"]);
769 $line["description"] = htmlspecialchars($line["description"]);
771 if (!$edit_filter_id ||
$subop != "edit") {
773 if (!$line["description"]) $line["description"] = "[No description]";
775 print "<td><input onclick='toggleSelectRow(this);'
776 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
778 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
779 $line["regexp"] . "</td>";
781 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
782 $line["description"] . "</td>";
784 print "<td>".$line["filter_type_descr"]."</td>";
786 } else if ($filter_id != $edit_filter_id) {
788 if (!$line["description"]) $line["description"] = "[No description]";
790 print "<td><input disabled=\"true\" type=\"checkbox\"
791 id=\"FICHK-".$line["id"]."\"></td>";
793 print "<td>".$line["regexp"]."</td>";
794 print "<td>".$line["description"]."</td>";
795 print "<td>".$line["filter_type_descr"]."</td>";
799 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
801 print "<td><input id=\"iedit_regexp\" value=\"".$line["regexp"].
804 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
808 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
820 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
827 if ($subop == "edit") {
829 <input type=\"submit\" class=\"button\"
830 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
831 <input type=\"submit\" class=\"button\"
832 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
838 <input type=\"submit\" class=\"button\"
839 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
840 <input type=\"submit\" class=\"button\"
841 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
845 if ($op == "error") {
846 print "<div width=\"100%\" align='center'>";