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 == "MarkAllRead") {
464 if (sprintf("%d", $feed) != 0) {
467 db_query($link, "UPDATE ttrss_entries
468 SET unread = false,last_read = NOW()
469 WHERE feed_id = '$feed'");
471 } else if ($feed < 0 && $feed > -10) { // special, like starred
474 db_query($link, "UPDATE ttrss_entries
475 SET unread = false,last_read = NOW()
476 WHERE marked = true");
479 } else if ($feed < -10) { // label
481 $label_id = -$feed - 11;
483 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
484 WHERE id = '$label_id'");
487 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
489 db_query($link, "UPDATE ttrss_entries
490 SET unread = false,last_read = NOW()
495 // FIXME, implement catchup for tags
500 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
502 $search = $_GET["search"];
504 $search_mode = $_GET["smode"];
507 $search_query_part = "(upper(title) LIKE upper('%$search%')
508 OR content LIKE '%$search%') AND";
510 $search_query_part = "";
513 $view_query_part = "";
515 if ($view_mode == "Starred") {
516 $view_query_part = " marked = true AND ";
519 if ($view_mode == "Unread") {
520 $view_query_part = " unread = true AND ";
523 if ($view_mode == "Unread or Starred") {
524 $view_query_part = " (unread = true OR marked = true) AND ";
527 if ($view_mode == "Unread or Updated") {
528 $view_query_part = " (unread = true OR last_read is NULL) AND ";
531 /* $result = db_query($link, "SELECT count(id) AS total_entries
532 FROM ttrss_entries WHERE
536 $total_entries = db_fetch_result($result, 0, "total_entries"); */
538 /* $result = db_query("SELECT count(id) AS unread_entries
539 FROM ttrss_entries WHERE
544 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
546 if ($limit && $limit != "All") {
547 $limit_query_part = "LIMIT " . $limit;
550 $vfeed_query_part = "";
552 // override query strategy and enable feed display when searching globally
553 if ($search_mode == "All feeds") {
554 $query_strategy_part = "id > 0";
555 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
556 id = feed_id) as feed_title,";
557 } else if (sprintf("%d", $feed) == 0) {
558 $query_strategy_part = "ttrss_entries.id > 0";
559 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
560 id = feed_id) as feed_title,";
561 } else if ($feed >= 0) {
562 $query_strategy_part = "feed_id = '$feed'";
563 } else if ($feed == -1) { // starred virtual feed
564 $query_strategy_part = "marked = true";
565 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
566 id = feed_id) as feed_title,";
567 } else if ($feed <= -10) { // labels
568 $label_id = -$feed - 11;
570 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
571 WHERE id = '$label_id'");
573 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
575 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
576 id = feed_id) as feed_title,";
578 $query_strategy_part = "id > 0"; // dumb
582 $order_by = "updated DESC";
584 // if ($feed < -10) {
585 // $order_by = "feed_id,updated DESC";
588 if ($feed < -10) error_reporting (0);
590 if (sprintf("%d", $feed) != 0) {
592 $result = db_query($link, "SELECT
593 id,title,updated,unread,feed_id,marked,link,last_read,
594 SUBSTRING(last_read,1,19) as last_read_noms,
596 SUBSTRING(updated,1,19) as updated_noms
602 $query_strategy_part ORDER BY $order_by
608 $result = db_query($link, "SELECT
609 ttrss_entries.id as id,title,updated,unread,feed_id,
610 marked,link,last_read,
611 SUBSTRING(last_read,1,19) as last_read_noms,
613 SUBSTRING(updated,1,19) as updated_noms
615 ttrss_entries,ttrss_tags
617 post_id = ttrss_entries.id AND tag_name = '$feed' AND
620 $query_strategy_part ORDER BY $order_by
625 print "<tr><td colspan='4' align='center'>
626 Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>";
632 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
636 while ($line = db_fetch_assoc($result)) {
638 $class = ($lnum %
2) ?
"even" : "odd";
641 $feed_id = $line["feed_id"];
643 // printf("L %d (%s) > U %d (%s) = %d<br>",
644 // strtotime($line["last_read_noms"]), $line["last_read_noms"],
645 // strtotime($line["updated"]), $line["updated"],
646 // strtotime($line["last_read"]) >= strtotime($line["updated"]));
648 /* if ($line["last_read"] != "" && $line["updated"] != "" &&
649 strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) {
651 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
656 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
661 if ($line["last_read"] == "" &&
662 ($line["unread"] != "t" && $line["unread"] != "1")) {
664 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
667 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
671 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
676 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
677 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
678 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
680 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
681 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
684 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
685 $line["title"] . "</a>";
687 print "<tr class='$class' id='RROW-$id'>";
688 // onclick=\"javascript:view($id,$feed_id)\">
690 print "<td valign='center' align='center'>$update_pic</td>";
691 print "<td valign='center' align='center'>$marked_pic</td>";
693 print "<td width='25%'>
694 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
696 if ($line["feed_title"]) {
697 print "<td width='50%'>$content_link</td>";
698 print "<td width='20%'>".$line["feed_title"]."</td>";
700 print "<td width='70%'>$content_link</td>";
709 print "<tr><td align='center'>No articles found.</td></tr>";
714 print "<script type=\"text/javascript\">
715 document.onkeydown = hotkey_handler;
716 update_label_counters('$feed');
720 print "</body></html>";
725 if ($op == "pref-rpc") {
727 $subop = $_GET["subop"];
729 if ($subop == "unread") {
730 $ids = split(",", $_GET["ids"]);
731 foreach ($ids as $id) {
732 db_query($link, "UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'");
735 print "Marked selected feeds as read.";
738 if ($subop == "read") {
739 $ids = split(",", $_GET["ids"]);
740 foreach ($ids as $id) {
741 db_query($link, "UPDATE ttrss_entries
742 SET unread = false,last_read = NOW() WHERE feed_id = '$id'");
745 print "Marked selected feeds as unread.";
751 if ($op == "pref-feeds") {
753 $subop = $_GET["subop"];
755 if ($subop == "editSave") {
756 $feed_title = db_escape_string($_GET["t"]);
757 $feed_link = db_escape_string($_GET["l"]);
758 $upd_intl = db_escape_string($_GET["ui"]);
759 $feed_id = $_GET["id"];
761 if (strtoupper($upd_intl) == "DEFAULT")
764 $result = db_query($link, "UPDATE ttrss_feeds SET
765 title = '$feed_title', feed_url = '$feed_link',
766 update_interval = '$upd_intl' WHERE id = '$feed_id'");
770 if ($subop == "remove") {
772 if (!WEB_DEMO_MODE
) {
774 $ids = split(",", $_GET["ids"]);
776 foreach ($ids as $id) {
777 db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'");
779 if (file_exists(ICONS_DIR
. "/$id.ico")) {
780 unlink(ICONS_DIR
. "/$id.ico");
786 if ($subop == "add") {
788 if (!WEB_DEMO_MODE
) {
790 $feed_link = db_escape_string($_GET["link"]);
792 $result = db_query($link,
793 "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')");
795 $result = db_query($link,
796 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'");
798 $feed_id = db_fetch_result($result, 0, "id");
801 update_rss_feed($link, $feed_link, $feed_id);
806 print "<table class=\"prefAddFeed\"><tr>
807 <td><input id=\"fadd_link\"></td>
808 <td colspan=\"4\" align=\"right\">
809 <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr>
812 $result = db_query($link, "SELECT
813 id,title,feed_url,substring(last_updated,1,16) as last_updated,
816 ttrss_feeds ORDER by title");
818 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
819 print "<tr class=\"title\">
820 <td> </td><td>Select</td><td width=\"40%\">Title</td>
821 <td width=\"30%\">Link</td><td width=\"10%\">Update Interval</td>
822 <td>Last updated</td></tr>";
826 while ($line = db_fetch_assoc($result)) {
828 $class = ($lnum %
2) ?
"even" : "odd";
830 $feed_id = $line["id"];
832 $edit_feed_id = $_GET["id"];
834 if ($subop == "edit" && $feed_id != $edit_feed_id) {
838 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
840 $icon_file = ICONS_DIR
. "/$feed_id.ico";
842 if (file_exists($icon_file) && filesize($icon_file) > 0) {
843 $feed_icon = "<img width=\"16\" height=\"16\"
844 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
846 $feed_icon = " ";
848 print "<td align='center'>$feed_icon</td>";
850 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
851 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
853 if (!$edit_feed_id ||
$subop != "edit") {
855 print "<td><input onclick='toggleSelectRow(this);'
856 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
858 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
859 $edit_title . "</td>";
860 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
861 $edit_link . "</td>";
863 if ($line["update_interval"] == "0")
864 $line["update_interval"] = "Default";
866 print "<td>" . $line["update_interval"] . "</td>";
869 } else if ($feed_id != $edit_feed_id) {
871 print "<td><input disabled=\"true\" type=\"checkbox\"
872 id=\"FRCHK-".$line["id"]."\"></td>";
874 print "<td>$edit_title</td>";
875 print "<td>$edit_link</td>";
877 if ($line["update_interval"] == "0")
878 $line["update_interval"] = "Default";
880 print "<td>" . $line["update_interval"] . "</td>";
884 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
886 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
887 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
888 print "<td><input id=\"iedit_updintl\" value=\"".$line["update_interval"]."\"></td>";
892 if (!$line["last_updated"]) $line["last_updated"] = "Never";
894 print "<td>" . $line["last_updated"] . "</td>";
902 print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>";
909 if ($subop == "edit") {
910 print "Edit feed:
911 <input type=\"submit\" class=\"button\"
912 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
913 <input type=\"submit\" class=\"button\"
914 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
919 <input type=\"submit\" class=\"button\"
920 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
921 <input type=\"submit\" class=\"button\"
922 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
924 if (ENABLE_PREFS_CATCHUP_UNCATCHUP
) {
926 <input type=\"submit\" class=\"button\"
927 onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\">
928 <input type=\"submit\" class=\"button\"
929 onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\"> ";
933 <input type=\"submit\"
934 class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">";
940 if ($op == "pref-filters") {
942 $subop = $_GET["subop"];
944 if ($subop == "editSave") {
946 $regexp = db_escape_string($_GET["r"]);
947 $descr = db_escape_string($_GET["d"]);
948 $match = db_escape_string($_GET["m"]);
949 $filter_id = db_escape_string($_GET["id"]);
951 $result = db_query($link, "UPDATE ttrss_filters SET
953 description = '$descr',
954 filter_type = (SELECT id FROM ttrss_filter_types WHERE
955 description = '$match')
956 WHERE id = '$filter_id'");
959 if ($subop == "remove") {
961 if (!WEB_DEMO_MODE
) {
963 $ids = split(",", $_GET["ids"]);
965 foreach ($ids as $id) {
966 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
972 if ($subop == "add") {
974 if (!WEB_DEMO_MODE
) {
976 $regexp = db_escape_string($_GET["regexp"]);
977 $match = db_escape_string($_GET["match"]);
979 $result = db_query($link,
980 "INSERT INTO ttrss_filters (reg_exp,filter_type) VALUES
981 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
982 description = '$match'))");
986 $result = db_query($link, "SELECT description
987 FROM ttrss_filter_types ORDER BY description");
989 $filter_types = array();
991 while ($line = db_fetch_assoc($result)) {
992 array_push($filter_types, $line["description"]);
995 print "<table class=\"prefAddFeed\"><tr>
996 <td><input id=\"fadd_regexp\"></td>
998 print_select("fadd_match", "Title", $filter_types);
1000 print"</td><td colspan=\"4\" align=\"right\">
1001 <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr>
1004 $result = db_query($link, "SELECT
1005 id,reg_exp,description,
1006 (SELECT name FROM ttrss_filter_types WHERE
1007 id = filter_type) as filter_type_name,
1008 (SELECT description FROM ttrss_filter_types
1009 WHERE id = filter_type) as filter_type_descr
1011 ttrss_filters ORDER by reg_exp");
1013 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
1015 print "<tr class=\"title\">
1016 <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td>
1017 <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>";
1021 while ($line = db_fetch_assoc($result)) {
1023 $class = ($lnum %
2) ?
"even" : "odd";
1025 $filter_id = $line["id"];
1026 $edit_filter_id = $_GET["id"];
1028 if ($subop == "edit" && $filter_id != $edit_filter_id) {
1032 print "<tr class=\"$class\" id=\"FILRR-$filter_id\">";
1034 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
1035 $line["description"] = htmlspecialchars($line["description"]);
1037 if (!$edit_filter_id ||
$subop != "edit") {
1039 if (!$line["description"]) $line["description"] = "[No description]";
1041 print "<td><input onclick='toggleSelectRow(this);'
1042 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
1044 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1045 $line["reg_exp"] . "</td>";
1047 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1048 $line["description"] . "</td>";
1050 print "<td>".$line["filter_type_descr"]."</td>";
1052 } else if ($filter_id != $edit_filter_id) {
1054 if (!$line["description"]) $line["description"] = "[No description]";
1056 print "<td><input disabled=\"true\" type=\"checkbox\"
1057 id=\"FICHK-".$line["id"]."\"></td>";
1059 print "<td>".$line["reg_exp"]."</td>";
1060 print "<td>".$line["description"]."</td>";
1061 print "<td>".$line["filter_type_descr"]."</td>";
1065 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
1067 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
1070 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1074 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
1086 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
1093 if ($subop == "edit") {
1095 <input type=\"submit\" class=\"button\"
1096 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
1097 <input type=\"submit\" class=\"button\"
1098 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
1104 <input type=\"submit\" class=\"button\"
1105 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
1106 <input type=\"submit\" class=\"button\"
1107 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
1111 if ($op == "pref-labels") {
1113 $subop = $_GET["subop"];
1115 if ($subop == "editSave") {
1117 $sql_exp = $_GET["s"];
1118 $descr = $_GET["d"];
1119 $label_id = db_escape_string($_GET["id"]);
1121 // print "$sql_exp : $descr : $label_id";
1123 $result = db_query($link, "UPDATE ttrss_labels SET
1124 sql_exp = '$sql_exp',
1125 description = '$descr'
1126 WHERE id = '$label_id'");
1129 if ($subop == "remove") {
1131 if (!WEB_DEMO_MODE
) {
1133 $ids = split(",", $_GET["ids"]);
1135 foreach ($ids as $id) {
1136 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
1142 if ($subop == "add") {
1144 if (!WEB_DEMO_MODE
) {
1146 $exp = $_GET["exp"];
1148 $result = db_query($link,
1149 "INSERT INTO ttrss_labels (sql_exp,description)
1150 VALUES ('$exp', '$exp')");
1154 print "<table class=\"prefAddFeed\"><tr>
1155 <td><input id=\"ladd_expr\"></td>";
1157 print"<td colspan=\"4\" align=\"right\">
1158 <a class=\"button\" href=\"javascript:addLabel()\">Add label</a></td></tr>
1161 $result = db_query($link, "SELECT
1162 id,sql_exp,description
1164 ttrss_labels ORDER by description");
1166 print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">";
1168 print "<tr class=\"title\">
1169 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
1170 <a class=\"helpLink\" href=\"javascript:popupHelp(1)\">(?)</a>
1172 <td width=\"40%\">Caption</td></tr>";
1176 while ($line = db_fetch_assoc($result)) {
1178 $class = ($lnum %
2) ?
"even" : "odd";
1180 $label_id = $line["id"];
1181 $edit_label_id = $_GET["id"];
1183 if ($subop == "edit" && $label_id != $edit_label_id) {
1187 print "<tr class=\"$class\" id=\"LILRR-$label_id\">";
1189 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
1190 $line["description"] = htmlspecialchars($line["description"]);
1192 if (!$edit_label_id ||
$subop != "edit") {
1194 if (!$line["description"]) $line["description"] = "[No caption]";
1196 print "<td><input onclick='toggleSelectRow(this);'
1197 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
1199 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1200 $line["sql_exp"] . "</td>";
1202 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1203 $line["description"] . "</td>";
1205 } else if ($label_id != $edit_label_id) {
1207 if (!$line["description"]) $line["description"] = "[No description]";
1209 print "<td><input disabled=\"true\" type=\"checkbox\"
1210 id=\"LICHK-".$line["id"]."\"></td>";
1212 print "<td>".$line["sql_exp"]."</td>";
1213 print "<td>".$line["description"]."</td>";
1217 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
1219 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
1222 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1234 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
1241 if ($subop == "edit") {
1243 <input type=\"submit\" class=\"button\"
1244 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
1245 <input type=\"submit\" class=\"button\"
1246 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
1252 <input type=\"submit\" class=\"button\"
1253 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
1254 <input type=\"submit\" class=\"button\"
1255 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
1259 if ($op == "error") {
1260 print "<div width=\"100%\" align='center'>";
1261 $msg = $_GET["msg"];
1266 if ($op == "help") {
1268 <title>Tiny Tiny RSS : Help</title>
1269 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
1270 <script type=\"text/javascript\" src=\"functions.js\"></script>
1271 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
1272 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1275 $tid = sprintf("%d", $_GET["tid"]);
1277 /* FIXME this badly needs real implementation */
1279 print "<div class='helpResponse'>";
1283 <h1
>Help
for SQL expressions
</h1
>
1285 <h2
>Description
</h2
>
1287 <p
>The
«
;SQL expression
»
; is added to WHERE clause of
1288 view feed query
. You can match on ttrss_entries table fields
1289 and even
use subselect to query additional information
. This
1290 functionality is considered to be advanced
and requires basic
1291 understanding of SQL
.</p
>
1295 <pre
>unread
= true</pre
>
1297 Matches all unread articles
1299 <pre
>title like
'%Linux%'</pre
>
1301 Matches all articles which mention Linux in the title
. You get the idea
.
1303 <p
>See the database schema included in the distribution package
for gruesome
1308 print "<div align='center'>
1309 <a class=\"helpLink\"
1310 href=\"javascript:window.close()\">(Close this window)</a></div>";
1314 print "</body></html>";
1321 if ($id == "quickAddFeed") {
1322 print "Feed URL: <input id=\"qafInput\">
1323 <input class=\"button\"
1324 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
1325 <input class=\"button\"
1326 type=\"submit\" onclick=\"javascript:closeDlg()\"
1334 <!-- <?
= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?
> -->