2 // header("Content-Type: application/xml");
4 require_once "config.php";
6 require_once "functions.php";
7 require_once "magpierss/rss_fetch.inc";
9 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
11 if (DB_TYPE
== "pgsql") {
12 pg_query("set client_encoding = 'utf-8'");
16 $fetch = $_GET["fetch"];
18 function outputFeedList($link) {
21 <title>Tiny Tiny RSS : Feedlist</title>
22 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
23 <script type=\"text/javascript\" src=\"functions.js\"></script>
24 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
25 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
28 print "<ul class=\"feedList\" id=\"feedList\">";
32 $result = db_query($link, "SELECT count(id) as num_starred
33 FROM ttrss_entries WHERE marked = true");
34 $num_starred = db_fetch_result($result, 0, "num_starred");
36 printFeedEntry(-1, "odd", "Starred articles", $num_starred, "images/mark_set.png");
38 print "<li><hr></li>";
40 $result = db_query($link, "SELECT *,
41 (SELECT count(id) FROM ttrss_entries
42 WHERE feed_id = ttrss_feeds.id) AS total,
43 (SELECT count(id) FROM ttrss_entries
44 WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
45 FROM ttrss_feeds ORDER BY title");
47 $actid = $_GET["actid"];
55 while ($line = db_fetch_assoc($result)) {
57 $feed = $line["title"];
58 $feed_id = $line["id"];
60 $subop = $_GET["subop"];
62 $total = $line["total"];
63 $unread = $line["unread"];
65 // $class = ($lnum % 2) ? "even" : "odd";
69 if ($unread > 0) $class .= "Unread";
71 if ($actid == $feed_id) {
75 $total_unread +
= $unread;
77 printFeedEntry($feed_id, $class, $feed, $unread, "icons/$feed_id.ico");
84 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
91 $subop = $_GET["subop"];
93 if ($subop == "mark") {
94 $mark = $_GET["mark"];
95 $id = db_escape_string($_GET["id"]);
103 $result = db_query($link, "UPDATE ttrss_entries SET marked = $mark
107 if ($subop == "updateFeed") {
108 $feed_id = db_escape_string($_GET["feed"]);
110 $result = db_query($link,
111 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'");
113 if (db_num_rows($result) > 0) {
114 $feed_url = db_fetch_result($result, 0, "feed_url");
115 // update_rss_feed($link, $feed_url, $feed_id);
118 print "DONE-$feed_id";
123 if ($subop == "forceUpdateAllFeeds") {
124 update_all_feeds($link, true);
127 if ($subop == "updateAllFeeds") {
128 update_all_feeds($link, false);
131 if ($subop == "catchupPage") {
133 $ids = split(",", $_GET["ids"]);
135 foreach ($ids as $id) {
137 db_query($link, "UPDATE ttrss_entries SET unread=false,last_read = NOW()
142 print "Marked active page as read.";
147 if ($op == "feeds") {
149 $subop = $_GET["subop"];
151 if ($subop == "catchupAll") {
152 db_query($link, "UPDATE ttrss_entries SET last_read = NOW(),unread = false");
155 outputFeedList($link);
163 $result = db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'");
165 $addheader = $_GET["addheader"];
167 $result = db_query($link, "SELECT title,link,content,feed_id,comments,
168 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
174 <title>Tiny Tiny RSS : Article $id</title>
175 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
176 <script type=\"text/javascript\" src=\"functions.js\"></script>
177 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
183 $line = db_fetch_assoc($result);
185 if ($line["icon_url"]) {
186 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
188 $feed_icon = " ";
191 if ($line["comments"] && $line["link"] != $line["comments"]) {
192 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
194 $entry_comments = "";
197 print "<div class=\"postReply\">";
199 print "<div class=\"postHeader\"><table>";
201 print "<tr><td><b>Title:</b></td>
202 <td width='100%'>" . $line["title"] . "</td></tr>";
204 print "<tr><td><b>Link:</b></td>
206 <a href=\"" . $line["link"] . "\">".$line["link"]."</a>
207 $entry_comments</td></tr>";
209 print "</table></div>";
211 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
212 print "<div class=\"postContent\">" . $line["content"] . "</div>";
219 print "</body></html>";
223 if ($op == "viewfeed") {
225 $feed = $_GET["feed"];
226 $skip = $_GET["skip"];
227 $subop = $_GET["subop"];
228 $view_mode = $_GET["view"];
229 $addheader = $_GET["addheader"];
230 $limit = $_GET["limit"];
233 print "Error: no feed to display.";
237 if (!$skip) $skip = 0;
239 if ($subop == "undefined") $subop = "";
243 <title>Tiny Tiny RSS : Feed $feed</title>
244 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
245 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
246 <script type=\"text/javascript\" src=\"functions.js\"></script>
247 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
253 $result = db_query($link,
254 "SELECT *,SUBSTRING(last_updated,1,16) as last_updated_s
255 FROM ttrss_feeds WHERE id = '$feed'");
259 $line = db_fetch_assoc($result);
261 update_rss_feed($link, $line["feed_url"], $feed);
263 if ($subop == "MarkAllRead") {
265 db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW()
266 WHERE feed_id = '$feed'");
271 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
273 $search = $_GET["search"];
276 $search_query_part = "(upper(title) LIKE upper('%$search%')
277 OR content LIKE '%$search%') AND";
279 $search_query_part = "";
282 $view_query_part = "";
284 if ($view_mode == "Starred") {
285 $view_query_part = " marked = true AND ";
288 if ($view_mode == "Unread") {
289 $view_query_part = " unread = true AND ";
292 /* $result = db_query($link, "SELECT count(id) AS total_entries
293 FROM ttrss_entries WHERE
297 $total_entries = db_fetch_result($result, 0, "total_entries"); */
299 /* $result = db_query("SELECT count(id) AS unread_entries
300 FROM ttrss_entries WHERE
305 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
307 if ($limit && $limit != "All") {
308 $limit_query_part = "LIMIT " . $limit;
311 $vfeed_query_part = "";
314 $query_strategy_part = "feed_id = '$feed'";
315 } else if ($feed == -1) {
316 $query_strategy_part = "marked = true";
317 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
318 id = feed_id) as feed_title,";
320 $query_strategy_part = "id => 0"; // dumb
323 $result = db_query($link, "SELECT
324 id,title,updated,unread,feed_id,marked,link,last_read,
325 SUBSTRING(last_read,1,19) as last_read_noms,
327 SUBSTRING(updated,1,19) as updated_noms
333 $query_strategy_part ORDER BY updated DESC
340 while ($line = db_fetch_assoc($result)) {
342 $class = ($lnum %
2) ?
"even" : "odd";
345 $feed_id = $line["feed_id"];
347 // printf("L %d (%s) > U %d (%s) = %d<br>",
348 // strtotime($line["last_read_noms"]), $line["last_read_noms"],
349 // strtotime($line["updated"]), $line["updated"],
350 // strtotime($line["last_read"]) >= strtotime($line["updated"]));
352 if ($line["last_read"] != "" && $line["updated"] != "" &&
353 strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) {
355 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
360 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
365 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
370 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
371 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
372 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
374 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
375 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
378 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
379 $line["title"] . "</a>";
381 print "<tr class='$class' id='RROW-$id'>";
382 // onclick=\"javascript:view($id,$feed_id)\">
384 print "<td valign='center' align='center'>$update_pic</td>";
385 print "<td valign='center' align='center'>$marked_pic</td>";
387 print "<td width='25%'>
388 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
390 if ($line["feed_title"]) {
391 print "<td width='50%'>$content_link</td>";
392 print "<td width='20%'>".$line["feed_title"]."</td>";
394 print "<td width='70%'>$content_link</td>";
403 print "<tr><td align='center'>No entries found.</td></tr>";
406 /* while ($lnum < HEADLINES_PER_PAGE) {
408 print "<tr><td> </td></tr>";
415 $result = db_query($link, "SELECT count(id) as unread FROM ttrss_entries
416 WHERE feed_id = ttrss_feeds.id AND $query_strategy_part
418 } else if ($feed == -1) {
419 $result = db_query($link, "SELECT count(id) as unread FROM ttrss_entries
420 WHERE $query_strategy_part");
423 print "[viewfeed] feed type not implemented<br>";
426 $unread = db_fetch_result($result, 0, "unread");
428 // update unread/total counters and status for active feed in the feedlist
429 // kludge, because iframe doesn't seem to support onload()
431 print "<script type=\"text/javascript\">
432 document.onkeydown = hotkey_handler;
434 var p_document = parent.frames['feeds-frame'].document;
436 var feedr = p_document.getElementById(\"FEEDR-\" + $feed);
437 var feedu = p_document.getElementById(\"FEEDU-\" + $feed);
440 feedu.innerHTML = \"$unread\";
443 var feedctr = p_document.getElementById(\"FEEDCTR-\" + $feed);
445 if ($unread > 0 && $feed != -1 && !feedr.className.match(\"Unread\")) {
446 feedr.className = feedr.className + \"Unread\";
447 feedctr.className = '';
448 } else if ($unread <= 0) {
449 feedr.className = feedr.className.replace(\"Unread\", \"\");
450 feedctr.className = 'invisible';
458 print "</body></html>";
463 if ($op == "pref-rpc") {
465 $subop = $_GET["subop"];
467 if ($subop == "unread") {
468 $ids = split(",", $_GET["ids"]);
469 foreach ($ids as $id) {
470 db_query($link, "UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'");
473 print "Marked selected feeds as read.";
476 if ($subop == "read") {
477 $ids = split(",", $_GET["ids"]);
478 foreach ($ids as $id) {
479 db_query($link, "UPDATE ttrss_entries
480 SET unread = false,last_read = NOW() WHERE feed_id = '$id'");
483 print "Marked selected feeds as unread.";
489 if ($op == "pref-feeds") {
491 $subop = $_GET["subop"];
493 if ($subop == "editSave") {
494 $feed_title = db_escape_string($_GET["t"]);
495 $feed_link = db_escape_string($_GET["l"]);
496 $feed_id = $_GET["id"];
498 $result = db_query($link, "UPDATE ttrss_feeds SET
499 title = '$feed_title', feed_url = '$feed_link' WHERE id = '$feed_id'");
503 if ($subop == "remove") {
505 if (!WEB_DEMO_MODE
) {
507 $ids = split(",", $_GET["ids"]);
509 foreach ($ids as $id) {
510 db_query($link, "BEGIN");
511 db_query($link, "DELETE FROM ttrss_entries WHERE feed_id = '$id'");
512 db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'");
513 db_query($link, "COMMIT");
515 if (file_exists(ICONS_DIR
. "/$id.ico")) {
516 unlink(ICONS_DIR
. "/$id.ico");
522 if ($subop == "add") {
524 if (!WEB_DEMO_MODE
) {
526 $feed_link = db_escape_string($_GET["link"]);
528 $result = db_query($link,
529 "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')");
531 $result = db_query($link,
532 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'");
534 $feed_id = db_fetch_result($result, 0, "id");
537 update_rss_feed($link, $feed_link, $feed_id);
542 print "<table class=\"prefAddFeed\"><tr>
543 <td><input id=\"fadd_link\"></td>
544 <td colspan=\"4\" align=\"right\">
545 <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr>
548 $result = db_query($link, "SELECT
549 id,title,feed_url,substring(last_updated,1,16) as last_updated
551 ttrss_feeds ORDER by title");
553 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
554 print "<tr class=\"title\">
555 <td> </td><td>Select</td><td width=\"40%\">Title</td>
556 <td width=\"40%\">Link</td><td>Last updated</td></tr>";
560 while ($line = db_fetch_assoc($result)) {
562 $class = ($lnum %
2) ?
"even" : "odd";
564 $feed_id = $line["id"];
566 $edit_feed_id = $_GET["id"];
568 if ($subop == "edit" && $feed_id != $edit_feed_id) {
572 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
574 $icon_file = ICONS_DIR
. "/$feed_id.ico";
576 if (file_exists($icon_file) && filesize($icon_file) > 0) {
577 $feed_icon = "<img width=\"16\" height=\"16\"
578 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
580 $feed_icon = " ";
582 print "<td align='center'>$feed_icon</td>";
584 if (!$edit_feed_id ||
$subop != "edit") {
586 print "<td><input onclick='toggleSelectRow(this);'
587 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
589 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
590 $line["title"] . "</td>";
591 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
592 $line["feed_url"] . "</td>";
595 } else if ($feed_id != $edit_feed_id) {
597 print "<td><input disabled=\"true\" type=\"checkbox\"
598 id=\"FRCHK-".$line["id"]."\"></td>";
600 print "<td>".$line["title"]."</td>";
601 print "<td>".$line["feed_url"]."</td>";
605 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
607 print "<td><input id=\"iedit_title\" value=\"".$line["title"]."\"></td>";
608 print "<td><input id=\"iedit_link\" value=\"".$line["feed_url"]."\"></td>";
612 if (!$line["last_updated"]) $line["last_updated"] = "Never";
614 print "<td>" . $line["last_updated"] . "</td>";
622 print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>";
629 if ($subop == "edit") {
630 print "Edit feed:
631 <input type=\"submit\" class=\"button\"
632 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
633 <input type=\"submit\" class=\"button\"
634 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
639 <input type=\"submit\" class=\"button\"
640 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
641 <input type=\"submit\" class=\"button\"
642 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
644 if (ENABLE_PREFS_CATCHUP_UNCATCHUP
) {
646 <input type=\"submit\" class=\"button\"
647 onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\">
648 <input type=\"submit\" class=\"button\"
649 onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\"> ";
653 <input type=\"submit\"
654 class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">";
660 if ($op == "pref-filters") {
662 $subop = $_GET["subop"];
664 if ($subop == "editSave") {
666 $regexp = db_escape_string($_GET["r"]);
667 $descr = db_escape_string($_GET["d"]);
668 $match = db_escape_string($_GET["m"]);
669 $filter_id = db_escape_string($_GET["id"]);
671 $result = db_query($link, "UPDATE ttrss_filters SET
673 description = '$descr',
674 filter_type = (SELECT id FROM ttrss_filter_types WHERE
675 description = '$match')
676 WHERE id = '$filter_id'");
679 if ($subop == "remove") {
681 if (!WEB_DEMO_MODE
) {
683 $ids = split(",", $_GET["ids"]);
685 foreach ($ids as $id) {
686 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
692 if ($subop == "add") {
694 if (!WEB_DEMO_MODE
) {
696 $regexp = db_escape_string($_GET["regexp"]);
697 $match = db_escape_string($_GET["match"]);
699 $result = db_query($link,
700 "INSERT INTO ttrss_filters (reg_exp,filter_type) VALUES
701 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
702 description = '$match'))");
706 $result = db_query($link, "SELECT description
707 FROM ttrss_filter_types ORDER BY description");
709 $filter_types = array();
711 while ($line = db_fetch_assoc($result)) {
712 array_push($filter_types, $line["description"]);
715 print "<table class=\"prefAddFeed\"><tr>
716 <td><input id=\"fadd_regexp\"></td>
718 print_select("fadd_match", "Title", $filter_types);
720 print"</td><td colspan=\"4\" align=\"right\">
721 <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr>
724 $result = db_query($link, "SELECT
725 id,reg_exp,description,
726 (SELECT name FROM ttrss_filter_types WHERE
727 id = filter_type) as filter_type_name,
728 (SELECT description FROM ttrss_filter_types
729 WHERE id = filter_type) as filter_type_descr
731 ttrss_filters ORDER by reg_exp");
733 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
735 print "<tr class=\"title\">
736 <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td>
737 <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>";
741 while ($line = db_fetch_assoc($result)) {
743 $class = ($lnum %
2) ?
"even" : "odd";
745 $filter_id = $line["id"];
746 $edit_filter_id = $_GET["id"];
748 if ($subop == "edit" && $filter_id != $edit_filter_id) {
752 print "<tr class=\"$class\" id=\"FILRR-$filter_id\">";
754 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
755 $line["description"] = htmlspecialchars($line["description"]);
757 if (!$edit_filter_id ||
$subop != "edit") {
759 if (!$line["description"]) $line["description"] = "[No description]";
761 print "<td><input onclick='toggleSelectRow(this);'
762 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
764 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
765 $line["reg_exp"] . "</td>";
767 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
768 $line["description"] . "</td>";
770 print "<td>".$line["filter_type_descr"]."</td>";
772 } else if ($filter_id != $edit_filter_id) {
774 if (!$line["description"]) $line["description"] = "[No description]";
776 print "<td><input disabled=\"true\" type=\"checkbox\"
777 id=\"FICHK-".$line["id"]."\"></td>";
779 print "<td>".$line["reg_exp"]."</td>";
780 print "<td>".$line["description"]."</td>";
781 print "<td>".$line["filter_type_descr"]."</td>";
785 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
787 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
790 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
794 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
806 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
813 if ($subop == "edit") {
815 <input type=\"submit\" class=\"button\"
816 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
817 <input type=\"submit\" class=\"button\"
818 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
824 <input type=\"submit\" class=\"button\"
825 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
826 <input type=\"submit\" class=\"button\"
827 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
831 if ($op == "error") {
832 print "<div width=\"100%\" align='center'>";