2 define(SCHEMA_VERSION
, 2);
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'");
32 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
34 $schema_version = db_fetch_result($result, 0, "schema_version");
36 if ($schema_version != SCHEMA_VERSION) {
37 print "Error: database schema is invalid
38 (got version $schema_version; expected ".SCHEMA_VERSION.")";
43 $fetch = $_GET["fetch"];
45 /* FIXME this needs reworking */
47 function getGlobalCounters($link) {
48 $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries
49 WHERE unread = true");
50 $c_id = db_fetch_result($result, 0, "c_id");
51 print "<counter id='global-unread' counter='$c_id'/>";
54 function getTagCounters($link) {
55 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
56 FROM ttrss_tags,ttrss_entries WHERE
57 post_id = ttrss_entries.id AND unread = true GROUP BY tag_name
59 select tag_name,0 as count FROM ttrss_tags");
63 while ($line = db_fetch_assoc($result)) {
64 $tags[$line["tag_name"]] +
= $line["count"];
67 foreach (array_keys($tags) as $tag) {
68 $unread = $tags[$tag];
70 $tag = htmlspecialchars($tag);
71 print "<tag id=\"$tag\" counter=\"$unread\"/>";
75 function getLabelCounters($link) {
77 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
78 WHERE marked = true AND unread = true");
80 $count = db_fetch_result($result, 0, "count");
82 print "<label id=\"-1\" counter=\"$count\"/>";
84 $result = db_query($link, "SELECT id,sql_exp,description FROM
85 ttrss_labels ORDER by description");
87 while ($line = db_fetch_assoc($result)) {
89 $id = -$line["id"] - 11;
93 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
94 WHERE (" . $line["sql_exp"] . ") AND unread = true");
96 $count = db_fetch_result($tmp_result, 0, "count");
98 print "<label id=\"$id\" counter=\"$count\"/>";
100 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
105 function getFeedCounter($link, $id) {
107 $result = db_query($link, "SELECT
108 count(id) as count FROM ttrss_entries
109 WHERE feed_id = '$id' AND unread = true");
111 $count = db_fetch_result($result, 0, "count");
113 print "<feed id=\"$id\" counter=\"$count\"/>";
116 function getFeedCounters($link) {
118 $result = db_query($link, "SELECT id,
119 (SELECT count(id) FROM ttrss_entries WHERE feed_id = ttrss_feeds.id
120 AND unread = true) as count
123 while ($line = db_fetch_assoc($result)) {
126 $count = $line["count"];
128 print "<feed id=\"$id\" counter=\"$count\"/>";
132 function outputFeedList($link, $tags = false) {
135 <title>Tiny Tiny RSS : Feedlist</title>
136 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
138 if (USE_COMPACT_STYLESHEET
) {
139 print "<link rel=\"stylesheet\" type=\"text/css\"
140 href=\"tt-rss_compact.css\"/>";
142 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
143 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
146 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
147 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
148 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
149 </head><body onload=\"init()\">";
151 print "<ul class=\"feedList\" id=\"feedList\">";
157 $result = db_query($link, "SELECT count(id) as num_starred
158 FROM ttrss_entries WHERE marked = true AND unread = true");
159 $num_starred = db_fetch_result($result, 0, "num_starred");
163 if ($num_starred > 0) $class .= "Unread";
165 printFeedEntry(-1, $class, "Starred articles", $num_starred,
166 "images/mark_set.png");
170 $result = db_query($link, "SELECT id,sql_exp,description FROM
171 ttrss_labels ORDER by description");
173 if (db_num_rows($result) > 0) {
174 print "<li><hr></li>";
177 while ($line = db_fetch_assoc($result)) {
181 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
182 WHERE (" . $line["sql_exp"] . ") AND unread = true");
184 $count = db_fetch_result($tmp_result, 0, "count");
192 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
194 printFeedEntry(-$line["id"]-11,
195 $class, $line["description"], $count, "images/label.png");
200 print "<li><hr></li>";
202 $result = db_query($link, "SELECT *,
203 (SELECT count(id) FROM ttrss_entries
204 WHERE feed_id = ttrss_feeds.id) AS total,
205 (SELECT count(id) FROM ttrss_entries
206 WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
207 FROM ttrss_feeds ORDER BY title");
209 $actid = $_GET["actid"];
217 while ($line = db_fetch_assoc($result)) {
219 $feed = $line["title"];
220 $feed_id = $line["id"];
222 $subop = $_GET["subop"];
224 $total = $line["total"];
225 $unread = $line["unread"];
227 // $class = ($lnum % 2) ? "even" : "odd";
231 if ($unread > 0) $class .= "Unread";
233 if ($actid == $feed_id) {
234 $class .= "Selected";
237 $total_unread +
= $unread;
239 printFeedEntry($feed_id, $class, $feed, $unread, "icons/$feed_id.ico");
247 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
248 FROM ttrss_tags,ttrss_entries WHERE
249 post_id = ttrss_entries.id AND unread = true GROUP BY tag_name
251 select tag_name,0 as count FROM ttrss_tags");
255 while ($line = db_fetch_assoc($result)) {
256 $tags[$line["tag_name"]] +
= $line["count"];
259 foreach (array_keys($tags) as $tag) {
261 $unread = $tags[$tag];
269 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png");
275 if (db_num_rows($result) == 0) {
276 print "<li>No tags to display.</li>";
281 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
288 $subop = $_GET["subop"];
290 if ($subop == "getLabelCounters") {
293 getLabelCounters($link);
295 getFeedCounter($link, $aid);
297 print "</rpc-reply>";
300 if ($subop == "getFeedCounters") {
302 getFeedCounters($link);
303 print "</rpc-reply>";
306 if ($subop == "getAllCounters") {
308 getLabelCounters($link);
309 getFeedCounters($link);
310 getTagCounters($link);
311 getGlobalCounters($link);
312 print "</rpc-reply>";
315 if ($subop == "mark") {
316 $mark = $_GET["mark"];
317 $id = db_escape_string($_GET["id"]);
325 $result = db_query($link, "UPDATE ttrss_entries SET marked = $mark
329 if ($subop == "updateFeed") {
330 $feed_id = db_escape_string($_GET["feed"]);
332 $result = db_query($link,
333 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'");
335 if (db_num_rows($result) > 0) {
336 $feed_url = db_fetch_result($result, 0, "feed_url");
337 // update_rss_feed($link, $feed_url, $feed_id);
340 print "DONE-$feed_id";
345 if ($subop == "forceUpdateAllFeeds" ||
$subop == "updateAllFeeds") {
347 update_all_feeds($link, true);
349 $omode = $_GET["omode"];
351 if (!$omode) $omode = "tfl";
354 if (strchr($omode, "l")) getLabelCounters($link);
355 if (strchr($omode, "f")) getFeedCounters($link);
356 if (strchr($omode, "t")) getTagCounters($link);
357 getGlobalCounters($link);
358 print "</rpc-reply>";
361 if ($subop == "catchupPage") {
363 $ids = split(",", $_GET["ids"]);
365 foreach ($ids as $id) {
367 db_query($link, "UPDATE ttrss_entries SET unread=false,last_read = NOW()
372 print "Marked active page as read.";
375 if ($subop == "sanityCheck") {
379 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
381 $schema_version = db_fetch_result($result, 0, "schema_version");
383 if ($schema_version != SCHEMA_VERSION
) {
387 print "<error code='$error_code'/>";
391 if ($op == "feeds") {
393 $tags = $_GET["tags"];
395 $subop = $_GET["subop"];
397 if ($subop == "catchupAll") {
398 db_query($link, "UPDATE ttrss_entries SET last_read = NOW(),unread = false");
401 outputFeedList($link, $tags);
408 $feed_id = $_GET["feed"];
410 $result = db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'");
412 $addheader = $_GET["addheader"];
414 $result = db_query($link, "SELECT title,link,content,feed_id,comments,
415 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
421 <title>Tiny Tiny RSS : Article $id</title>
422 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
423 <script type=\"text/javascript\" src=\"functions.js\"></script>
424 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
430 $line = db_fetch_assoc($result);
432 if ($line["icon_url"]) {
433 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
435 $feed_icon = " ";
438 if ($line["comments"] && $line["link"] != $line["comments"]) {
439 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
441 $entry_comments = "";
444 print "<div class=\"postReply\">";
446 print "<div class=\"postHeader\"><table>";
448 print "<tr><td><b>Title:</b></td>
449 <td width='100%'>" . $line["title"] . "</td></tr>";
451 print "<tr><td><b>Link:</b></td>
453 <a href=\"" . $line["link"] . "\">".$line["link"]."</a>
454 $entry_comments</td></tr>";
456 print "</table></div>";
458 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
459 print "<div class=\"postContent\">" . $line["content"] . "</div>";
463 print "<script type=\"text/javascript\">
464 update_label_counters('$feed_id');
469 print "</body></html>";
473 if ($op == "viewfeed") {
475 $feed = $_GET["feed"];
476 $skip = $_GET["skip"];
477 $subop = $_GET["subop"];
478 $view_mode = $_GET["view"];
479 $addheader = $_GET["addheader"];
480 $limit = $_GET["limit"];
483 print "Error: no feed to display.";
487 if (!$skip) $skip = 0;
489 if ($subop == "undefined") $subop = "";
493 <title>Tiny Tiny RSS : Feed $feed</title>
494 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
496 if (USE_COMPACT_STYLESHEET
) {
497 print "<link rel=\"stylesheet\"
498 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
501 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
502 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
504 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
505 <script type=\"text/javascript\" src=\"functions.js\"></script>
506 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
507 </head><body onload='init()'>";
510 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
512 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
513 WHERE id = '$feed'");
515 $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
517 update_rss_feed($link, $feed_url, $feed);
521 if ($subop == "MarkAllRead") {
523 if (sprintf("%d", $feed) != 0) {
526 db_query($link, "UPDATE ttrss_entries
527 SET unread = false,last_read = NOW()
528 WHERE feed_id = '$feed'");
530 } else if ($feed < 0 && $feed > -10) { // special, like starred
533 db_query($link, "UPDATE ttrss_entries
534 SET unread = false,last_read = NOW()
535 WHERE marked = true");
538 } else if ($feed < -10) { // label
540 $label_id = -$feed - 11;
542 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
543 WHERE id = '$label_id'");
546 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
548 db_query($link, "UPDATE ttrss_entries
549 SET unread = false,last_read = NOW()
554 // FIXME, implement catchup for tags
559 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
561 $search = $_GET["search"];
563 $search_mode = $_GET["smode"];
566 $search_query_part = "(upper(title) LIKE upper('%$search%')
567 OR content LIKE '%$search%') AND";
569 $search_query_part = "";
572 $view_query_part = "";
574 if ($view_mode == "Starred") {
575 $view_query_part = " marked = true AND ";
578 if ($view_mode == "Unread") {
579 $view_query_part = " unread = true AND ";
582 if ($view_mode == "Unread or Starred") {
583 $view_query_part = " (unread = true OR marked = true) AND ";
586 if ($view_mode == "Unread or Updated") {
587 $view_query_part = " (unread = true OR last_read is NULL) AND ";
590 /* $result = db_query($link, "SELECT count(id) AS total_entries
591 FROM ttrss_entries WHERE
595 $total_entries = db_fetch_result($result, 0, "total_entries"); */
597 /* $result = db_query("SELECT count(id) AS unread_entries
598 FROM ttrss_entries WHERE
603 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
605 if ($limit && $limit != "All") {
606 $limit_query_part = "LIMIT " . $limit;
609 $vfeed_query_part = "";
611 // override query strategy and enable feed display when searching globally
612 if ($search_mode == "All feeds") {
613 $query_strategy_part = "id > 0";
614 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
615 id = feed_id) as feed_title,";
616 } else if (sprintf("%d", $feed) == 0) {
617 $query_strategy_part = "ttrss_entries.id > 0";
618 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
619 id = feed_id) as feed_title,";
620 } else if ($feed >= 0) {
621 $query_strategy_part = "feed_id = '$feed'";
622 } else if ($feed == -1) { // starred virtual feed
623 $query_strategy_part = "marked = true";
624 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
625 id = feed_id) as feed_title,";
626 } else if ($feed <= -10) { // labels
627 $label_id = -$feed - 11;
629 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
630 WHERE id = '$label_id'");
632 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
634 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
635 id = feed_id) as feed_title,";
637 $query_strategy_part = "id > 0"; // dumb
641 $order_by = "updated DESC";
643 // if ($feed < -10) {
644 // $order_by = "feed_id,updated DESC";
647 if ($feed < -10) error_reporting (0);
649 if (sprintf("%d", $feed) != 0) {
651 $result = db_query($link, "SELECT
652 id,title,updated,unread,feed_id,marked,link,last_read,
653 SUBSTRING(last_read,1,19) as last_read_noms,
655 SUBSTRING(updated,1,19) as updated_noms
661 $query_strategy_part ORDER BY $order_by
667 $result = db_query($link, "SELECT
668 ttrss_entries.id as id,title,updated,unread,feed_id,
669 marked,link,last_read,
670 SUBSTRING(last_read,1,19) as last_read_noms,
672 SUBSTRING(updated,1,19) as updated_noms
674 ttrss_entries,ttrss_tags
676 post_id = ttrss_entries.id AND tag_name = '$feed' AND
679 $query_strategy_part ORDER BY $order_by
684 print "<tr><td colspan='4' align='center'>
685 Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>";
691 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
695 while ($line = db_fetch_assoc($result)) {
697 $class = ($lnum %
2) ?
"even" : "odd";
700 $feed_id = $line["feed_id"];
702 // printf("L %d (%s) > U %d (%s) = %d<br>",
703 // strtotime($line["last_read_noms"]), $line["last_read_noms"],
704 // strtotime($line["updated"]), $line["updated"],
705 // strtotime($line["last_read"]) >= strtotime($line["updated"]));
707 /* if ($line["last_read"] != "" && $line["updated"] != "" &&
708 strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) {
710 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
715 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
720 if ($line["last_read"] == "" &&
721 ($line["unread"] != "t" && $line["unread"] != "1")) {
723 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
726 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
730 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
735 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
736 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
737 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
739 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
740 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
743 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
744 $line["title"] . "</a>";
746 print "<tr class='$class' id='RROW-$id'>";
747 // onclick=\"javascript:view($id,$feed_id)\">
749 print "<td valign='center' align='center'>$update_pic</td>";
750 print "<td valign='center' align='center'>$marked_pic</td>";
752 print "<td width='25%'>
753 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
755 if ($line["feed_title"]) {
756 print "<td width='50%'>$content_link</td>";
757 print "<td width='20%'>
758 <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a></td>";
760 print "<td width='70%'>$content_link</td>";
769 print "<tr><td align='center'>No articles found.</td></tr>";
774 print "<script type=\"text/javascript\">
775 document.onkeydown = hotkey_handler;
776 update_label_counters('$feed');
780 print "</body></html>";
785 if ($op == "pref-rpc") {
787 $subop = $_GET["subop"];
789 if ($subop == "unread") {
790 $ids = split(",", $_GET["ids"]);
791 foreach ($ids as $id) {
792 db_query($link, "UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'");
795 print "Marked selected feeds as read.";
798 if ($subop == "read") {
799 $ids = split(",", $_GET["ids"]);
800 foreach ($ids as $id) {
801 db_query($link, "UPDATE ttrss_entries
802 SET unread = false,last_read = NOW() WHERE feed_id = '$id'");
805 print "Marked selected feeds as unread.";
811 if ($op == "pref-feeds") {
813 $subop = $_GET["subop"];
815 if ($subop == "editSave") {
816 $feed_title = db_escape_string($_GET["t"]);
817 $feed_link = db_escape_string($_GET["l"]);
818 $upd_intl = db_escape_string($_GET["ui"]);
819 $feed_id = $_GET["id"];
821 if (strtoupper($upd_intl) == "DEFAULT")
824 $result = db_query($link, "UPDATE ttrss_feeds SET
825 title = '$feed_title', feed_url = '$feed_link',
826 update_interval = '$upd_intl' WHERE id = '$feed_id'");
830 if ($subop == "remove") {
832 if (!WEB_DEMO_MODE
) {
834 $ids = split(",", $_GET["ids"]);
836 foreach ($ids as $id) {
837 db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'");
839 if (file_exists(ICONS_DIR
. "/$id.ico")) {
840 unlink(ICONS_DIR
. "/$id.ico");
846 if ($subop == "add") {
848 if (!WEB_DEMO_MODE
) {
850 $feed_link = db_escape_string($_GET["link"]);
852 $result = db_query($link,
853 "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')");
855 $result = db_query($link,
856 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'");
858 $feed_id = db_fetch_result($result, 0, "id");
861 update_rss_feed($link, $feed_link, $feed_id);
866 $result = db_query($link, "SELECT id,title,feed_url,last_error
867 FROM ttrss_feeds WHERE last_error != ''");
869 if (db_num_rows($result) > 0) {
871 print "<div class=\"warning\">";
873 print "<b>Feeds with update errors:</b>";
875 print "<ul class=\"nomarks\">";
877 while ($line = db_fetch_assoc($result)) {
878 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
887 print "<table class=\"prefAddFeed\"><tr>
888 <td><input id=\"fadd_link\"></td>
889 <td colspan=\"4\" align=\"right\">
890 <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr>
893 $result = db_query($link, "SELECT
894 id,title,feed_url,substring(last_updated,1,16) as last_updated,
897 ttrss_feeds ORDER by title");
899 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
900 print "<tr class=\"title\">
901 <td> </td><td>Select</td><td width=\"40%\">Title</td>
902 <td width=\"30%\">Link</td><td width=\"10%\">Update Interval</td>
903 <td>Last updated</td></tr>";
907 while ($line = db_fetch_assoc($result)) {
909 $class = ($lnum %
2) ?
"even" : "odd";
911 $feed_id = $line["id"];
913 $edit_feed_id = $_GET["id"];
915 if ($subop == "edit" && $feed_id != $edit_feed_id) {
919 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
921 $icon_file = ICONS_DIR
. "/$feed_id.ico";
923 if (file_exists($icon_file) && filesize($icon_file) > 0) {
924 $feed_icon = "<img width=\"16\" height=\"16\"
925 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
927 $feed_icon = " ";
929 print "<td align='center'>$feed_icon</td>";
931 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
932 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
934 if (!$edit_feed_id ||
$subop != "edit") {
936 print "<td><input onclick='toggleSelectRow(this);'
937 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
939 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
940 $edit_title . "</td>";
941 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
942 $edit_link . "</td>";
944 if ($line["update_interval"] == "0")
945 $line["update_interval"] = "Default";
947 print "<td>" . $line["update_interval"] . "</td>";
950 } else if ($feed_id != $edit_feed_id) {
952 print "<td><input disabled=\"true\" type=\"checkbox\"
953 id=\"FRCHK-".$line["id"]."\"></td>";
955 print "<td>$edit_title</td>";
956 print "<td>$edit_link</td>";
958 if ($line["update_interval"] == "0")
959 $line["update_interval"] = "Default";
961 print "<td>" . $line["update_interval"] . "</td>";
965 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
967 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
968 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
969 print "<td><input id=\"iedit_updintl\" value=\"".$line["update_interval"]."\"></td>";
973 if (!$line["last_updated"]) $line["last_updated"] = "Never";
975 print "<td>" . $line["last_updated"] . "</td>";
983 print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>";
990 if ($subop == "edit") {
991 print "Edit feed:
992 <input type=\"submit\" class=\"button\"
993 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
994 <input type=\"submit\" class=\"button\"
995 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1000 <input type=\"submit\" class=\"button\"
1001 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
1002 <input type=\"submit\" class=\"button\"
1003 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
1005 if (ENABLE_PREFS_CATCHUP_UNCATCHUP
) {
1007 <input type=\"submit\" class=\"button\"
1008 onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\">
1009 <input type=\"submit\" class=\"button\"
1010 onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\"> ";
1014 <input type=\"submit\"
1015 class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">";
1019 print "<h3>OPML Import</h3>
1020 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1021 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">
1022 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
1023 type=\"submit\" value=\"Import\">
1028 if ($op == "pref-filters") {
1030 $subop = $_GET["subop"];
1032 if ($subop == "editSave") {
1034 $regexp = db_escape_string($_GET["r"]);
1035 $descr = db_escape_string($_GET["d"]);
1036 $match = db_escape_string($_GET["m"]);
1037 $filter_id = db_escape_string($_GET["id"]);
1039 $result = db_query($link, "UPDATE ttrss_filters SET
1040 reg_exp = '$regexp',
1041 description = '$descr',
1042 filter_type = (SELECT id FROM ttrss_filter_types WHERE
1043 description = '$match')
1044 WHERE id = '$filter_id'");
1047 if ($subop == "remove") {
1049 if (!WEB_DEMO_MODE
) {
1051 $ids = split(",", $_GET["ids"]);
1053 foreach ($ids as $id) {
1054 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
1060 if ($subop == "add") {
1062 if (!WEB_DEMO_MODE
) {
1064 $regexp = db_escape_string($_GET["regexp"]);
1065 $match = db_escape_string($_GET["match"]);
1067 $result = db_query($link,
1068 "INSERT INTO ttrss_filters (reg_exp,filter_type) VALUES
1069 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
1070 description = '$match'))");
1074 $result = db_query($link, "SELECT description
1075 FROM ttrss_filter_types ORDER BY description");
1077 $filter_types = array();
1079 while ($line = db_fetch_assoc($result)) {
1080 array_push($filter_types, $line["description"]);
1083 print "<table class=\"prefAddFeed\"><tr>
1084 <td><input id=\"fadd_regexp\"></td>
1086 print_select("fadd_match", "Title", $filter_types);
1088 print"</td><td colspan=\"4\" align=\"right\">
1089 <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr>
1092 $result = db_query($link, "SELECT
1093 id,reg_exp,description,
1094 (SELECT name FROM ttrss_filter_types WHERE
1095 id = filter_type) as filter_type_name,
1096 (SELECT description FROM ttrss_filter_types
1097 WHERE id = filter_type) as filter_type_descr
1099 ttrss_filters ORDER by reg_exp");
1101 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
1103 print "<tr class=\"title\">
1104 <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td>
1105 <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>";
1109 while ($line = db_fetch_assoc($result)) {
1111 $class = ($lnum %
2) ?
"even" : "odd";
1113 $filter_id = $line["id"];
1114 $edit_filter_id = $_GET["id"];
1116 if ($subop == "edit" && $filter_id != $edit_filter_id) {
1120 print "<tr class=\"$class\" id=\"FILRR-$filter_id\">";
1122 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
1123 $line["description"] = htmlspecialchars($line["description"]);
1125 if (!$edit_filter_id ||
$subop != "edit") {
1127 if (!$line["description"]) $line["description"] = "[No description]";
1129 print "<td><input onclick='toggleSelectRow(this);'
1130 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
1132 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1133 $line["reg_exp"] . "</td>";
1135 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1136 $line["description"] . "</td>";
1138 print "<td>".$line["filter_type_descr"]."</td>";
1140 } else if ($filter_id != $edit_filter_id) {
1142 if (!$line["description"]) $line["description"] = "[No description]";
1144 print "<td><input disabled=\"true\" type=\"checkbox\"
1145 id=\"FICHK-".$line["id"]."\"></td>";
1147 print "<td>".$line["reg_exp"]."</td>";
1148 print "<td>".$line["description"]."</td>";
1149 print "<td>".$line["filter_type_descr"]."</td>";
1153 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
1155 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
1158 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1162 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
1174 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
1181 if ($subop == "edit") {
1183 <input type=\"submit\" class=\"button\"
1184 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
1185 <input type=\"submit\" class=\"button\"
1186 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
1192 <input type=\"submit\" class=\"button\"
1193 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
1194 <input type=\"submit\" class=\"button\"
1195 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
1199 if ($op == "pref-labels") {
1201 $subop = $_GET["subop"];
1203 if ($subop == "editSave") {
1205 $sql_exp = $_GET["s"];
1206 $descr = $_GET["d"];
1207 $label_id = db_escape_string($_GET["id"]);
1209 // print "$sql_exp : $descr : $label_id";
1211 $result = db_query($link, "UPDATE ttrss_labels SET
1212 sql_exp = '$sql_exp',
1213 description = '$descr'
1214 WHERE id = '$label_id'");
1217 if ($subop == "remove") {
1219 if (!WEB_DEMO_MODE
) {
1221 $ids = split(",", $_GET["ids"]);
1223 foreach ($ids as $id) {
1224 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
1230 if ($subop == "add") {
1232 if (!WEB_DEMO_MODE
) {
1234 $exp = $_GET["exp"];
1236 $result = db_query($link,
1237 "INSERT INTO ttrss_labels (sql_exp,description)
1238 VALUES ('$exp', '$exp')");
1242 print "<table class=\"prefAddFeed\"><tr>
1243 <td><input id=\"ladd_expr\"></td>";
1245 print"<td colspan=\"4\" align=\"right\">
1246 <a class=\"button\" href=\"javascript:addLabel()\">Add label</a></td></tr>
1249 $result = db_query($link, "SELECT
1250 id,sql_exp,description
1252 ttrss_labels ORDER by description");
1254 print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">";
1256 print "<tr class=\"title\">
1257 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
1258 <a class=\"helpLink\" href=\"javascript:popupHelp(1)\">(?)</a>
1260 <td width=\"40%\">Caption</td></tr>";
1264 while ($line = db_fetch_assoc($result)) {
1266 $class = ($lnum %
2) ?
"even" : "odd";
1268 $label_id = $line["id"];
1269 $edit_label_id = $_GET["id"];
1271 if ($subop == "edit" && $label_id != $edit_label_id) {
1275 print "<tr class=\"$class\" id=\"LILRR-$label_id\">";
1277 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
1278 $line["description"] = htmlspecialchars($line["description"]);
1280 if (!$edit_label_id ||
$subop != "edit") {
1282 if (!$line["description"]) $line["description"] = "[No caption]";
1284 print "<td><input onclick='toggleSelectRow(this);'
1285 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
1287 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1288 $line["sql_exp"] . "</td>";
1290 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1291 $line["description"] . "</td>";
1293 } else if ($label_id != $edit_label_id) {
1295 if (!$line["description"]) $line["description"] = "[No description]";
1297 print "<td><input disabled=\"true\" type=\"checkbox\"
1298 id=\"LICHK-".$line["id"]."\"></td>";
1300 print "<td>".$line["sql_exp"]."</td>";
1301 print "<td>".$line["description"]."</td>";
1305 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
1307 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
1310 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1322 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
1329 if ($subop == "edit") {
1331 <input type=\"submit\" class=\"button\"
1332 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
1333 <input type=\"submit\" class=\"button\"
1334 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
1340 <input type=\"submit\" class=\"button\"
1341 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
1342 <input type=\"submit\" class=\"button\"
1343 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
1347 if ($op == "error") {
1348 print "<div width=\"100%\" align='center'>";
1349 $msg = $_GET["msg"];
1354 if ($op == "help") {
1356 <title>Tiny Tiny RSS : Help</title>
1357 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
1358 <script type=\"text/javascript\" src=\"functions.js\"></script>
1359 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1362 $tid = sprintf("%d", $_GET["tid"]);
1364 /* FIXME this badly needs real implementation */
1366 print "<div class='helpResponse'>";
1370 <h1
>Help
for SQL expressions
</h1
>
1372 <h2
>Description
</h2
>
1374 <p
>The
«
;SQL expression
»
; is added to WHERE clause of
1375 view feed query
. You can match on ttrss_entries table fields
1376 and even
use subselect to query additional information
. This
1377 functionality is considered to be advanced
and requires basic
1378 understanding of SQL
.</p
>
1382 <pre
>unread
= true</pre
>
1384 Matches all unread articles
1386 <pre
>title like
'%Linux%'</pre
>
1388 Matches all articles which mention Linux in the title
. You get the idea
.
1390 <p
>See the database schema included in the distribution package
for gruesome
1395 print "<div align='center'>
1396 <a class=\"helpLink\"
1397 href=\"javascript:window.close()\">(Close this window)</a></div>";
1401 print "</body></html>";
1407 $param = $_GET["param"];
1409 if ($id == "quickAddFeed") {
1410 print "Feed URL: <input
1411 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1413 <input class=\"button\"
1414 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
1415 <input class=\"button\"
1416 type=\"submit\" onclick=\"javascript:closeDlg()\"
1420 if ($id == "quickDelFeed") {
1422 $param = db_escape_string($param);
1424 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
1428 $f_title = db_fetch_result($result, 0, "title");
1430 print "Remove current feed ($f_title)?
1431 <input class=\"button\"
1432 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
1433 <input class=\"button\"
1434 type=\"submit\" onclick=\"javascript:closeDlg()\"
1437 print "Error: Feed $param not found.
1438 <input class=\"button\"
1439 type=\"submit\" onclick=\"javascript:closeDlg()\"
1444 if ($id == "search") {
1446 print "<input id=\"searchbox\" class=\"extSearch\"
1447 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1448 onchange=\"javascript:search()\">
1449 <select id=\"searchmodebox\">
1450 <option selected>All feeds</option>
1451 <option>This feed</option>
1453 <input type=\"submit\"
1454 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
1455 <input class=\"button\"
1456 type=\"submit\" onclick=\"javascript:closeDlg()\"
1466 <!-- <?
= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?
> -->