5 header("Content-Type: application/xml");
8 require_once "config.php";
10 require_once "functions.php";
11 require_once "magpierss/rss_fetch.inc";
13 $script_started = getmicrotime();
15 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
18 if (DB_TYPE
== "mysql") {
21 // PG seems to display its own errors just fine by default.
25 if (DB_TYPE
== "pgsql") {
26 pg_query("set client_encoding = 'utf-8'");
29 $fetch = $_GET["fetch"];
31 /* FIXME this needs reworking */
33 function getGlobalCounters($link) {
34 $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries
35 WHERE unread = true");
36 $c_id = db_fetch_result($result, 0, "c_id");
37 print "<counter id='global-unread' counter='$c_id'/>";
40 function getTagCounters($link) {
41 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
42 FROM ttrss_tags,ttrss_entries WHERE
43 post_id = ttrss_entries.id AND unread = true GROUP BY tag_name
45 select tag_name,0 as count FROM ttrss_tags");
49 while ($line = db_fetch_assoc($result)) {
50 $tags[$line["tag_name"]] +
= $line["count"];
53 foreach (array_keys($tags) as $tag) {
54 $unread = $tags[$tag];
56 $tag = htmlspecialchars($tag);
57 print "<tag id=\"$tag\" counter=\"$unread\"/>";
61 function getLabelCounters($link) {
63 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
64 WHERE marked = true AND unread = true");
66 $count = db_fetch_result($result, 0, "count");
68 print "<label id=\"-1\" counter=\"$count\"/>";
70 $result = db_query($link, "SELECT id,sql_exp,description FROM
71 ttrss_labels ORDER by description");
73 while ($line = db_fetch_assoc($result)) {
75 $id = -$line["id"] - 11;
79 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
80 WHERE (" . $line["sql_exp"] . ") AND unread = true");
82 $count = db_fetch_result($tmp_result, 0, "count");
84 print "<label id=\"$id\" counter=\"$count\"/>";
86 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
91 function getFeedCounter($link, $id) {
93 $result = db_query($link, "SELECT
94 count(id) as count FROM ttrss_entries
95 WHERE feed_id = '$id' AND unread = true");
97 $count = db_fetch_result($result, 0, "count");
99 print "<feed id=\"$id\" counter=\"$count\"/>";
102 function getFeedCounters($link) {
104 $result = db_query($link, "SELECT id,
105 (SELECT count(id) FROM ttrss_entries WHERE feed_id = ttrss_feeds.id
106 AND unread = true) as count
109 while ($line = db_fetch_assoc($result)) {
112 $count = $line["count"];
114 print "<feed id=\"$id\" counter=\"$count\"/>";
118 function outputFeedList($link, $tags = false) {
121 <title>Tiny Tiny RSS : Feedlist</title>
122 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
123 <script type=\"text/javascript\" src=\"functions.js\"></script>
124 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
125 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
128 print "<ul class=\"feedList\" id=\"feedList\">";
134 $result = db_query($link, "SELECT count(id) as num_starred
135 FROM ttrss_entries WHERE marked = true AND unread = true");
136 $num_starred = db_fetch_result($result, 0, "num_starred");
140 if ($num_starred > 0) $class .= "Unread";
142 printFeedEntry(-1, $class, "Starred articles", $num_starred,
143 "images/mark_set.png");
147 $result = db_query($link, "SELECT id,sql_exp,description FROM
148 ttrss_labels ORDER by description");
150 if (db_num_rows($result) > 0) {
151 print "<li><hr></li>";
154 while ($line = db_fetch_assoc($result)) {
158 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
159 WHERE (" . $line["sql_exp"] . ") AND unread = true");
161 $count = db_fetch_result($tmp_result, 0, "count");
169 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
171 printFeedEntry(-$line["id"]-11,
172 $class, $line["description"], $count, "images/label.png");
177 print "<li><hr></li>";
179 $result = db_query($link, "SELECT *,
180 (SELECT count(id) FROM ttrss_entries
181 WHERE feed_id = ttrss_feeds.id) AS total,
182 (SELECT count(id) FROM ttrss_entries
183 WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
184 FROM ttrss_feeds ORDER BY title");
186 $actid = $_GET["actid"];
194 while ($line = db_fetch_assoc($result)) {
196 $feed = $line["title"];
197 $feed_id = $line["id"];
199 $subop = $_GET["subop"];
201 $total = $line["total"];
202 $unread = $line["unread"];
204 // $class = ($lnum % 2) ? "even" : "odd";
208 if ($unread > 0) $class .= "Unread";
210 if ($actid == $feed_id) {
211 $class .= "Selected";
214 $total_unread +
= $unread;
216 printFeedEntry($feed_id, $class, $feed, $unread, "icons/$feed_id.ico");
224 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
225 FROM ttrss_tags,ttrss_entries WHERE
226 post_id = ttrss_entries.id AND unread = true GROUP BY tag_name
228 select tag_name,0 as count FROM ttrss_tags");
232 while ($line = db_fetch_assoc($result)) {
233 $tags[$line["tag_name"]] +
= $line["count"];
236 foreach (array_keys($tags) as $tag) {
238 $unread = $tags[$tag];
246 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png");
252 if (db_num_rows($result) == 0) {
253 print "<li>No tags to display.</li>";
258 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
265 $subop = $_GET["subop"];
267 if ($subop == "getLabelCounters") {
270 getLabelCounters($link);
272 getFeedCounter($link, $aid);
274 print "</rpc-reply>";
277 if ($subop == "getFeedCounters") {
279 getFeedCounters($link);
280 print "</rpc-reply>";
283 if ($subop == "getAllCounters") {
285 getLabelCounters($link);
286 getFeedCounters($link);
287 getTagCounters($link);
288 getGlobalCounters($link);
289 print "</rpc-reply>";
292 if ($subop == "mark") {
293 $mark = $_GET["mark"];
294 $id = db_escape_string($_GET["id"]);
302 $result = db_query($link, "UPDATE ttrss_entries SET marked = $mark
306 if ($subop == "updateFeed") {
307 $feed_id = db_escape_string($_GET["feed"]);
309 $result = db_query($link,
310 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'");
312 if (db_num_rows($result) > 0) {
313 $feed_url = db_fetch_result($result, 0, "feed_url");
314 // update_rss_feed($link, $feed_url, $feed_id);
317 print "DONE-$feed_id";
322 if ($subop == "forceUpdateAllFeeds" ||
$subop == "updateAllFeeds") {
323 update_all_feeds($link, true);
325 $omode = $_GET["omode"];
327 if (!$omode) $omode = "tfl";
330 if (strchr($omode, "l")) getLabelCounters($link);
331 if (strchr($omode, "f")) getFeedCounters($link);
332 if (strchr($omode, "t")) getTagCounters($link);
333 getGlobalCounters($link);
334 print "</rpc-reply>";
337 if ($subop == "catchupPage") {
339 $ids = split(",", $_GET["ids"]);
341 foreach ($ids as $id) {
343 db_query($link, "UPDATE ttrss_entries SET unread=false,last_read = NOW()
348 print "Marked active page as read.";
352 if ($op == "feeds") {
354 $tags = $_GET["tags"];
356 $subop = $_GET["subop"];
358 if ($subop == "catchupAll") {
359 db_query($link, "UPDATE ttrss_entries SET last_read = NOW(),unread = false");
362 outputFeedList($link, $tags);
369 $feed_id = $_GET["feed"];
371 $result = db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'");
373 $addheader = $_GET["addheader"];
375 $result = db_query($link, "SELECT title,link,content,feed_id,comments,
376 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
382 <title>Tiny Tiny RSS : Article $id</title>
383 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
384 <script type=\"text/javascript\" src=\"functions.js\"></script>
385 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
391 $line = db_fetch_assoc($result);
393 if ($line["icon_url"]) {
394 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
396 $feed_icon = " ";
399 if ($line["comments"] && $line["link"] != $line["comments"]) {
400 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
402 $entry_comments = "";
405 print "<div class=\"postReply\">";
407 print "<div class=\"postHeader\"><table>";
409 print "<tr><td><b>Title:</b></td>
410 <td width='100%'>" . $line["title"] . "</td></tr>";
412 print "<tr><td><b>Link:</b></td>
414 <a href=\"" . $line["link"] . "\">".$line["link"]."</a>
415 $entry_comments</td></tr>";
417 print "</table></div>";
419 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
420 print "<div class=\"postContent\">" . $line["content"] . "</div>";
424 print "<script type=\"text/javascript\">
425 update_label_counters('$feed_id');
430 print "</body></html>";
434 if ($op == "viewfeed") {
436 $feed = $_GET["feed"];
437 $skip = $_GET["skip"];
438 $subop = $_GET["subop"];
439 $view_mode = $_GET["view"];
440 $addheader = $_GET["addheader"];
441 $limit = $_GET["limit"];
444 print "Error: no feed to display.";
448 if (!$skip) $skip = 0;
450 if ($subop == "undefined") $subop = "";
454 <title>Tiny Tiny RSS : Feed $feed</title>
455 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
456 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
457 <script type=\"text/javascript\" src=\"functions.js\"></script>
458 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
462 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
464 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
465 WHERE id = '$feed'");
467 $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
469 update_rss_feed($link, $feed_url, $feed);
473 if ($subop == "MarkAllRead") {
475 if (sprintf("%d", $feed) != 0) {
478 db_query($link, "UPDATE ttrss_entries
479 SET unread = false,last_read = NOW()
480 WHERE feed_id = '$feed'");
482 } else if ($feed < 0 && $feed > -10) { // special, like starred
485 db_query($link, "UPDATE ttrss_entries
486 SET unread = false,last_read = NOW()
487 WHERE marked = true");
490 } else if ($feed < -10) { // label
492 $label_id = -$feed - 11;
494 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
495 WHERE id = '$label_id'");
498 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
500 db_query($link, "UPDATE ttrss_entries
501 SET unread = false,last_read = NOW()
506 // FIXME, implement catchup for tags
511 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
513 $search = $_GET["search"];
515 $search_mode = $_GET["smode"];
518 $search_query_part = "(upper(title) LIKE upper('%$search%')
519 OR content LIKE '%$search%') AND";
521 $search_query_part = "";
524 $view_query_part = "";
526 if ($view_mode == "Starred") {
527 $view_query_part = " marked = true AND ";
530 if ($view_mode == "Unread") {
531 $view_query_part = " unread = true AND ";
534 if ($view_mode == "Unread or Starred") {
535 $view_query_part = " (unread = true OR marked = true) AND ";
538 if ($view_mode == "Unread or Updated") {
539 $view_query_part = " (unread = true OR last_read is NULL) AND ";
542 /* $result = db_query($link, "SELECT count(id) AS total_entries
543 FROM ttrss_entries WHERE
547 $total_entries = db_fetch_result($result, 0, "total_entries"); */
549 /* $result = db_query("SELECT count(id) AS unread_entries
550 FROM ttrss_entries WHERE
555 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
557 if ($limit && $limit != "All") {
558 $limit_query_part = "LIMIT " . $limit;
561 $vfeed_query_part = "";
563 // override query strategy and enable feed display when searching globally
564 if ($search_mode == "All feeds") {
565 $query_strategy_part = "id > 0";
566 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
567 id = feed_id) as feed_title,";
568 } else if (sprintf("%d", $feed) == 0) {
569 $query_strategy_part = "ttrss_entries.id > 0";
570 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
571 id = feed_id) as feed_title,";
572 } else if ($feed >= 0) {
573 $query_strategy_part = "feed_id = '$feed'";
574 } else if ($feed == -1) { // starred virtual feed
575 $query_strategy_part = "marked = true";
576 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
577 id = feed_id) as feed_title,";
578 } else if ($feed <= -10) { // labels
579 $label_id = -$feed - 11;
581 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
582 WHERE id = '$label_id'");
584 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
586 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
587 id = feed_id) as feed_title,";
589 $query_strategy_part = "id > 0"; // dumb
593 $order_by = "updated DESC";
595 // if ($feed < -10) {
596 // $order_by = "feed_id,updated DESC";
599 if ($feed < -10) error_reporting (0);
601 if (sprintf("%d", $feed) != 0) {
603 $result = db_query($link, "SELECT
604 id,title,updated,unread,feed_id,marked,link,last_read,
605 SUBSTRING(last_read,1,19) as last_read_noms,
607 SUBSTRING(updated,1,19) as updated_noms
613 $query_strategy_part ORDER BY $order_by
619 $result = db_query($link, "SELECT
620 ttrss_entries.id as id,title,updated,unread,feed_id,
621 marked,link,last_read,
622 SUBSTRING(last_read,1,19) as last_read_noms,
624 SUBSTRING(updated,1,19) as updated_noms
626 ttrss_entries,ttrss_tags
628 post_id = ttrss_entries.id AND tag_name = '$feed' AND
631 $query_strategy_part ORDER BY $order_by
636 print "<tr><td colspan='4' align='center'>
637 Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>";
643 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
647 while ($line = db_fetch_assoc($result)) {
649 $class = ($lnum %
2) ?
"even" : "odd";
652 $feed_id = $line["feed_id"];
654 // printf("L %d (%s) > U %d (%s) = %d<br>",
655 // strtotime($line["last_read_noms"]), $line["last_read_noms"],
656 // strtotime($line["updated"]), $line["updated"],
657 // strtotime($line["last_read"]) >= strtotime($line["updated"]));
659 /* if ($line["last_read"] != "" && $line["updated"] != "" &&
660 strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) {
662 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
667 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
672 if ($line["last_read"] == "" &&
673 ($line["unread"] != "t" && $line["unread"] != "1")) {
675 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
678 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
682 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
687 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
688 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
689 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
691 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
692 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
695 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
696 $line["title"] . "</a>";
698 print "<tr class='$class' id='RROW-$id'>";
699 // onclick=\"javascript:view($id,$feed_id)\">
701 print "<td valign='center' align='center'>$update_pic</td>";
702 print "<td valign='center' align='center'>$marked_pic</td>";
704 print "<td width='25%'>
705 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
707 if ($line["feed_title"]) {
708 print "<td width='50%'>$content_link</td>";
709 print "<td width='20%'>".$line["feed_title"]."</td>";
711 print "<td width='70%'>$content_link</td>";
720 print "<tr><td align='center'>No articles found.</td></tr>";
725 print "<script type=\"text/javascript\">
726 document.onkeydown = hotkey_handler;
727 update_label_counters('$feed');
731 print "</body></html>";
736 if ($op == "pref-rpc") {
738 $subop = $_GET["subop"];
740 if ($subop == "unread") {
741 $ids = split(",", $_GET["ids"]);
742 foreach ($ids as $id) {
743 db_query($link, "UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'");
746 print "Marked selected feeds as read.";
749 if ($subop == "read") {
750 $ids = split(",", $_GET["ids"]);
751 foreach ($ids as $id) {
752 db_query($link, "UPDATE ttrss_entries
753 SET unread = false,last_read = NOW() WHERE feed_id = '$id'");
756 print "Marked selected feeds as unread.";
762 if ($op == "pref-feeds") {
764 $subop = $_GET["subop"];
766 if ($subop == "editSave") {
767 $feed_title = db_escape_string($_GET["t"]);
768 $feed_link = db_escape_string($_GET["l"]);
769 $upd_intl = db_escape_string($_GET["ui"]);
770 $feed_id = $_GET["id"];
772 if (strtoupper($upd_intl) == "DEFAULT")
775 $result = db_query($link, "UPDATE ttrss_feeds SET
776 title = '$feed_title', feed_url = '$feed_link',
777 update_interval = '$upd_intl' WHERE id = '$feed_id'");
781 if ($subop == "remove") {
783 if (!WEB_DEMO_MODE
) {
785 $ids = split(",", $_GET["ids"]);
787 foreach ($ids as $id) {
788 db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'");
790 if (file_exists(ICONS_DIR
. "/$id.ico")) {
791 unlink(ICONS_DIR
. "/$id.ico");
797 if ($subop == "add") {
799 if (!WEB_DEMO_MODE
) {
801 $feed_link = db_escape_string($_GET["link"]);
803 $result = db_query($link,
804 "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')");
806 $result = db_query($link,
807 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'");
809 $feed_id = db_fetch_result($result, 0, "id");
812 update_rss_feed($link, $feed_link, $feed_id);
817 print "<table class=\"prefAddFeed\"><tr>
818 <td><input id=\"fadd_link\"></td>
819 <td colspan=\"4\" align=\"right\">
820 <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr>
823 $result = db_query($link, "SELECT
824 id,title,feed_url,substring(last_updated,1,16) as last_updated,
827 ttrss_feeds ORDER by title");
829 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
830 print "<tr class=\"title\">
831 <td> </td><td>Select</td><td width=\"40%\">Title</td>
832 <td width=\"30%\">Link</td><td width=\"10%\">Update Interval</td>
833 <td>Last updated</td></tr>";
837 while ($line = db_fetch_assoc($result)) {
839 $class = ($lnum %
2) ?
"even" : "odd";
841 $feed_id = $line["id"];
843 $edit_feed_id = $_GET["id"];
845 if ($subop == "edit" && $feed_id != $edit_feed_id) {
849 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
851 $icon_file = ICONS_DIR
. "/$feed_id.ico";
853 if (file_exists($icon_file) && filesize($icon_file) > 0) {
854 $feed_icon = "<img width=\"16\" height=\"16\"
855 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
857 $feed_icon = " ";
859 print "<td align='center'>$feed_icon</td>";
861 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
862 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
864 if (!$edit_feed_id ||
$subop != "edit") {
866 print "<td><input onclick='toggleSelectRow(this);'
867 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
869 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
870 $edit_title . "</td>";
871 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
872 $edit_link . "</td>";
874 if ($line["update_interval"] == "0")
875 $line["update_interval"] = "Default";
877 print "<td>" . $line["update_interval"] . "</td>";
880 } else if ($feed_id != $edit_feed_id) {
882 print "<td><input disabled=\"true\" type=\"checkbox\"
883 id=\"FRCHK-".$line["id"]."\"></td>";
885 print "<td>$edit_title</td>";
886 print "<td>$edit_link</td>";
888 if ($line["update_interval"] == "0")
889 $line["update_interval"] = "Default";
891 print "<td>" . $line["update_interval"] . "</td>";
895 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
897 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
898 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
899 print "<td><input id=\"iedit_updintl\" value=\"".$line["update_interval"]."\"></td>";
903 if (!$line["last_updated"]) $line["last_updated"] = "Never";
905 print "<td>" . $line["last_updated"] . "</td>";
913 print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>";
920 if ($subop == "edit") {
921 print "Edit feed:
922 <input type=\"submit\" class=\"button\"
923 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
924 <input type=\"submit\" class=\"button\"
925 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
930 <input type=\"submit\" class=\"button\"
931 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
932 <input type=\"submit\" class=\"button\"
933 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
935 if (ENABLE_PREFS_CATCHUP_UNCATCHUP
) {
937 <input type=\"submit\" class=\"button\"
938 onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\">
939 <input type=\"submit\" class=\"button\"
940 onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\"> ";
944 <input type=\"submit\"
945 class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">";
951 if ($op == "pref-filters") {
953 $subop = $_GET["subop"];
955 if ($subop == "editSave") {
957 $regexp = db_escape_string($_GET["r"]);
958 $descr = db_escape_string($_GET["d"]);
959 $match = db_escape_string($_GET["m"]);
960 $filter_id = db_escape_string($_GET["id"]);
962 $result = db_query($link, "UPDATE ttrss_filters SET
964 description = '$descr',
965 filter_type = (SELECT id FROM ttrss_filter_types WHERE
966 description = '$match')
967 WHERE id = '$filter_id'");
970 if ($subop == "remove") {
972 if (!WEB_DEMO_MODE
) {
974 $ids = split(",", $_GET["ids"]);
976 foreach ($ids as $id) {
977 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
983 if ($subop == "add") {
985 if (!WEB_DEMO_MODE
) {
987 $regexp = db_escape_string($_GET["regexp"]);
988 $match = db_escape_string($_GET["match"]);
990 $result = db_query($link,
991 "INSERT INTO ttrss_filters (reg_exp,filter_type) VALUES
992 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
993 description = '$match'))");
997 $result = db_query($link, "SELECT description
998 FROM ttrss_filter_types ORDER BY description");
1000 $filter_types = array();
1002 while ($line = db_fetch_assoc($result)) {
1003 array_push($filter_types, $line["description"]);
1006 print "<table class=\"prefAddFeed\"><tr>
1007 <td><input id=\"fadd_regexp\"></td>
1009 print_select("fadd_match", "Title", $filter_types);
1011 print"</td><td colspan=\"4\" align=\"right\">
1012 <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr>
1015 $result = db_query($link, "SELECT
1016 id,reg_exp,description,
1017 (SELECT name FROM ttrss_filter_types WHERE
1018 id = filter_type) as filter_type_name,
1019 (SELECT description FROM ttrss_filter_types
1020 WHERE id = filter_type) as filter_type_descr
1022 ttrss_filters ORDER by reg_exp");
1024 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
1026 print "<tr class=\"title\">
1027 <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td>
1028 <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>";
1032 while ($line = db_fetch_assoc($result)) {
1034 $class = ($lnum %
2) ?
"even" : "odd";
1036 $filter_id = $line["id"];
1037 $edit_filter_id = $_GET["id"];
1039 if ($subop == "edit" && $filter_id != $edit_filter_id) {
1043 print "<tr class=\"$class\" id=\"FILRR-$filter_id\">";
1045 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
1046 $line["description"] = htmlspecialchars($line["description"]);
1048 if (!$edit_filter_id ||
$subop != "edit") {
1050 if (!$line["description"]) $line["description"] = "[No description]";
1052 print "<td><input onclick='toggleSelectRow(this);'
1053 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
1055 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1056 $line["reg_exp"] . "</td>";
1058 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1059 $line["description"] . "</td>";
1061 print "<td>".$line["filter_type_descr"]."</td>";
1063 } else if ($filter_id != $edit_filter_id) {
1065 if (!$line["description"]) $line["description"] = "[No description]";
1067 print "<td><input disabled=\"true\" type=\"checkbox\"
1068 id=\"FICHK-".$line["id"]."\"></td>";
1070 print "<td>".$line["reg_exp"]."</td>";
1071 print "<td>".$line["description"]."</td>";
1072 print "<td>".$line["filter_type_descr"]."</td>";
1076 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
1078 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
1081 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1085 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
1097 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
1104 if ($subop == "edit") {
1106 <input type=\"submit\" class=\"button\"
1107 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
1108 <input type=\"submit\" class=\"button\"
1109 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
1115 <input type=\"submit\" class=\"button\"
1116 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
1117 <input type=\"submit\" class=\"button\"
1118 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
1122 if ($op == "pref-labels") {
1124 $subop = $_GET["subop"];
1126 if ($subop == "editSave") {
1128 $sql_exp = $_GET["s"];
1129 $descr = $_GET["d"];
1130 $label_id = db_escape_string($_GET["id"]);
1132 // print "$sql_exp : $descr : $label_id";
1134 $result = db_query($link, "UPDATE ttrss_labels SET
1135 sql_exp = '$sql_exp',
1136 description = '$descr'
1137 WHERE id = '$label_id'");
1140 if ($subop == "remove") {
1142 if (!WEB_DEMO_MODE
) {
1144 $ids = split(",", $_GET["ids"]);
1146 foreach ($ids as $id) {
1147 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
1153 if ($subop == "add") {
1155 if (!WEB_DEMO_MODE
) {
1157 $exp = $_GET["exp"];
1159 $result = db_query($link,
1160 "INSERT INTO ttrss_labels (sql_exp,description)
1161 VALUES ('$exp', '$exp')");
1165 print "<table class=\"prefAddFeed\"><tr>
1166 <td><input id=\"ladd_expr\"></td>";
1168 print"<td colspan=\"4\" align=\"right\">
1169 <a class=\"button\" href=\"javascript:addLabel()\">Add label</a></td></tr>
1172 $result = db_query($link, "SELECT
1173 id,sql_exp,description
1175 ttrss_labels ORDER by description");
1177 print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">";
1179 print "<tr class=\"title\">
1180 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
1181 <a class=\"helpLink\" href=\"javascript:popupHelp(1)\">(?)</a>
1183 <td width=\"40%\">Caption</td></tr>";
1187 while ($line = db_fetch_assoc($result)) {
1189 $class = ($lnum %
2) ?
"even" : "odd";
1191 $label_id = $line["id"];
1192 $edit_label_id = $_GET["id"];
1194 if ($subop == "edit" && $label_id != $edit_label_id) {
1198 print "<tr class=\"$class\" id=\"LILRR-$label_id\">";
1200 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
1201 $line["description"] = htmlspecialchars($line["description"]);
1203 if (!$edit_label_id ||
$subop != "edit") {
1205 if (!$line["description"]) $line["description"] = "[No caption]";
1207 print "<td><input onclick='toggleSelectRow(this);'
1208 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
1210 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1211 $line["sql_exp"] . "</td>";
1213 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1214 $line["description"] . "</td>";
1216 } else if ($label_id != $edit_label_id) {
1218 if (!$line["description"]) $line["description"] = "[No description]";
1220 print "<td><input disabled=\"true\" type=\"checkbox\"
1221 id=\"LICHK-".$line["id"]."\"></td>";
1223 print "<td>".$line["sql_exp"]."</td>";
1224 print "<td>".$line["description"]."</td>";
1228 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
1230 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
1233 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1245 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
1252 if ($subop == "edit") {
1254 <input type=\"submit\" class=\"button\"
1255 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
1256 <input type=\"submit\" class=\"button\"
1257 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
1263 <input type=\"submit\" class=\"button\"
1264 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
1265 <input type=\"submit\" class=\"button\"
1266 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
1270 if ($op == "error") {
1271 print "<div width=\"100%\" align='center'>";
1272 $msg = $_GET["msg"];
1277 if ($op == "help") {
1279 <title>Tiny Tiny RSS : Help</title>
1280 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
1281 <script type=\"text/javascript\" src=\"functions.js\"></script>
1282 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
1283 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1286 $tid = sprintf("%d", $_GET["tid"]);
1288 /* FIXME this badly needs real implementation */
1290 print "<div class='helpResponse'>";
1294 <h1
>Help
for SQL expressions
</h1
>
1296 <h2
>Description
</h2
>
1298 <p
>The
«
;SQL expression
»
; is added to WHERE clause of
1299 view feed query
. You can match on ttrss_entries table fields
1300 and even
use subselect to query additional information
. This
1301 functionality is considered to be advanced
and requires basic
1302 understanding of SQL
.</p
>
1306 <pre
>unread
= true</pre
>
1308 Matches all unread articles
1310 <pre
>title like
'%Linux%'</pre
>
1312 Matches all articles which mention Linux in the title
. You get the idea
.
1314 <p
>See the database schema included in the distribution package
for gruesome
1319 print "<div align='center'>
1320 <a class=\"helpLink\"
1321 href=\"javascript:window.close()\">(Close this window)</a></div>";
1325 print "</body></html>";
1331 $param = $_GET["param"];
1333 if ($id == "quickAddFeed") {
1334 print "Feed URL: <input
1335 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1337 <input class=\"button\"
1338 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
1339 <input class=\"button\"
1340 type=\"submit\" onclick=\"javascript:closeDlg()\"
1344 if ($id == "quickDelFeed") {
1346 $param = db_escape_string($param);
1348 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
1352 $f_title = db_fetch_result($result, 0, "title");
1354 print "Remove current feed ($f_title)?
1355 <input class=\"button\"
1356 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
1357 <input class=\"button\"
1358 type=\"submit\" onclick=\"javascript:closeDlg()\"
1361 print "Error: Feed $param not found.
1362 <input class=\"button\"
1363 type=\"submit\" onclick=\"javascript:closeDlg()\"
1368 if ($id == "search") {
1370 print "<input id=\"searchbox\" class=\"extSearch\"
1371 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1372 onchange=\"javascript:search()\">
1373 <select id=\"searchmodebox\">
1374 <option selected>All feeds</option>
1375 <option>This feed</option>
1377 <input type=\"submit\"
1378 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
1379 <input class=\"button\"
1380 type=\"submit\" onclick=\"javascript:closeDlg()\"
1390 <!-- <?
= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?
> -->