2 define(SCHEMA_VERSION
, 2);
6 if ($op == "rpc" ||
$op == "updateAllFeeds") {
7 header("Content-Type: application/xml");
10 require_once "config.php";
11 require_once "db.php";
12 require_once "db-prefs.php";
13 require_once "functions.php";
14 require_once "magpierss/rss_fetch.inc";
16 $script_started = getmicrotime();
18 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
19 $dbprefs_link = $link;
22 if (DB_TYPE
== "mysql") {
25 // PG seems to display its own errors just fine by default.
29 if (DB_TYPE
== "pgsql") {
30 pg_query("set client_encoding = 'utf-8'");
34 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
36 $schema_version = db_fetch_result($result, 0, "schema_version");
38 if ($schema_version != SCHEMA_VERSION) {
39 print "Error: database schema is invalid
40 (got version $schema_version; expected ".SCHEMA_VERSION.")";
45 $fetch = $_GET["fetch"];
47 /* FIXME this needs reworking */
49 function getGlobalCounters($link) {
50 $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries
51 WHERE unread = true");
52 $c_id = db_fetch_result($result, 0, "c_id");
53 print "<counter id='global-unread' counter='$c_id'/>";
56 function getTagCounters($link) {
57 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
58 FROM ttrss_tags,ttrss_entries WHERE
59 post_id = ttrss_entries.id AND unread = true GROUP BY tag_name
61 select tag_name,0 as count FROM ttrss_tags");
65 while ($line = db_fetch_assoc($result)) {
66 $tags[$line["tag_name"]] +
= $line["count"];
69 foreach (array_keys($tags) as $tag) {
70 $unread = $tags[$tag];
72 $tag = htmlspecialchars($tag);
73 print "<tag id=\"$tag\" counter=\"$unread\"/>";
77 function getLabelCounters($link) {
79 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
80 WHERE marked = true AND unread = true");
82 $count = db_fetch_result($result, 0, "count");
84 print "<label id=\"-1\" counter=\"$count\"/>";
86 $result = db_query($link, "SELECT id,sql_exp,description FROM
87 ttrss_labels ORDER by description");
89 while ($line = db_fetch_assoc($result)) {
91 $id = -$line["id"] - 11;
95 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
96 WHERE (" . $line["sql_exp"] . ") AND unread = true");
98 $count = db_fetch_result($tmp_result, 0, "count");
100 print "<label id=\"$id\" counter=\"$count\"/>";
102 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
107 function getFeedCounter($link, $id) {
109 $result = db_query($link, "SELECT
110 count(id) as count FROM ttrss_entries
111 WHERE feed_id = '$id' AND unread = true");
113 $count = db_fetch_result($result, 0, "count");
115 print "<feed id=\"$id\" counter=\"$count\"/>";
118 function getFeedCounters($link) {
120 $result = db_query($link, "SELECT id,
121 (SELECT count(id) FROM ttrss_entries WHERE feed_id = ttrss_feeds.id
122 AND unread = true) as count
125 while ($line = db_fetch_assoc($result)) {
128 $count = $line["count"];
130 print "<feed id=\"$id\" counter=\"$count\"/>";
134 function outputFeedList($link, $tags = false) {
137 <title>Tiny Tiny RSS : Feedlist</title>
138 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
140 if (USE_COMPACT_STYLESHEET
) {
141 print "<link rel=\"stylesheet\" type=\"text/css\"
142 href=\"tt-rss_compact.css\"/>";
144 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
145 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
148 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
149 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
150 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
151 </head><body onload=\"init()\">";
153 print "<ul class=\"feedList\" id=\"feedList\">";
159 $result = db_query($link, "SELECT count(id) as num_starred
160 FROM ttrss_entries WHERE marked = true AND unread = true");
161 $num_starred = db_fetch_result($result, 0, "num_starred");
165 if ($num_starred > 0) $class .= "Unread";
167 printFeedEntry(-1, $class, "Starred articles", $num_starred,
168 "images/mark_set.png");
172 $result = db_query($link, "SELECT id,sql_exp,description FROM
173 ttrss_labels ORDER by description");
175 if (db_num_rows($result) > 0) {
176 print "<li><hr></li>";
179 while ($line = db_fetch_assoc($result)) {
183 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
184 WHERE (" . $line["sql_exp"] . ") AND unread = true");
186 $count = db_fetch_result($tmp_result, 0, "count");
194 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
196 printFeedEntry(-$line["id"]-11,
197 $class, $line["description"], $count, "images/label.png");
202 print "<li><hr></li>";
204 $result = db_query($link, "SELECT *,
205 (SELECT count(id) FROM ttrss_entries
206 WHERE feed_id = ttrss_feeds.id) AS total,
207 (SELECT count(id) FROM ttrss_entries
208 WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
209 FROM ttrss_feeds ORDER BY title");
211 $actid = $_GET["actid"];
219 while ($line = db_fetch_assoc($result)) {
221 $feed = $line["title"];
222 $feed_id = $line["id"];
224 $subop = $_GET["subop"];
226 $total = $line["total"];
227 $unread = $line["unread"];
229 // $class = ($lnum % 2) ? "even" : "odd";
233 if ($unread > 0) $class .= "Unread";
235 if ($actid == $feed_id) {
236 $class .= "Selected";
239 $total_unread +
= $unread;
241 printFeedEntry($feed_id, $class, $feed, $unread, "icons/$feed_id.ico");
249 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
250 FROM ttrss_tags,ttrss_entries WHERE
251 post_id = ttrss_entries.id AND unread = true GROUP BY tag_name
253 select tag_name,0 as count FROM ttrss_tags");
257 while ($line = db_fetch_assoc($result)) {
258 $tags[$line["tag_name"]] +
= $line["count"];
261 foreach (array_keys($tags) as $tag) {
263 $unread = $tags[$tag];
271 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png");
277 if (db_num_rows($result) == 0) {
278 print "<li>No tags to display.</li>";
283 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
290 $subop = $_GET["subop"];
292 if ($subop == "getLabelCounters") {
295 getLabelCounters($link);
297 getFeedCounter($link, $aid);
299 print "</rpc-reply>";
302 if ($subop == "getFeedCounters") {
304 getFeedCounters($link);
305 print "</rpc-reply>";
308 if ($subop == "getAllCounters") {
310 getLabelCounters($link);
311 getFeedCounters($link);
312 getTagCounters($link);
313 getGlobalCounters($link);
314 print "</rpc-reply>";
317 if ($subop == "mark") {
318 $mark = $_GET["mark"];
319 $id = db_escape_string($_GET["id"]);
327 $result = db_query($link, "UPDATE ttrss_entries SET marked = $mark
331 if ($subop == "updateFeed") {
332 $feed_id = db_escape_string($_GET["feed"]);
334 $result = db_query($link,
335 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'");
337 if (db_num_rows($result) > 0) {
338 $feed_url = db_fetch_result($result, 0, "feed_url");
339 // update_rss_feed($link, $feed_url, $feed_id);
342 print "DONE-$feed_id";
347 if ($subop == "forceUpdateAllFeeds" ||
$subop == "updateAllFeeds") {
349 update_all_feeds($link, true);
351 $omode = $_GET["omode"];
353 if (!$omode) $omode = "tfl";
356 if (strchr($omode, "l")) getLabelCounters($link);
357 if (strchr($omode, "f")) getFeedCounters($link);
358 if (strchr($omode, "t")) getTagCounters($link);
359 getGlobalCounters($link);
360 print "</rpc-reply>";
363 if ($subop == "catchupPage") {
365 $ids = split(",", $_GET["ids"]);
367 foreach ($ids as $id) {
369 db_query($link, "UPDATE ttrss_entries SET unread=false,last_read = NOW()
374 print "Marked active page as read.";
377 if ($subop == "sanityCheck") {
381 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
383 $schema_version = db_fetch_result($result, 0, "schema_version");
385 if ($schema_version != SCHEMA_VERSION
) {
389 print "<error code='$error_code'/>";
393 if ($op == "feeds") {
395 $tags = $_GET["tags"];
397 $subop = $_GET["subop"];
399 if ($subop == "catchupAll") {
400 db_query($link, "UPDATE ttrss_entries SET last_read = NOW(),unread = false");
403 outputFeedList($link, $tags);
410 $feed_id = $_GET["feed"];
412 $result = db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'");
414 $addheader = $_GET["addheader"];
416 $result = db_query($link, "SELECT title,link,content,feed_id,comments,
417 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
423 <title>Tiny Tiny RSS : Article $id</title>
424 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
425 <script type=\"text/javascript\" src=\"functions.js\"></script>
426 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
432 $line = db_fetch_assoc($result);
434 if ($line["icon_url"]) {
435 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
437 $feed_icon = " ";
440 if ($line["comments"] && $line["link"] != $line["comments"]) {
441 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
443 $entry_comments = "";
446 print "<div class=\"postReply\">";
448 print "<div class=\"postHeader\"><table>";
450 print "<tr><td><b>Title:</b></td>
451 <td width='100%'>" . $line["title"] . "</td></tr>";
453 print "<tr><td><b>Link:</b></td>
455 <a href=\"" . $line["link"] . "\">".$line["link"]."</a>
456 $entry_comments</td></tr>";
458 print "</table></div>";
460 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
461 print "<div class=\"postContent\">" . $line["content"] . "</div>";
465 print "<script type=\"text/javascript\">
466 update_label_counters('$feed_id');
471 print "</body></html>";
475 if ($op == "viewfeed") {
477 $feed = $_GET["feed"];
478 $skip = $_GET["skip"];
479 $subop = $_GET["subop"];
480 $view_mode = $_GET["view"];
481 $addheader = $_GET["addheader"];
482 $limit = $_GET["limit"];
485 print "Error: no feed to display.";
489 if (!$skip) $skip = 0;
491 if ($subop == "undefined") $subop = "";
495 <title>Tiny Tiny RSS : Feed $feed</title>
496 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
498 if (USE_COMPACT_STYLESHEET
) {
499 print "<link rel=\"stylesheet\"
500 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
503 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
504 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
506 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
507 <script type=\"text/javascript\" src=\"functions.js\"></script>
508 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
509 </head><body onload='init()'>";
512 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
514 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
515 WHERE id = '$feed'");
517 $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
519 update_rss_feed($link, $feed_url, $feed);
523 if ($subop == "MarkAllRead") {
525 if (sprintf("%d", $feed) != 0) {
528 db_query($link, "UPDATE ttrss_entries
529 SET unread = false,last_read = NOW()
530 WHERE feed_id = '$feed'");
532 } else if ($feed < 0 && $feed > -10) { // special, like starred
535 db_query($link, "UPDATE ttrss_entries
536 SET unread = false,last_read = NOW()
537 WHERE marked = true");
540 } else if ($feed < -10) { // label
542 $label_id = -$feed - 11;
544 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
545 WHERE id = '$label_id'");
548 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
550 db_query($link, "UPDATE ttrss_entries
551 SET unread = false,last_read = NOW()
556 // FIXME, implement catchup for tags
561 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
563 $search = $_GET["search"];
565 $search_mode = $_GET["smode"];
568 $search_query_part = "(upper(title) LIKE upper('%$search%')
569 OR content LIKE '%$search%') AND";
571 $search_query_part = "";
574 $view_query_part = "";
576 if ($view_mode == "Starred") {
577 $view_query_part = " marked = true AND ";
580 if ($view_mode == "Unread") {
581 $view_query_part = " unread = true AND ";
584 if ($view_mode == "Unread or Starred") {
585 $view_query_part = " (unread = true OR marked = true) AND ";
588 if ($view_mode == "Unread or Updated") {
589 $view_query_part = " (unread = true OR last_read is NULL) AND ";
592 /* $result = db_query($link, "SELECT count(id) AS total_entries
593 FROM ttrss_entries WHERE
597 $total_entries = db_fetch_result($result, 0, "total_entries"); */
599 /* $result = db_query("SELECT count(id) AS unread_entries
600 FROM ttrss_entries WHERE
605 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
607 if ($limit && $limit != "All") {
608 $limit_query_part = "LIMIT " . $limit;
611 $vfeed_query_part = "";
613 // override query strategy and enable feed display when searching globally
614 if ($search_mode == "All feeds") {
615 $query_strategy_part = "id > 0";
616 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
617 id = feed_id) as feed_title,";
618 } else if (sprintf("%d", $feed) == 0) {
619 $query_strategy_part = "ttrss_entries.id > 0";
620 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
621 id = feed_id) as feed_title,";
622 } else if ($feed >= 0) {
623 $query_strategy_part = "feed_id = '$feed'";
624 } else if ($feed == -1) { // starred virtual feed
625 $query_strategy_part = "marked = true";
626 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
627 id = feed_id) as feed_title,";
628 } else if ($feed <= -10) { // labels
629 $label_id = -$feed - 11;
631 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
632 WHERE id = '$label_id'");
634 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
636 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
637 id = feed_id) as feed_title,";
639 $query_strategy_part = "id > 0"; // dumb
643 $order_by = "updated DESC";
645 // if ($feed < -10) {
646 // $order_by = "feed_id,updated DESC";
649 if ($feed < -10) error_reporting (0);
651 if (sprintf("%d", $feed) != 0) {
653 $result = db_query($link, "SELECT
654 id,title,updated,unread,feed_id,marked,link,last_read,
655 SUBSTRING(last_read,1,19) as last_read_noms,
657 SUBSTRING(updated,1,19) as updated_noms
663 $query_strategy_part ORDER BY $order_by
669 $result = db_query($link, "SELECT
670 ttrss_entries.id as id,title,updated,unread,feed_id,
671 marked,link,last_read,
672 SUBSTRING(last_read,1,19) as last_read_noms,
674 SUBSTRING(updated,1,19) as updated_noms
676 ttrss_entries,ttrss_tags
678 post_id = ttrss_entries.id AND tag_name = '$feed' AND
681 $query_strategy_part ORDER BY $order_by
686 print "<tr><td colspan='4' align='center'>
687 Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>";
693 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
697 while ($line = db_fetch_assoc($result)) {
699 $class = ($lnum %
2) ?
"even" : "odd";
702 $feed_id = $line["feed_id"];
704 // printf("L %d (%s) > U %d (%s) = %d<br>",
705 // strtotime($line["last_read_noms"]), $line["last_read_noms"],
706 // strtotime($line["updated"]), $line["updated"],
707 // strtotime($line["last_read"]) >= strtotime($line["updated"]));
709 /* if ($line["last_read"] != "" && $line["updated"] != "" &&
710 strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) {
712 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
717 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
722 if ($line["last_read"] == "" &&
723 ($line["unread"] != "t" && $line["unread"] != "1")) {
725 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
728 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
732 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
737 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
738 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
739 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
741 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
742 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
745 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
746 $line["title"] . "</a>";
748 print "<tr class='$class' id='RROW-$id'>";
749 // onclick=\"javascript:view($id,$feed_id)\">
751 print "<td valign='center' align='center'>$update_pic</td>";
752 print "<td valign='center' align='center'>$marked_pic</td>";
754 print "<td width='25%'>
755 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
757 if ($line["feed_title"]) {
758 print "<td width='50%'>$content_link</td>";
759 print "<td width='20%'>
760 <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a></td>";
762 print "<td width='70%'>$content_link</td>";
771 print "<tr><td align='center'>No articles found.</td></tr>";
776 print "<script type=\"text/javascript\">
777 document.onkeydown = hotkey_handler;
778 update_label_counters('$feed');
782 print "</body></html>";
787 if ($op == "pref-rpc") {
789 $subop = $_GET["subop"];
791 if ($subop == "unread") {
792 $ids = split(",", $_GET["ids"]);
793 foreach ($ids as $id) {
794 db_query($link, "UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'");
797 print "Marked selected feeds as read.";
800 if ($subop == "read") {
801 $ids = split(",", $_GET["ids"]);
802 foreach ($ids as $id) {
803 db_query($link, "UPDATE ttrss_entries
804 SET unread = false,last_read = NOW() WHERE feed_id = '$id'");
807 print "Marked selected feeds as unread.";
813 if ($op == "pref-feeds") {
815 $subop = $_GET["subop"];
817 if ($subop == "editSave") {
818 $feed_title = db_escape_string($_GET["t"]);
819 $feed_link = db_escape_string($_GET["l"]);
820 $upd_intl = db_escape_string($_GET["ui"]);
821 $purge_intl = db_escape_string($_GET["pi"]);
822 $feed_id = $_GET["id"];
824 if (strtoupper($upd_intl) == "DEFAULT")
827 if (strtoupper($purge_intl) == "DEFAULT")
830 if (strtoupper($purge_intl) == "DISABLED")
833 $result = db_query($link, "UPDATE ttrss_feeds SET
834 title = '$feed_title', feed_url = '$feed_link',
835 update_interval = '$upd_intl',
836 purge_interval = '$purge_intl'
837 WHERE id = '$feed_id'");
841 if ($subop == "remove") {
843 if (!WEB_DEMO_MODE
) {
845 $ids = split(",", $_GET["ids"]);
847 foreach ($ids as $id) {
848 db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'");
850 if (file_exists(ICONS_DIR
. "/$id.ico")) {
851 unlink(ICONS_DIR
. "/$id.ico");
857 if ($subop == "add") {
859 if (!WEB_DEMO_MODE
) {
861 $feed_link = db_escape_string($_GET["link"]);
863 $result = db_query($link,
864 "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')");
866 $result = db_query($link,
867 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'");
869 $feed_id = db_fetch_result($result, 0, "id");
872 update_rss_feed($link, $feed_link, $feed_id);
877 $result = db_query($link, "SELECT id,title,feed_url,last_error
878 FROM ttrss_feeds WHERE last_error != ''");
880 if (db_num_rows($result) > 0) {
882 print "<div class=\"warning\">";
884 print "<b>Feeds with update errors:</b>";
886 print "<ul class=\"nomarks\">";
888 while ($line = db_fetch_assoc($result)) {
889 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
898 print "<table class=\"prefAddFeed\"><tr>
899 <td><input id=\"fadd_link\"></td>
900 <td colspan=\"4\" align=\"right\">
901 <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr>
904 $result = db_query($link, "SELECT
905 id,title,feed_url,substring(last_updated,1,16) as last_updated,
906 update_interval,purge_interval
908 ttrss_feeds ORDER by title");
910 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
911 print "<tr class=\"title\">
912 <td> </td><td>Select</td><td width=\"30%\">Title</td>
913 <td width=\"30%\">Link</td>
914 <td width=\"10%\">Update Interval</td>
915 <td width=\"10%\">Purge Days</td>
916 <td>Last updated</td></tr>";
920 while ($line = db_fetch_assoc($result)) {
922 $class = ($lnum %
2) ?
"even" : "odd";
924 $feed_id = $line["id"];
926 $edit_feed_id = $_GET["id"];
928 if ($subop == "edit" && $feed_id != $edit_feed_id) {
932 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
934 $icon_file = ICONS_DIR
. "/$feed_id.ico";
936 if (file_exists($icon_file) && filesize($icon_file) > 0) {
937 $feed_icon = "<img width=\"16\" height=\"16\"
938 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
940 $feed_icon = " ";
942 print "<td align='center'>$feed_icon</td>";
944 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
945 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
947 if (!$edit_feed_id ||
$subop != "edit") {
949 print "<td><input onclick='toggleSelectRow(this);'
950 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
952 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
953 $edit_title . "</a></td>";
954 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
955 $edit_link . "</a></td>";
957 if ($line["update_interval"] == "0")
958 $line["update_interval"] = "Default";
960 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
961 $line["update_interval"] . "</a></td>";
963 if ($line["purge_interval"] == "0")
964 $line["purge_interval"] = "Default";
966 if ($line["purge_interval"] < 0)
967 $line["purge_interval"] = "Disabled";
969 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
970 $line["purge_interval"] . "</a></td>";
972 } else if ($feed_id != $edit_feed_id) {
974 print "<td><input disabled=\"true\" type=\"checkbox\"
975 id=\"FRCHK-".$line["id"]."\"></td>";
977 print "<td>$edit_title</td>";
978 print "<td>$edit_link</td>";
980 if ($line["update_interval"] == "0")
981 $line["update_interval"] = "Default";
983 print "<td>" . $line["update_interval"] . "</td>";
985 if ($line["purge_interval"] == "0")
986 $line["purge_interval"] = "Default";
988 if ($line["purge_interval"] < 0)
989 $line["purge_interval"] = "Disabled";
991 print "<td>" . $line["purge_interval"] . "</td>";
995 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
997 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
998 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
999 print "<td><input id=\"iedit_updintl\" value=\"".$line["update_interval"]."\"></td>";
1000 print "<td><input id=\"iedit_purgintl\" value=\"".$line["purge_interval"]."\"></td>";
1004 if (!$line["last_updated"]) $line["last_updated"] = "Never";
1006 print "<td>" . $line["last_updated"] . "</td>";
1014 print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>";
1021 if ($subop == "edit") {
1022 print "Edit feed:
1023 <input type=\"submit\" class=\"button\"
1024 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
1025 <input type=\"submit\" class=\"button\"
1026 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1031 <input type=\"submit\" class=\"button\"
1032 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
1033 <input type=\"submit\" class=\"button\"
1034 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
1036 if (ENABLE_PREFS_CATCHUP_UNCATCHUP
) {
1038 <input type=\"submit\" class=\"button\"
1039 onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\">
1040 <input type=\"submit\" class=\"button\"
1041 onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\"> ";
1045 <input type=\"submit\"
1046 class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">";
1050 print "<h3>OPML Import</h3>
1051 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1052 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">
1053 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
1054 type=\"submit\" value=\"Import\">
1059 if ($op == "pref-filters") {
1061 $subop = $_GET["subop"];
1063 if ($subop == "editSave") {
1065 $regexp = db_escape_string($_GET["r"]);
1066 $descr = db_escape_string($_GET["d"]);
1067 $match = db_escape_string($_GET["m"]);
1068 $filter_id = db_escape_string($_GET["id"]);
1070 $result = db_query($link, "UPDATE ttrss_filters SET
1071 reg_exp = '$regexp',
1072 description = '$descr',
1073 filter_type = (SELECT id FROM ttrss_filter_types WHERE
1074 description = '$match')
1075 WHERE id = '$filter_id'");
1078 if ($subop == "remove") {
1080 if (!WEB_DEMO_MODE
) {
1082 $ids = split(",", $_GET["ids"]);
1084 foreach ($ids as $id) {
1085 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
1091 if ($subop == "add") {
1093 if (!WEB_DEMO_MODE
) {
1095 $regexp = db_escape_string($_GET["regexp"]);
1096 $match = db_escape_string($_GET["match"]);
1098 $result = db_query($link,
1099 "INSERT INTO ttrss_filters (reg_exp,filter_type) VALUES
1100 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
1101 description = '$match'))");
1105 $result = db_query($link, "SELECT description
1106 FROM ttrss_filter_types ORDER BY description");
1108 $filter_types = array();
1110 while ($line = db_fetch_assoc($result)) {
1111 array_push($filter_types, $line["description"]);
1114 print "<table class=\"prefAddFeed\"><tr>
1115 <td><input id=\"fadd_regexp\"></td>
1117 print_select("fadd_match", "Title", $filter_types);
1119 print"</td><td colspan=\"4\" align=\"right\">
1120 <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr>
1123 $result = db_query($link, "SELECT
1124 id,reg_exp,description,
1125 (SELECT name FROM ttrss_filter_types WHERE
1126 id = filter_type) as filter_type_name,
1127 (SELECT description FROM ttrss_filter_types
1128 WHERE id = filter_type) as filter_type_descr
1130 ttrss_filters ORDER by reg_exp");
1132 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
1134 print "<tr class=\"title\">
1135 <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td>
1136 <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>";
1140 while ($line = db_fetch_assoc($result)) {
1142 $class = ($lnum %
2) ?
"even" : "odd";
1144 $filter_id = $line["id"];
1145 $edit_filter_id = $_GET["id"];
1147 if ($subop == "edit" && $filter_id != $edit_filter_id) {
1151 print "<tr class=\"$class\" id=\"FILRR-$filter_id\">";
1153 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
1154 $line["description"] = htmlspecialchars($line["description"]);
1156 if (!$edit_filter_id ||
$subop != "edit") {
1158 if (!$line["description"]) $line["description"] = "[No description]";
1160 print "<td><input onclick='toggleSelectRow(this);'
1161 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
1163 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1164 $line["reg_exp"] . "</td>";
1166 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1167 $line["description"] . "</td>";
1169 print "<td>".$line["filter_type_descr"]."</td>";
1171 } else if ($filter_id != $edit_filter_id) {
1173 if (!$line["description"]) $line["description"] = "[No description]";
1175 print "<td><input disabled=\"true\" type=\"checkbox\"
1176 id=\"FICHK-".$line["id"]."\"></td>";
1178 print "<td>".$line["reg_exp"]."</td>";
1179 print "<td>".$line["description"]."</td>";
1180 print "<td>".$line["filter_type_descr"]."</td>";
1184 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
1186 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
1189 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1193 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
1205 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
1212 if ($subop == "edit") {
1214 <input type=\"submit\" class=\"button\"
1215 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
1216 <input type=\"submit\" class=\"button\"
1217 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
1223 <input type=\"submit\" class=\"button\"
1224 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
1225 <input type=\"submit\" class=\"button\"
1226 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
1230 if ($op == "pref-labels") {
1232 $subop = $_GET["subop"];
1234 if ($subop == "editSave") {
1236 $sql_exp = $_GET["s"];
1237 $descr = $_GET["d"];
1238 $label_id = db_escape_string($_GET["id"]);
1240 // print "$sql_exp : $descr : $label_id";
1242 $result = db_query($link, "UPDATE ttrss_labels SET
1243 sql_exp = '$sql_exp',
1244 description = '$descr'
1245 WHERE id = '$label_id'");
1248 if ($subop == "remove") {
1250 if (!WEB_DEMO_MODE
) {
1252 $ids = split(",", $_GET["ids"]);
1254 foreach ($ids as $id) {
1255 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
1261 if ($subop == "add") {
1263 if (!WEB_DEMO_MODE
) {
1265 $exp = $_GET["exp"];
1267 $result = db_query($link,
1268 "INSERT INTO ttrss_labels (sql_exp,description)
1269 VALUES ('$exp', '$exp')");
1273 print "<table class=\"prefAddFeed\"><tr>
1274 <td><input id=\"ladd_expr\"></td>";
1276 print"<td colspan=\"4\" align=\"right\">
1277 <a class=\"button\" href=\"javascript:addLabel()\">Add label</a></td></tr>
1280 $result = db_query($link, "SELECT
1281 id,sql_exp,description
1283 ttrss_labels ORDER by description");
1285 print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">";
1287 print "<tr class=\"title\">
1288 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
1289 <a class=\"helpLink\" href=\"javascript:popupHelp(1)\">(?)</a>
1291 <td width=\"40%\">Caption</td></tr>";
1295 while ($line = db_fetch_assoc($result)) {
1297 $class = ($lnum %
2) ?
"even" : "odd";
1299 $label_id = $line["id"];
1300 $edit_label_id = $_GET["id"];
1302 if ($subop == "edit" && $label_id != $edit_label_id) {
1306 print "<tr class=\"$class\" id=\"LILRR-$label_id\">";
1308 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
1309 $line["description"] = htmlspecialchars($line["description"]);
1311 if (!$edit_label_id ||
$subop != "edit") {
1313 if (!$line["description"]) $line["description"] = "[No caption]";
1315 print "<td><input onclick='toggleSelectRow(this);'
1316 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
1318 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1319 $line["sql_exp"] . "</td>";
1321 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1322 $line["description"] . "</td>";
1324 } else if ($label_id != $edit_label_id) {
1326 if (!$line["description"]) $line["description"] = "[No description]";
1328 print "<td><input disabled=\"true\" type=\"checkbox\"
1329 id=\"LICHK-".$line["id"]."\"></td>";
1331 print "<td>".$line["sql_exp"]."</td>";
1332 print "<td>".$line["description"]."</td>";
1336 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
1338 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
1341 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1353 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
1360 if ($subop == "edit") {
1362 <input type=\"submit\" class=\"button\"
1363 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
1364 <input type=\"submit\" class=\"button\"
1365 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
1371 <input type=\"submit\" class=\"button\"
1372 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
1373 <input type=\"submit\" class=\"button\"
1374 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
1378 if ($op == "error") {
1379 print "<div width=\"100%\" align='center'>";
1380 $msg = $_GET["msg"];
1385 if ($op == "help") {
1387 <title>Tiny Tiny RSS : Help</title>
1388 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
1389 <script type=\"text/javascript\" src=\"functions.js\"></script>
1390 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1393 $tid = sprintf("%d", $_GET["tid"]);
1395 /* FIXME this badly needs real implementation */
1397 print "<div class='helpResponse'>";
1401 <h1
>Help
for SQL expressions
</h1
>
1403 <h2
>Description
</h2
>
1405 <p
>The
«
;SQL expression
»
; is added to WHERE clause of
1406 view feed query
. You can match on ttrss_entries table fields
1407 and even
use subselect to query additional information
. This
1408 functionality is considered to be advanced
and requires basic
1409 understanding of SQL
.</p
>
1413 <pre
>unread
= true</pre
>
1415 Matches all unread articles
1417 <pre
>title like
'%Linux%'</pre
>
1419 Matches all articles which mention Linux in the title
. You get the idea
.
1421 <p
>See the database schema included in the distribution package
for gruesome
1426 print "<div align='center'>
1427 <a class=\"helpLink\"
1428 href=\"javascript:window.close()\">(Close this window)</a></div>";
1432 print "</body></html>";
1438 $param = $_GET["param"];
1440 if ($id == "quickAddFeed") {
1441 print "Feed URL: <input
1442 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1444 <input class=\"button\"
1445 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
1446 <input class=\"button\"
1447 type=\"submit\" onclick=\"javascript:closeDlg()\"
1451 if ($id == "quickDelFeed") {
1453 $param = db_escape_string($param);
1455 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
1459 $f_title = db_fetch_result($result, 0, "title");
1461 print "Remove current feed ($f_title)?
1462 <input class=\"button\"
1463 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
1464 <input class=\"button\"
1465 type=\"submit\" onclick=\"javascript:closeDlg()\"
1468 print "Error: Feed $param not found.
1469 <input class=\"button\"
1470 type=\"submit\" onclick=\"javascript:closeDlg()\"
1475 if ($id == "search") {
1477 print "<input id=\"searchbox\" class=\"extSearch\"
1478 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1479 onchange=\"javascript:search()\">
1480 <select id=\"searchmodebox\">
1481 <option selected>All feeds</option>
1482 <option>This feed</option>
1484 <input type=\"submit\"
1485 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
1486 <input class=\"button\"
1487 type=\"submit\" onclick=\"javascript:closeDlg()\"
1494 if ($op == "updateAllFeeds") {
1495 update_all_feeds($link, true);
1497 print "<rpc-reply>";
1498 getLabelCounters($link);
1499 getFeedCounters($link);
1500 getTagCounters($link);
1501 getGlobalCounters($link);
1502 print "</rpc-reply>";
1509 <!-- <?
= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?
> -->