2 define(SCHEMA_VERSION
, 1);
7 header("Content-Type: application/xml");
10 require_once "config.php";
11 require_once "db.php";
12 require_once "functions.php";
13 require_once "magpierss/rss_fetch.inc";
15 $script_started = getmicrotime();
17 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
20 if (DB_TYPE
== "mysql") {
23 // PG seems to display its own errors just fine by default.
27 if (DB_TYPE
== "pgsql") {
28 pg_query("set client_encoding = 'utf-8'");
31 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
33 $schema_version = db_fetch_result($result, 0, "schema_version");
35 if ($schema_version != SCHEMA_VERSION
) {
36 print "Error: database schema is invalid
37 (got version $schema_version; expected ".SCHEMA_VERSION
.")";
41 $fetch = $_GET["fetch"];
43 /* FIXME this needs reworking */
45 function getGlobalCounters($link) {
46 $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries
47 WHERE unread = true");
48 $c_id = db_fetch_result($result, 0, "c_id");
49 print "<counter id='global-unread' counter='$c_id'/>";
52 function getTagCounters($link) {
53 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
54 FROM ttrss_tags,ttrss_entries WHERE
55 post_id = ttrss_entries.id AND unread = true GROUP BY tag_name
57 select tag_name,0 as count FROM ttrss_tags");
61 while ($line = db_fetch_assoc($result)) {
62 $tags[$line["tag_name"]] +
= $line["count"];
65 foreach (array_keys($tags) as $tag) {
66 $unread = $tags[$tag];
68 $tag = htmlspecialchars($tag);
69 print "<tag id=\"$tag\" counter=\"$unread\"/>";
73 function getLabelCounters($link) {
75 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
76 WHERE marked = true AND unread = true");
78 $count = db_fetch_result($result, 0, "count");
80 print "<label id=\"-1\" counter=\"$count\"/>";
82 $result = db_query($link, "SELECT id,sql_exp,description FROM
83 ttrss_labels ORDER by description");
85 while ($line = db_fetch_assoc($result)) {
87 $id = -$line["id"] - 11;
91 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
92 WHERE (" . $line["sql_exp"] . ") AND unread = true");
94 $count = db_fetch_result($tmp_result, 0, "count");
96 print "<label id=\"$id\" counter=\"$count\"/>";
98 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
103 function getFeedCounter($link, $id) {
105 $result = db_query($link, "SELECT
106 count(id) as count FROM ttrss_entries
107 WHERE feed_id = '$id' AND unread = true");
109 $count = db_fetch_result($result, 0, "count");
111 print "<feed id=\"$id\" counter=\"$count\"/>";
114 function getFeedCounters($link) {
116 $result = db_query($link, "SELECT id,
117 (SELECT count(id) FROM ttrss_entries WHERE feed_id = ttrss_feeds.id
118 AND unread = true) as count
121 while ($line = db_fetch_assoc($result)) {
124 $count = $line["count"];
126 print "<feed id=\"$id\" counter=\"$count\"/>";
130 function outputFeedList($link, $tags = false) {
133 <title>Tiny Tiny RSS : Feedlist</title>
134 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
135 <script type=\"text/javascript\" src=\"functions.js\"></script>
136 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
137 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
138 </head><body onload=\"init()\">";
140 print "<ul class=\"feedList\" id=\"feedList\">";
146 $result = db_query($link, "SELECT count(id) as num_starred
147 FROM ttrss_entries WHERE marked = true AND unread = true");
148 $num_starred = db_fetch_result($result, 0, "num_starred");
152 if ($num_starred > 0) $class .= "Unread";
154 printFeedEntry(-1, $class, "Starred articles", $num_starred,
155 "images/mark_set.png");
159 $result = db_query($link, "SELECT id,sql_exp,description FROM
160 ttrss_labels ORDER by description");
162 if (db_num_rows($result) > 0) {
163 print "<li><hr></li>";
166 while ($line = db_fetch_assoc($result)) {
170 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
171 WHERE (" . $line["sql_exp"] . ") AND unread = true");
173 $count = db_fetch_result($tmp_result, 0, "count");
181 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
183 printFeedEntry(-$line["id"]-11,
184 $class, $line["description"], $count, "images/label.png");
189 print "<li><hr></li>";
191 $result = db_query($link, "SELECT *,
192 (SELECT count(id) FROM ttrss_entries
193 WHERE feed_id = ttrss_feeds.id) AS total,
194 (SELECT count(id) FROM ttrss_entries
195 WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
196 FROM ttrss_feeds ORDER BY title");
198 $actid = $_GET["actid"];
206 while ($line = db_fetch_assoc($result)) {
208 $feed = $line["title"];
209 $feed_id = $line["id"];
211 $subop = $_GET["subop"];
213 $total = $line["total"];
214 $unread = $line["unread"];
216 // $class = ($lnum % 2) ? "even" : "odd";
220 if ($unread > 0) $class .= "Unread";
222 if ($actid == $feed_id) {
223 $class .= "Selected";
226 $total_unread +
= $unread;
228 printFeedEntry($feed_id, $class, $feed, $unread, "icons/$feed_id.ico");
236 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
237 FROM ttrss_tags,ttrss_entries WHERE
238 post_id = ttrss_entries.id AND unread = true GROUP BY tag_name
240 select tag_name,0 as count FROM ttrss_tags");
244 while ($line = db_fetch_assoc($result)) {
245 $tags[$line["tag_name"]] +
= $line["count"];
248 foreach (array_keys($tags) as $tag) {
250 $unread = $tags[$tag];
258 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png");
264 if (db_num_rows($result) == 0) {
265 print "<li>No tags to display.</li>";
270 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
277 $subop = $_GET["subop"];
279 if ($subop == "getLabelCounters") {
282 getLabelCounters($link);
284 getFeedCounter($link, $aid);
286 print "</rpc-reply>";
289 if ($subop == "getFeedCounters") {
291 getFeedCounters($link);
292 print "</rpc-reply>";
295 if ($subop == "getAllCounters") {
297 getLabelCounters($link);
298 getFeedCounters($link);
299 getTagCounters($link);
300 getGlobalCounters($link);
301 print "</rpc-reply>";
304 if ($subop == "mark") {
305 $mark = $_GET["mark"];
306 $id = db_escape_string($_GET["id"]);
314 $result = db_query($link, "UPDATE ttrss_entries SET marked = $mark
318 if ($subop == "updateFeed") {
319 $feed_id = db_escape_string($_GET["feed"]);
321 $result = db_query($link,
322 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'");
324 if (db_num_rows($result) > 0) {
325 $feed_url = db_fetch_result($result, 0, "feed_url");
326 // update_rss_feed($link, $feed_url, $feed_id);
329 print "DONE-$feed_id";
334 if ($subop == "forceUpdateAllFeeds" ||
$subop == "updateAllFeeds") {
336 update_all_feeds($link, true);
338 $omode = $_GET["omode"];
340 if (!$omode) $omode = "tfl";
343 if (strchr($omode, "l")) getLabelCounters($link);
344 if (strchr($omode, "f")) getFeedCounters($link);
345 if (strchr($omode, "t")) getTagCounters($link);
346 getGlobalCounters($link);
347 print "</rpc-reply>";
350 if ($subop == "catchupPage") {
352 $ids = split(",", $_GET["ids"]);
354 foreach ($ids as $id) {
356 db_query($link, "UPDATE ttrss_entries SET unread=false,last_read = NOW()
361 print "Marked active page as read.";
365 if ($op == "feeds") {
367 $tags = $_GET["tags"];
369 $subop = $_GET["subop"];
371 if ($subop == "catchupAll") {
372 db_query($link, "UPDATE ttrss_entries SET last_read = NOW(),unread = false");
375 outputFeedList($link, $tags);
382 $feed_id = $_GET["feed"];
384 $result = db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'");
386 $addheader = $_GET["addheader"];
388 $result = db_query($link, "SELECT title,link,content,feed_id,comments,
389 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
395 <title>Tiny Tiny RSS : Article $id</title>
396 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
397 <script type=\"text/javascript\" src=\"functions.js\"></script>
398 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
404 $line = db_fetch_assoc($result);
406 if ($line["icon_url"]) {
407 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
409 $feed_icon = " ";
412 if ($line["comments"] && $line["link"] != $line["comments"]) {
413 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
415 $entry_comments = "";
418 print "<div class=\"postReply\">";
420 print "<div class=\"postHeader\"><table>";
422 print "<tr><td><b>Title:</b></td>
423 <td width='100%'>" . $line["title"] . "</td></tr>";
425 print "<tr><td><b>Link:</b></td>
427 <a href=\"" . $line["link"] . "\">".$line["link"]."</a>
428 $entry_comments</td></tr>";
430 print "</table></div>";
432 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
433 print "<div class=\"postContent\">" . $line["content"] . "</div>";
437 print "<script type=\"text/javascript\">
438 update_label_counters('$feed_id');
443 print "</body></html>";
447 if ($op == "viewfeed") {
449 $feed = $_GET["feed"];
450 $skip = $_GET["skip"];
451 $subop = $_GET["subop"];
452 $view_mode = $_GET["view"];
453 $addheader = $_GET["addheader"];
454 $limit = $_GET["limit"];
457 print "Error: no feed to display.";
461 if (!$skip) $skip = 0;
463 if ($subop == "undefined") $subop = "";
467 <title>Tiny Tiny RSS : Feed $feed</title>
468 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
469 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
470 <script type=\"text/javascript\" src=\"functions.js\"></script>
471 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
475 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
477 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
478 WHERE id = '$feed'");
480 $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
482 update_rss_feed($link, $feed_url, $feed);
486 if ($subop == "MarkAllRead") {
488 if (sprintf("%d", $feed) != 0) {
491 db_query($link, "UPDATE ttrss_entries
492 SET unread = false,last_read = NOW()
493 WHERE feed_id = '$feed'");
495 } else if ($feed < 0 && $feed > -10) { // special, like starred
498 db_query($link, "UPDATE ttrss_entries
499 SET unread = false,last_read = NOW()
500 WHERE marked = true");
503 } else if ($feed < -10) { // label
505 $label_id = -$feed - 11;
507 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
508 WHERE id = '$label_id'");
511 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
513 db_query($link, "UPDATE ttrss_entries
514 SET unread = false,last_read = NOW()
519 // FIXME, implement catchup for tags
524 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
526 $search = $_GET["search"];
528 $search_mode = $_GET["smode"];
531 $search_query_part = "(upper(title) LIKE upper('%$search%')
532 OR content LIKE '%$search%') AND";
534 $search_query_part = "";
537 $view_query_part = "";
539 if ($view_mode == "Starred") {
540 $view_query_part = " marked = true AND ";
543 if ($view_mode == "Unread") {
544 $view_query_part = " unread = true AND ";
547 if ($view_mode == "Unread or Starred") {
548 $view_query_part = " (unread = true OR marked = true) AND ";
551 if ($view_mode == "Unread or Updated") {
552 $view_query_part = " (unread = true OR last_read is NULL) AND ";
555 /* $result = db_query($link, "SELECT count(id) AS total_entries
556 FROM ttrss_entries WHERE
560 $total_entries = db_fetch_result($result, 0, "total_entries"); */
562 /* $result = db_query("SELECT count(id) AS unread_entries
563 FROM ttrss_entries WHERE
568 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
570 if ($limit && $limit != "All") {
571 $limit_query_part = "LIMIT " . $limit;
574 $vfeed_query_part = "";
576 // override query strategy and enable feed display when searching globally
577 if ($search_mode == "All feeds") {
578 $query_strategy_part = "id > 0";
579 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
580 id = feed_id) as feed_title,";
581 } else if (sprintf("%d", $feed) == 0) {
582 $query_strategy_part = "ttrss_entries.id > 0";
583 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
584 id = feed_id) as feed_title,";
585 } else if ($feed >= 0) {
586 $query_strategy_part = "feed_id = '$feed'";
587 } else if ($feed == -1) { // starred virtual feed
588 $query_strategy_part = "marked = true";
589 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
590 id = feed_id) as feed_title,";
591 } else if ($feed <= -10) { // labels
592 $label_id = -$feed - 11;
594 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
595 WHERE id = '$label_id'");
597 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
599 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
600 id = feed_id) as feed_title,";
602 $query_strategy_part = "id > 0"; // dumb
606 $order_by = "updated DESC";
608 // if ($feed < -10) {
609 // $order_by = "feed_id,updated DESC";
612 if ($feed < -10) error_reporting (0);
614 if (sprintf("%d", $feed) != 0) {
616 $result = db_query($link, "SELECT
617 id,title,updated,unread,feed_id,marked,link,last_read,
618 SUBSTRING(last_read,1,19) as last_read_noms,
620 SUBSTRING(updated,1,19) as updated_noms
626 $query_strategy_part ORDER BY $order_by
632 $result = db_query($link, "SELECT
633 ttrss_entries.id as id,title,updated,unread,feed_id,
634 marked,link,last_read,
635 SUBSTRING(last_read,1,19) as last_read_noms,
637 SUBSTRING(updated,1,19) as updated_noms
639 ttrss_entries,ttrss_tags
641 post_id = ttrss_entries.id AND tag_name = '$feed' AND
644 $query_strategy_part ORDER BY $order_by
649 print "<tr><td colspan='4' align='center'>
650 Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>";
656 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
660 while ($line = db_fetch_assoc($result)) {
662 $class = ($lnum %
2) ?
"even" : "odd";
665 $feed_id = $line["feed_id"];
667 // printf("L %d (%s) > U %d (%s) = %d<br>",
668 // strtotime($line["last_read_noms"]), $line["last_read_noms"],
669 // strtotime($line["updated"]), $line["updated"],
670 // strtotime($line["last_read"]) >= strtotime($line["updated"]));
672 /* if ($line["last_read"] != "" && $line["updated"] != "" &&
673 strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) {
675 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
680 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
685 if ($line["last_read"] == "" &&
686 ($line["unread"] != "t" && $line["unread"] != "1")) {
688 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
691 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
695 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
700 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
701 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
702 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
704 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
705 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
708 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
709 $line["title"] . "</a>";
711 print "<tr class='$class' id='RROW-$id'>";
712 // onclick=\"javascript:view($id,$feed_id)\">
714 print "<td valign='center' align='center'>$update_pic</td>";
715 print "<td valign='center' align='center'>$marked_pic</td>";
717 print "<td width='25%'>
718 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
720 if ($line["feed_title"]) {
721 print "<td width='50%'>$content_link</td>";
722 print "<td width='20%'>".$line["feed_title"]."</td>";
724 print "<td width='70%'>$content_link</td>";
733 print "<tr><td align='center'>No articles found.</td></tr>";
738 print "<script type=\"text/javascript\">
739 document.onkeydown = hotkey_handler;
740 update_label_counters('$feed');
744 print "</body></html>";
749 if ($op == "pref-rpc") {
751 $subop = $_GET["subop"];
753 if ($subop == "unread") {
754 $ids = split(",", $_GET["ids"]);
755 foreach ($ids as $id) {
756 db_query($link, "UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'");
759 print "Marked selected feeds as read.";
762 if ($subop == "read") {
763 $ids = split(",", $_GET["ids"]);
764 foreach ($ids as $id) {
765 db_query($link, "UPDATE ttrss_entries
766 SET unread = false,last_read = NOW() WHERE feed_id = '$id'");
769 print "Marked selected feeds as unread.";
775 if ($op == "pref-feeds") {
777 $subop = $_GET["subop"];
779 if ($subop == "editSave") {
780 $feed_title = db_escape_string($_GET["t"]);
781 $feed_link = db_escape_string($_GET["l"]);
782 $upd_intl = db_escape_string($_GET["ui"]);
783 $feed_id = $_GET["id"];
785 if (strtoupper($upd_intl) == "DEFAULT")
788 $result = db_query($link, "UPDATE ttrss_feeds SET
789 title = '$feed_title', feed_url = '$feed_link',
790 update_interval = '$upd_intl' WHERE id = '$feed_id'");
794 if ($subop == "remove") {
796 if (!WEB_DEMO_MODE
) {
798 $ids = split(",", $_GET["ids"]);
800 foreach ($ids as $id) {
801 db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'");
803 if (file_exists(ICONS_DIR
. "/$id.ico")) {
804 unlink(ICONS_DIR
. "/$id.ico");
810 if ($subop == "add") {
812 if (!WEB_DEMO_MODE
) {
814 $feed_link = db_escape_string($_GET["link"]);
816 $result = db_query($link,
817 "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')");
819 $result = db_query($link,
820 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'");
822 $feed_id = db_fetch_result($result, 0, "id");
825 update_rss_feed($link, $feed_link, $feed_id);
830 $result = db_query($link, "SELECT id,title,feed_url,last_error
831 FROM ttrss_feeds WHERE last_error != ''");
833 if (db_num_rows($result) > 0) {
835 print "<div class=\"warning\">";
837 print "<b>Feeds with update errors:</b>";
839 print "<ul class=\"nomarks\">";
841 while ($line = db_fetch_assoc($result)) {
842 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
851 print "<table class=\"prefAddFeed\"><tr>
852 <td><input id=\"fadd_link\"></td>
853 <td colspan=\"4\" align=\"right\">
854 <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr>
857 $result = db_query($link, "SELECT
858 id,title,feed_url,substring(last_updated,1,16) as last_updated,
861 ttrss_feeds ORDER by title");
863 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
864 print "<tr class=\"title\">
865 <td> </td><td>Select</td><td width=\"40%\">Title</td>
866 <td width=\"30%\">Link</td><td width=\"10%\">Update Interval</td>
867 <td>Last updated</td></tr>";
871 while ($line = db_fetch_assoc($result)) {
873 $class = ($lnum %
2) ?
"even" : "odd";
875 $feed_id = $line["id"];
877 $edit_feed_id = $_GET["id"];
879 if ($subop == "edit" && $feed_id != $edit_feed_id) {
883 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
885 $icon_file = ICONS_DIR
. "/$feed_id.ico";
887 if (file_exists($icon_file) && filesize($icon_file) > 0) {
888 $feed_icon = "<img width=\"16\" height=\"16\"
889 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
891 $feed_icon = " ";
893 print "<td align='center'>$feed_icon</td>";
895 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
896 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
898 if (!$edit_feed_id ||
$subop != "edit") {
900 print "<td><input onclick='toggleSelectRow(this);'
901 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
903 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
904 $edit_title . "</td>";
905 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
906 $edit_link . "</td>";
908 if ($line["update_interval"] == "0")
909 $line["update_interval"] = "Default";
911 print "<td>" . $line["update_interval"] . "</td>";
914 } else if ($feed_id != $edit_feed_id) {
916 print "<td><input disabled=\"true\" type=\"checkbox\"
917 id=\"FRCHK-".$line["id"]."\"></td>";
919 print "<td>$edit_title</td>";
920 print "<td>$edit_link</td>";
922 if ($line["update_interval"] == "0")
923 $line["update_interval"] = "Default";
925 print "<td>" . $line["update_interval"] . "</td>";
929 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
931 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
932 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
933 print "<td><input id=\"iedit_updintl\" value=\"".$line["update_interval"]."\"></td>";
937 if (!$line["last_updated"]) $line["last_updated"] = "Never";
939 print "<td>" . $line["last_updated"] . "</td>";
947 print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>";
954 if ($subop == "edit") {
955 print "Edit feed:
956 <input type=\"submit\" class=\"button\"
957 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
958 <input type=\"submit\" class=\"button\"
959 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
964 <input type=\"submit\" class=\"button\"
965 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
966 <input type=\"submit\" class=\"button\"
967 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
969 if (ENABLE_PREFS_CATCHUP_UNCATCHUP
) {
971 <input type=\"submit\" class=\"button\"
972 onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\">
973 <input type=\"submit\" class=\"button\"
974 onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\"> ";
978 <input type=\"submit\"
979 class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">";
983 print "<h3>OPML Import</h3>
984 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
985 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">
986 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
987 type=\"submit\" value=\"Import\">
992 if ($op == "pref-filters") {
994 $subop = $_GET["subop"];
996 if ($subop == "editSave") {
998 $regexp = db_escape_string($_GET["r"]);
999 $descr = db_escape_string($_GET["d"]);
1000 $match = db_escape_string($_GET["m"]);
1001 $filter_id = db_escape_string($_GET["id"]);
1003 $result = db_query($link, "UPDATE ttrss_filters SET
1004 reg_exp = '$regexp',
1005 description = '$descr',
1006 filter_type = (SELECT id FROM ttrss_filter_types WHERE
1007 description = '$match')
1008 WHERE id = '$filter_id'");
1011 if ($subop == "remove") {
1013 if (!WEB_DEMO_MODE
) {
1015 $ids = split(",", $_GET["ids"]);
1017 foreach ($ids as $id) {
1018 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
1024 if ($subop == "add") {
1026 if (!WEB_DEMO_MODE
) {
1028 $regexp = db_escape_string($_GET["regexp"]);
1029 $match = db_escape_string($_GET["match"]);
1031 $result = db_query($link,
1032 "INSERT INTO ttrss_filters (reg_exp,filter_type) VALUES
1033 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
1034 description = '$match'))");
1038 $result = db_query($link, "SELECT description
1039 FROM ttrss_filter_types ORDER BY description");
1041 $filter_types = array();
1043 while ($line = db_fetch_assoc($result)) {
1044 array_push($filter_types, $line["description"]);
1047 print "<table class=\"prefAddFeed\"><tr>
1048 <td><input id=\"fadd_regexp\"></td>
1050 print_select("fadd_match", "Title", $filter_types);
1052 print"</td><td colspan=\"4\" align=\"right\">
1053 <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr>
1056 $result = db_query($link, "SELECT
1057 id,reg_exp,description,
1058 (SELECT name FROM ttrss_filter_types WHERE
1059 id = filter_type) as filter_type_name,
1060 (SELECT description FROM ttrss_filter_types
1061 WHERE id = filter_type) as filter_type_descr
1063 ttrss_filters ORDER by reg_exp");
1065 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
1067 print "<tr class=\"title\">
1068 <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td>
1069 <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>";
1073 while ($line = db_fetch_assoc($result)) {
1075 $class = ($lnum %
2) ?
"even" : "odd";
1077 $filter_id = $line["id"];
1078 $edit_filter_id = $_GET["id"];
1080 if ($subop == "edit" && $filter_id != $edit_filter_id) {
1084 print "<tr class=\"$class\" id=\"FILRR-$filter_id\">";
1086 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
1087 $line["description"] = htmlspecialchars($line["description"]);
1089 if (!$edit_filter_id ||
$subop != "edit") {
1091 if (!$line["description"]) $line["description"] = "[No description]";
1093 print "<td><input onclick='toggleSelectRow(this);'
1094 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
1096 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1097 $line["reg_exp"] . "</td>";
1099 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1100 $line["description"] . "</td>";
1102 print "<td>".$line["filter_type_descr"]."</td>";
1104 } else if ($filter_id != $edit_filter_id) {
1106 if (!$line["description"]) $line["description"] = "[No description]";
1108 print "<td><input disabled=\"true\" type=\"checkbox\"
1109 id=\"FICHK-".$line["id"]."\"></td>";
1111 print "<td>".$line["reg_exp"]."</td>";
1112 print "<td>".$line["description"]."</td>";
1113 print "<td>".$line["filter_type_descr"]."</td>";
1117 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
1119 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
1122 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1126 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
1138 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
1145 if ($subop == "edit") {
1147 <input type=\"submit\" class=\"button\"
1148 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
1149 <input type=\"submit\" class=\"button\"
1150 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
1156 <input type=\"submit\" class=\"button\"
1157 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
1158 <input type=\"submit\" class=\"button\"
1159 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
1163 if ($op == "pref-labels") {
1165 $subop = $_GET["subop"];
1167 if ($subop == "editSave") {
1169 $sql_exp = $_GET["s"];
1170 $descr = $_GET["d"];
1171 $label_id = db_escape_string($_GET["id"]);
1173 // print "$sql_exp : $descr : $label_id";
1175 $result = db_query($link, "UPDATE ttrss_labels SET
1176 sql_exp = '$sql_exp',
1177 description = '$descr'
1178 WHERE id = '$label_id'");
1181 if ($subop == "remove") {
1183 if (!WEB_DEMO_MODE
) {
1185 $ids = split(",", $_GET["ids"]);
1187 foreach ($ids as $id) {
1188 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
1194 if ($subop == "add") {
1196 if (!WEB_DEMO_MODE
) {
1198 $exp = $_GET["exp"];
1200 $result = db_query($link,
1201 "INSERT INTO ttrss_labels (sql_exp,description)
1202 VALUES ('$exp', '$exp')");
1206 print "<table class=\"prefAddFeed\"><tr>
1207 <td><input id=\"ladd_expr\"></td>";
1209 print"<td colspan=\"4\" align=\"right\">
1210 <a class=\"button\" href=\"javascript:addLabel()\">Add label</a></td></tr>
1213 $result = db_query($link, "SELECT
1214 id,sql_exp,description
1216 ttrss_labels ORDER by description");
1218 print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">";
1220 print "<tr class=\"title\">
1221 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
1222 <a class=\"helpLink\" href=\"javascript:popupHelp(1)\">(?)</a>
1224 <td width=\"40%\">Caption</td></tr>";
1228 while ($line = db_fetch_assoc($result)) {
1230 $class = ($lnum %
2) ?
"even" : "odd";
1232 $label_id = $line["id"];
1233 $edit_label_id = $_GET["id"];
1235 if ($subop == "edit" && $label_id != $edit_label_id) {
1239 print "<tr class=\"$class\" id=\"LILRR-$label_id\">";
1241 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
1242 $line["description"] = htmlspecialchars($line["description"]);
1244 if (!$edit_label_id ||
$subop != "edit") {
1246 if (!$line["description"]) $line["description"] = "[No caption]";
1248 print "<td><input onclick='toggleSelectRow(this);'
1249 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
1251 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1252 $line["sql_exp"] . "</td>";
1254 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1255 $line["description"] . "</td>";
1257 } else if ($label_id != $edit_label_id) {
1259 if (!$line["description"]) $line["description"] = "[No description]";
1261 print "<td><input disabled=\"true\" type=\"checkbox\"
1262 id=\"LICHK-".$line["id"]."\"></td>";
1264 print "<td>".$line["sql_exp"]."</td>";
1265 print "<td>".$line["description"]."</td>";
1269 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
1271 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
1274 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1286 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
1293 if ($subop == "edit") {
1295 <input type=\"submit\" class=\"button\"
1296 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
1297 <input type=\"submit\" class=\"button\"
1298 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
1304 <input type=\"submit\" class=\"button\"
1305 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
1306 <input type=\"submit\" class=\"button\"
1307 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
1311 if ($op == "error") {
1312 print "<div width=\"100%\" align='center'>";
1313 $msg = $_GET["msg"];
1318 if ($op == "help") {
1320 <title>Tiny Tiny RSS : Help</title>
1321 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
1322 <script type=\"text/javascript\" src=\"functions.js\"></script>
1323 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
1324 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1327 $tid = sprintf("%d", $_GET["tid"]);
1329 /* FIXME this badly needs real implementation */
1331 print "<div class='helpResponse'>";
1335 <h1
>Help
for SQL expressions
</h1
>
1337 <h2
>Description
</h2
>
1339 <p
>The
«
;SQL expression
»
; is added to WHERE clause of
1340 view feed query
. You can match on ttrss_entries table fields
1341 and even
use subselect to query additional information
. This
1342 functionality is considered to be advanced
and requires basic
1343 understanding of SQL
.</p
>
1347 <pre
>unread
= true</pre
>
1349 Matches all unread articles
1351 <pre
>title like
'%Linux%'</pre
>
1353 Matches all articles which mention Linux in the title
. You get the idea
.
1355 <p
>See the database schema included in the distribution package
for gruesome
1360 print "<div align='center'>
1361 <a class=\"helpLink\"
1362 href=\"javascript:window.close()\">(Close this window)</a></div>";
1366 print "</body></html>";
1372 $param = $_GET["param"];
1374 if ($id == "quickAddFeed") {
1375 print "Feed URL: <input
1376 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1378 <input class=\"button\"
1379 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
1380 <input class=\"button\"
1381 type=\"submit\" onclick=\"javascript:closeDlg()\"
1385 if ($id == "quickDelFeed") {
1387 $param = db_escape_string($param);
1389 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
1393 $f_title = db_fetch_result($result, 0, "title");
1395 print "Remove current feed ($f_title)?
1396 <input class=\"button\"
1397 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
1398 <input class=\"button\"
1399 type=\"submit\" onclick=\"javascript:closeDlg()\"
1402 print "Error: Feed $param not found.
1403 <input class=\"button\"
1404 type=\"submit\" onclick=\"javascript:closeDlg()\"
1409 if ($id == "search") {
1411 print "<input id=\"searchbox\" class=\"extSearch\"
1412 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1413 onchange=\"javascript:search()\">
1414 <select id=\"searchmodebox\">
1415 <option selected>All feeds</option>
1416 <option>This feed</option>
1418 <input type=\"submit\"
1419 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
1420 <input class=\"button\"
1421 type=\"submit\" onclick=\"javascript:closeDlg()\"
1431 <!-- <?
= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?
> -->