4 define(SCHEMA_VERSION
, 2);
6 require_once "config.php";
8 require_once "db-prefs.php";
9 require_once "functions.php";
10 require_once "magpierss/rss_fetch.inc";
12 $_SESSION["uid"] = PLACEHOLDER_UID
; // FIXME: placeholder
14 $op = $_REQUEST["op"];
16 if ($op == "rpc" ||
$op == "updateAllFeeds") {
17 header("Content-Type: application/xml");
20 $script_started = getmicrotime();
22 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
25 if (DB_TYPE
== "mysql") {
28 // PG seems to display its own errors just fine by default.
32 if (DB_TYPE
== "pgsql") {
33 pg_query("set client_encoding = 'utf-8'");
37 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
39 $schema_version = db_fetch_result($result, 0, "schema_version");
41 if ($schema_version != SCHEMA_VERSION) {
42 print "Error: database schema is invalid
43 (got version $schema_version; expected ".SCHEMA_VERSION.")";
48 $fetch = $_GET["fetch"];
50 /* FIXME this needs reworking */
52 function getGlobalCounters($link) {
53 $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries
54 WHERE unread = true AND owner_uid = " . $_SESSION["uid"]);
55 $c_id = db_fetch_result($result, 0, "c_id");
56 print "<counter id='global-unread' counter='$c_id'/>";
59 function getTagCounters($link) {
60 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
61 FROM ttrss_tags,ttrss_entries WHERE
62 ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND
63 post_id = ttrss_entries.id AND unread = true GROUP BY tag_name
65 select tag_name,0 as count FROM ttrss_tags
66 WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]);
70 while ($line = db_fetch_assoc($result)) {
71 $tags[$line["tag_name"]] +
= $line["count"];
74 foreach (array_keys($tags) as $tag) {
75 $unread = $tags[$tag];
77 $tag = htmlspecialchars($tag);
78 print "<tag id=\"$tag\" counter=\"$unread\"/>";
82 function getLabelCounters($link) {
84 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
85 WHERE marked = true AND unread = true AND owner_uid = ".$_SESSION["uid"]);
87 $count = db_fetch_result($result, 0, "count");
89 print "<label id=\"-1\" counter=\"$count\"/>";
91 $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM
92 ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description");
94 while ($line = db_fetch_assoc($result)) {
96 $id = -$line["id"] - 11;
100 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
101 WHERE (" . $line["sql_exp"] . ") AND unread = true");
103 $count = db_fetch_result($tmp_result, 0, "count");
105 print "<label id=\"$id\" counter=\"$count\"/>";
107 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
112 function getFeedCounter($link, $id) {
114 $result = db_query($link, "SELECT
115 count(id) as count FROM ttrss_entries
116 WHERE feed_id = '$id' AND unread = true");
118 $count = db_fetch_result($result, 0, "count");
120 print "<feed id=\"$id\" counter=\"$count\"/>";
123 function getFeedCounters($link) {
125 $result = db_query($link, "SELECT id,
126 (SELECT count(id) FROM ttrss_entries WHERE feed_id = ttrss_feeds.id
127 AND unread = true) as count
128 FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]);
130 while ($line = db_fetch_assoc($result)) {
133 $count = $line["count"];
135 print "<feed id=\"$id\" counter=\"$count\"/>";
139 function outputFeedList($link, $tags = false) {
142 <title>Tiny Tiny RSS : Feedlist</title>
143 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
145 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
146 print "<link rel=\"stylesheet\" type=\"text/css\"
147 href=\"tt-rss_compact.css\"/>";
149 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
150 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
153 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
154 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
155 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
156 </head><body onload=\"init()\">";
158 print "<ul class=\"feedList\" id=\"feedList\">";
160 $owner_uid = $_SESSION["uid"];
166 $result = db_query($link, "SELECT count(id) as num_starred
167 FROM ttrss_entries WHERE marked = true AND unread = true AND owner_uid = '$owner_uid'");
168 $num_starred = db_fetch_result($result, 0, "num_starred");
172 if ($num_starred > 0) $class .= "Unread";
174 printFeedEntry(-1, $class, "Starred articles", $num_starred,
175 "images/mark_set.png", $link);
177 if (get_pref($link, 'ENABLE_LABELS')) {
179 $result = db_query($link, "SELECT id,sql_exp,description FROM
180 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
182 if (db_num_rows($result) > 0) {
183 print "<li><hr></li>";
186 while ($line = db_fetch_assoc($result)) {
190 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
191 WHERE (" . $line["sql_exp"] . ") AND unread = true");
193 $count = db_fetch_result($tmp_result, 0, "count");
201 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
203 printFeedEntry(-$line["id"]-11,
204 $class, $line["description"], $count, "images/label.png", $link);
209 print "<li><hr></li>";
211 $result = db_query($link, "SELECT *,
212 (SELECT count(id) FROM ttrss_entries
213 WHERE feed_id = ttrss_feeds.id) AS total,
214 (SELECT count(id) FROM ttrss_entries
215 WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
216 FROM ttrss_feeds WHERE owner_uid = '$owner_uid' ORDER BY title");
218 $actid = $_GET["actid"];
226 while ($line = db_fetch_assoc($result)) {
228 $feed = $line["title"];
229 $feed_id = $line["id"];
231 $subop = $_GET["subop"];
233 $total = $line["total"];
234 $unread = $line["unread"];
236 // $class = ($lnum % 2) ? "even" : "odd";
240 if ($unread > 0) $class .= "Unread";
242 if ($actid == $feed_id) {
243 $class .= "Selected";
246 $total_unread +
= $unread;
248 printFeedEntry($feed_id, $class, $feed, $unread, "icons/$feed_id.ico", $link);
256 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
257 FROM ttrss_tags,ttrss_entries WHERE
258 post_id = ttrss_entries.id AND unread = true
259 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
261 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'");
265 while ($line = db_fetch_assoc($result)) {
266 $tags[$line["tag_name"]] +
= $line["count"];
269 foreach (array_keys($tags) as $tag) {
271 $unread = $tags[$tag];
279 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
285 if (db_num_rows($result) == 0) {
286 print "<li>No tags/feeds to display.</li>";
291 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
298 $subop = $_GET["subop"];
300 if ($subop == "getLabelCounters") {
303 getLabelCounters($link);
305 getFeedCounter($link, $aid);
307 print "</rpc-reply>";
310 if ($subop == "getFeedCounters") {
312 getFeedCounters($link);
313 print "</rpc-reply>";
316 if ($subop == "getAllCounters") {
318 getLabelCounters($link);
319 getFeedCounters($link);
320 getTagCounters($link);
321 getGlobalCounters($link);
322 print "</rpc-reply>";
325 if ($subop == "mark") {
326 $mark = $_GET["mark"];
327 $id = db_escape_string($_GET["id"]);
335 $result = db_query($link, "UPDATE ttrss_entries SET marked = $mark
339 if ($subop == "updateFeed") {
340 $feed_id = db_escape_string($_GET["feed"]);
342 $result = db_query($link,
343 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'");
345 if (db_num_rows($result) > 0) {
346 $feed_url = db_fetch_result($result, 0, "feed_url");
347 // update_rss_feed($link, $feed_url, $feed_id);
350 print "DONE-$feed_id";
355 if ($subop == "forceUpdateAllFeeds" ||
$subop == "updateAllFeeds") {
357 update_all_feeds($link, true);
359 $omode = $_GET["omode"];
361 if (!$omode) $omode = "tfl";
364 if (strchr($omode, "l")) getLabelCounters($link);
365 if (strchr($omode, "f")) getFeedCounters($link);
366 if (strchr($omode, "t")) getTagCounters($link);
367 getGlobalCounters($link);
368 print "</rpc-reply>";
371 if ($subop == "catchupPage") {
373 $ids = split(",", $_GET["ids"]);
375 foreach ($ids as $id) {
377 db_query($link, "UPDATE ttrss_entries SET unread=false,last_read = NOW()
382 print "Marked active page as read.";
385 if ($subop == "sanityCheck") {
389 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
391 $schema_version = db_fetch_result($result, 0, "schema_version");
393 if ($schema_version != SCHEMA_VERSION
) {
397 print "<error code='$error_code'/>";
401 if ($op == "feeds") {
403 $tags = $_GET["tags"];
405 $subop = $_GET["subop"];
407 if ($subop == "catchupAll") {
408 db_query($link, "UPDATE ttrss_entries SET last_read = NOW(),unread = false");
411 outputFeedList($link, $tags);
418 $feed_id = $_GET["feed"];
420 $result = db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'");
422 $addheader = $_GET["addheader"];
424 $result = db_query($link, "SELECT title,link,content,feed_id,comments,
425 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
431 <title>Tiny Tiny RSS : Article $id</title>
432 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
433 <script type=\"text/javascript\" src=\"functions.js\"></script>
434 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
440 $line = db_fetch_assoc($result);
442 if ($line["icon_url"]) {
443 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
445 $feed_icon = " ";
448 if ($line["comments"] && $line["link"] != $line["comments"]) {
449 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
451 $entry_comments = "";
454 print "<div class=\"postReply\">";
456 print "<div class=\"postHeader\"><table>";
458 print "<tr><td><b>Title:</b></td>
459 <td width='100%'>" . $line["title"] . "</td></tr>";
461 print "<tr><td><b>Link:</b></td>
463 <a href=\"" . $line["link"] . "\">".$line["link"]."</a>
464 $entry_comments</td></tr>";
466 print "</table></div>";
468 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
469 print "<div class=\"postContent\">" . $line["content"] . "</div>";
473 print "<script type=\"text/javascript\">
474 update_label_counters('$feed_id');
479 print "</body></html>";
483 if ($op == "viewfeed") {
485 $feed = $_GET["feed"];
486 $skip = $_GET["skip"];
487 $subop = $_GET["subop"];
488 $view_mode = $_GET["view"];
489 $addheader = $_GET["addheader"];
490 $limit = $_GET["limit"];
493 print "Error: no feed to display.";
497 if (!$skip) $skip = 0;
499 if ($subop == "undefined") $subop = "";
503 <title>Tiny Tiny RSS : Feed $feed</title>
504 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
506 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
507 print "<link rel=\"stylesheet\"
508 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
511 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
512 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
514 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
515 <script type=\"text/javascript\" src=\"functions.js\"></script>
516 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
517 </head><body onload='init()'>";
520 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
522 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
523 WHERE id = '$feed'");
525 $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
527 update_rss_feed($link, $feed_url, $feed);
531 if ($subop == "MarkAllRead") {
533 if (sprintf("%d", $feed) != 0) {
536 db_query($link, "UPDATE ttrss_entries
537 SET unread = false,last_read = NOW()
538 WHERE feed_id = '$feed'");
540 } else if ($feed < 0 && $feed > -10) { // special, like starred
543 db_query($link, "UPDATE ttrss_entries
544 SET unread = false,last_read = NOW()
545 WHERE marked = true");
548 } else if ($feed < -10) { // label
550 $label_id = -$feed - 11;
552 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
553 WHERE id = '$label_id'");
556 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
558 db_query($link, "UPDATE ttrss_entries
559 SET unread = false,last_read = NOW()
564 // FIXME, implement catchup for tags
569 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
571 $search = $_GET["search"];
573 $search_mode = $_GET["smode"];
576 $search_query_part = "(upper(title) LIKE upper('%$search%')
577 OR content LIKE '%$search%') AND";
579 $search_query_part = "";
582 $view_query_part = "";
584 if ($view_mode == "Starred") {
585 $view_query_part = " marked = true AND ";
588 if ($view_mode == "Unread") {
589 $view_query_part = " unread = true AND ";
592 if ($view_mode == "Unread or Starred") {
593 $view_query_part = " (unread = true OR marked = true) AND ";
596 if ($view_mode == "Unread or Updated") {
597 $view_query_part = " (unread = true OR last_read is NULL) AND ";
600 /* $result = db_query($link, "SELECT count(id) AS total_entries
601 FROM ttrss_entries WHERE
605 $total_entries = db_fetch_result($result, 0, "total_entries"); */
607 /* $result = db_query("SELECT count(id) AS unread_entries
608 FROM ttrss_entries WHERE
613 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
615 if ($limit && $limit != "All") {
616 $limit_query_part = "LIMIT " . $limit;
619 $vfeed_query_part = "";
621 // override query strategy and enable feed display when searching globally
622 if ($search_mode == "All feeds") {
623 $query_strategy_part = "id > 0";
624 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
625 id = feed_id) as feed_title,";
626 } else if (sprintf("%d", $feed) == 0) {
627 $query_strategy_part = "ttrss_entries.id > 0";
628 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
629 id = feed_id) as feed_title,";
630 } else if ($feed >= 0) {
631 $query_strategy_part = "feed_id = '$feed'";
632 } else if ($feed == -1) { // starred virtual feed
633 $query_strategy_part = "marked = true";
634 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
635 id = feed_id) as feed_title,";
636 } else if ($feed <= -10) { // labels
637 $label_id = -$feed - 11;
639 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
640 WHERE id = '$label_id'");
642 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
644 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
645 id = feed_id) as feed_title,";
647 $query_strategy_part = "id > 0"; // dumb
651 $order_by = "updated DESC";
653 // if ($feed < -10) {
654 // $order_by = "feed_id,updated DESC";
657 if ($feed < -10) error_reporting (0);
659 if (sprintf("%d", $feed) != 0) {
661 $result = db_query($link, "SELECT
662 id,title,updated,unread,feed_id,marked,link,last_read,
663 SUBSTRING(last_read,1,19) as last_read_noms,
665 SUBSTRING(updated,1,19) as updated_noms
671 $query_strategy_part ORDER BY $order_by
677 $result = db_query($link, "SELECT
678 ttrss_entries.id as id,title,updated,unread,feed_id,
679 marked,link,last_read,
680 SUBSTRING(last_read,1,19) as last_read_noms,
682 SUBSTRING(updated,1,19) as updated_noms
684 ttrss_entries,ttrss_tags
686 post_id = ttrss_entries.id AND tag_name = '$feed' AND
689 $query_strategy_part ORDER BY $order_by
694 print "<tr><td colspan='4' align='center'>
695 Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>";
701 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
705 while ($line = db_fetch_assoc($result)) {
707 $class = ($lnum %
2) ?
"even" : "odd";
710 $feed_id = $line["feed_id"];
712 // printf("L %d (%s) > U %d (%s) = %d<br>",
713 // strtotime($line["last_read_noms"]), $line["last_read_noms"],
714 // strtotime($line["updated"]), $line["updated"],
715 // strtotime($line["last_read"]) >= strtotime($line["updated"]));
717 /* if ($line["last_read"] != "" && $line["updated"] != "" &&
718 strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) {
720 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
725 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
730 if ($line["last_read"] == "" &&
731 ($line["unread"] != "t" && $line["unread"] != "1")) {
733 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
736 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
740 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
745 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
746 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
747 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
749 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
750 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
753 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
754 $line["title"] . "</a>";
756 print "<tr class='$class' id='RROW-$id'>";
757 // onclick=\"javascript:view($id,$feed_id)\">
759 print "<td valign='center' align='center'>$update_pic</td>";
760 print "<td valign='center' align='center'>$marked_pic</td>";
762 print "<td width='25%'>
763 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
765 if ($line["feed_title"]) {
766 print "<td width='50%'>$content_link</td>";
767 print "<td width='20%'>
768 <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a></td>";
770 print "<td width='70%'>$content_link</td>";
779 print "<tr><td align='center'>No articles found.</td></tr>";
784 print "<script type=\"text/javascript\">
785 document.onkeydown = hotkey_handler;
786 update_label_counters('$feed');
790 print "</body></html>";
795 if ($op == "pref-rpc") {
797 $subop = $_GET["subop"];
799 if ($subop == "unread") {
800 $ids = split(",", $_GET["ids"]);
801 foreach ($ids as $id) {
802 db_query($link, "UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'");
805 print "Marked selected feeds as read.";
808 if ($subop == "read") {
809 $ids = split(",", $_GET["ids"]);
810 foreach ($ids as $id) {
811 db_query($link, "UPDATE ttrss_entries
812 SET unread = false,last_read = NOW() WHERE feed_id = '$id'");
815 print "Marked selected feeds as unread.";
821 if ($op == "pref-feeds") {
823 $subop = $_GET["subop"];
825 if ($subop == "editSave") {
826 $feed_title = db_escape_string($_GET["t"]);
827 $feed_link = db_escape_string($_GET["l"]);
828 $upd_intl = db_escape_string($_GET["ui"]);
829 $purge_intl = db_escape_string($_GET["pi"]);
830 $feed_id = $_GET["id"];
832 if (strtoupper($upd_intl) == "DEFAULT")
835 if (strtoupper($purge_intl) == "DEFAULT")
838 if (strtoupper($purge_intl) == "DISABLED")
841 $result = db_query($link, "UPDATE ttrss_feeds SET
842 title = '$feed_title', feed_url = '$feed_link',
843 update_interval = '$upd_intl',
844 purge_interval = '$purge_intl'
845 WHERE id = '$feed_id'");
849 if ($subop == "remove") {
851 if (!WEB_DEMO_MODE
) {
853 $ids = split(",", $_GET["ids"]);
855 foreach ($ids as $id) {
856 db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'");
858 $icons_dir = get_pref($link, 'ICONS_DIR');
860 if (file_exists($icons_dir . "/$id.ico")) {
861 unlink($icons_dir . "/$id.ico");
867 if ($subop == "add") {
869 if (!WEB_DEMO_MODE
) {
871 $feed_link = db_escape_string($_GET["link"]);
873 $result = db_query($link,
874 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title) VALUES ('".$_SESSION["uid"]."', '$feed_link', '')");
876 $result = db_query($link,
877 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'");
879 $feed_id = db_fetch_result($result, 0, "id");
882 update_rss_feed($link, $feed_link, $feed_id);
887 $result = db_query($link, "SELECT id,title,feed_url,last_error
888 FROM ttrss_feeds WHERE last_error != ''");
890 if (db_num_rows($result) > 0) {
892 print "<div class=\"warning\">";
894 print "<b>Feeds with update errors:</b>";
896 print "<ul class=\"nomarks\">";
898 while ($line = db_fetch_assoc($result)) {
899 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
908 print "<table class=\"prefAddFeed\"><tr>
909 <td><input id=\"fadd_link\"></td>
910 <td colspan=\"4\" align=\"right\">
911 <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr>
914 $result = db_query($link, "SELECT
915 id,title,feed_url,substring(last_updated,1,16) as last_updated,
916 update_interval,purge_interval
918 ttrss_feeds WHERE owner_uid = '".$_SESSION["uid"]."' ORDER by title");
920 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
921 print "<tr class=\"title\">
922 <td> </td><td>Select</td><td width=\"30%\">Title</td>
923 <td width=\"30%\">Link</td>
924 <td width=\"10%\">Update Interval</td>
925 <td width=\"10%\">Purge Days</td>
926 <td>Last updated</td></tr>";
930 while ($line = db_fetch_assoc($result)) {
932 $class = ($lnum %
2) ?
"even" : "odd";
934 $feed_id = $line["id"];
936 $edit_feed_id = $_GET["id"];
938 if ($subop == "edit" && $feed_id != $edit_feed_id) {
942 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
944 $icon_file = get_pref($link, 'ICONS_DIR') . "/$feed_id.ico";
946 if (file_exists($icon_file) && filesize($icon_file) > 0) {
947 $feed_icon = "<img width=\"16\" height=\"16\"
948 src=\"" . get_pref($link, 'ICONS_URL') . "/$feed_id.ico\">";
950 $feed_icon = " ";
952 print "<td align='center'>$feed_icon</td>";
954 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
955 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
957 if (!$edit_feed_id ||
$subop != "edit") {
959 print "<td><input onclick='toggleSelectRow(this);'
960 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
962 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
963 $edit_title . "</a></td>";
964 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
965 $edit_link . "</a></td>";
967 if ($line["update_interval"] == "0")
968 $line["update_interval"] = "Default";
970 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
971 $line["update_interval"] . "</a></td>";
973 if ($line["purge_interval"] == "0")
974 $line["purge_interval"] = "Default";
976 if ($line["purge_interval"] < 0)
977 $line["purge_interval"] = "Disabled";
979 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
980 $line["purge_interval"] . "</a></td>";
982 } else if ($feed_id != $edit_feed_id) {
984 print "<td><input disabled=\"true\" type=\"checkbox\"
985 id=\"FRCHK-".$line["id"]."\"></td>";
987 print "<td>$edit_title</td>";
988 print "<td>$edit_link</td>";
990 if ($line["update_interval"] == "0")
991 $line["update_interval"] = "Default";
993 print "<td>" . $line["update_interval"] . "</td>";
995 if ($line["purge_interval"] == "0")
996 $line["purge_interval"] = "Default";
998 if ($line["purge_interval"] < 0)
999 $line["purge_interval"] = "Disabled";
1001 print "<td>" . $line["purge_interval"] . "</td>";
1005 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
1007 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
1008 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
1009 print "<td><input id=\"iedit_updintl\" value=\"".$line["update_interval"]."\"></td>";
1010 print "<td><input id=\"iedit_purgintl\" value=\"".$line["purge_interval"]."\"></td>";
1014 if (!$line["last_updated"]) $line["last_updated"] = "Never";
1016 print "<td>" . $line["last_updated"] . "</td>";
1024 print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>";
1031 if ($subop == "edit") {
1032 print "Edit feed:
1033 <input type=\"submit\" class=\"button\"
1034 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
1035 <input type=\"submit\" class=\"button\"
1036 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1041 <input type=\"submit\" class=\"button\"
1042 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
1043 <input type=\"submit\" class=\"button\"
1044 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
1046 if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
1048 <input type=\"submit\" class=\"button\"
1049 onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\">
1050 <input type=\"submit\" class=\"button\"
1051 onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\"> ";
1055 <input type=\"submit\"
1056 class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">";
1060 print "<h3>OPML Import</h3>
1061 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1062 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">
1063 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
1064 type=\"submit\" value=\"Import\">
1069 if ($op == "pref-filters") {
1071 $subop = $_GET["subop"];
1073 if ($subop == "editSave") {
1075 $regexp = db_escape_string($_GET["r"]);
1076 $descr = db_escape_string($_GET["d"]);
1077 $match = db_escape_string($_GET["m"]);
1078 $filter_id = db_escape_string($_GET["id"]);
1080 $result = db_query($link, "UPDATE ttrss_filters SET
1081 reg_exp = '$regexp',
1082 description = '$descr',
1083 filter_type = (SELECT id FROM ttrss_filter_types WHERE
1084 description = '$match')
1085 WHERE id = '$filter_id'");
1088 if ($subop == "remove") {
1090 if (!WEB_DEMO_MODE
) {
1092 $ids = split(",", $_GET["ids"]);
1094 foreach ($ids as $id) {
1095 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
1101 if ($subop == "add") {
1103 if (!WEB_DEMO_MODE
) {
1105 $regexp = db_escape_string($_GET["regexp"]);
1106 $match = db_escape_string($_GET["match"]);
1108 $result = db_query($link,
1109 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid) VALUES
1110 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
1111 description = '$match'),'".$_SESSION["uid"]."')");
1115 $result = db_query($link, "SELECT description
1116 FROM ttrss_filter_types ORDER BY description");
1118 $filter_types = array();
1120 while ($line = db_fetch_assoc($result)) {
1121 array_push($filter_types, $line["description"]);
1124 print "<table class=\"prefAddFeed\"><tr>
1125 <td><input id=\"fadd_regexp\"></td>
1127 print_select("fadd_match", "Title", $filter_types);
1129 print"</td><td colspan=\"4\" align=\"right\">
1130 <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr>
1133 $result = db_query($link, "SELECT
1134 id,reg_exp,description,
1135 (SELECT name FROM ttrss_filter_types WHERE
1136 id = filter_type) as filter_type_name,
1137 (SELECT description FROM ttrss_filter_types
1138 WHERE id = filter_type) as filter_type_descr
1142 owner_uid = ".$_SESSION["uid"]."
1145 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
1147 print "<tr class=\"title\">
1148 <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td>
1149 <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>";
1153 while ($line = db_fetch_assoc($result)) {
1155 $class = ($lnum %
2) ?
"even" : "odd";
1157 $filter_id = $line["id"];
1158 $edit_filter_id = $_GET["id"];
1160 if ($subop == "edit" && $filter_id != $edit_filter_id) {
1164 print "<tr class=\"$class\" id=\"FILRR-$filter_id\">";
1166 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
1167 $line["description"] = htmlspecialchars($line["description"]);
1169 if (!$edit_filter_id ||
$subop != "edit") {
1171 if (!$line["description"]) $line["description"] = "[No description]";
1173 print "<td><input onclick='toggleSelectRow(this);'
1174 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
1176 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1177 $line["reg_exp"] . "</td>";
1179 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1180 $line["description"] . "</td>";
1182 print "<td>".$line["filter_type_descr"]."</td>";
1184 } else if ($filter_id != $edit_filter_id) {
1186 if (!$line["description"]) $line["description"] = "[No description]";
1188 print "<td><input disabled=\"true\" type=\"checkbox\"
1189 id=\"FICHK-".$line["id"]."\"></td>";
1191 print "<td>".$line["reg_exp"]."</td>";
1192 print "<td>".$line["description"]."</td>";
1193 print "<td>".$line["filter_type_descr"]."</td>";
1197 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
1199 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
1202 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1206 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
1218 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
1225 if ($subop == "edit") {
1227 <input type=\"submit\" class=\"button\"
1228 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
1229 <input type=\"submit\" class=\"button\"
1230 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
1236 <input type=\"submit\" class=\"button\"
1237 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
1238 <input type=\"submit\" class=\"button\"
1239 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
1243 if ($op == "pref-labels") {
1245 $subop = $_GET["subop"];
1247 if ($subop == "editSave") {
1249 $sql_exp = $_GET["s"];
1250 $descr = $_GET["d"];
1251 $label_id = db_escape_string($_GET["id"]);
1253 // print "$sql_exp : $descr : $label_id";
1255 $result = db_query($link, "UPDATE ttrss_labels SET
1256 sql_exp = '$sql_exp',
1257 description = '$descr'
1258 WHERE id = '$label_id'");
1261 if ($subop == "remove") {
1263 if (!WEB_DEMO_MODE
) {
1265 $ids = split(",", $_GET["ids"]);
1267 foreach ($ids as $id) {
1268 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
1274 if ($subop == "add") {
1276 if (!WEB_DEMO_MODE
) {
1278 $exp = $_GET["exp"];
1280 $result = db_query($link,
1281 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
1282 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
1286 print "<table class=\"prefAddFeed\"><tr>
1287 <td><input id=\"ladd_expr\"></td>";
1289 print"<td colspan=\"4\" align=\"right\">
1290 <a class=\"button\" href=\"javascript:addLabel()\">Add label</a></td></tr>
1293 $result = db_query($link, "SELECT
1294 id,sql_exp,description
1298 owner_uid = ".$_SESSION["uid"]."
1299 ORDER by description");
1301 print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">";
1303 print "<tr class=\"title\">
1304 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
1305 <a class=\"helpLink\" href=\"javascript:popupHelp(1)\">(?)</a>
1307 <td width=\"40%\">Caption</td></tr>";
1311 while ($line = db_fetch_assoc($result)) {
1313 $class = ($lnum %
2) ?
"even" : "odd";
1315 $label_id = $line["id"];
1316 $edit_label_id = $_GET["id"];
1318 if ($subop == "edit" && $label_id != $edit_label_id) {
1322 print "<tr class=\"$class\" id=\"LILRR-$label_id\">";
1324 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
1325 $line["description"] = htmlspecialchars($line["description"]);
1327 if (!$edit_label_id ||
$subop != "edit") {
1329 if (!$line["description"]) $line["description"] = "[No caption]";
1331 print "<td><input onclick='toggleSelectRow(this);'
1332 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
1334 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1335 $line["sql_exp"] . "</td>";
1337 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1338 $line["description"] . "</td>";
1340 } else if ($label_id != $edit_label_id) {
1342 if (!$line["description"]) $line["description"] = "[No description]";
1344 print "<td><input disabled=\"true\" type=\"checkbox\"
1345 id=\"LICHK-".$line["id"]."\"></td>";
1347 print "<td>".$line["sql_exp"]."</td>";
1348 print "<td>".$line["description"]."</td>";
1352 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
1354 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
1357 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1369 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
1376 if ($subop == "edit") {
1378 <input type=\"submit\" class=\"button\"
1379 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
1380 <input type=\"submit\" class=\"button\"
1381 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
1387 <input type=\"submit\" class=\"button\"
1388 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
1389 <input type=\"submit\" class=\"button\"
1390 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
1394 if ($op == "error") {
1395 print "<div width=\"100%\" align='center'>";
1396 $msg = $_GET["msg"];
1401 if ($op == "help") {
1403 <title>Tiny Tiny RSS : Help</title>
1404 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
1405 <script type=\"text/javascript\" src=\"functions.js\"></script>
1406 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1409 $tid = sprintf("%d", $_GET["tid"]);
1411 /* FIXME this badly needs real implementation */
1413 print "<div class='helpResponse'>";
1417 <h1
>Help
for SQL expressions
</h1
>
1419 <h2
>Description
</h2
>
1421 <p
>The
«
;SQL expression
»
; is added to WHERE clause of
1422 view feed query
. You can match on ttrss_entries table fields
1423 and even
use subselect to query additional information
. This
1424 functionality is considered to be advanced
and requires basic
1425 understanding of SQL
.</p
>
1429 <pre
>unread
= true</pre
>
1431 Matches all unread articles
1433 <pre
>title like
'%Linux%'</pre
>
1435 Matches all articles which mention Linux in the title
. You get the idea
.
1437 <p
>See the database schema included in the distribution package
for gruesome
1442 print "<div align='center'>
1443 <a class=\"helpLink\"
1444 href=\"javascript:window.close()\">(Close this window)</a></div>";
1448 print "</body></html>";
1454 $param = $_GET["param"];
1456 if ($id == "quickAddFeed") {
1457 print "Feed URL: <input
1458 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1460 <input class=\"button\"
1461 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
1462 <input class=\"button\"
1463 type=\"submit\" onclick=\"javascript:closeDlg()\"
1467 if ($id == "quickDelFeed") {
1469 $param = db_escape_string($param);
1471 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
1475 $f_title = db_fetch_result($result, 0, "title");
1477 print "Remove current feed ($f_title)?
1478 <input class=\"button\"
1479 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
1480 <input class=\"button\"
1481 type=\"submit\" onclick=\"javascript:closeDlg()\"
1484 print "Error: Feed $param not found.
1485 <input class=\"button\"
1486 type=\"submit\" onclick=\"javascript:closeDlg()\"
1491 if ($id == "search") {
1493 print "<input id=\"searchbox\" class=\"extSearch\"
1494 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1495 onchange=\"javascript:search()\">
1496 <select id=\"searchmodebox\">
1497 <option selected>All feeds</option>
1498 <option>This feed</option>
1500 <input type=\"submit\"
1501 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
1502 <input class=\"button\"
1503 type=\"submit\" onclick=\"javascript:closeDlg()\"
1510 if ($op == "updateAllFeeds") {
1511 update_all_feeds($link, true);
1513 print "<rpc-reply>";
1514 getLabelCounters($link);
1515 getFeedCounters($link);
1516 getTagCounters($link);
1517 getGlobalCounters($link);
1518 print "</rpc-reply>";
1522 if ($op == "pref-prefs") {
1524 $subop = $_REQUEST["subop"];
1526 if ($subop == "Save configuration") {
1528 if (WEB_DEMO_MODE
) return;
1530 foreach (array_keys($_POST) as $pref_name) {
1532 $pref_name = db_escape_string($pref_name);
1533 $value = db_escape_string($_POST[$pref_name]);
1535 $result = db_query($link, "SELECT type_name
1536 FROM ttrss_prefs,ttrss_prefs_types
1537 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
1539 if (db_num_rows($result) > 0) {
1541 $type_name = db_fetch_result($result, 0, "type_name");
1543 // print "$pref_name : $type_name : $value<br>";
1545 if ($type_name == "bool") {
1546 if ($value == "1") {
1551 } else if ($type_name == "integer") {
1552 $value = sprintf("%d", $value);
1555 // print "$pref_name : $type_name : $value<br>";
1557 db_query($link, "UPDATE ttrss_prefs SET value = '$value'
1558 WHERE pref_name = '$pref_name'");
1562 header("Location: prefs.php");
1566 } else if ($subop == "getHelp") {
1568 $pref_name = db_escape_string($_GET["pn"]);
1570 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
1571 WHERE pref_name = '$pref_name'");
1573 if (db_num_rows($result) > 0) {
1574 $help_text = db_fetch_result($result, 0, "help_text");
1577 print "Unknown option: $pref_name";
1580 } else if ($subop == "Reset to defaults") {
1582 if (WEB_DEMO_MODE
) return;
1584 db_query($link, "UPDATE ttrss_prefs SET value = def_value");
1586 header("Location: prefs.php");
1590 $result = db_query($link, "SELECT
1591 pref_name,short_desc,help_text,value,type_name,
1592 section_name,def_value
1593 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections
1594 WHERE type_id = ttrss_prefs_types.id AND
1595 section_id = ttrss_prefs_sections.id
1596 ORDER BY section_id,short_desc");
1598 print "<form action=\"backend.php\" method=\"POST\">";
1600 print "<table width=\"100%\" class=\"prefPrefsList\">";
1604 $active_section = "";
1606 while ($line = db_fetch_assoc($result)) {
1608 if ($active_section != $line["section_name"]) {
1610 if ($active_section != "") {
1611 print "</table><p><table width=\"100%\" class=\"prefPrefsList\">";
1614 $active_section = $line["section_name"];
1616 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
1617 // print "<tr class=\"title\">
1618 // <td width=\"25%\">Option</td><td>Value</td></tr>";
1623 // $class = ($lnum % 2) ? "even" : "odd";
1627 $type_name = $line["type_name"];
1628 $pref_name = $line["pref_name"];
1629 $value = $line["value"];
1630 $def_value = $line["def_value"];
1631 $help_text = $line["help_text"];
1633 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
1635 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
1641 if ($type_name == "bool") {
1642 // print_select($pref_name, $value, array("true", "false"));
1644 if ($value == "true") {
1650 print_radio($pref_name, $value, array("Yes", "No"));
1653 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
1665 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
1667 print "<p><input class=\"button\" type=\"submit\"
1668 name=\"subop\" value=\"Save configuration\">";
1670 print " <input class=\"button\" type=\"submit\"
1671 name=\"subop\" value=\"Reset to defaults\"></p>";
1682 <!-- <?
= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?
> -->