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 (sprintf("%d", $feed) != 0 && $feed >= 0) {
464 $result = db_query($link,
465 "SELECT *,SUBSTRING(last_updated,1,16) as last_updated_s
466 FROM ttrss_feeds WHERE id = '$feed'");
470 // $line = db_fetch_assoc($result);
471 // update_rss_feed($link, $line["feed_url"], $feed);
473 if ($subop == "MarkAllRead") {
475 db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW()
476 WHERE feed_id = '$feed'");
481 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
483 $search = $_GET["search"];
485 $search_mode = $_GET["smode"];
488 $search_query_part = "(upper(title) LIKE upper('%$search%')
489 OR content LIKE '%$search%') AND";
491 $search_query_part = "";
494 $view_query_part = "";
496 if ($view_mode == "Starred") {
497 $view_query_part = " marked = true AND ";
500 if ($view_mode == "Unread") {
501 $view_query_part = " unread = true AND ";
504 if ($view_mode == "Unread or Starred") {
505 $view_query_part = " (unread = true OR marked = true) AND ";
508 if ($view_mode == "Unread or Updated") {
509 $view_query_part = " (unread = true OR last_read is NULL) AND ";
512 /* $result = db_query($link, "SELECT count(id) AS total_entries
513 FROM ttrss_entries WHERE
517 $total_entries = db_fetch_result($result, 0, "total_entries"); */
519 /* $result = db_query("SELECT count(id) AS unread_entries
520 FROM ttrss_entries WHERE
525 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
527 if ($limit && $limit != "All") {
528 $limit_query_part = "LIMIT " . $limit;
531 $vfeed_query_part = "";
533 // override query strategy and enable feed display when searching globally
534 if ($search_mode == "All feeds") {
535 $query_strategy_part = "id > 0";
536 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
537 id = feed_id) as feed_title,";
538 } else if (sprintf("%d", $feed) == 0) {
539 $query_strategy_part = "ttrss_entries.id > 0";
540 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
541 id = feed_id) as feed_title,";
542 } else if ($feed >= 0) {
543 $query_strategy_part = "feed_id = '$feed'";
544 } else if ($feed == -1) { // starred virtual feed
545 $query_strategy_part = "marked = true";
546 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
547 id = feed_id) as feed_title,";
548 } else if ($feed <= -10) { // labels
549 $label_id = -$feed - 11;
551 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
552 WHERE id = '$label_id'");
554 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
556 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
557 id = feed_id) as feed_title,";
559 $query_strategy_part = "id > 0"; // dumb
563 $order_by = "updated DESC";
565 // if ($feed < -10) {
566 // $order_by = "feed_id,updated DESC";
569 if ($feed < -10) error_reporting (0);
571 if (sprintf("%d", $feed) != 0) {
573 $result = db_query($link, "SELECT
574 id,title,updated,unread,feed_id,marked,link,last_read,
575 SUBSTRING(last_read,1,19) as last_read_noms,
577 SUBSTRING(updated,1,19) as updated_noms
583 $query_strategy_part ORDER BY $order_by
589 $result = db_query($link, "SELECT
590 ttrss_entries.id as id,title,updated,unread,feed_id,
591 marked,link,last_read,
592 SUBSTRING(last_read,1,19) as last_read_noms,
594 SUBSTRING(updated,1,19) as updated_noms
596 ttrss_entries,ttrss_tags
598 post_id = ttrss_entries.id AND tag_name = '$feed' AND
601 $query_strategy_part ORDER BY $order_by
606 print "<tr><td colspan='4' align='center'>
607 Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>";
613 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
617 while ($line = db_fetch_assoc($result)) {
619 $class = ($lnum %
2) ?
"even" : "odd";
622 $feed_id = $line["feed_id"];
624 // printf("L %d (%s) > U %d (%s) = %d<br>",
625 // strtotime($line["last_read_noms"]), $line["last_read_noms"],
626 // strtotime($line["updated"]), $line["updated"],
627 // strtotime($line["last_read"]) >= strtotime($line["updated"]));
629 /* if ($line["last_read"] != "" && $line["updated"] != "" &&
630 strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) {
632 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
637 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
642 if ($line["last_read"] == "" &&
643 ($line["unread"] != "t" && $line["unread"] != "1")) {
645 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
648 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
652 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
657 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
658 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
659 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
661 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
662 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
665 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
666 $line["title"] . "</a>";
668 print "<tr class='$class' id='RROW-$id'>";
669 // onclick=\"javascript:view($id,$feed_id)\">
671 print "<td valign='center' align='center'>$update_pic</td>";
672 print "<td valign='center' align='center'>$marked_pic</td>";
674 print "<td width='25%'>
675 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
677 if ($line["feed_title"]) {
678 print "<td width='50%'>$content_link</td>";
679 print "<td width='20%'>".$line["feed_title"]."</td>";
681 print "<td width='70%'>$content_link</td>";
690 print "<tr><td align='center'>No articles found.</td></tr>";
695 print "<script type=\"text/javascript\">
696 document.onkeydown = hotkey_handler;
697 update_label_counters('$feed');
701 print "</body></html>";
706 if ($op == "pref-rpc") {
708 $subop = $_GET["subop"];
710 if ($subop == "unread") {
711 $ids = split(",", $_GET["ids"]);
712 foreach ($ids as $id) {
713 db_query($link, "UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'");
716 print "Marked selected feeds as read.";
719 if ($subop == "read") {
720 $ids = split(",", $_GET["ids"]);
721 foreach ($ids as $id) {
722 db_query($link, "UPDATE ttrss_entries
723 SET unread = false,last_read = NOW() WHERE feed_id = '$id'");
726 print "Marked selected feeds as unread.";
732 if ($op == "pref-feeds") {
734 $subop = $_GET["subop"];
736 if ($subop == "editSave") {
737 $feed_title = db_escape_string($_GET["t"]);
738 $feed_link = db_escape_string($_GET["l"]);
739 $upd_intl = db_escape_string($_GET["ui"]);
740 $feed_id = $_GET["id"];
742 if (strtoupper($upd_intl) == "DEFAULT")
745 $result = db_query($link, "UPDATE ttrss_feeds SET
746 title = '$feed_title', feed_url = '$feed_link',
747 update_interval = '$upd_intl' WHERE id = '$feed_id'");
751 if ($subop == "remove") {
753 if (!WEB_DEMO_MODE
) {
755 $ids = split(",", $_GET["ids"]);
757 foreach ($ids as $id) {
758 db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'");
760 if (file_exists(ICONS_DIR
. "/$id.ico")) {
761 unlink(ICONS_DIR
. "/$id.ico");
767 if ($subop == "add") {
769 if (!WEB_DEMO_MODE
) {
771 $feed_link = db_escape_string($_GET["link"]);
773 $result = db_query($link,
774 "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')");
776 $result = db_query($link,
777 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'");
779 $feed_id = db_fetch_result($result, 0, "id");
782 update_rss_feed($link, $feed_link, $feed_id);
787 print "<table class=\"prefAddFeed\"><tr>
788 <td><input id=\"fadd_link\"></td>
789 <td colspan=\"4\" align=\"right\">
790 <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr>
793 $result = db_query($link, "SELECT
794 id,title,feed_url,substring(last_updated,1,16) as last_updated,
797 ttrss_feeds ORDER by title");
799 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
800 print "<tr class=\"title\">
801 <td> </td><td>Select</td><td width=\"40%\">Title</td>
802 <td width=\"30%\">Link</td><td width=\"10%\">Update Interval</td>
803 <td>Last updated</td></tr>";
807 while ($line = db_fetch_assoc($result)) {
809 $class = ($lnum %
2) ?
"even" : "odd";
811 $feed_id = $line["id"];
813 $edit_feed_id = $_GET["id"];
815 if ($subop == "edit" && $feed_id != $edit_feed_id) {
819 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
821 $icon_file = ICONS_DIR
. "/$feed_id.ico";
823 if (file_exists($icon_file) && filesize($icon_file) > 0) {
824 $feed_icon = "<img width=\"16\" height=\"16\"
825 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
827 $feed_icon = " ";
829 print "<td align='center'>$feed_icon</td>";
831 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
832 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
834 if (!$edit_feed_id ||
$subop != "edit") {
836 print "<td><input onclick='toggleSelectRow(this);'
837 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
839 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
840 $edit_title . "</td>";
841 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
842 $edit_link . "</td>";
844 if ($line["update_interval"] == "0")
845 $line["update_interval"] = "Default";
847 print "<td>" . $line["update_interval"] . "</td>";
850 } else if ($feed_id != $edit_feed_id) {
852 print "<td><input disabled=\"true\" type=\"checkbox\"
853 id=\"FRCHK-".$line["id"]."\"></td>";
855 print "<td>$edit_title</td>";
856 print "<td>$edit_link</td>";
858 if ($line["update_interval"] == "0")
859 $line["update_interval"] = "Default";
861 print "<td>" . $line["update_interval"] . "</td>";
865 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
867 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
868 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
869 print "<td><input id=\"iedit_updintl\" value=\"".$line["update_interval"]."\"></td>";
873 if (!$line["last_updated"]) $line["last_updated"] = "Never";
875 print "<td>" . $line["last_updated"] . "</td>";
883 print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>";
890 if ($subop == "edit") {
891 print "Edit feed:
892 <input type=\"submit\" class=\"button\"
893 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
894 <input type=\"submit\" class=\"button\"
895 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
900 <input type=\"submit\" class=\"button\"
901 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
902 <input type=\"submit\" class=\"button\"
903 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
905 if (ENABLE_PREFS_CATCHUP_UNCATCHUP
) {
907 <input type=\"submit\" class=\"button\"
908 onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\">
909 <input type=\"submit\" class=\"button\"
910 onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\"> ";
914 <input type=\"submit\"
915 class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">";
921 if ($op == "pref-filters") {
923 $subop = $_GET["subop"];
925 if ($subop == "editSave") {
927 $regexp = db_escape_string($_GET["r"]);
928 $descr = db_escape_string($_GET["d"]);
929 $match = db_escape_string($_GET["m"]);
930 $filter_id = db_escape_string($_GET["id"]);
932 $result = db_query($link, "UPDATE ttrss_filters SET
934 description = '$descr',
935 filter_type = (SELECT id FROM ttrss_filter_types WHERE
936 description = '$match')
937 WHERE id = '$filter_id'");
940 if ($subop == "remove") {
942 if (!WEB_DEMO_MODE
) {
944 $ids = split(",", $_GET["ids"]);
946 foreach ($ids as $id) {
947 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
953 if ($subop == "add") {
955 if (!WEB_DEMO_MODE
) {
957 $regexp = db_escape_string($_GET["regexp"]);
958 $match = db_escape_string($_GET["match"]);
960 $result = db_query($link,
961 "INSERT INTO ttrss_filters (reg_exp,filter_type) VALUES
962 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
963 description = '$match'))");
967 $result = db_query($link, "SELECT description
968 FROM ttrss_filter_types ORDER BY description");
970 $filter_types = array();
972 while ($line = db_fetch_assoc($result)) {
973 array_push($filter_types, $line["description"]);
976 print "<table class=\"prefAddFeed\"><tr>
977 <td><input id=\"fadd_regexp\"></td>
979 print_select("fadd_match", "Title", $filter_types);
981 print"</td><td colspan=\"4\" align=\"right\">
982 <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr>
985 $result = db_query($link, "SELECT
986 id,reg_exp,description,
987 (SELECT name FROM ttrss_filter_types WHERE
988 id = filter_type) as filter_type_name,
989 (SELECT description FROM ttrss_filter_types
990 WHERE id = filter_type) as filter_type_descr
992 ttrss_filters ORDER by reg_exp");
994 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
996 print "<tr class=\"title\">
997 <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td>
998 <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>";
1002 while ($line = db_fetch_assoc($result)) {
1004 $class = ($lnum %
2) ?
"even" : "odd";
1006 $filter_id = $line["id"];
1007 $edit_filter_id = $_GET["id"];
1009 if ($subop == "edit" && $filter_id != $edit_filter_id) {
1013 print "<tr class=\"$class\" id=\"FILRR-$filter_id\">";
1015 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
1016 $line["description"] = htmlspecialchars($line["description"]);
1018 if (!$edit_filter_id ||
$subop != "edit") {
1020 if (!$line["description"]) $line["description"] = "[No description]";
1022 print "<td><input onclick='toggleSelectRow(this);'
1023 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
1025 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1026 $line["reg_exp"] . "</td>";
1028 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1029 $line["description"] . "</td>";
1031 print "<td>".$line["filter_type_descr"]."</td>";
1033 } else if ($filter_id != $edit_filter_id) {
1035 if (!$line["description"]) $line["description"] = "[No description]";
1037 print "<td><input disabled=\"true\" type=\"checkbox\"
1038 id=\"FICHK-".$line["id"]."\"></td>";
1040 print "<td>".$line["reg_exp"]."</td>";
1041 print "<td>".$line["description"]."</td>";
1042 print "<td>".$line["filter_type_descr"]."</td>";
1046 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
1048 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
1051 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1055 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
1067 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
1074 if ($subop == "edit") {
1076 <input type=\"submit\" class=\"button\"
1077 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
1078 <input type=\"submit\" class=\"button\"
1079 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
1085 <input type=\"submit\" class=\"button\"
1086 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
1087 <input type=\"submit\" class=\"button\"
1088 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
1092 if ($op == "pref-labels") {
1094 $subop = $_GET["subop"];
1096 if ($subop == "editSave") {
1098 $sql_exp = $_GET["s"];
1099 $descr = $_GET["d"];
1100 $label_id = db_escape_string($_GET["id"]);
1102 // print "$sql_exp : $descr : $label_id";
1104 $result = db_query($link, "UPDATE ttrss_labels SET
1105 sql_exp = '$sql_exp',
1106 description = '$descr'
1107 WHERE id = '$label_id'");
1110 if ($subop == "remove") {
1112 if (!WEB_DEMO_MODE
) {
1114 $ids = split(",", $_GET["ids"]);
1116 foreach ($ids as $id) {
1117 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
1123 if ($subop == "add") {
1125 if (!WEB_DEMO_MODE
) {
1127 $exp = $_GET["exp"];
1129 $result = db_query($link,
1130 "INSERT INTO ttrss_labels (sql_exp,description)
1131 VALUES ('$exp', '$exp')");
1135 print "<table class=\"prefAddFeed\"><tr>
1136 <td><input id=\"ladd_expr\"></td>";
1138 print"<td colspan=\"4\" align=\"right\">
1139 <a class=\"button\" href=\"javascript:addLabel()\">Add label</a></td></tr>
1142 $result = db_query($link, "SELECT
1143 id,sql_exp,description
1145 ttrss_labels ORDER by description");
1147 print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">";
1149 print "<tr class=\"title\">
1150 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
1151 <a class=\"helpLink\" href=\"javascript:popupHelp(1)\">(?)</a>
1153 <td width=\"40%\">Caption</td></tr>";
1157 while ($line = db_fetch_assoc($result)) {
1159 $class = ($lnum %
2) ?
"even" : "odd";
1161 $label_id = $line["id"];
1162 $edit_label_id = $_GET["id"];
1164 if ($subop == "edit" && $label_id != $edit_label_id) {
1168 print "<tr class=\"$class\" id=\"LILRR-$label_id\">";
1170 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
1171 $line["description"] = htmlspecialchars($line["description"]);
1173 if (!$edit_label_id ||
$subop != "edit") {
1175 if (!$line["description"]) $line["description"] = "[No caption]";
1177 print "<td><input onclick='toggleSelectRow(this);'
1178 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
1180 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1181 $line["sql_exp"] . "</td>";
1183 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1184 $line["description"] . "</td>";
1186 } else if ($label_id != $edit_label_id) {
1188 if (!$line["description"]) $line["description"] = "[No description]";
1190 print "<td><input disabled=\"true\" type=\"checkbox\"
1191 id=\"LICHK-".$line["id"]."\"></td>";
1193 print "<td>".$line["sql_exp"]."</td>";
1194 print "<td>".$line["description"]."</td>";
1198 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
1200 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
1203 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1215 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
1222 if ($subop == "edit") {
1224 <input type=\"submit\" class=\"button\"
1225 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
1226 <input type=\"submit\" class=\"button\"
1227 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
1233 <input type=\"submit\" class=\"button\"
1234 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
1235 <input type=\"submit\" class=\"button\"
1236 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
1240 if ($op == "error") {
1241 print "<div width=\"100%\" align='center'>";
1242 $msg = $_GET["msg"];
1247 if ($op == "help") {
1249 <title>Tiny Tiny RSS : Help</title>
1250 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
1251 <script type=\"text/javascript\" src=\"functions.js\"></script>
1252 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
1253 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1256 $tid = sprintf("%d", $_GET["tid"]);
1258 /* FIXME this badly needs real implementation */
1260 print "<div class='helpResponse'>";
1264 <h1
>Help
for SQL expressions
</h1
>
1266 <h2
>Description
</h2
>
1268 <p
>The
«
;SQL expression
»
; is added to WHERE clause of
1269 view feed query
. You can match on ttrss_entries table fields
1270 and even
use subselect to query additional information
. This
1271 functionality is considered to be advanced
and requires basic
1272 understanding of SQL
.</p
>
1276 <pre
>unread
= true</pre
>
1278 Matches all unread articles
1280 <pre
>title like
'%Linux%'</pre
>
1282 Matches all articles which mention Linux in the title
. You get the idea
.
1284 <p
>See the database schema included in the distribution package
for gruesome
1289 print "<div align='center'>
1290 <a class=\"helpLink\"
1291 href=\"javascript:window.close()\">(Close this window)</a></div>";
1295 print "</body></html>";
1302 <!-- <?
= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?
> -->