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>";
110 print "<span id=\"FEEDCTR-$feed_id\">
111 (<span id=\"FEEDU-$feed_id\">$unread</span>)</span>";
121 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
122 print "<div class=\"invisible\" id=\"ACTFEEDID\">$actid</div>";
129 $subop = $_GET["subop"];
131 if ($subop == "mark") {
132 $mark = $_GET["mark"];
133 $id = pg_escape_string($_GET["id"]);
141 $result = pg_query("UPDATE ttrss_entries SET marked = $mark
145 if ($subop == "updateFeed") {
146 $feed_id = pg_escape_string($_GET["feed"]);
148 $result = pg_query($link,
149 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'");
151 if (pg_num_rows($result) > 0) {
152 $feed_url = pg_fetch_result($result, 0, "feed_url");
153 // update_rss_feed($link, $feed_url, $feed_id);
156 print "DONE-$feed_id";
161 if ($subop == "forceUpdateAllFeeds") {
162 update_all_feeds($link, true);
165 if ($subop == "updateAllFeeds") {
166 update_all_feeds($link, false);
169 if ($subop == "catchupPage") {
171 $ids = split(",", $_GET["ids"]);
173 foreach ($ids as $id) {
175 pg_query("UPDATE ttrss_entries SET unread=false,last_read = NOW()
180 print "Marked active page as read.";
185 if ($op == "feeds") {
187 $subop = $_GET["subop"];
189 if ($subop == "catchupAll") {
190 pg_query("UPDATE ttrss_entries SET last_read = NOW(),unread = false");
193 outputFeedList($link);
201 $result = pg_query("UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'");
203 $addheader = $_GET["addheader"];
205 $result = pg_query("SELECT title,link,content,feed_id,comments,
206 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
212 <title>Tiny Tiny RSS : Article $id</title>
213 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
214 <script type=\"text/javascript\" src=\"functions.js\"></script>
215 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
221 $line = pg_fetch_assoc($result);
223 if ($line["icon_url"]) {
224 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
226 $feed_icon = " ";
229 print "<div class=\"postReply\">";
231 print "<div class=\"postHeader\"><table>";
233 print "<tr><td><b>Title:</b></td>
234 <td width='100%'>" . $line["title"] . "</td></tr>";
235 print "<tr><td><b>Link:</b></td>
236 <td width='100%'>" . $line["link"] . "</td></tr>";
238 print "</table></div>";
240 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
241 print "<div class=\"postContent\">" . $line["content"] . "</div>";
245 /* print "<table class=\"postTable\" width=\"100%\" cellspacing=\"0\"
248 print "<tr class=\"titleTop\"><td align=\"right\"><b>Title:</b></td>
249 <td width=\"100%\">".$line["title"]."</td>
250 <td> </td></tr>";
252 if ($line["comments"] && $line["comments"] != $line["link"]) {
253 $comments_prompt = "(<a href=\"".$line["comments"]."\">Comments</a>)";
256 print "<tr class=\"titleBottom\"><td align=\"right\"><b>Link:</b></td>
257 <td><a href=\"".$line["link"]."\">".$line["link"]."</a> $comments_prompt</td>
258 <td> </td></tr>";
259 print "<tr><td valign=\"top\" class=\"post\"
260 colspan=\"2\" width=\"100%\">" . $line["content"] . "</td>
261 <td valign=\"top\">$feed_icon</td>
268 print "</body></html>";
272 if ($op == "viewfeed") {
274 $feed = $_GET["feed"];
275 $skip = $_GET["skip"];
276 $subop = $_GET["subop"];
277 $view_mode = $_GET["view"];
278 $addheader = $_GET["addheader"];
279 $limit = $_GET["limit"];
281 if (!$skip) $skip = 0;
283 if ($subop == "undefined") $subop = "";
287 <title>Tiny Tiny RSS : Feed $feed</title>
288 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
289 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
290 <script type=\"text/javascript\" src=\"functions.js\"></script>
291 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
295 // FIXME: check for null value here
297 $result = pg_query("SELECT *,SUBSTRING(last_updated,1,16) as last_updated_s,
298 EXTRACT(EPOCH FROM NOW()) - EXTRACT(EPOCH FROM last_updated) as update_timeout
299 FROM ttrss_feeds WHERE id = '$feed'");
303 $line = pg_fetch_assoc($result);
305 if ($subop == "ForceUpdate" ||
306 $line["last_updated"] == "" ||
307 $line["update_timeout"] > MIN_UPDATE_TIME
) {
309 update_rss_feed($link, $line["feed_url"], $feed);
313 if ($subop == "MarkAllRead") {
315 pg_query("UPDATE ttrss_entries SET unread = false,last_read = NOW()
316 WHERE feed_id = '$feed'");
321 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
323 $feed_last_updated = "Updated: " . $line["last_updated"];
325 $search = $_GET["search"];
328 $search_query_part = "(upper(title) LIKE upper('%$search%')
329 OR content LIKE '%$search%') AND";
331 $search_query_part = "";
334 $view_query_part = "";
336 if ($view_mode == "Starred") {
337 $view_query_part = " marked = true AND ";
340 if ($view_mode == "Unread") {
341 $view_query_part = " unread = true AND ";
344 $result = pg_query("SELECT count(id) AS total_entries
345 FROM ttrss_entries WHERE
349 $total_entries = pg_fetch_result($result, 0, "total_entries");
351 /* $result = pg_query("SELECT count(id) AS unread_entries
352 FROM ttrss_entries WHERE
357 $unread_entries = pg_fetch_result($result, 0, "unread_entries"); */
359 /* if ($limit < $unread_entries)
360 $limit = $unread_entries;
362 if ($limit != "All") {
363 $limit_query_part = "LIMIT " . $limit;
366 $result = pg_query("SELECT
367 id,title,updated,unread,feed_id,marked,link,
368 EXTRACT(EPOCH FROM last_read) AS last_read_ts,
369 EXTRACT(EPOCH FROM updated) AS updated_ts
375 feed_id = '$feed' ORDER BY updated DESC
382 while ($line = pg_fetch_assoc($result)) {
384 $class = ($lnum %
2) ?
"even" : "odd";
386 if ($line["last_read_ts"] < $line["updated_ts"] && $line["unread"] == "f") {
387 $update_pic = "<img src=\"images/updated.png\" alt=\"Updated\">";
390 $update_pic = " ";
393 if ($line["unread"] == "t") {
399 $feed_id = $line["feed_id"];
401 if ($line["marked"] == "t") {
402 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
403 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
405 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
406 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
409 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
410 $line["title"] . "</a>";
412 print "<tr class='$class' id='RROW-$id'";
413 // onclick=\"javascript:view($id,$feed_id)\">
415 print "<td id='FUPDPIC-$id' valign='center'
416 class='headlineUpdateMark'>$update_pic</td>";
418 print "<td valign='center'
419 class='headlineUpdateMark'>$marked_pic</td>";
421 print "<td class='headlineUpdated'>
422 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
423 print "<td class='headlineTitle'>$content_link</td>";
431 print "<tr><td align='center'>No entries found.</td></tr>";
434 while ($lnum < HEADLINES_PER_PAGE
) {
436 print "<tr><td> </td></tr>";
441 $result = pg_query("SELECT id, (SELECT count(id) FROM ttrss_entries
442 WHERE feed_id = ttrss_feeds.id) AS total,
443 (SELECT count(id) FROM ttrss_entries
444 WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
445 FROM ttrss_feeds WHERE id = '$feed'");
447 $total = pg_fetch_result($result, 0, "total");
448 $unread = pg_fetch_result($result, 0, "unread");
450 // update unread/total counters and status for active feed in the feedlist
451 // kludge, because iframe doesn't seem to support onload()
453 print "<script type=\"text/javascript\">
454 document.onkeydown = hotkey_handler;
456 var p_document = parent.frames['feeds-frame'].document;
458 var feedr = p_document.getElementById(\"FEEDR-\" + $feed);
459 var feedt = p_document.getElementById(\"FEEDT-\" + $feed);
460 var feedu = p_document.getElementById(\"FEEDU-\" + $feed);
462 feedt.innerHTML = \"$total\";
463 feedu.innerHTML = \"$unread\";
465 if ($unread > 0 && !feedr.className.match(\"Unread\")) {
466 feedr.className = feedr.className + \"Unread\";
467 } else if ($unread <= 0) {
468 feedr.className = feedr.className.replace(\"Unread\", \"\");
475 print "</body></html>";
480 if ($op == "pref-rpc") {
482 $subop = $_GET["subop"];
484 if ($subop == "unread") {
485 $ids = split(",", $_GET["ids"]);
486 foreach ($ids as $id) {
487 pg_query("UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'");
490 print "Marked selected feeds as read.";
493 if ($subop == "read") {
494 $ids = split(",", $_GET["ids"]);
495 foreach ($ids as $id) {
496 pg_query("UPDATE ttrss_entries
497 SET unread = false,last_read = NOW() WHERE feed_id = '$id'");
500 print "Marked selected feeds as unread.";
506 if ($op == "pref-feeds") {
508 $subop = $_GET["subop"];
510 if ($subop == "editSave") {
511 $feed_title = pg_escape_string($_GET["t"]);
512 $feed_link = pg_escape_string($_GET["l"]);
513 $feed_id = $_GET["id"];
515 $result = pg_query("UPDATE ttrss_feeds SET
516 title = '$feed_title', feed_url = '$feed_link' WHERE id = '$feed_id'");
520 if ($subop == "remove") {
522 if (!WEB_DEMO_MODE
) {
524 $ids = split(",", $_GET["ids"]);
526 foreach ($ids as $id) {
528 pg_query("DELETE FROM ttrss_entries WHERE feed_id = '$id'");
529 pg_query("DELETE FROM ttrss_feeds WHERE id = '$id'");
532 if (file_exists(ICONS_DIR
. "/$id.ico")) {
533 unlink(ICONS_DIR
. "/$id.ico");
539 if ($subop == "add") {
541 if (!WEB_DEMO_MODE
) {
543 $feed_link = pg_escape_string($_GET["link"]);
546 "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')");
549 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'");
551 $feed_id = pg_fetch_result($result, 0, "id");
554 update_rss_feed($link, $feed_link, $feed_id);
559 print "<table class=\"prefAddFeed\"><tr>
560 <td><input id=\"fadd_link\"></td>
561 <td colspan=\"4\" align=\"right\">
562 <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr>
565 $result = pg_query("SELECT
566 id,title,feed_url,substring(last_updated,1,16) as last_updated
568 ttrss_feeds ORDER by title");
570 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
571 print "<tr class=\"title\">
572 <td> </td><td>Select</td><td width=\"40%\">Title</td>
573 <td width=\"40%\">Link</td><td>Last updated</td></tr>";
577 while ($line = pg_fetch_assoc($result)) {
579 $class = ($lnum %
2) ?
"even" : "odd";
581 $feed_id = $line["id"];
583 $edit_feed_id = $_GET["id"];
585 if ($subop == "edit" && $feed_id != $edit_feed_id) {
589 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
591 $icon_file = ICONS_DIR
. "/$feed_id.ico";
593 if (file_exists($icon_file) && filesize($icon_file) > 0) {
594 $feed_icon = "<img width=\"16\" height=\"16\"
595 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
597 $feed_icon = " ";
599 print "<td align='center'>$feed_icon</td>";
601 if (!$edit_feed_id ||
$subop != "edit") {
603 print "<td><input onclick='toggleSelectRow(this);'
604 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
606 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
607 $line["title"] . "</td>";
608 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
609 $line["feed_url"] . "</td>";
612 } else if ($feed_id != $edit_feed_id) {
614 print "<td><input disabled=\"true\" type=\"checkbox\"
615 id=\"FRCHK-".$line["id"]."\"></td>";
617 print "<td>".$line["title"]."</td>";
618 print "<td>".$line["feed_url"]."</td>";
622 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
624 print "<td><input id=\"iedit_title\" value=\"".$line["title"]."\"></td>";
625 print "<td><input id=\"iedit_link\" value=\"".$line["feed_url"]."\"></td>";
629 if (!$line["last_updated"]) $line["last_updated"] = "Never";
631 print "<td>" . $line["last_updated"] . "</td>";
639 print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>";
646 if ($subop == "edit") {
647 print "Edit feed:
648 <input type=\"submit\" class=\"button\"
649 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
650 <input type=\"submit\" class=\"button\"
651 onclickf=\"javascript:feedEditSave()\" value=\"Save\">";
656 <input type=\"submit\" class=\"button\"
657 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
658 <input type=\"submit\" class=\"button\"
659 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
661 if (ENABLE_PREFS_CATCHUP_UNCATCHUP
) {
663 <input type=\"submit\" class=\"button\"
664 onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\">
665 <input type=\"submit\" class=\"button\"
666 onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\"> ";
670 <input type=\"submit\"
671 class=\"button\" onclick=\"opml.php?op=Export\" value=\"Export OPML\">";
677 if ($op == "pref-filters") {
679 $subop = $_GET["subop"];
681 if ($subop == "editSave") {
683 $regexp = pg_escape_string($_GET["r"]);
684 $descr = pg_escape_string($_GET["d"]);
685 $match = pg_escape_string($_GET["m"]);
686 $filter_id = pg_escape_string($_GET["id"]);
688 $result = pg_query("UPDATE ttrss_filters SET
690 description = '$descr',
691 filter_type = (SELECT id FROM ttrss_filter_types WHERE
692 description = '$match')
693 WHERE id = '$filter_id'");
696 if ($subop == "remove") {
698 if (!WEB_DEMO_MODE
) {
700 $ids = split(",", $_GET["ids"]);
702 foreach ($ids as $id) {
703 pg_query("DELETE FROM ttrss_filters WHERE id = '$id'");
709 if ($subop == "add") {
711 if (!WEB_DEMO_MODE
) {
713 $regexp = pg_escape_string($_GET["regexp"]);
714 $match = pg_escape_string($_GET["match"]);
717 "INSERT INTO ttrss_filters (regexp,filter_type) VALUES
718 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
719 description = '$match'))");
723 $result = pg_query("SELECT description
724 FROM ttrss_filter_types ORDER BY description");
726 $filter_types = array();
728 while ($line = pg_fetch_assoc($result)) {
729 array_push($filter_types, $line["description"]);
732 print "<table class=\"prefAddFeed\"><tr>
733 <td><input id=\"fadd_regexp\"></td>
735 print_select("fadd_match", "Title", $filter_types);
737 print"</td><td colspan=\"4\" align=\"right\">
738 <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr>
741 $result = pg_query("SELECT
742 id,regexp,description,
743 (SELECT name FROM ttrss_filter_types WHERE
744 id = filter_type) as filter_type_name,
745 (SELECT description FROM ttrss_filter_types
746 WHERE id = filter_type) as filter_type_descr
748 ttrss_filters ORDER by regexp");
750 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
752 print "<tr class=\"title\">
753 <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td>
754 <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>";
758 while ($line = pg_fetch_assoc($result)) {
760 $class = ($lnum %
2) ?
"even" : "odd";
762 $filter_id = $line["id"];
763 $edit_filter_id = $_GET["id"];
765 if ($subop == "edit" && $filter_id != $edit_filter_id) {
769 print "<tr class=\"$class\" id=\"FILRR-$filter_id\">";
771 $line["regexp"] = htmlspecialchars($line["regexp"]);
772 $line["description"] = htmlspecialchars($line["description"]);
774 if (!$edit_filter_id ||
$subop != "edit") {
776 if (!$line["description"]) $line["description"] = "[No description]";
778 print "<td><input onclick='toggleSelectRow(this);'
779 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
781 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
782 $line["regexp"] . "</td>";
784 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
785 $line["description"] . "</td>";
787 print "<td>".$line["filter_type_descr"]."</td>";
789 } else if ($filter_id != $edit_filter_id) {
791 if (!$line["description"]) $line["description"] = "[No description]";
793 print "<td><input disabled=\"true\" type=\"checkbox\"
794 id=\"FICHK-".$line["id"]."\"></td>";
796 print "<td>".$line["regexp"]."</td>";
797 print "<td>".$line["description"]."</td>";
798 print "<td>".$line["filter_type_descr"]."</td>";
802 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
804 print "<td><input id=\"iedit_regexp\" value=\"".$line["regexp"].
807 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
811 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
823 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
830 if ($subop == "edit") {
832 <input type=\"submit\" class=\"button\"
833 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
834 <input type=\"submit\" class=\"button\"
835 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
841 <input type=\"submit\" class=\"button\"
842 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
843 <input type=\"submit\" class=\"button\"
844 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
848 if ($op == "error") {
849 print "<div width=\"100%\" align='center'>";