2 define(SCHEMA_VERSION
, 1);
7 header("Content-Type: application/xml");
10 require_once "config.php";
11 require_once "db.php";
12 require_once "functions.php";
13 require_once "magpierss/rss_fetch.inc";
15 $script_started = getmicrotime();
17 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
20 if (DB_TYPE
== "mysql") {
23 // PG seems to display its own errors just fine by default.
27 if (DB_TYPE
== "pgsql") {
28 pg_query("set client_encoding = 'utf-8'");
31 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
33 $schema_version = db_fetch_result($result, 0, "schema_version");
35 if ($schema_version != SCHEMA_VERSION
) {
36 print "Error: database schema is invalid
37 (got version $schema_version; expected ".SCHEMA_VERSION
.")";
41 $fetch = $_GET["fetch"];
43 /* FIXME this needs reworking */
45 function getGlobalCounters($link) {
46 $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries
47 WHERE unread = true");
48 $c_id = db_fetch_result($result, 0, "c_id");
49 print "<counter id='global-unread' counter='$c_id'/>";
52 function getTagCounters($link) {
53 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
54 FROM ttrss_tags,ttrss_entries WHERE
55 post_id = ttrss_entries.id AND unread = true GROUP BY tag_name
57 select tag_name,0 as count FROM ttrss_tags");
61 while ($line = db_fetch_assoc($result)) {
62 $tags[$line["tag_name"]] +
= $line["count"];
65 foreach (array_keys($tags) as $tag) {
66 $unread = $tags[$tag];
68 $tag = htmlspecialchars($tag);
69 print "<tag id=\"$tag\" counter=\"$unread\"/>";
73 function getLabelCounters($link) {
75 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
76 WHERE marked = true AND unread = true");
78 $count = db_fetch_result($result, 0, "count");
80 print "<label id=\"-1\" counter=\"$count\"/>";
82 $result = db_query($link, "SELECT id,sql_exp,description FROM
83 ttrss_labels ORDER by description");
85 while ($line = db_fetch_assoc($result)) {
87 $id = -$line["id"] - 11;
91 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
92 WHERE (" . $line["sql_exp"] . ") AND unread = true");
94 $count = db_fetch_result($tmp_result, 0, "count");
96 print "<label id=\"$id\" counter=\"$count\"/>";
98 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
103 function getFeedCounter($link, $id) {
105 $result = db_query($link, "SELECT
106 count(id) as count FROM ttrss_entries
107 WHERE feed_id = '$id' AND unread = true");
109 $count = db_fetch_result($result, 0, "count");
111 print "<feed id=\"$id\" counter=\"$count\"/>";
114 function getFeedCounters($link) {
116 $result = db_query($link, "SELECT id,
117 (SELECT count(id) FROM ttrss_entries WHERE feed_id = ttrss_feeds.id
118 AND unread = true) as count
121 while ($line = db_fetch_assoc($result)) {
124 $count = $line["count"];
126 print "<feed id=\"$id\" counter=\"$count\"/>";
130 function outputFeedList($link, $tags = false) {
133 <title>Tiny Tiny RSS : Feedlist</title>
134 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
135 <script type=\"text/javascript\" src=\"functions.js\"></script>
136 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
137 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
138 </head><body onload=\"init()\">";
140 print "<ul class=\"feedList\" id=\"feedList\">";
146 $result = db_query($link, "SELECT count(id) as num_starred
147 FROM ttrss_entries WHERE marked = true AND unread = true");
148 $num_starred = db_fetch_result($result, 0, "num_starred");
152 if ($num_starred > 0) $class .= "Unread";
154 printFeedEntry(-1, $class, "Starred articles", $num_starred,
155 "images/mark_set.png");
159 $result = db_query($link, "SELECT id,sql_exp,description FROM
160 ttrss_labels ORDER by description");
162 if (db_num_rows($result) > 0) {
163 print "<li><hr></li>";
166 while ($line = db_fetch_assoc($result)) {
170 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
171 WHERE (" . $line["sql_exp"] . ") AND unread = true");
173 $count = db_fetch_result($tmp_result, 0, "count");
181 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
183 printFeedEntry(-$line["id"]-11,
184 $class, $line["description"], $count, "images/label.png");
189 print "<li><hr></li>";
191 $result = db_query($link, "SELECT *,
192 (SELECT count(id) FROM ttrss_entries
193 WHERE feed_id = ttrss_feeds.id) AS total,
194 (SELECT count(id) FROM ttrss_entries
195 WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
196 FROM ttrss_feeds ORDER BY title");
198 $actid = $_GET["actid"];
206 while ($line = db_fetch_assoc($result)) {
208 $feed = $line["title"];
209 $feed_id = $line["id"];
211 $subop = $_GET["subop"];
213 $total = $line["total"];
214 $unread = $line["unread"];
216 // $class = ($lnum % 2) ? "even" : "odd";
220 if ($unread > 0) $class .= "Unread";
222 if ($actid == $feed_id) {
223 $class .= "Selected";
226 $total_unread +
= $unread;
228 printFeedEntry($feed_id, $class, $feed, $unread, "icons/$feed_id.ico");
236 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
237 FROM ttrss_tags,ttrss_entries WHERE
238 post_id = ttrss_entries.id AND unread = true GROUP BY tag_name
240 select tag_name,0 as count FROM ttrss_tags");
244 while ($line = db_fetch_assoc($result)) {
245 $tags[$line["tag_name"]] +
= $line["count"];
248 foreach (array_keys($tags) as $tag) {
250 $unread = $tags[$tag];
258 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png");
264 if (db_num_rows($result) == 0) {
265 print "<li>No tags to display.</li>";
270 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
277 $subop = $_GET["subop"];
279 if ($subop == "getLabelCounters") {
282 getLabelCounters($link);
284 getFeedCounter($link, $aid);
286 print "</rpc-reply>";
289 if ($subop == "getFeedCounters") {
291 getFeedCounters($link);
292 print "</rpc-reply>";
295 if ($subop == "getAllCounters") {
297 getLabelCounters($link);
298 getFeedCounters($link);
299 getTagCounters($link);
300 getGlobalCounters($link);
301 print "</rpc-reply>";
304 if ($subop == "mark") {
305 $mark = $_GET["mark"];
306 $id = db_escape_string($_GET["id"]);
314 $result = db_query($link, "UPDATE ttrss_entries SET marked = $mark
318 if ($subop == "updateFeed") {
319 $feed_id = db_escape_string($_GET["feed"]);
321 $result = db_query($link,
322 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'");
324 if (db_num_rows($result) > 0) {
325 $feed_url = db_fetch_result($result, 0, "feed_url");
326 // update_rss_feed($link, $feed_url, $feed_id);
329 print "DONE-$feed_id";
334 if ($subop == "forceUpdateAllFeeds" ||
$subop == "updateAllFeeds") {
336 update_all_feeds($link, true);
338 $omode = $_GET["omode"];
340 if (!$omode) $omode = "tfl";
343 if (strchr($omode, "l")) getLabelCounters($link);
344 if (strchr($omode, "f")) getFeedCounters($link);
345 if (strchr($omode, "t")) getTagCounters($link);
346 getGlobalCounters($link);
347 print "</rpc-reply>";
350 if ($subop == "catchupPage") {
352 $ids = split(",", $_GET["ids"]);
354 foreach ($ids as $id) {
356 db_query($link, "UPDATE ttrss_entries SET unread=false,last_read = NOW()
361 print "Marked active page as read.";
365 if ($op == "feeds") {
367 $tags = $_GET["tags"];
369 $subop = $_GET["subop"];
371 if ($subop == "catchupAll") {
372 db_query($link, "UPDATE ttrss_entries SET last_read = NOW(),unread = false");
375 outputFeedList($link, $tags);
382 $feed_id = $_GET["feed"];
384 $result = db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'");
386 $addheader = $_GET["addheader"];
388 $result = db_query($link, "SELECT title,link,content,feed_id,comments,
389 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
395 <title>Tiny Tiny RSS : Article $id</title>
396 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
397 <script type=\"text/javascript\" src=\"functions.js\"></script>
398 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
404 $line = db_fetch_assoc($result);
406 if ($line["icon_url"]) {
407 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
409 $feed_icon = " ";
412 if ($line["comments"] && $line["link"] != $line["comments"]) {
413 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
415 $entry_comments = "";
418 print "<div class=\"postReply\">";
420 print "<div class=\"postHeader\"><table>";
422 print "<tr><td><b>Title:</b></td>
423 <td width='100%'>" . $line["title"] . "</td></tr>";
425 print "<tr><td><b>Link:</b></td>
427 <a href=\"" . $line["link"] . "\">".$line["link"]."</a>
428 $entry_comments</td></tr>";
430 print "</table></div>";
432 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
433 print "<div class=\"postContent\">" . $line["content"] . "</div>";
437 print "<script type=\"text/javascript\">
438 update_label_counters('$feed_id');
443 print "</body></html>";
447 if ($op == "viewfeed") {
449 $feed = $_GET["feed"];
450 $skip = $_GET["skip"];
451 $subop = $_GET["subop"];
452 $view_mode = $_GET["view"];
453 $addheader = $_GET["addheader"];
454 $limit = $_GET["limit"];
457 print "Error: no feed to display.";
461 if (!$skip) $skip = 0;
463 if ($subop == "undefined") $subop = "";
467 <title>Tiny Tiny RSS : Feed $feed</title>
468 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
469 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
470 <script type=\"text/javascript\" src=\"functions.js\"></script>
471 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
475 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
477 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
478 WHERE id = '$feed'");
480 $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
482 update_rss_feed($link, $feed_url, $feed);
486 if ($subop == "MarkAllRead") {
488 if (sprintf("%d", $feed) != 0) {
491 db_query($link, "UPDATE ttrss_entries
492 SET unread = false,last_read = NOW()
493 WHERE feed_id = '$feed'");
495 } else if ($feed < 0 && $feed > -10) { // special, like starred
498 db_query($link, "UPDATE ttrss_entries
499 SET unread = false,last_read = NOW()
500 WHERE marked = true");
503 } else if ($feed < -10) { // label
505 $label_id = -$feed - 11;
507 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
508 WHERE id = '$label_id'");
511 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
513 db_query($link, "UPDATE ttrss_entries
514 SET unread = false,last_read = NOW()
519 // FIXME, implement catchup for tags
524 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
526 $search = $_GET["search"];
528 $search_mode = $_GET["smode"];
531 $search_query_part = "(upper(title) LIKE upper('%$search%')
532 OR content LIKE '%$search%') AND";
534 $search_query_part = "";
537 $view_query_part = "";
539 if ($view_mode == "Starred") {
540 $view_query_part = " marked = true AND ";
543 if ($view_mode == "Unread") {
544 $view_query_part = " unread = true AND ";
547 if ($view_mode == "Unread or Starred") {
548 $view_query_part = " (unread = true OR marked = true) AND ";
551 if ($view_mode == "Unread or Updated") {
552 $view_query_part = " (unread = true OR last_read is NULL) AND ";
555 /* $result = db_query($link, "SELECT count(id) AS total_entries
556 FROM ttrss_entries WHERE
560 $total_entries = db_fetch_result($result, 0, "total_entries"); */
562 /* $result = db_query("SELECT count(id) AS unread_entries
563 FROM ttrss_entries WHERE
568 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
570 if ($limit && $limit != "All") {
571 $limit_query_part = "LIMIT " . $limit;
574 $vfeed_query_part = "";
576 // override query strategy and enable feed display when searching globally
577 if ($search_mode == "All feeds") {
578 $query_strategy_part = "id > 0";
579 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
580 id = feed_id) as feed_title,";
581 } else if (sprintf("%d", $feed) == 0) {
582 $query_strategy_part = "ttrss_entries.id > 0";
583 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
584 id = feed_id) as feed_title,";
585 } else if ($feed >= 0) {
586 $query_strategy_part = "feed_id = '$feed'";
587 } else if ($feed == -1) { // starred virtual feed
588 $query_strategy_part = "marked = true";
589 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
590 id = feed_id) as feed_title,";
591 } else if ($feed <= -10) { // labels
592 $label_id = -$feed - 11;
594 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
595 WHERE id = '$label_id'");
597 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
599 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
600 id = feed_id) as feed_title,";
602 $query_strategy_part = "id > 0"; // dumb
606 $order_by = "updated DESC";
608 // if ($feed < -10) {
609 // $order_by = "feed_id,updated DESC";
612 if ($feed < -10) error_reporting (0);
614 if (sprintf("%d", $feed) != 0) {
616 $result = db_query($link, "SELECT
617 id,title,updated,unread,feed_id,marked,link,last_read,
618 SUBSTRING(last_read,1,19) as last_read_noms,
620 SUBSTRING(updated,1,19) as updated_noms
626 $query_strategy_part ORDER BY $order_by
632 $result = db_query($link, "SELECT
633 ttrss_entries.id as id,title,updated,unread,feed_id,
634 marked,link,last_read,
635 SUBSTRING(last_read,1,19) as last_read_noms,
637 SUBSTRING(updated,1,19) as updated_noms
639 ttrss_entries,ttrss_tags
641 post_id = ttrss_entries.id AND tag_name = '$feed' AND
644 $query_strategy_part ORDER BY $order_by
649 print "<tr><td colspan='4' align='center'>
650 Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>";
656 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
660 while ($line = db_fetch_assoc($result)) {
662 $class = ($lnum %
2) ?
"even" : "odd";
665 $feed_id = $line["feed_id"];
667 // printf("L %d (%s) > U %d (%s) = %d<br>",
668 // strtotime($line["last_read_noms"]), $line["last_read_noms"],
669 // strtotime($line["updated"]), $line["updated"],
670 // strtotime($line["last_read"]) >= strtotime($line["updated"]));
672 /* if ($line["last_read"] != "" && $line["updated"] != "" &&
673 strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) {
675 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
680 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
685 if ($line["last_read"] == "" &&
686 ($line["unread"] != "t" && $line["unread"] != "1")) {
688 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
691 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
695 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
700 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
701 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
702 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
704 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
705 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
708 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
709 $line["title"] . "</a>";
711 print "<tr class='$class' id='RROW-$id'>";
712 // onclick=\"javascript:view($id,$feed_id)\">
714 print "<td valign='center' align='center'>$update_pic</td>";
715 print "<td valign='center' align='center'>$marked_pic</td>";
717 print "<td width='25%'>
718 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
720 if ($line["feed_title"]) {
721 print "<td width='50%'>$content_link</td>";
722 print "<td width='20%'>
723 <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a></td>";
725 print "<td width='70%'>$content_link</td>";
734 print "<tr><td align='center'>No articles found.</td></tr>";
739 print "<script type=\"text/javascript\">
740 document.onkeydown = hotkey_handler;
741 update_label_counters('$feed');
745 print "</body></html>";
750 if ($op == "pref-rpc") {
752 $subop = $_GET["subop"];
754 if ($subop == "unread") {
755 $ids = split(",", $_GET["ids"]);
756 foreach ($ids as $id) {
757 db_query($link, "UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'");
760 print "Marked selected feeds as read.";
763 if ($subop == "read") {
764 $ids = split(",", $_GET["ids"]);
765 foreach ($ids as $id) {
766 db_query($link, "UPDATE ttrss_entries
767 SET unread = false,last_read = NOW() WHERE feed_id = '$id'");
770 print "Marked selected feeds as unread.";
776 if ($op == "pref-feeds") {
778 $subop = $_GET["subop"];
780 if ($subop == "editSave") {
781 $feed_title = db_escape_string($_GET["t"]);
782 $feed_link = db_escape_string($_GET["l"]);
783 $upd_intl = db_escape_string($_GET["ui"]);
784 $feed_id = $_GET["id"];
786 if (strtoupper($upd_intl) == "DEFAULT")
789 $result = db_query($link, "UPDATE ttrss_feeds SET
790 title = '$feed_title', feed_url = '$feed_link',
791 update_interval = '$upd_intl' WHERE id = '$feed_id'");
795 if ($subop == "remove") {
797 if (!WEB_DEMO_MODE
) {
799 $ids = split(",", $_GET["ids"]);
801 foreach ($ids as $id) {
802 db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'");
804 if (file_exists(ICONS_DIR
. "/$id.ico")) {
805 unlink(ICONS_DIR
. "/$id.ico");
811 if ($subop == "add") {
813 if (!WEB_DEMO_MODE
) {
815 $feed_link = db_escape_string($_GET["link"]);
817 $result = db_query($link,
818 "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')");
820 $result = db_query($link,
821 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'");
823 $feed_id = db_fetch_result($result, 0, "id");
826 update_rss_feed($link, $feed_link, $feed_id);
831 $result = db_query($link, "SELECT id,title,feed_url,last_error
832 FROM ttrss_feeds WHERE last_error != ''");
834 if (db_num_rows($result) > 0) {
836 print "<div class=\"warning\">";
838 print "<b>Feeds with update errors:</b>";
840 print "<ul class=\"nomarks\">";
842 while ($line = db_fetch_assoc($result)) {
843 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
852 print "<table class=\"prefAddFeed\"><tr>
853 <td><input id=\"fadd_link\"></td>
854 <td colspan=\"4\" align=\"right\">
855 <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr>
858 $result = db_query($link, "SELECT
859 id,title,feed_url,substring(last_updated,1,16) as last_updated,
862 ttrss_feeds ORDER by title");
864 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
865 print "<tr class=\"title\">
866 <td> </td><td>Select</td><td width=\"40%\">Title</td>
867 <td width=\"30%\">Link</td><td width=\"10%\">Update Interval</td>
868 <td>Last updated</td></tr>";
872 while ($line = db_fetch_assoc($result)) {
874 $class = ($lnum %
2) ?
"even" : "odd";
876 $feed_id = $line["id"];
878 $edit_feed_id = $_GET["id"];
880 if ($subop == "edit" && $feed_id != $edit_feed_id) {
884 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
886 $icon_file = ICONS_DIR
. "/$feed_id.ico";
888 if (file_exists($icon_file) && filesize($icon_file) > 0) {
889 $feed_icon = "<img width=\"16\" height=\"16\"
890 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
892 $feed_icon = " ";
894 print "<td align='center'>$feed_icon</td>";
896 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
897 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
899 if (!$edit_feed_id ||
$subop != "edit") {
901 print "<td><input onclick='toggleSelectRow(this);'
902 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
904 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
905 $edit_title . "</td>";
906 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
907 $edit_link . "</td>";
909 if ($line["update_interval"] == "0")
910 $line["update_interval"] = "Default";
912 print "<td>" . $line["update_interval"] . "</td>";
915 } else if ($feed_id != $edit_feed_id) {
917 print "<td><input disabled=\"true\" type=\"checkbox\"
918 id=\"FRCHK-".$line["id"]."\"></td>";
920 print "<td>$edit_title</td>";
921 print "<td>$edit_link</td>";
923 if ($line["update_interval"] == "0")
924 $line["update_interval"] = "Default";
926 print "<td>" . $line["update_interval"] . "</td>";
930 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
932 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
933 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
934 print "<td><input id=\"iedit_updintl\" value=\"".$line["update_interval"]."\"></td>";
938 if (!$line["last_updated"]) $line["last_updated"] = "Never";
940 print "<td>" . $line["last_updated"] . "</td>";
948 print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>";
955 if ($subop == "edit") {
956 print "Edit feed:
957 <input type=\"submit\" class=\"button\"
958 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
959 <input type=\"submit\" class=\"button\"
960 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
965 <input type=\"submit\" class=\"button\"
966 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
967 <input type=\"submit\" class=\"button\"
968 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
970 if (ENABLE_PREFS_CATCHUP_UNCATCHUP
) {
972 <input type=\"submit\" class=\"button\"
973 onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\">
974 <input type=\"submit\" class=\"button\"
975 onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\"> ";
979 <input type=\"submit\"
980 class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">";
984 print "<h3>OPML Import</h3>
985 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
986 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">
987 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
988 type=\"submit\" value=\"Import\">
993 if ($op == "pref-filters") {
995 $subop = $_GET["subop"];
997 if ($subop == "editSave") {
999 $regexp = db_escape_string($_GET["r"]);
1000 $descr = db_escape_string($_GET["d"]);
1001 $match = db_escape_string($_GET["m"]);
1002 $filter_id = db_escape_string($_GET["id"]);
1004 $result = db_query($link, "UPDATE ttrss_filters SET
1005 reg_exp = '$regexp',
1006 description = '$descr',
1007 filter_type = (SELECT id FROM ttrss_filter_types WHERE
1008 description = '$match')
1009 WHERE id = '$filter_id'");
1012 if ($subop == "remove") {
1014 if (!WEB_DEMO_MODE
) {
1016 $ids = split(",", $_GET["ids"]);
1018 foreach ($ids as $id) {
1019 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
1025 if ($subop == "add") {
1027 if (!WEB_DEMO_MODE
) {
1029 $regexp = db_escape_string($_GET["regexp"]);
1030 $match = db_escape_string($_GET["match"]);
1032 $result = db_query($link,
1033 "INSERT INTO ttrss_filters (reg_exp,filter_type) VALUES
1034 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
1035 description = '$match'))");
1039 $result = db_query($link, "SELECT description
1040 FROM ttrss_filter_types ORDER BY description");
1042 $filter_types = array();
1044 while ($line = db_fetch_assoc($result)) {
1045 array_push($filter_types, $line["description"]);
1048 print "<table class=\"prefAddFeed\"><tr>
1049 <td><input id=\"fadd_regexp\"></td>
1051 print_select("fadd_match", "Title", $filter_types);
1053 print"</td><td colspan=\"4\" align=\"right\">
1054 <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr>
1057 $result = db_query($link, "SELECT
1058 id,reg_exp,description,
1059 (SELECT name FROM ttrss_filter_types WHERE
1060 id = filter_type) as filter_type_name,
1061 (SELECT description FROM ttrss_filter_types
1062 WHERE id = filter_type) as filter_type_descr
1064 ttrss_filters ORDER by reg_exp");
1066 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
1068 print "<tr class=\"title\">
1069 <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td>
1070 <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>";
1074 while ($line = db_fetch_assoc($result)) {
1076 $class = ($lnum %
2) ?
"even" : "odd";
1078 $filter_id = $line["id"];
1079 $edit_filter_id = $_GET["id"];
1081 if ($subop == "edit" && $filter_id != $edit_filter_id) {
1085 print "<tr class=\"$class\" id=\"FILRR-$filter_id\">";
1087 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
1088 $line["description"] = htmlspecialchars($line["description"]);
1090 if (!$edit_filter_id ||
$subop != "edit") {
1092 if (!$line["description"]) $line["description"] = "[No description]";
1094 print "<td><input onclick='toggleSelectRow(this);'
1095 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
1097 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1098 $line["reg_exp"] . "</td>";
1100 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1101 $line["description"] . "</td>";
1103 print "<td>".$line["filter_type_descr"]."</td>";
1105 } else if ($filter_id != $edit_filter_id) {
1107 if (!$line["description"]) $line["description"] = "[No description]";
1109 print "<td><input disabled=\"true\" type=\"checkbox\"
1110 id=\"FICHK-".$line["id"]."\"></td>";
1112 print "<td>".$line["reg_exp"]."</td>";
1113 print "<td>".$line["description"]."</td>";
1114 print "<td>".$line["filter_type_descr"]."</td>";
1118 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
1120 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
1123 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1127 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
1139 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
1146 if ($subop == "edit") {
1148 <input type=\"submit\" class=\"button\"
1149 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
1150 <input type=\"submit\" class=\"button\"
1151 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
1157 <input type=\"submit\" class=\"button\"
1158 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
1159 <input type=\"submit\" class=\"button\"
1160 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
1164 if ($op == "pref-labels") {
1166 $subop = $_GET["subop"];
1168 if ($subop == "editSave") {
1170 $sql_exp = $_GET["s"];
1171 $descr = $_GET["d"];
1172 $label_id = db_escape_string($_GET["id"]);
1174 // print "$sql_exp : $descr : $label_id";
1176 $result = db_query($link, "UPDATE ttrss_labels SET
1177 sql_exp = '$sql_exp',
1178 description = '$descr'
1179 WHERE id = '$label_id'");
1182 if ($subop == "remove") {
1184 if (!WEB_DEMO_MODE
) {
1186 $ids = split(",", $_GET["ids"]);
1188 foreach ($ids as $id) {
1189 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
1195 if ($subop == "add") {
1197 if (!WEB_DEMO_MODE
) {
1199 $exp = $_GET["exp"];
1201 $result = db_query($link,
1202 "INSERT INTO ttrss_labels (sql_exp,description)
1203 VALUES ('$exp', '$exp')");
1207 print "<table class=\"prefAddFeed\"><tr>
1208 <td><input id=\"ladd_expr\"></td>";
1210 print"<td colspan=\"4\" align=\"right\">
1211 <a class=\"button\" href=\"javascript:addLabel()\">Add label</a></td></tr>
1214 $result = db_query($link, "SELECT
1215 id,sql_exp,description
1217 ttrss_labels ORDER by description");
1219 print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">";
1221 print "<tr class=\"title\">
1222 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
1223 <a class=\"helpLink\" href=\"javascript:popupHelp(1)\">(?)</a>
1225 <td width=\"40%\">Caption</td></tr>";
1229 while ($line = db_fetch_assoc($result)) {
1231 $class = ($lnum %
2) ?
"even" : "odd";
1233 $label_id = $line["id"];
1234 $edit_label_id = $_GET["id"];
1236 if ($subop == "edit" && $label_id != $edit_label_id) {
1240 print "<tr class=\"$class\" id=\"LILRR-$label_id\">";
1242 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
1243 $line["description"] = htmlspecialchars($line["description"]);
1245 if (!$edit_label_id ||
$subop != "edit") {
1247 if (!$line["description"]) $line["description"] = "[No caption]";
1249 print "<td><input onclick='toggleSelectRow(this);'
1250 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
1252 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1253 $line["sql_exp"] . "</td>";
1255 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1256 $line["description"] . "</td>";
1258 } else if ($label_id != $edit_label_id) {
1260 if (!$line["description"]) $line["description"] = "[No description]";
1262 print "<td><input disabled=\"true\" type=\"checkbox\"
1263 id=\"LICHK-".$line["id"]."\"></td>";
1265 print "<td>".$line["sql_exp"]."</td>";
1266 print "<td>".$line["description"]."</td>";
1270 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
1272 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
1275 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1287 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
1294 if ($subop == "edit") {
1296 <input type=\"submit\" class=\"button\"
1297 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
1298 <input type=\"submit\" class=\"button\"
1299 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
1305 <input type=\"submit\" class=\"button\"
1306 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
1307 <input type=\"submit\" class=\"button\"
1308 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
1312 if ($op == "error") {
1313 print "<div width=\"100%\" align='center'>";
1314 $msg = $_GET["msg"];
1319 if ($op == "help") {
1321 <title>Tiny Tiny RSS : Help</title>
1322 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
1323 <script type=\"text/javascript\" src=\"functions.js\"></script>
1324 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
1325 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1328 $tid = sprintf("%d", $_GET["tid"]);
1330 /* FIXME this badly needs real implementation */
1332 print "<div class='helpResponse'>";
1336 <h1
>Help
for SQL expressions
</h1
>
1338 <h2
>Description
</h2
>
1340 <p
>The
«
;SQL expression
»
; is added to WHERE clause of
1341 view feed query
. You can match on ttrss_entries table fields
1342 and even
use subselect to query additional information
. This
1343 functionality is considered to be advanced
and requires basic
1344 understanding of SQL
.</p
>
1348 <pre
>unread
= true</pre
>
1350 Matches all unread articles
1352 <pre
>title like
'%Linux%'</pre
>
1354 Matches all articles which mention Linux in the title
. You get the idea
.
1356 <p
>See the database schema included in the distribution package
for gruesome
1361 print "<div align='center'>
1362 <a class=\"helpLink\"
1363 href=\"javascript:window.close()\">(Close this window)</a></div>";
1367 print "</body></html>";
1373 $param = $_GET["param"];
1375 if ($id == "quickAddFeed") {
1376 print "Feed URL: <input
1377 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1379 <input class=\"button\"
1380 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
1381 <input class=\"button\"
1382 type=\"submit\" onclick=\"javascript:closeDlg()\"
1386 if ($id == "quickDelFeed") {
1388 $param = db_escape_string($param);
1390 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
1394 $f_title = db_fetch_result($result, 0, "title");
1396 print "Remove current feed ($f_title)?
1397 <input class=\"button\"
1398 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
1399 <input class=\"button\"
1400 type=\"submit\" onclick=\"javascript:closeDlg()\"
1403 print "Error: Feed $param not found.
1404 <input class=\"button\"
1405 type=\"submit\" onclick=\"javascript:closeDlg()\"
1410 if ($id == "search") {
1412 print "<input id=\"searchbox\" class=\"extSearch\"
1413 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1414 onchange=\"javascript:search()\">
1415 <select id=\"searchmodebox\">
1416 <option selected>All feeds</option>
1417 <option>This feed</option>
1419 <input type=\"submit\"
1420 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
1421 <input class=\"button\"
1422 type=\"submit\" onclick=\"javascript:closeDlg()\"
1432 <!-- <?
= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?
> -->