2 require_once "sessions.php";
3 require_once "backend-rpc.php";
5 header("Cache-Control: no-cache, must-revalidate");
6 header("Pragma: no-cache");
9 /* if ($_GET["debug"]) {
10 define('DEFAULT_ERROR_LEVEL', E_ALL);
12 define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE);
15 error_reporting(DEFAULT_ERROR_LEVEL); */
17 $op = $_REQUEST["op"];
19 define('SCHEMA_VERSION', 8);
21 require_once "sanity_check.php";
22 require_once "config.php";
24 require_once "db.php";
25 require_once "db-prefs.php";
26 require_once "functions.php";
27 require_once "magpierss/rss_fetch.inc";
29 $err_msg = check_configuration_variables();
32 header("Content-Type: application/xml");
33 print_error_xml(9, $err_msg); die;
36 if ((!$op ||
$op == "rpc" ||
$op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
37 header("Content-Type: application/xml");
40 if (!$_SESSION["uid"] && $op != "globalUpdateFeeds") {
43 print_error_xml(6); die;
47 <p>Error: Not logged in.</p>
48 <script type=\"text/javascript\">
49 if (parent.window != 'undefined') {
50 parent.window.location = \"login.php\";
52 window.location = \"login.php\";
62 print_error_xml(7); exit;
65 $purge_intervals = array(
74 $update_intervals = array(
76 -1 => "Disable updates",
84 $script_started = getmicrotime();
86 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
89 if (DB_TYPE
== "mysql") {
92 // PG seems to display its own errors just fine by default.
96 if (DB_TYPE
== "pgsql") {
97 pg_query("set client_encoding = 'utf-8'");
100 if ($_SESSION["uid"]) {
101 if (get_pref($link, "HIDE_READ_FEEDS") == "true") {
102 setcookie("ttrss_vf_hreadf", 1);
104 setcookie("ttrss_vf_hreadf", 0);
107 setcookie('ttrss_vf_refresh', FEEDS_FRAME_REFRESH
);
108 setcookie('ttrss_vf_daemon', ENABLE_UPDATE_DAEMON
);
110 if (get_pref($link, "ON_CATCHUP_SHOW_NEXT_FEED")) {
111 setcookie('ttrss_vf_catchupnext', 1);
113 setcookie('ttrss_vf_catchupnext', 0);
117 $fetch = $_GET["fetch"];
119 // setcookie("ttrss_icons_url", ICONS_URL);
121 if (!sanity_check($link)) { return; }
123 function outputFeedList($link, $tags = false) {
126 <title>Tiny Tiny RSS : Feedlist</title>
127 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
129 $user_theme = $_SESSION["theme"];
131 print "<link rel=\"stylesheet\" type=\"text/css\"
132 href=\"themes/$user_theme/theme.css\">";
135 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
136 print "<link rel=\"stylesheet\" type=\"text/css\"
137 href=\"tt-rss_compact.css\"/>";
139 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
140 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
143 $script_dt_add = get_script_dt_add();
145 print "<script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
146 <script type=\"text/javascript\" src=\"feedlist.js?$script_dt_add\"></script>
147 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
148 <!--[if gte IE 5.5000]>
149 <script type=\"text/javascript\" src=\"pngfix.js\"></script>
150 <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
153 <script type=\"text/javascript\">
154 if (document.addEventListener) {
155 document.addEventListener(\"DOMContentLoaded\", init, null);
157 window.onload = init;
160 print "<ul class=\"feedList\" id=\"feedList\">\n";
162 $owner_uid = $_SESSION["uid"];
168 if (get_pref($link, 'ENABLE_FEED_CATS')) {
169 print "<li class=\"feedCat\">Special</li>";
170 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
173 $result = db_query($link, "SELECT count(id) as num_starred
174 FROM ttrss_entries,ttrss_user_entries
175 WHERE marked = true AND
176 ttrss_user_entries.ref_id = ttrss_entries.id AND
177 unread = true AND owner_uid = '$owner_uid'");
178 $num_starred = db_fetch_result($result, 0, "num_starred");
182 if ($num_starred > 0) $class .= "Unread";
184 printFeedEntry(-1, $class, "Starred articles", $num_starred,
185 "images/mark_set.png", $link);
187 if (get_pref($link, 'ENABLE_FEED_CATS')) {
191 if (GLOBAL_ENABLE_LABELS
&& get_pref($link, 'ENABLE_LABELS')) {
193 $result = db_query($link, "SELECT id,sql_exp,description FROM
194 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
196 if (db_num_rows($result) > 0) {
197 if (get_pref($link, 'ENABLE_FEED_CATS')) {
198 print "<li class=\"feedCat\">Labels</li>";
199 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
201 print "<li><hr></li>";
205 while ($line = db_fetch_assoc($result)) {
209 $tmp_result = db_query($link, "SELECT count(id) as count
210 FROM ttrss_entries,ttrss_user_entries
211 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
212 ttrss_user_entries.ref_id = ttrss_entries.id
213 AND owner_uid = '$owner_uid'");
215 $count = db_fetch_result($tmp_result, 0, "count");
223 error_reporting (DEFAULT_ERROR_LEVEL
);
225 printFeedEntry(-$line["id"]-11,
226 $class, $line["description"], $count, "images/label.png", $link);
230 if (db_num_rows($result) > 0) {
231 if (get_pref($link, 'ENABLE_FEED_CATS')) {
238 // if (!get_pref($link, 'ENABLE_FEED_CATS')) {
239 print "<li><hr></li>";
242 if (get_pref($link, 'ENABLE_FEED_CATS')) {
243 $order_by_qpart = "category,title";
245 $order_by_qpart = "title";
248 $result = db_query($link, "SELECT ttrss_feeds.*,
249 SUBSTRING(last_updated,1,19) AS last_updated_noms,
250 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
251 WHERE feed_id = ttrss_feeds.id AND
252 ttrss_user_entries.ref_id = ttrss_entries.id AND
253 owner_uid = '$owner_uid') AS total,
254 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
255 WHERE feed_id = ttrss_feeds.id AND unread = true
256 AND ttrss_user_entries.ref_id = ttrss_entries.id
257 AND owner_uid = '$owner_uid') as unread,
259 ttrss_feed_categories.title AS category,
260 ttrss_feed_categories.collapsed
261 FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
262 ON (ttrss_feed_categories.id = cat_id)
264 ttrss_feeds.owner_uid = '$owner_uid' AND parent_feed IS NULL
265 ORDER BY $order_by_qpart");
267 $actid = $_GET["actid"];
277 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
279 while ($line = db_fetch_assoc($result)) {
281 $feed = db_unescape_string($line["title"]);
282 $feed_id = $line["id"];
284 $subop = $_GET["subop"];
286 $total = $line["total"];
287 $unread = $line["unread"];
289 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
290 $last_updated = smart_date_time(strtotime($line["last_updated_noms"]));
292 $last_updated = date($short_date, strtotime($line["last_updated_noms"]));
295 $rtl_content = sql_bool_to_bool($line["rtl_content"]);
298 $rtl_tag = "dir=\"RTL\"";
303 $tmp_result = db_query($link,
304 "SELECT id,COUNT(unread) AS unread
305 FROM ttrss_feeds LEFT JOIN ttrss_user_entries
306 ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
307 WHERE parent_feed = '$feed_id' AND unread = true
308 GROUP BY ttrss_feeds.id");
310 if (db_num_rows($tmp_result) > 0) {
311 while ($l = db_fetch_assoc($tmp_result)) {
312 $unread +
= $l["unread"];
316 $cat_id = $line["cat_id"];
318 $tmp_category = $line["category"];
320 if (!$tmp_category) {
321 $tmp_category = "Uncategorized";
324 // $class = ($lnum % 2) ? "even" : "odd";
326 if ($line["last_error"]) {
332 if ($unread > 0) $class .= "Unread";
334 if ($actid == $feed_id) {
335 $class .= "Selected";
338 $total_unread +
= $unread;
340 if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
346 $category = $tmp_category;
348 $collapsed = $line["collapsed"];
350 // workaround for NULL category
351 if ($category == "Uncategorized") {
352 if ($_COOKIE["ttrss_vf_uclps"] == 1) {
357 if ($collapsed == "t" ||
$collapsed == "1") {
358 $holder_class = "invisible";
366 $cat_id_qpart = "cat_id = '$cat_id'";
368 $cat_id_qpart = "cat_id IS NULL";
371 $tmp_result = db_query($link, "SELECT count(int_id) AS unread
372 FROM ttrss_user_entries,ttrss_feeds WHERE
374 feed_id = ttrss_feeds.id AND $cat_id_qpart AND
375 ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
377 $cat_unread = db_fetch_result($tmp_result, 0, "unread");
379 $cat_id = sprintf("%d", $cat_id);
381 print "<li class=\"feedCat\" id=\"FCAT-$cat_id\">
382 <a href=\"javascript:toggleCollapseCat($cat_id)\">$tmp_category</a>
383 <a href=\"javascript:viewCategory($cat_id)\" id=\"FCAP-$cat_id\">
384 <span id=\"FCATCTR-$cat_id\"
385 class=\"$catctr_class\">($cat_unread unread)$ellipsis</span>
388 // !!! NO SPACE before <ul...feedCatList - breaks firstChild DOM function
389 // -> keyboard navigation, etc.
390 print "<li id=\"feedCatHolder\" class=\"$holder_class\"><ul class=\"feedCatList\" id=\"FCATLIST-$cat_id\">";
393 printFeedEntry($feed_id, $class, $feed, $unread,
394 "icons/$feed_id.ico", $link, $rtl_content,
395 $last_updated, $line["last_error"]);
404 /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
405 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
406 post_int_id = ttrss_user_entries.int_id AND
407 unread = true AND ref_id = ttrss_entries.id
408 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
410 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'
411 ORDER BY tag_name"); */
413 $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
414 FROM ttrss_user_entries WHERE int_id = post_int_id
415 AND unread = true)) AS count FROM ttrss_tags
416 WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name");
420 while ($line = db_fetch_assoc($result)) {
421 $tags[$line["tag_name"]] +
= $line["count"];
424 foreach (array_keys($tags) as $tag) {
426 $unread = $tags[$tag];
434 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
440 if (db_num_rows($result) == 0) {
446 print "<li>No $what to display.</li>";
452 <script type="text/javascript">
454 function statechange() {
455 if (document.readyState == "interactive") init();
458 if (document.readyState) {
459 if (document.readyState == "interactive" || document.readyState == "complete") {
462 document.onreadystatechange = statechange;
465 </script></body></html>';
470 handle_rpc_request($link);
473 if ($op == "feeds") {
475 $tags = $_GET["tags"];
477 $subop = $_GET["subop"];
479 if ($subop == "catchupAll") {
480 db_query($link, "UPDATE ttrss_user_entries SET
481 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
484 if ($subop == "collapse") {
485 $cat_id = db_escape_string($_GET["cid"]);
487 db_query($link, "UPDATE ttrss_feed_categories SET
488 collapsed = NOT collapsed WHERE id = '$cat_id' AND owner_uid = " .
493 outputFeedList($link, $tags);
499 $id = db_escape_string($_GET["id"]);
500 $feed_id = db_escape_string($_GET["feed"]);
502 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
503 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
505 if (db_num_rows($result) == 1) {
506 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
508 $rtl_content = false;
512 $rtl_tag = "dir=\"RTL\"";
519 $result = db_query($link, "UPDATE ttrss_user_entries
520 SET unread = false,last_read = NOW()
521 WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
523 $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
524 SUBSTRING(updated,1,16) as updated,
525 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url,
528 FROM ttrss_entries,ttrss_user_entries
529 WHERE id = '$id' AND ref_id = id AND owner_uid = " . $_SESSION["uid"]);
532 <title>Tiny Tiny RSS : Article $id</title>
533 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
535 $user_theme = $_SESSION["theme"];
537 print "<link rel=\"stylesheet\" type=\"text/css\"
538 href=\"themes/$user_theme/theme.css\">";
541 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
542 print "<link rel=\"stylesheet\" type=\"text/css\"
543 href=\"tt-rss_compact.css\"/>";
545 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
546 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
549 $script_dt_add = get_script_dt_add();
551 print "<script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
552 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
553 </head><body $rtl_tag>";
557 $line = db_fetch_assoc($result);
559 if ($line["icon_url"]) {
560 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
562 $feed_icon = " ";
565 /* if ($line["comments"] && $line["link"] != $line["comments"]) {
566 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
568 $entry_comments = "";
571 $num_comments = $line["num_comments"];
572 $entry_comments = "";
574 if ($num_comments > 0) {
575 if ($line["comments"]) {
576 $comments_url = $line["comments"];
578 $comments_url = $line["link"];
580 $entry_comments = "<a href=\"$comments_url\">$num_comments comments</a>";
582 if ($line["comments"] && $line["link"] != $line["comments"]) {
583 $entry_comments = "<a href=\"".$line["comments"]."\">comments</a>";
587 print "<div class=\"postReply\">";
589 print "<div class=\"postHeader\"><table width=\"100%\">";
591 $entry_author = $line["author"];
594 $entry_author = " - by $entry_author";
597 print "<tr><td><a href=\"" . $line["link"] . "\">" . $line["title"] .
598 "</a>$entry_author</td>";
600 $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
601 strtotime($line["updated"]));
603 print "<td class=\"postDate$rtl_class\">$parsed_updated</td>";
607 $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
608 ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
616 while ($tmp_line = db_fetch_assoc($tmp_result)) {
618 $tag = $tmp_line["tag_name"];
619 $tag_str = "<a href=\"javascript:parent.viewfeed('$tag')\">$tag</a>, ";
621 if ($num_tags == 5) {
622 $tags_str .= "<a href=\"javascript:showBlockElement('allEntryTags')\">...</a>";
623 } else if ($num_tags < 5) {
624 $tags_str .= $tag_str;
626 $f_tags_str .= $tag_str;
629 $tags_str = preg_replace("/, $/", "", $tags_str);
630 $f_tags_str = preg_replace("/, $/", "", $f_tags_str);
632 // $truncated_link = truncate_string($line["link"], 60);
634 if ($tags_str ||
$entry_comments) {
635 print "<tr><td width='50%'>
637 <td align=\"right\">$tags_str</td></tr>";
640 print "</table></div>";
642 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
643 print "<div class=\"postContent\">";
645 if (db_num_rows($tmp_result) > 5) {
646 print "<div id=\"allEntryTags\">Tags: $f_tags_str</div>";
649 if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
650 $line["content"] = preg_replace("/href=/i", "target=\"_new\" href=", $line["content"]);
653 print $line["content"] . "</div>";
657 print "<script type=\"text/javascript\">
658 update_all_counters('$feed_id');
662 print "</body></html>";
665 if ($op == "viewfeed") {
667 $feed = db_escape_string($_GET["feed"]);
668 $skip = db_escape_string($_GET["skip"]);
669 $subop = db_escape_string($_GET["subop"]);
670 $view_mode = db_escape_string($_GET["view"]);
671 $limit = db_escape_string($_GET["limit"]);
672 $cat_view = db_escape_string($_GET["cat"]);
673 $next_unread_feed = db_escape_string($_GET["nuf"]);
675 if (!$skip) $skip = 0;
677 if ($subop == "undefined") $subop = "";
680 <title>Tiny Tiny RSS : Feed $feed</title>
681 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
683 $user_theme = $_SESSION["theme"];
685 print "<link rel=\"stylesheet\" type=\"text/css\"
686 href=\"themes/$user_theme/theme.css\">";
689 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
690 print "<link rel=\"stylesheet\"
691 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
694 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
695 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
698 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
699 update_generic_feed($link, $feed, $cat_view);
702 if ($subop == "MarkAllRead") {
703 catchup_feed($link, $feed, $cat_view);
705 if (get_pref($link, 'ON_CATCHUP_SHOW_NEXT_FEED')) {
706 if ($next_unread_feed) {
707 $feed = $next_unread_feed;
712 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
714 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
715 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
717 if (db_num_rows($result) == 1) {
718 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
720 $rtl_content = false;
724 $rtl_tag = "dir=\"RTL\"";
730 $rtl_content = false;
733 $script_dt_add = get_script_dt_add();
735 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
736 <script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
737 <script type=\"text/javascript\" src=\"viewfeed.js?$script_dt_add\"></script>
738 <!--[if gte IE 5.5000]>
739 <script type=\"text/javascript\" src=\"pngfix.js\"></script>
740 <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
742 </head><body $rtl_tag>
743 <script type=\"text/javascript\">
744 if (document.addEventListener) {
745 document.addEventListener(\"DOMContentLoaded\", init, null);
747 window.onload = init;
750 $search = db_escape_string($_GET["search"]);
751 $search_mode = db_escape_string($_GET["smode"]);
754 $search_query_part = "(upper(ttrss_entries.title) LIKE upper('%$search%')
755 OR ttrss_entries.content LIKE '%$search%') AND";
757 $search_query_part = "";
760 $view_query_part = "";
762 if ($view_mode == "Adaptive") {
764 $view_query_part = " ";
765 } else if ($feed != -1) {
766 $unread = getFeedUnread($link, $feed);
768 $view_query_part = " unread = true AND ";
773 if ($view_mode == "Starred") {
774 $view_query_part = " marked = true AND ";
777 if ($view_mode == "Unread") {
778 $view_query_part = " unread = true AND ";
781 if ($limit && $limit != "All") {
782 $limit_query_part = "LIMIT " . $limit;
785 $vfeed_query_part = "";
787 // override query strategy and enable feed display when searching globally
788 if ($search && $search_mode == "All feeds") {
789 $query_strategy_part = "ttrss_entries.id > 0";
790 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
791 } else if (preg_match("/^-?[0-9][0-9]*$/", $feed) == false) {
792 $query_strategy_part = "ttrss_entries.id > 0";
793 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
794 id = feed_id) as feed_title,";
795 } else if ($feed >= 0 && $search && $search_mode == "This category") {
797 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
799 $tmp_result = db_query($link, "SELECT id
800 FROM ttrss_feeds WHERE cat_id =
801 (SELECT cat_id FROM ttrss_feeds WHERE id = '$feed') AND id != '$feed'");
803 $cat_siblings = array();
805 if (db_num_rows($tmp_result) > 0) {
806 while ($p = db_fetch_assoc($tmp_result)) {
807 array_push($cat_siblings, "feed_id = " . $p["id"]);
810 $query_strategy_part = sprintf("(feed_id = %d OR %s)",
811 $feed, implode(" OR ", $cat_siblings));
814 $query_strategy_part = "ttrss_entries.id > 0";
817 } else if ($feed >= 0) {
822 $query_strategy_part = "cat_id = '$feed'";
824 $query_strategy_part = "cat_id IS NULL";
827 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
830 $tmp_result = db_query($link, "SELECT id
831 FROM ttrss_feeds WHERE parent_feed = '$feed'
832 ORDER BY cat_id,title");
834 $parent_ids = array();
836 if (db_num_rows($tmp_result) > 0) {
837 while ($p = db_fetch_assoc($tmp_result)) {
838 array_push($parent_ids, "feed_id = " . $p["id"]);
841 $query_strategy_part = sprintf("(feed_id = %d OR %s)",
842 $feed, implode(" OR ", $parent_ids));
844 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
846 $query_strategy_part = "feed_id = '$feed'";
849 } else if ($feed == -1) { // starred virtual feed
850 $query_strategy_part = "marked = true";
851 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
852 } else if ($feed <= -10) { // labels
853 $label_id = -$feed - 11;
855 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
856 WHERE id = '$label_id'");
858 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
860 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
862 $query_strategy_part = "id > 0"; // dumb
865 $order_by = "updated DESC";
867 // if ($feed < -10) {
868 // $order_by = "feed_id,updated DESC";
873 if ($search && $search_mode == "All feeds") {
874 $feed_title = "Global search results ($search)";
875 } else if ($search && preg_match('/^-?[0-9][0-9]*$/', $feed) == false) {
876 $feed_title = "Feed search results ($search, $feed)";
877 } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) == false) {
879 } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) != false && $feed >= 0) {
884 $result = db_query($link, "SELECT title FROM ttrss_feed_categories
885 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
886 $feed_title = db_fetch_result($result, 0, "title");
888 $feed_title = "Uncategorized";
892 $result = db_query($link, "SELECT title,site_url,last_error FROM ttrss_feeds
893 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
895 $feed_title = db_fetch_result($result, 0, "title");
896 $feed_site_url = db_fetch_result($result, 0, "site_url");
897 $last_error = db_fetch_result($result, 0, "last_error");
901 } else if ($feed == -1) {
902 $feed_title = "Starred articles";
903 } else if ($feed < -10) {
904 $label_id = -$feed - 11;
905 $result = db_query($link, "SELECT description FROM ttrss_labels
906 WHERE id = '$label_id'");
907 $feed_title = db_fetch_result($result, 0, "description");
912 $feed_title = db_unescape_string($feed_title);
914 if ($feed < -10) error_reporting (0);
916 print "<div id=\"headlinesContainer\">";
918 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
921 $feed_kind = "Feeds";
923 $feed_kind = "Labels";
926 // if (!$vfeed_query_part) {
927 $content_query_part = "content as content_preview,";
929 // $content_query_part = "";
933 ttrss_entries.id,ttrss_entries.title,
934 SUBSTRING(updated,1,16) as updated,
935 unread,feed_id,marked,link,last_read,
936 SUBSTRING(last_read,1,19) as last_read_noms,
939 SUBSTRING(updated,1,19) as updated_noms
941 ttrss_entries,ttrss_user_entries,ttrss_feeds
943 ttrss_user_entries.feed_id = ttrss_feeds.id AND
944 ttrss_user_entries.ref_id = ttrss_entries.id AND
945 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
948 $query_strategy_part ORDER BY $order_by
951 $result = db_query($link, $query);
953 if ($_GET["debug"]) print $query;
960 $result = db_query($link, "SELECT
961 ttrss_entries.id as id,title,
962 SUBSTRING(updated,1,16) as updated,
964 marked,link,last_read,
965 SUBSTRING(last_read,1,19) as last_read_noms,
968 SUBSTRING(updated,1,19) as updated_noms
970 ttrss_entries,ttrss_user_entries,ttrss_tags
972 ref_id = ttrss_entries.id AND
973 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
974 post_int_id = int_id AND tag_name = '$feed' AND
977 $query_strategy_part ORDER BY $order_by
982 print "<div align='center'>
983 Could not display feed (query failed). Please check label match syntax or local configuration.</div>";
987 function print_headline_subtoolbar($link, $feed_site_url, $feed_title,
988 $bottom = false, $rtl_content = false) {
991 $class = "headlinesSubToolbar";
992 $tid = "headlineActionsTop";
994 $class = "invisible";
995 $tid = "headlineActionsBottom";
998 print "<table class=\"$class\" id=\"$tid\"
999 width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
1007 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1009 print "<td class=\"headlineActions$rtl_cpart\">
1011 <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, '', true)\">All</a>,
1012 <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true)\">Unread</a>,
1013 <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false)\">None</a>
1015 Toggle: <a href='#' onclick=\"javascript:selectionToggleUnread()\">Unread</a>,
1016 <a href='#' onclick=\"javascript:selectionToggleMarked()\">Starred</a>";
1021 print "<td class=\"headlineActions$rtl_cpart\">
1023 <a href=\"#\" onclick=\"javascript:cdmSelectArticles('all')\">All</a>,
1024 <a href=\"#\" onclick=\"javascript:cdmSelectArticles('unread')\">Unread</a>,
1025 <a href=\"#\" onclick=\"javascript:cdmSelectArticles('none')\">None</a>
1027 Toggle: <a href=\"#\" onclick=\"javascript:selectionToggleUnread(true)\">Unread</a>,
1028 <a href=\"#\" onclick=\"javascript:selectionToggleMarked(true)\">Starred</a>";
1034 print "<td class=\"headlineTitle$rtl_cpart\">";
1036 if ($feed_site_url) {
1038 $target = "target=\"_blank\"";
1040 print "<a $target href=\"$feed_site_url\">$feed_title</a>";
1046 print "</tr></table>";
1050 if (db_num_rows($result) > 0) {
1052 print_headline_subtoolbar($link, $feed_site_url, $feed_title, false,
1055 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1056 print "<table class=\"headlinesList\" id=\"headlinesList\"
1057 cellspacing=\"0\" width=\"100%\">";
1062 error_reporting (DEFAULT_ERROR_LEVEL
);
1066 while ($line = db_fetch_assoc($result)) {
1068 $class = ($lnum %
2) ?
"even" : "odd";
1071 $feed_id = $line["feed_id"];
1073 if ($line["last_read"] == "" &&
1074 ($line["unread"] != "t" && $line["unread"] != "1")) {
1076 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
1079 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
1083 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
1091 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
1092 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
1093 alt=\"Reset mark\" onclick='javascript:toggleMark($id)'>";
1095 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
1096 alt=\"Set mark\" onclick='javascript:toggleMark($id)'>";
1099 $content_link = "<a href=\"javascript:view($id,$feed_id);\">" .
1100 $line["title"] . "</a>";
1102 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1103 $updated_fmt = smart_date_time(strtotime($line["updated"]));
1105 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1106 $updated_fmt = date($short_date, strtotime($line["updated"]));
1109 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
1110 $content_preview = truncate_string(strip_tags($line["content_preview"]),
1114 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1116 print "<tr class='$class' id='RROW-$id'>";
1118 print "<td class='hlUpdatePic'>$update_pic</td>";
1120 print "<td class='hlSelectRow'>
1121 <input type=\"checkbox\" onclick=\"toggleSelectRow(this)\"
1122 class=\"feedCheckBox\" id=\"RCHK-$id\">
1125 print "<td class='hlMarkedPic'>$marked_pic</td>";
1127 if ($line["feed_title"]) {
1128 print "<td class='hlContent'>$content_link</td>";
1129 print "<td class='hlFeed'>
1130 <a href='javascript:viewfeed($feed_id)'>".
1131 $line["feed_title"]."</a> </td>";
1133 print "<td class='hlContent' valign='middle'>";
1135 print "<a href=\"javascript:view($id,$feed_id);\">" .
1138 if (get_pref($link, 'SHOW_CONTENT_PREVIEW') && !$rtl_tag) {
1139 if ($content_preview) {
1140 print "<span class=\"contentPreview\"> - $content_preview</span>";
1148 print "<td class=\"hlUpdated\"><nobr>$updated_fmt </nobr></td>";
1155 $add_class = "Unread";
1160 print "<div class=\"cdmArticle$add_class\" id=\"RROW-$id\">";
1162 print "<div class=\"cdmHeader\">";
1164 print "<div style=\"float : right\">$updated_fmt,
1165 <a class=\"cdmToggleLink\"
1166 href=\"javascript:toggleUnread($id)\">Toggle unread</a>
1169 print "<a class=\"title\"
1170 onclick=\"javascript:toggleUnread($id, 0)\"
1171 target=\"new\" href=\"".$line["link"]."\">".$line["title"]."</a>";
1173 if ($line["feed_title"]) {
1174 print " (<a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>)";
1179 print "<div class=\"cdmContent\">" . $line["content_preview"] . "</div>";
1181 print "<div style=\"float : right\">$marked_pic</div>
1182 <div lass=\"cdmFooter\">
1183 <input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
1184 'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\"></div>";
1186 # print "<div align=\"center\"><a class=\"cdmToggleLink\"
1187 # href=\"javascript:toggleUnread($id)\">
1188 # Toggle unread</a></div>";
1197 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1201 print_headline_subtoolbar($link,
1202 "javascript:catchupPage()", "Mark page as read", true, $rtl_content);
1206 print "<div width='100%' align='center'>No articles found.</div>";
1211 print "<script type=\"text/javascript\">
1212 document.onkeydown = hotkey_handler;
1213 // if (parent.daemon_enabled) parent.updateTitle('$feed_title');
1214 update_all_counters('$feed');
1218 <script type="text/javascript">
1220 function statechange() {
1221 if (document.readyState == "interactive") init();
1224 if (document.readyState) {
1225 if (document.readyState == "interactive" || document.readyState == "complete") {
1228 document.onreadystatechange = statechange;
1233 print "</body></html>";
1236 if ($op == "pref-rpc") {
1238 $subop = $_GET["subop"];
1240 if ($subop == "unread") {
1241 $ids = split(",", db_escape_string($_GET["ids"]));
1242 foreach ($ids as $id) {
1243 db_query($link, "UPDATE ttrss_user_entries SET unread = true
1244 WHERE feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
1247 print "Marked selected feeds as unread.";
1250 if ($subop == "read") {
1251 $ids = split(",", db_escape_string($_GET["ids"]));
1252 foreach ($ids as $id) {
1253 db_query($link, "UPDATE ttrss_user_entries
1254 SET unread = false,last_read = NOW() WHERE
1255 feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
1258 print "Marked selected feeds as read.";
1264 if ($op == "pref-feeds") {
1266 $subop = $_REQUEST["subop"];
1267 $quiet = $_REQUEST["quiet"];
1269 if ($subop == "massSubscribe") {
1270 $ids = split(",", db_escape_string($_GET["ids"]));
1272 $subscribed = array();
1274 foreach ($ids as $id) {
1275 $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds
1278 $feed_url = db_fetch_result($result, 0, "feed_url");
1279 $title = db_fetch_result($result, 0, "title");
1281 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
1282 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
1284 if (db_num_rows($result) == 0) {
1285 $result = db_query($link,
1286 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
1287 VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)");
1289 array_push($subscribed, $title);
1293 if (count($subscribed) > 0) {
1294 print "<div class=\"notice\">";
1295 print "<b>Subscribed to feeds:</b>";
1296 print "<ul class=\"nomarks\">";
1297 foreach ($subscribed as $title) {
1298 print "<li>$title</li>";
1305 if ($subop == "browse") {
1307 if (!ENABLE_FEED_BROWSER
) {
1308 print "Feed browser is administratively disabled.";
1312 print "<div id=\"infoBoxTitle\">Other feeds: Top 50</div>";
1314 print "<div class=\"infoBoxContents\">";
1316 print "<p>Showing top 50 registered feeds, sorted by popularity:</p>";
1318 $result = db_query($link, "SELECT feed_url,count(id) AS subscribers
1320 WHERE auth_login = '' AND auth_pass = '' AND private = false
1321 GROUP BY feed_url ORDER BY subscribers DESC LIMIT 50");
1323 print "<ul class='browseFeedList' id='browseFeedList'>";
1327 while ($line = db_fetch_assoc($result)) {
1328 $feed_url = $line["feed_url"];
1329 $subscribers = $line["subscribers"];
1331 $sub_result = db_query($link, "SELECT id
1332 FROM ttrss_feeds WHERE feed_url = '$feed_url' AND owner_uid =" .
1335 if (db_num_rows($sub_result) > 0) {
1336 continue; // already subscribed
1339 $det_result = db_query($link, "SELECT site_url,title,id
1340 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
1342 $details = db_fetch_assoc($det_result);
1344 $icon_file = ICONS_DIR
. "/" . $details["id"] . ".ico";
1346 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1347 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL
.
1348 "/".$details["id"].".ico\">";
1350 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1353 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
1354 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
1356 $class = ($feedctr %
2) ?
"even" : "odd";
1358 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
1359 "$feed_icon " . db_unescape_string($details["title"]) .
1360 " <span class='subscribers'>($subscribers)</span></li>";
1365 if ($feedctr == 0) {
1366 print "<li>No feeds found to subscribe.</li>";
1371 print "<div align='center'>
1372 <input type=\"submit\" class=\"button\"
1373 onclick=\"feedBrowserSubscribe()\" value=\"Subscribe\">
1374 <input type='submit' class='button'
1375 onclick=\"closeInfoBox()\" value=\"Cancel\"></div>";
1381 if ($subop == "editfeed") {
1382 $feed_id = db_escape_string($_GET["id"]);
1384 $result = db_query($link,
1385 "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
1386 owner_uid = " . $_SESSION["uid"]);
1388 $title = htmlspecialchars(db_unescape_string(db_fetch_result($result,
1391 $icon_file = ICONS_DIR
. "/$feed_id.ico";
1393 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1394 $feed_icon = "<img width=\"16\" height=\"16\"
1395 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
1400 print "<div id=\"infoBoxTitle\">Feed editor</div>";
1402 print "<div class=\"infoBoxContents\">";
1404 # print "<h1>$feed_icon $title</h1>";
1406 print "<table width='100%'>";
1408 # $row_class = "odd";
1410 print "<tr class='$row_class'><td>Title:</td>";
1411 print "<td><input id=\"iedit_title\" value=\"$title\"></td></tr>";
1413 $feed_url = db_fetch_result($result, 0, "feed_url");
1414 $feed_url = htmlspecialchars(db_unescape_string(db_fetch_result($result,
1416 # $row_class = toggleEvenOdd($row_class);
1418 print "<tr class='$row_class'><td>Feed URL:</td>";
1419 print "<td><input id=\"iedit_link\" value=\"$feed_url\"></td></tr>";
1421 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1423 $cat_id = db_fetch_result($result, 0, "cat_id");
1425 # $row_class = toggleEvenOdd($row_class);
1427 print "<tr class='$row_class'><td>Category:</td>";
1429 print "<select id=\"iedit_fcat\">";
1430 print "<option id=\"0\">Uncategorized</option>";
1432 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feed_categories
1433 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1435 if (db_num_rows($tmp_result) > 0) {
1436 print "<option disabled>--------</option>";
1439 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1440 if ($tmp_line["id"] == $cat_id) {
1441 $is_selected = "selected";
1445 printf("<option $is_selected id='%d'>%s</option>",
1446 $tmp_line["id"], $tmp_line["title"]);
1449 print "</select></td>";
1454 $update_interval = db_fetch_result($result, 0, "update_interval");
1455 # $row_class = toggleEvenOdd($row_class);
1457 print "<tr class='$row_class'><td>Update Interval:</td>";
1458 // print "<td><input id=\"iedit_updintl\"
1459 // value=\"$update_interval\"></td></tr>";
1463 print "<select id=\"iedit_updintl\">";
1465 foreach (array_keys($update_intervals) as $i) {
1467 if ($i == $update_interval) {
1468 $selected = "selected";
1472 print "<option $selected id=\"$i\">" . $update_intervals[$i] . "</option>";
1479 # $row_class = toggleEvenOdd($row_class);
1481 print "<tr class='$row_class'><td>Link to:</td><td>";
1483 $tmp_result = db_query($link, "SELECT COUNT(id) AS count
1484 FROM ttrss_feeds WHERE parent_feed = '$feed_id'");
1486 $linked_count = db_fetch_result($tmp_result, 0, "count");
1488 $parent_feed = db_fetch_result($result, 0, "parent_feed");
1490 if ($linked_count > 0) {
1491 $disabled = "disabled";
1494 print "<select $disabled id=\"iedit_parent_feed\">";
1496 print "<option id=\"0\">Not linked</option>";
1498 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1500 $cat_qpart = "AND cat_id = '$cat_id'";
1502 $cat_qpart = "AND cat_id IS NULL";
1506 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
1507 WHERE id != '$feed_id' AND owner_uid = ".$_SESSION["uid"]."
1508 $cat_qpart ORDER BY title");
1510 if (db_num_rows($tmp_result) > 0) {
1511 print "<option disabled>--------</option>";
1514 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1515 if ($tmp_line["id"] == $parent_feed) {
1516 $is_selected = "selected";
1520 printf("<option $is_selected id='%d'>%s</option>",
1521 $tmp_line["id"], $tmp_line["title"]);
1527 $purge_interval = db_fetch_result($result, 0, "purge_interval");
1528 # $row_class = toggleEvenOdd($row_class);
1530 print "<tr class='$row_class'><td>Purge Days:</td>";
1531 // print "<td><input id=\"iedit_purgintl\"
1532 // value=\"$purge_interval\"></td></tr>";
1536 print "<select id=\"iedit_purgintl\">";
1538 foreach (array_keys($purge_intervals) as $i) {
1540 if ($i == $purge_interval) {
1541 $selected = "selected";
1545 print "<option $selected id=\"$i\">" . $purge_intervals[$i] . "</option>";
1552 // print "<tr><td colspan=\"2\"><b>Authentication</b></td></tr>";
1554 # $row_class = toggleEvenOdd($row_class);
1555 $auth_login = db_fetch_result($result, 0, "auth_login");
1557 print "<tr class='$row_class'><td>Login:</td>";
1558 print "<td><input id=\"iedit_login\"
1559 value=\"$auth_login\"></td></tr>";
1561 # $row_class = toggleEvenOdd($row_class);
1562 $auth_pass = db_fetch_result($result, 0, "auth_pass");
1564 print "<tr class='$row_class'><td>Password:</td>";
1565 print "<td><input type=\"password\" id=\"iedit_pass\"
1566 value=\"$auth_pass\"></td></tr>";
1568 # $row_class = toggleEvenOdd($row_class);
1569 $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
1572 $checked = "checked";
1577 print "<tr class='$row_class'><td valign='top'>Options:</td>";
1578 print "<td><input type=\"checkbox\" id=\"iedit_private\"
1579 $checked><label for=\"iedit_private\">Hide from feed browser</label>";
1581 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
1584 $checked = "checked";
1589 print "<br><input type=\"checkbox\" id=\"iedit_rtl\"
1590 $checked><label for=\"iedit_rtl\">Right-to-left content</label>";
1597 print "<div align='center'>
1598 <input type=\"submit\" class=\"button\"
1599 onclick=\"feedEditSave()\" value=\"Save\">
1600 <input type='submit' class='button'
1601 onclick=\"feedEditCancel()\" value=\"Cancel\"></div>";
1605 if ($subop == "editSave") {
1606 $feed_title = db_escape_string($_POST["t"]);
1607 $feed_link = db_escape_string($_POST["l"]);
1608 $upd_intl = db_escape_string($_POST["ui"]);
1609 $purge_intl = db_escape_string($_POST["pi"]);
1610 $feed_id = db_escape_string($_POST["id"]);
1611 $cat_id = db_escape_string($_POST["catid"]);
1612 $auth_login = db_escape_string($_POST["login"]);
1613 $auth_pass = db_escape_string($_POST["pass"]);
1614 $parent_feed = db_escape_string($_POST["pfeed"]);
1615 $private = db_escape_string($_POST["is_pvt"]);
1616 $rtl_content = db_escape_string($_POST["is_rtl"]);
1618 if (strtoupper($upd_intl) == "DEFAULT")
1621 if (strtoupper($upd_intl) == "DISABLED")
1624 if (strtoupper($purge_intl) == "DEFAULT")
1627 if (strtoupper($purge_intl) == "DISABLED")
1631 $category_qpart = "cat_id = '$cat_id'";
1633 $category_qpart = 'cat_id = NULL';
1636 if ($parent_feed != 0) {
1637 $parent_qpart = "parent_feed = '$parent_feed'";
1639 $parent_qpart = 'parent_feed = NULL';
1642 $result = db_query($link, "UPDATE ttrss_feeds SET
1645 title = '$feed_title', feed_url = '$feed_link',
1646 update_interval = '$upd_intl',
1647 purge_interval = '$purge_intl',
1648 auth_login = '$auth_login',
1649 auth_pass = '$auth_pass',
1651 rtl_content = $rtl_content
1652 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
1655 if ($subop == "saveCat") {
1656 $cat_title = db_escape_string($_GET["title"]);
1657 $cat_id = db_escape_string($_GET["id"]);
1659 $result = db_query($link, "UPDATE ttrss_feed_categories SET
1660 title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
1664 if ($subop == "remove") {
1666 if (!WEB_DEMO_MODE
) {
1668 $ids = split(",", db_escape_string($_GET["ids"]));
1670 foreach ($ids as $id) {
1671 db_query($link, "DELETE FROM ttrss_feeds
1672 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1674 $icons_dir = ICONS_DIR
;
1676 if (file_exists($icons_dir . "/$id.ico")) {
1677 unlink($icons_dir . "/$id.ico");
1683 if ($subop == "add") {
1685 if (!WEB_DEMO_MODE
) {
1687 $feed_link = db_escape_string(trim($_GET["link"]));
1688 $cat_id = db_escape_string($_GET["cid"]);
1690 if (subscribe_to_feed($link, $feed_link, $cat_id)) {
1691 print "Added feed.";
1693 print "<div class=\"warning\">
1694 Feed <b>$feed_link</b> already exists in the database.
1700 if ($subop == "addCat") {
1702 if (!WEB_DEMO_MODE
) {
1704 $feed_cat = db_escape_string(trim($_GET["cat"]));
1706 $result = db_query($link,
1707 "SELECT id FROM ttrss_feed_categories
1708 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
1710 if (db_num_rows($result) == 0) {
1712 $result = db_query($link,
1713 "INSERT INTO ttrss_feed_categories (owner_uid,title)
1714 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
1718 print "<div class=\"warning\">
1719 Category <b>$feed_cat</b> already exists in the database.
1727 if ($subop == "removeCats") {
1729 if (!WEB_DEMO_MODE
) {
1731 $ids = split(",", db_escape_string($_GET["ids"]));
1733 foreach ($ids as $id) {
1735 db_query($link, "BEGIN");
1737 $result = db_query($link,
1738 "SELECT count(id) as num_feeds FROM ttrss_feeds
1739 WHERE cat_id = '$id'");
1741 $num_feeds = db_fetch_result($result, 0, "num_feeds");
1743 if ($num_feeds == 0) {
1744 db_query($link, "DELETE FROM ttrss_feed_categories
1745 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1748 print "<div class=\"warning\">
1749 Unable to delete non empty feed categories.</div>";
1753 db_query($link, "COMMIT");
1758 if ($subop == "categorize") {
1760 if (!WEB_DEMO_MODE
) {
1762 $ids = split(",", db_escape_string($_GET["ids"]));
1764 $cat_id = db_escape_string($_GET["cat_id"]);
1767 $cat_id_qpart = 'NULL';
1769 $cat_id_qpart = "'$cat_id'";
1772 db_query($link, "BEGIN");
1774 foreach ($ids as $id) {
1776 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
1777 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1780 db_query($link, "COMMIT");
1787 // print "<h3>Edit Feeds</h3>";
1789 $result = db_query($link, "SELECT id,title,feed_url,last_error
1790 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1792 if (db_num_rows($result) > 0) {
1794 print "<div class=\"warning\">";
1796 // print"<img class=\"closeButton\"
1797 // onclick=\"javascript:hideParentElement(this);\" src=\"images/close.png\">";
1799 print "<a href=\"javascript:showBlockElement('feedUpdateErrors')\">
1800 <b>Feeds with update errors</b> (click to expand)</a>";
1802 print "<ul id=\"feedUpdateErrors\" class=\"nomarks\">";
1804 while ($line = db_fetch_assoc($result)) {
1805 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
1806 $line["last_error"];
1814 $feed_search = db_escape_string($_GET["search"]);
1816 if (array_key_exists("search", $_GET)) {
1817 $_SESSION["prefs_feed_search"] = $feed_search;
1819 $feed_search = $_SESSION["prefs_feed_search"];
1822 print "<table width='100%' class=\"prefGenericAddBox\"
1823 cellspacing='0' cellpadding='0'><tr>
1825 <input id=\"fadd_link\"
1826 onchange=\"javascript:addFeed()\"
1828 <input type=\"submit\" class=\"button\"
1829 onclick=\"javascript:addFeed()\" value=\"Subscribe\">";
1831 if (ENABLE_FEED_BROWSER
&& !SINGLE_USER_MODE
) {
1832 print " <input type=\"submit\" class=\"button\"
1833 onclick=\"javascript:browseFeeds()\" value=\"Top 50\">";
1836 print "</td><td align='right'>
1837 <input id=\"feed_search\" size=\"20\"
1838 onchange=\"javascript:updateFeedList()\"
1839 value=\"$feed_search\">
1840 <input type=\"submit\" class=\"button\"
1841 onclick=\"javascript:updateFeedList()\" value=\"Search\">
1845 $feeds_sort = db_escape_string($_GET["sort"]);
1847 if (!$feeds_sort ||
$feeds_sort == "undefined") {
1848 $feeds_sort = $_SESSION["pref_sort_feeds"];
1849 if (!$feeds_sort) $feeds_sort = "title";
1852 $_SESSION["pref_sort_feeds"] = $feeds_sort;
1855 $search_qpart = "(UPPER(F1.title) LIKE UPPER('%$feed_search%') OR
1856 UPPER(F1.feed_url) LIKE UPPER('%$feed_search%')) AND";
1861 $result = db_query($link, "SELECT
1865 substring(F1.last_updated,1,16) AS last_updated,
1870 F2.title AS parent_title,
1871 C1.title AS category
1874 LEFT JOIN ttrss_feeds AS F2
1875 ON (F1.parent_feed = F2.id)
1876 LEFT JOIN ttrss_feed_categories AS C1
1877 ON (F1.cat_id = C1.id)
1879 $search_qpart F1.owner_uid = '".$_SESSION["uid"]."'
1880 ORDER by category,$feeds_sort,title");
1882 if (db_num_rows($result) != 0) {
1884 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1886 print "<p><table width=\"100%\" cellspacing=\"0\"
1887 class=\"prefFeedList\" id=\"prefFeedList\">";
1888 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1890 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
1891 'FEEDR-', 'FRCHK-', true)\">All</a>,
1892 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
1893 'FEEDR-', 'FRCHK-', false)\">None</a>
1896 if (!get_pref($link, 'ENABLE_FEED_CATS')) {
1897 print "<tr class=\"title\">
1898 <td width='5%' align='center'> </td>
1899 <td width='40%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
1900 <td width='45%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
1901 <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
1908 while ($line = db_fetch_assoc($result)) {
1910 $feed_id = $line["id"];
1911 $cat_id = $line["cat_id"];
1913 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1914 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
1915 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
1917 if (!$edit_cat) $edit_cat = "Uncategorized";
1919 $last_updated = $line["last_updated"];
1921 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1922 $last_updated = smart_date_time(strtotime($last_updated));
1924 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1925 $last_updated = date($short_date, strtotime($last_updated));
1928 if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
1931 print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>";
1933 print "<tr class=\"title\">
1934 <td width='5%'> </td>";
1936 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1937 print "<td width='3%'> </td>";
1940 print "<td width='40%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
1941 <td width='45%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
1942 <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
1944 $cur_cat_id = $cat_id;
1947 $class = ($lnum %
2) ?
"even" : "odd";
1948 $this_row_id = "id=\"FEEDR-$feed_id\"";
1950 print "<tr class=\"$class\" $this_row_id>";
1952 $icon_file = ICONS_DIR
. "/$feed_id.ico";
1954 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1955 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL
. "/$feed_id.ico\">";
1957 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1960 print "<td class='feedSelect'><input onclick='toggleSelectRow(this);'
1961 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
1963 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1964 print "<td class='feedIcon'>$feed_icon</td>";
1967 $edit_title = truncate_string($edit_title, 40);
1968 $edit_link = truncate_string($edit_link, 60);
1970 $parent_title = $line["parent_title"];
1971 if ($parent_title) {
1972 $parent_title = "<span class='groupPrompt'>(linked to
1973 $parent_title)</span>";
1976 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1977 "$edit_title $parent_title" . "</a></td>";
1979 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1980 $edit_link . "</a></td>";
1982 /* if (get_pref($link, 'ENABLE_FEED_CATS')) {
1983 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1984 $edit_cat . "</a></td>";
1987 /* print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1988 $update_intervals[$line["update_interval"]] . "</a></td>";
1990 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1991 $purge_intervals[$line["purge_interval"]] . "</a></td>"; */
1993 print "<td align='right'><a href=\"javascript:editFeed($feed_id);\">" .
1994 "$last_updated</a></td>";
2005 if ($subop == "edit") {
2006 print "Edit feed:
2007 <input type=\"submit\" class=\"button\"
2008 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
2009 <input type=\"submit\" class=\"button\"
2010 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
2015 <!-- <input type=\"submit\" class=\"button\"
2016 onclick=\"javascript:selectedFeedDetails()\" value=\"Details\"> -->
2017 <input type=\"submit\" class=\"button\"
2018 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
2019 <input type=\"submit\" class=\"button\"
2020 onclick=\"javascript:removeSelectedFeeds()\" value=\"Unsubscribe\">";
2022 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2024 print " | ";
2026 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2027 WHERE owner_uid = ".$_SESSION["uid"]."
2030 print "<select id=\"sfeed_set_fcat\">";
2031 print "<option id=\"0\">Uncategorized</option>";
2033 if (db_num_rows($result) != 0) {
2035 print "<option disabled>--------</option>";
2037 while ($line = db_fetch_assoc($result)) {
2038 printf("<option id='%d'>%s</option>",
2039 $line["id"], $line["title"]);
2045 print " <input type=\"submit\" class=\"button\"
2046 onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Recategorize\">";
2051 All feeds: <input type=\"submit\"
2052 class=\"button\" onclick=\"gotoExportOpml()\"
2053 value=\"Export OPML\">";
2057 print "<p>No feeds defined.</p>";
2061 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2063 print "<h3>Edit Categories</h3>";
2065 // print "<h3>Categories</h3>";
2067 print "<div class=\"prefGenericAddBox\">
2068 <input id=\"fadd_cat\"
2069 onchange=\"javascript:addFeedCat()\"
2072 type=\"submit\" class=\"button\"
2073 onclick=\"javascript:addFeedCat()\" value=\"Create category\"></div>";
2075 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2076 WHERE owner_uid = ".$_SESSION["uid"]."
2079 if (db_num_rows($result) != 0) {
2081 print "<p><table width=\"100%\" class=\"prefFeedCatList\"
2082 cellspacing=\"0\" id=\"prefFeedCatList\">";
2084 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2086 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
2087 'FCATR-', 'FCCHK-', true)\">All</a>,
2088 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
2089 'FCATR-', 'FCCHK-', false)\">None</a>
2092 print "<tr class=\"title\">
2093 <td width=\"5%\"> </td><td width=\"80%\">Title</td>
2098 while ($line = db_fetch_assoc($result)) {
2100 $class = ($lnum %
2) ?
"even" : "odd";
2102 $cat_id = $line["id"];
2104 $edit_cat_id = $_GET["id"];
2106 if ($subop == "editCat" && $cat_id != $edit_cat_id) {
2110 $this_row_id = "id=\"FCATR-$cat_id\"";
2113 print "<tr class=\"$class\" $this_row_id>";
2115 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
2117 if (!$edit_cat_id ||
$subop != "editCat") {
2119 print "<td align='center'><input onclick='toggleSelectRow(this);'
2120 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
2122 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
2123 $edit_title . "</a></td>";
2125 } else if ($cat_id != $edit_cat_id) {
2127 print "<td><input disabled=\"true\" type=\"checkbox\"
2128 id=\"FRCHK-".$line["id"]."\"></td>";
2130 print "<td>$edit_title</td>";
2134 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2136 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
2149 if ($subop == "editCat") {
2150 print "Edit category:
2151 <input type=\"submit\" class=\"button\"
2152 onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\">
2153 <input type=\"submit\" class=\"button\"
2154 onclick=\"javascript:feedCatEditSave()\" value=\"Save\">";
2159 <input type=\"submit\" class=\"button\"
2160 onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\">
2161 <input type=\"submit\" class=\"button\"
2162 onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">";
2167 print "<p>No feed categories defined.</p>";
2171 print "<h3>Import OPML</h3>
2172 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
2173 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">
2174 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
2175 type=\"submit\" value=\"Import\">
2180 if ($op == "pref-filters") {
2182 $subop = $_GET["subop"];
2183 $quiet = $_GET["quiet"];
2185 if ($subop == "editSave") {
2187 $regexp = db_escape_string($_GET["r"]);
2188 $match = db_escape_string($_GET["m"]);
2189 $filter_id = db_escape_string($_GET["id"]);
2190 $feed_id = db_escape_string($_GET["fid"]);
2191 $action_id = db_escape_string($_GET["aid"]);
2196 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2199 $result = db_query($link, "UPDATE ttrss_filters SET
2200 reg_exp = '$regexp',
2202 action_id = '$action_id',
2203 filter_type = (SELECT id FROM ttrss_filter_types WHERE
2204 description = '$match')
2205 WHERE id = '$filter_id'");
2208 if ($subop == "remove") {
2210 if (!WEB_DEMO_MODE
) {
2212 $ids = split(",", db_escape_string($_GET["ids"]));
2214 foreach ($ids as $id) {
2215 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
2221 if ($subop == "add") {
2223 if (!WEB_DEMO_MODE
) {
2225 $regexp = db_escape_string(trim($_GET["regexp"]));
2226 $match = db_escape_string(trim($_GET["match"]));
2227 $feed_id = db_escape_string($_GET["fid"]);
2228 $action_id = db_escape_string($_GET["aid"]);
2233 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2236 $result = db_query($link,
2237 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
2240 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
2241 description = '$match'),'".$_SESSION["uid"]."',
2242 $feed_id, '$action_id')");
2248 print "<div id=\"infoBoxShadow\">
2249 <div id=\"infoBox\">PLACEHOLDER</div></div>";
2251 $result = db_query($link, "SELECT description
2252 FROM ttrss_filter_types ORDER BY description");
2254 $filter_types = array();
2256 while ($line = db_fetch_assoc($result)) {
2257 array_push($filter_types, $line["description"]);
2260 /* print "<div class=\"prefGenericAddBox\">
2261 <input id=\"fadd_regexp\" size=\"40\"> ";
2263 print_select("fadd_match", "Title", $filter_types);
2265 print " <select id=\"fadd_feed\">";
2267 print "<option selected id=\"0\">All feeds</option>";
2269 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
2270 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2272 if (db_num_rows($result) > 0) {
2273 print "<option disabled>--------</option>";
2276 while ($line = db_fetch_assoc($result)) {
2277 printf("<option id='%d'>%s</option>", $line["id"],
2278 db_unescape_string($line["title"]));
2281 print "</select> ";
2283 print " Action: ";
2285 print "<select id=\"fadd_action\">";
2287 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2290 while ($line = db_fetch_assoc($result)) {
2291 printf("<option id='%d'>%s</option>", $line["id"], $line["description"]);
2294 print "</select> ";
2296 /* print "<input type=\"submit\"
2297 class=\"button\" onclick=\"javascript:testFilter()\"
2298 value=\"Test filter\"> "; */
2300 /* print "<input type=\"submit\"
2301 class=\"button\" onclick=\"javascript:addFilter()\"
2302 value=\"Create filter\">"; */
2304 print "<input type=\"submit\"
2306 onclick=\"javascript:displayDlg('quickAddFilter', false)\"
2307 value=\"Create filter\">";
2311 $result = db_query($link, "SELECT
2312 ttrss_filters.id AS id,reg_exp,
2313 ttrss_filter_types.name AS filter_type_name,
2314 ttrss_filter_types.description AS filter_type_descr,
2316 ttrss_filter_actions.description AS action_description,
2317 ttrss_feeds.title AS feed_title
2319 ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN
2320 ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id)
2322 filter_type = ttrss_filter_types.id AND
2323 ttrss_filter_actions.id = action_id AND
2324 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
2327 if (db_num_rows($result) != 0) {
2329 print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\"
2330 id=\"prefFilterList\">";
2332 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2334 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
2335 'FILRR-', 'FICHK-', true)\">All</a>,
2336 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
2337 'FILRR-', 'FICHK-', false)\">None</a>
2340 print "<tr class=\"title\">
2341 <td align='center' width=\"5%\"> </td>
2342 <td width=\"20%\">Filter expression</td>
2343 <td width=\"20%\">Feed</td>
2344 <td width=\"15%\">Match</td>
2345 <td width=\"15%\">Action</td>";
2349 while ($line = db_fetch_assoc($result)) {
2351 $class = ($lnum %
2) ?
"even" : "odd";
2353 $filter_id = $line["id"];
2354 $edit_filter_id = $_GET["id"];
2356 if ($subop == "edit" && $filter_id != $edit_filter_id) {
2360 $this_row_id = "id=\"FILRR-$filter_id\"";
2363 print "<tr class=\"$class\" $this_row_id>";
2365 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
2367 if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
2369 if (!$edit_filter_id ||
$subop != "edit") {
2371 print "<td align='center'><input onclick='toggleSelectRow(this);'
2372 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
2374 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2375 $line["reg_exp"] . "</td>";
2377 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2378 $line["feed_title"] . "</td>";
2380 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2381 $line["filter_type_descr"] . "</td>";
2383 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2384 $line["action_description"] . "</td>";
2386 } else if ($filter_id != $edit_filter_id) {
2388 if (!$line["description"]) $line["description"] = "[No description]";
2390 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
2391 id=\"FICHK-".$line["id"]."\"></td>";
2393 print "<td>".$line["reg_exp"]."</td>";
2394 print "<td>".$line["feed_title"]."</td>";
2395 print "<td>".$line["filter_type_descr"]."</td>";
2396 print "<td>".$line["action_description"]."</td>";
2400 print "<td align='center'><input disabled=\"true\" type=\"checkbox\" checked></td>";
2402 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
2406 print "<select id=\"iedit_feed\">";
2407 print "<option id=\"0\">All feeds</option>";
2409 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
2410 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2412 if (db_num_rows($tmp_result) > 0) {
2413 print "<option disabled>--------</option>";
2416 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2417 if ($tmp_line["id"] == $line["feed_id"]) {
2418 $is_selected = "selected";
2422 printf("<option $is_selected id='%d'>%s</option>",
2423 $tmp_line["id"], db_unescape_string($tmp_line["title"]));
2426 print "</select></td>";
2429 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
2433 print "<select id=\"iedit_filter_action\">";
2435 $tmp_result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2436 ORDER BY description");
2438 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2439 if ($tmp_line["description"] == $line["action_description"]) {
2440 $is_selected = "selected";
2444 printf("<option $is_selected id='%d'>%s</option>",
2445 $tmp_line["id"], $tmp_line["description"]);
2448 print "</select></td>";
2459 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
2466 if ($subop == "edit") {
2468 <input type=\"submit\" class=\"button\"
2469 onclick=\"javascript:filterEditSave()\" value=\"Save\">
2470 <input type=\"submit\" class=\"button\"
2471 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">";
2477 <input type=\"submit\" class=\"button\"
2478 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
2479 <input type=\"submit\" class=\"button\"
2480 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
2485 print "<p>No filters defined.</p>";
2490 // We need to accept raw SQL data in label queries, so not everything is escaped
2491 // here, this is by design. If you don't like the whole idea, disable labels
2492 // altogether with GLOBAL_ENABLE_LABELS = false
2494 if ($op == "pref-labels") {
2496 if (!GLOBAL_ENABLE_LABELS
) {
2500 $subop = $_GET["subop"];
2502 if ($subop == "test") {
2504 $expr = $_GET["expr"];
2505 $descr = $_GET["descr"];
2507 print "<div id=\"infoBoxTitle\">Test label: $descr</div>";
2509 print "<div class='infoBoxContents'>";
2511 # print "<h1>Label «$descr»</h1>";
2513 // print "<p><b>Expression</b>: $expr</p>";
2515 $result = db_query($link,
2516 "SELECT count(id) AS num_matches
2517 FROM ttrss_entries,ttrss_user_entries
2519 ttrss_user_entries.ref_id = ttrss_entries.id AND
2520 owner_uid = " . $_SESSION["uid"]);
2522 $num_matches = db_fetch_result($result, 0, "num_matches");;
2524 if ($num_matches > 0) {
2526 print "<p>Query returned <b>$num_matches</b> matches, first 5 follow:</p>";
2528 $result = db_query($link,
2530 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
2531 FROM ttrss_entries,ttrss_user_entries
2533 ttrss_user_entries.ref_id = ttrss_entries.id
2534 AND owner_uid = " . $_SESSION["uid"] . "
2535 ORDER BY date_entered DESC LIMIT 5");
2537 print "<ul class=\"nomarks\">";
2538 while ($line = db_fetch_assoc($result)) {
2539 print "<li>".$line["title"].
2540 " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
2545 print "<p>Query didn't return any matches.</p>";
2550 print "<div align='center'>
2551 <input type='submit' class='button'
2552 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2556 if ($subop == "editSave") {
2558 $sql_exp = $_GET["s"];
2559 $descr = $_GET["d"];
2560 $label_id = db_escape_string($_GET["id"]);
2562 // print "$sql_exp : $descr : $label_id";
2564 $result = db_query($link, "UPDATE ttrss_labels SET
2565 sql_exp = '$sql_exp',
2566 description = '$descr'
2567 WHERE id = '$label_id'");
2570 if ($subop == "remove") {
2572 if (!WEB_DEMO_MODE
) {
2574 $ids = split(",", db_escape_string($_GET["ids"]));
2576 foreach ($ids as $id) {
2577 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
2583 if ($subop == "add") {
2585 if (!WEB_DEMO_MODE
) {
2587 // no escaping is done here on purpose
2588 $exp = trim($_GET["exp"]);
2590 $result = db_query($link,
2591 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
2592 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
2596 print "<div class=\"prefGenericAddBox\">
2597 <input size=\"40\" id=\"ladd_expr\"> ";
2599 print"<input type=\"submit\" class=\"button\"
2600 onclick=\"javascript:addLabel()\" value=\"Add label\"></div>";
2602 $result = db_query($link, "SELECT
2603 id,sql_exp,description
2607 owner_uid = ".$_SESSION["uid"]."
2608 ORDER by description");
2610 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2612 if (db_num_rows($result) != 0) {
2614 print "<p><table width=\"100%\" cellspacing=\"0\"
2615 class=\"prefLabelList\" id=\"prefLabelList\">";
2617 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2619 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2620 'LILRR-', 'LICHK-', true)\">All</a>,
2621 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2622 'LILRR-', 'LICHK-', false)\">None</a>
2625 print "<tr class=\"title\">
2626 <td align='center' width=\"5%\"> </td>
2627 <td width=\"40%\">SQL expression
2628 <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a>
2630 <td width=\"40%\">Caption</td></tr>";
2634 while ($line = db_fetch_assoc($result)) {
2636 $class = ($lnum %
2) ?
"even" : "odd";
2638 $label_id = $line["id"];
2639 $edit_label_id = $_GET["id"];
2641 if ($subop == "edit" && $label_id != $edit_label_id) {
2645 $this_row_id = "id=\"LILRR-$label_id\"";
2648 print "<tr class=\"$class\" $this_row_id>";
2650 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
2651 $line["description"] = htmlspecialchars($line["description"]);
2653 if (!$edit_label_id ||
$subop != "edit") {
2655 if (!$line["description"]) $line["description"] = "[No caption]";
2657 print "<td align='center'><input onclick='toggleSelectRow(this);'
2658 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
2660 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2661 $line["sql_exp"] . "</td>";
2663 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2664 $line["description"] . "</td>";
2666 } else if ($label_id != $edit_label_id) {
2668 if (!$line["description"]) $line["description"] = "[No description]";
2670 print "<td><input disabled=\"true\" type=\"checkbox\"
2671 id=\"LICHK-".$line["id"]."\"></td>";
2673 print "<td>".$line["sql_exp"]."</td>";
2674 print "<td>".$line["description"]."</td>";
2678 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2680 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
2683 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2695 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
2702 if ($subop == "edit") {
2704 <input type=\"submit\" class=\"button\"
2705 onclick=\"javascript:labelTest()\" value=\"Test\">
2706 <input type=\"submit\" class=\"button\"
2707 onclick=\"javascript:labelEditSave()\" value=\"Save\">
2708 <input type=\"submit\" class=\"button\"
2709 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">";
2715 <input type=\"submit\" class=\"button\"
2716 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
2717 <input type=\"submit\" class=\"button\"
2718 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
2721 print "<p>No labels defined.</p>";
2725 if ($op == "error") {
2726 print "<div width=\"100%\" align='center'>";
2727 $msg = $_GET["msg"];
2732 if ($op == "help") {
2733 if (!$_GET["noheaders"]) {
2735 <title>Tiny Tiny RSS : Help</title>
2736 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2737 <script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
2738 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2742 $tid = sprintf("%d", $_GET["tid"]);
2744 print "<div id=\"infoBoxTitle\">Help</div>";
2746 print "<div class='infoBoxContents'>";
2748 if (file_exists("help/$tid.php")) {
2749 include("help/$tid.php");
2751 print "<p>Help topic not found.</p>";
2756 print "<div align='center'>
2757 <input type='submit' class='button'
2758 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2760 if (!$_GET["noheaders"]) {
2761 print "</body></html>";
2768 $param = $_GET["param"];
2770 if ($id == "quickAddFeed") {
2772 print "<div id=\"infoBoxTitle\">Subscribe to feed</div>";
2773 print "<div class=\"infoBoxContents\">";
2775 print "<table width='100%'>
2776 <tr><td>Feed URL:</td><td>
2777 <input onblur=\"javascript:enableHotkeys()\"
2778 onfocus=\"javascript:disableHotkeys()\" id=\"qafInput\"></td></tr>";
2780 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2781 print "<tr><td>Category:</td><td>";
2783 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2784 WHERE owner_uid = ".$_SESSION["uid"]."
2787 print "<select id=\"qafCat\">";
2788 print "<option id=\"0\">Uncategorized</option>";
2790 if (db_num_rows($result) != 0) {
2792 print "<option disabled>--------</option>";
2794 while ($line = db_fetch_assoc($result)) {
2795 printf("<option id='%d'>%s</option>",
2796 $line["id"], $line["title"]);
2804 print "<tr><td colspan='2' align='right'><input class=\"button\"
2805 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Subscribe\">
2806 <input class=\"button\"
2807 type=\"submit\" onclick=\"javascript:closeInfoBox()\"
2808 value=\"Cancel\"></td></tr></table>";
2811 if ($id == "quickDelFeed") {
2813 $param = db_escape_string($param);
2815 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
2819 $f_title = db_fetch_result($result, 0, "title");
2821 print "Remove current feed (<b>$f_title</b>)?
2822 <input class=\"button\"
2823 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
2824 <input class=\"button\"
2825 type=\"submit\" onclick=\"javascript:closeInfoBox()\"
2828 print "Error: Feed $param not found.
2829 <input class=\"button\"
2830 type=\"submit\" onclick=\"javascript:closeInfoBox()\"
2835 if ($id == "search") {
2837 print "<div id=\"infoBoxTitle\">Search</div>";
2838 print "<div class=\"infoBoxContents\">";
2840 $active_feed_id = db_escape_string($_GET["param"]);
2842 print "<table width='100%'><tr><td>Search:</td><td>";
2844 print "<input id=\"searchbox\" class=\"extSearch\"
2845 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2846 onchange=\"javascript:search()\">
2847 </td></tr><tr><td>Where:</td><td>
2848 <select id=\"searchmodebox\">
2849 <option selected>All feeds</option>";
2851 if ($active_feed_id) {
2852 print "<option>This feed</option>";
2854 print "<option disabled>This feed</option>";
2857 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2858 print "<option>This category</option>";
2861 print "</select></td></tr>
2863 <tr><td colspan='2' align='right'>
2864 <input type=\"submit\"
2865 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
2866 <input class=\"button\"
2867 type=\"submit\" onclick=\"javascript:closeInfoBox()\"
2868 value=\"Cancel\"></td></tr></table>";
2872 if ($id == "quickAddFilter") {
2874 print "<div id=\"infoBoxTitle\">Create filter</div>";
2875 print "<div class=\"infoBoxContents\">";
2877 $result = db_query($link, "SELECT description
2878 FROM ttrss_filter_types ORDER BY description");
2880 $filter_types = array();
2882 while ($line = db_fetch_assoc($result)) {
2883 array_push($filter_types, $line["description"]);
2886 print "<table width='100%'>";
2888 print "<tr><td>Match:</td><td><input id=\"fadd_regexp\" size=\"30\"> ";
2890 print_select("fadd_match", "Title", $filter_types);
2893 print "<tr><td>Feed:</td><td><select id=\"fadd_feed\">";
2895 print "<option selected id=\"0\">All feeds</option>";
2897 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
2898 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2900 if (db_num_rows($result) > 0) {
2901 print "<option disabled>--------</option>";
2904 while ($line = db_fetch_assoc($result)) {
2905 if ($param == $line["id"]) {
2906 $selected = "selected";
2910 printf("<option id='%d' %s>%s</option>", $line["id"], $selected, $line["title"]);
2913 print "</select></td></tr>";
2915 print "<tr><td>Action:</td>";
2917 print "<td><select id=\"fadd_action\">";
2919 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2922 while ($line = db_fetch_assoc($result)) {
2923 printf("<option id='%d'>%s</option>", $line["id"], $line["description"]);
2928 print "</td></tr><tr><td colspan=\"2\" align=\"right\">";
2930 print "<input type=\"submit\"
2931 class=\"button\" onclick=\"javascript:qaddFilter()\"
2932 value=\"Create\"> ";
2934 print "<input class=\"button\"
2935 type=\"submit\" onclick=\"javascript:closeInfoBox()\"
2938 print "</td></tr></table>";
2946 // update feeds of all users, may be used anonymously
2947 if ($op == "globalUpdateFeeds") {
2949 $result = db_query($link, "SELECT id FROM ttrss_users");
2951 while ($line = db_fetch_assoc($result)) {
2952 $user_id = $line["id"];
2953 // print "<!-- updating feeds of uid $user_id -->";
2954 update_all_feeds($link, false, $user_id);
2958 <message msg=\"All feeds updated\"/>
2963 if ($op == "pref-prefs") {
2965 $subop = $_REQUEST["subop"];
2967 if ($subop == "Save configuration") {
2969 if (WEB_DEMO_MODE
) {
2970 header("Location: prefs.php");
2974 $_SESSION["prefs_op_result"] = "save-config";
2976 $_SESSION["prefs_cache"] = false;
2978 foreach (array_keys($_POST) as $pref_name) {
2980 $pref_name = db_escape_string($pref_name);
2981 $value = db_escape_string($_POST[$pref_name]);
2983 $result = db_query($link, "SELECT type_name
2984 FROM ttrss_prefs,ttrss_prefs_types
2985 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
2987 if (db_num_rows($result) > 0) {
2989 $type_name = db_fetch_result($result, 0, "type_name");
2991 // print "$pref_name : $type_name : $value<br>";
2993 if ($type_name == "bool") {
2994 if ($value == "1") {
2999 } else if ($type_name == "integer") {
3000 $value = sprintf("%d", $value);
3003 // print "$pref_name : $type_name : $value<br>";
3005 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
3006 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
3010 header("Location: prefs.php");
3014 } else if ($subop == "getHelp") {
3016 $pref_name = db_escape_string($_GET["pn"]);
3018 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
3019 WHERE pref_name = '$pref_name'");
3021 if (db_num_rows($result) > 0) {
3022 $help_text = db_fetch_result($result, 0, "help_text");
3025 print "Unknown option: $pref_name";
3028 } else if ($subop == "Change e-mail") {
3030 if (WEB_DEMO_MODE
) {
3031 header("Location: prefs.php");
3035 $email = db_escape_string($_GET["email"]);
3036 $active_uid = $_SESSION["uid"];
3039 db_query($link, "UPDATE ttrss_users SET email = '$email'
3040 WHERE id = '$active_uid'");
3043 header("Location: prefs.php");
3045 } else if ($subop == "Change password") {
3047 if (WEB_DEMO_MODE
) {
3048 header("Location: prefs.php");
3052 $old_pw = $_POST["OLD_PASSWORD"];
3053 $new_pw = $_POST["OLD_PASSWORD"];
3055 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
3056 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
3058 $active_uid = $_SESSION["uid"];
3060 if ($old_pw && $new_pw) {
3062 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
3064 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3065 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
3066 pwd_hash = '$old_pw_hash')");
3068 if (db_num_rows($result) == 1) {
3069 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
3070 WHERE id = '$active_uid'");
3072 $_SESSION["pwd_change_result"] = "ok";
3074 $_SESSION["pwd_change_result"] = "failed";
3078 header("Location: prefs.php");
3080 } else if ($subop == "Reset to defaults") {
3082 if (WEB_DEMO_MODE
) {
3083 header("Location: prefs.php");
3087 $_SESSION["prefs_op_result"] = "reset-to-defaults";
3089 if (DB_TYPE
== "pgsql") {
3090 db_query($link,"UPDATE ttrss_user_prefs
3091 SET value = ttrss_prefs.def_value
3092 WHERE owner_uid = '".$_SESSION["uid"]."' AND
3093 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
3095 db_query($link, "DELETE FROM ttrss_user_prefs
3096 WHERE owner_uid = ".$_SESSION["uid"]);
3097 initialize_user_prefs($link, $_SESSION["uid"]);
3100 header("Location: prefs.php");
3102 } else if ($subop == "Change theme") {
3104 $theme = db_escape_string($_POST["theme"]);
3106 if ($theme == "Default") {
3107 $theme_qpart = 'NULL';
3109 $theme_qpart = "'$theme'";
3112 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
3113 WHERE theme_name = '$theme'");
3115 if (db_num_rows($result) == 1) {
3116 $theme_id = db_fetch_result($result, 0, "id");
3117 $theme_path = db_fetch_result($result, 0, "theme_path");
3123 db_query($link, "UPDATE ttrss_users SET
3124 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
3126 $_SESSION["theme"] = $theme_path;
3128 header("Location: prefs.php");
3132 if (!SINGLE_USER_MODE
) {
3134 $result = db_query($link, "SELECT id,email FROM ttrss_users
3135 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
3136 pwd_hash = 'SHA1:".sha1("password")."')");
3138 if (db_num_rows($result) != 0) {
3139 print "<div class=\"warning\">
3140 Your password is at default value, please change it.
3144 if ($_SESSION["pwd_change_result"] == "failed") {
3145 print "<div class=\"warning\">
3146 There was an error while changing your password.
3150 if ($_SESSION["pwd_change_result"] == "ok") {
3151 print "<div class=\"notice\">
3152 Password changed successfully.
3156 $_SESSION["pwd_change_result"] = "";
3158 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
3159 print "<div class=\"notice\">
3160 Your configuration was reset to defaults.
3164 if ($_SESSION["prefs_op_result"] == "save-config") {
3165 print "<div class=\"notice\">
3166 Your configuration was saved successfully.
3170 $_SESSION["prefs_op_result"] = "";
3172 print "<form action=\"backend.php\" method=\"GET\">";
3174 print "<table width=\"100%\" class=\"prefPrefsList\">";
3175 print "<tr><td colspan='3'><h3>Personal data</h3></tr></td>";
3177 $result = db_query($link, "SELECT email FROM ttrss_users
3178 WHERE id = ".$_SESSION["uid"]);
3180 $email = db_fetch_result($result, 0, "email");
3182 print "<tr><td width=\"40%\">E-mail</td>";
3183 print "<td><input class=\"editbox\" name=\"email\"
3184 value=\"$email\"></td></tr>";
3188 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3190 print "<p><input class=\"button\" type=\"submit\"
3191 value=\"Change e-mail\" name=\"subop\">";
3195 print "<form action=\"backend.php\" method=\"POST\" name=\"changePassForm\">";
3197 print "<table width=\"100%\" class=\"prefPrefsList\">";
3198 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
3200 print "<tr><td width=\"40%\">Old password</td>";
3201 print "<td><input class=\"editbox\" type=\"password\"
3202 name=\"OLD_PASSWORD\"></td></tr>";
3204 print "<tr><td width=\"40%\">New password</td>";
3206 print "<td><input class=\"editbox\" type=\"password\"
3207 name=\"NEW_PASSWORD\"></td></tr>";
3211 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3213 print "<p><input class=\"button\" type=\"submit\"
3214 onclick=\"return validateNewPassword(this.form)\"
3215 value=\"Change password\" name=\"subop\">";
3221 $result = db_query($link, "SELECT
3222 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
3224 $user_theme_id = db_fetch_result($result, 0, "theme_id");
3226 $result = db_query($link, "SELECT
3227 id,theme_name FROM ttrss_themes ORDER BY theme_name");
3229 if (db_num_rows($result) > 0) {
3231 print "<form action=\"backend.php\" method=\"POST\">";
3232 print "<table width=\"100%\" class=\"prefPrefsList\">";
3233 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
3234 print "<tr><td width=\"40%\">Select theme</td>";
3235 print "<td><select name=\"theme\">";
3236 print "<option>Default</option>";
3237 print "<option disabled>--------</option>";
3239 while ($line = db_fetch_assoc($result)) {
3240 if ($line["id"] == $user_theme_id) {
3241 $selected = "selected";
3245 print "<option $selected>" . $line["theme_name"] . "</option>";
3247 print "</select></td></tr>";
3249 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3250 print "<p><input class=\"button\" type=\"submit\"
3251 value=\"Change theme\" name=\"subop\">";
3255 $result = db_query($link, "SELECT
3256 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
3257 section_name,def_value
3258 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
3259 WHERE type_id = ttrss_prefs_types.id AND
3260 section_id = ttrss_prefs_sections.id AND
3261 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
3262 owner_uid = ".$_SESSION["uid"]."
3263 ORDER BY section_id,short_desc");
3265 print "<form action=\"backend.php\" method=\"POST\">";
3269 $active_section = "";
3271 while ($line = db_fetch_assoc($result)) {
3273 if ($active_section != $line["section_name"]) {
3275 if ($active_section != "") {
3279 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
3281 $active_section = $line["section_name"];
3283 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
3284 // print "<tr class=\"title\">
3285 // <td width=\"25%\">Option</td><td>Value</td></tr>";
3290 // $class = ($lnum % 2) ? "even" : "odd";
3294 $type_name = $line["type_name"];
3295 $pref_name = $line["pref_name"];
3296 $value = $line["value"];
3297 $def_value = $line["def_value"];
3298 $help_text = $line["help_text"];
3300 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
3302 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
3308 if ($type_name == "bool") {
3309 // print_select($pref_name, $value, array("true", "false"));
3311 if ($value == "true") {
3317 print_radio($pref_name, $value, array("Yes", "No"));
3320 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
3332 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3334 print "<p><input class=\"button\" type=\"submit\"
3335 name=\"subop\" value=\"Save configuration\">";
3337 print " <input class=\"button\" type=\"submit\"
3338 name=\"subop\" onclick=\"return validatePrefsReset()\"
3339 value=\"Reset to defaults\"></p>";
3347 if ($op == "pref-users") {
3349 $subop = $_GET["subop"];
3351 if ($subop == "editSave") {
3353 if (!WEB_DEMO_MODE
) {
3355 $login = db_escape_string($_GET["l"]);
3356 $uid = db_escape_string($_GET["id"]);
3357 $access_level = sprintf("%d", $_GET["al"]);
3358 $email = db_escape_string($_GET["e"]);
3360 db_query($link, "UPDATE ttrss_users SET login = '$login',
3361 access_level = '$access_level', email = '$email' WHERE id = '$uid'");
3364 } else if ($subop == "remove") {
3366 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3368 $ids = split(",", db_escape_string($_GET["ids"]));
3370 foreach ($ids as $id) {
3371 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
3375 } else if ($subop == "add") {
3377 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3379 $login = db_escape_string(trim($_GET["login"]));
3380 $tmp_user_pwd = make_password(8);
3381 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3383 db_query($link, "INSERT INTO ttrss_users
3384 (login,pwd_hash,access_level,last_login)
3385 VALUES ('$login', '$pwd_hash', 0, NOW())");
3388 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3389 login = '$login' AND pwd_hash = '$pwd_hash'");
3391 if (db_num_rows($result) == 1) {
3393 $new_uid = db_fetch_result($result, 0, "id");
3395 print "<div class=\"notice\">Added user <b>".$_GET["login"].
3396 "</b> with password <b>$tmp_user_pwd</b>.</div>";
3398 initialize_user($link, $new_uid);
3402 print "<div class=\"warning\">Error while adding user <b>".
3403 $_GET["login"].".</b></div>";
3407 } else if ($subop == "resetPass") {
3409 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3411 $uid = db_escape_string($_GET["id"]);
3413 $result = db_query($link, "SELECT login,email
3414 FROM ttrss_users WHERE id = '$uid'");
3416 $login = db_fetch_result($result, 0, "login");
3417 $email = db_fetch_result($result, 0, "email");
3418 $tmp_user_pwd = make_password(8);
3419 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3421 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
3422 WHERE id = '$uid'");
3424 print "<div class=\"notice\">Changed password of
3425 user <b>$login</b> to <b>$tmp_user_pwd</b>.";
3427 if (MAIL_RESET_PASS
&& $email) {
3428 print " Notifying <b>$email</b>.";
3430 mail("$login <$email>", "Password reset notification",
3433 "Your password for this TT-RSS installation was reset by".
3434 " an administrator.\n".
3436 "Your new password is $tmp_user_pwd, please remember".
3437 " it for later reference.\n".
3439 "Sincerely, TT-RSS Mail Daemon.", "From: " . MAIL_FROM
);
3447 print "<div class=\"prefGenericAddBox\">
3448 <input id=\"uadd_box\" onchange=\"javascript:addUser()\" size=\"40\"> ";
3450 print"<input type=\"submit\" class=\"button\"
3451 onclick=\"javascript:addUser()\" value=\"Add user\"></div>";
3453 $result = db_query($link, "SELECT
3454 id,login,access_level,email,
3455 SUBSTRING(last_login,1,16) as last_login
3460 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
3462 print "<p><table width=\"100%\" cellspacing=\"0\"
3463 class=\"prefUserList\" id=\"prefUserList\">";
3465 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
3467 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3468 'UMRR-', 'UMCHK-', true)\">All</a>,
3469 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3470 'UMRR-', 'UMCHK-', false)\">None</a>
3473 print "<tr class=\"title\">
3474 <td align='center' width=\"5%\"> </td>
3475 <td width='20%'>Login</td>
3476 <td width='20%'>E-mail</td>
3477 <td width='20%'>Access Level</td>
3478 <td width='20%'>Last login</td></tr>";
3482 while ($line = db_fetch_assoc($result)) {
3484 $class = ($lnum %
2) ?
"even" : "odd";
3487 $edit_uid = $_GET["id"];
3489 if ($subop == "edit" && $uid != $edit_uid) {
3493 $this_row_id = "id=\"UMRR-$uid\"";
3496 print "<tr class=\"$class\" $this_row_id>";
3498 $line["login"] = htmlspecialchars($line["login"]);
3500 $line["last_login"] = date(get_pref($link, 'SHORT_DATE_FORMAT'),
3501 strtotime($line["last_login"]));
3503 $access_level_names = array(0 => "User", 10 => "Administrator");
3505 /* if ($uid == $_SESSION["uid"]) {
3507 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
3508 id=\"UMCHK-".$line["id"]."\"></td>";
3510 print "<td>".$line["login"]."</td>";
3511 print "<td>".$line["email"]."</td>";
3512 print "<td>".$line["access_level"]."</td>";
3514 } else */ if (!$edit_uid ||
$subop != "edit") {
3516 print "<td align='center'><input onclick='toggleSelectRow(this);'
3517 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
3519 print "<td><a href=\"javascript:editUser($uid);\">" .
3520 $line["login"] . "</td>";
3522 if (!$line["email"]) $line["email"] = " ";
3524 print "<td><a href=\"javascript:editUser($uid);\">" .
3525 $line["email"] . "</td>";
3527 print "<td><a href=\"javascript:editUser($uid);\">" .
3528 $access_level_names[$line["access_level"]] . "</td>";
3530 } else if ($uid != $edit_uid) {
3532 if (!$line["email"]) $line["email"] = " ";
3534 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
3535 id=\"UMCHK-".$line["id"]."\"></td>";
3537 print "<td>".$line["login"]."</td>";
3538 print "<td>".$line["email"]."</td>";
3539 print "<td>".$access_level_names[$line["access_level"]]."</td>";
3543 print "<td align='center'>
3544 <input disabled=\"true\" type=\"checkbox\" checked></td>";
3546 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
3549 print "<td><input id=\"iedit_email\" value=\"".$line["email"].
3552 // print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
3556 print "<select id=\"iedit_ulevel\">";
3557 foreach (array_keys($access_level_names) as $al) {
3558 if ($al == $line["access_level"]) {
3559 $selected = "selected";
3563 print "<option $selected id=\"$al\">" .
3564 $access_level_names[$al] . "</option>";
3571 print "<td>".$line["last_login"]."</td>";
3582 if ($subop == "edit") {
3584 <input type=\"submit\" class=\"button\"
3585 onclick=\"javascript:userEditSave()\" value=\"Save\">
3586 <input type=\"submit\" class=\"button\"
3587 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">";
3593 <input type=\"submit\" class=\"button\"
3594 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
3595 <input type=\"submit\" class=\"button\"
3596 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
3597 <input type=\"submit\" class=\"button\"
3598 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
3599 <input type=\"submit\" class=\"button\"
3600 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
3605 if ($op == "user-details") {
3607 if (WEB_DEMO_MODE ||
$_SESSION["access_level"] < 10) {
3611 /* print "<html><head>
3612 <title>Tiny Tiny RSS : User Details</title>
3613 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
3614 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
3617 $uid = sprintf("%d", $_GET["id"]);
3619 print "<div id=\"infoBoxTitle\">User details</div>";
3621 print "<div class='infoBoxContents'>";
3623 $result = db_query($link, "SELECT login,
3624 SUBSTRING(last_login,1,16) AS last_login,
3626 (SELECT COUNT(int_id) FROM ttrss_user_entries
3627 WHERE owner_uid = id) AS stored_articles
3629 WHERE id = '$uid'");
3631 if (db_num_rows($result) == 0) {
3632 print "<h1>User not found</h1>";
3636 # print "<h1>User Details</h1>";
3638 $login = db_fetch_result($result, 0, "login");
3640 print "<h1>$login</h1>";
3642 print "<table width='100%'>";
3644 $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'),
3645 strtotime(db_fetch_result($result, 0, "last_login")));
3646 $access_level = db_fetch_result($result, 0, "access_level");
3647 $stored_articles = db_fetch_result($result, 0, "stored_articles");
3649 # print "<tr><td>Username</td><td>$login</td></tr>";
3650 print "<tr><td>Access level</td><td>$access_level</td></tr>";
3651 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
3652 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
3654 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
3655 WHERE owner_uid = '$uid'");
3657 $num_feeds = db_fetch_result($result, 0, "num_feeds");
3659 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
3661 /* $result = db_query($link, "SELECT
3662 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
3663 FROM ttrss_user_entries,ttrss_entries
3664 WHERE owner_uid = '$uid' AND ref_id = id");
3666 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
3668 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
3672 print "<h1>Subscribed feeds</h1>";
3674 $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
3675 WHERE owner_uid = '$uid' ORDER BY title");
3677 print "<ul class=\"userFeedList\">";
3681 while ($line = db_fetch_assoc($result)) {
3683 $icon_file = ICONS_URL
."/".$line["id"].".ico";
3685 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3686 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
3688 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3691 print "<li class=\"$row_class\">$feed_icon <a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
3693 $row_class = toggleEvenOdd($row_class);
3697 if (db_num_rows($result) < $num_feeds) {
3698 // FIXME - add link to show ALL subscribed feeds here somewhere
3700 class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\"> ...</li>";
3707 print "<div align='center'>
3708 <input type='submit' class='button'
3709 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3711 // print "</body></html>";
3715 if ($op == "feed-details") {
3717 // $feed_id = $_GET["id"];
3719 $feed_ids = split(",", db_escape_string($_GET["id"]));
3721 print "<div id=\"infoBoxTitle\">Feed details</div>";
3722 print "<div class=\"infoBoxContents\">";
3724 foreach ($feed_ids as $feed_id) {
3726 $result = db_query($link,
3729 SUBSTRING(last_updated,1,16) as last_updated,
3731 (SELECT COUNT(int_id) FROM ttrss_user_entries
3732 WHERE feed_id = id) AS total,
3733 (SELECT COUNT(int_id) FROM ttrss_user_entries
3734 WHERE feed_id = id AND unread = true) AS unread,
3735 (SELECT COUNT(int_id) FROM ttrss_user_entries
3736 WHERE feed_id = id AND marked = true) AS marked
3738 WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]);
3740 if (db_num_rows($result) == 0) return;
3742 $title = db_unescape_string(db_fetch_result($result, 0, "title"));
3743 $last_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
3744 strtotime(db_fetch_result($result, 0, "last_updated")));
3745 $feed_url = db_fetch_result($result, 0, "feed_url");
3746 $icon_url = db_fetch_result($result, 0, "icon_url");
3747 $total = db_fetch_result($result, 0, "total");
3748 $unread = db_fetch_result($result, 0, "unread");
3749 $marked = db_fetch_result($result, 0, "marked");
3750 $site_url = db_fetch_result($result, 0, "site_url");
3752 $result = db_query($link, "SELECT COUNT(id) AS subscribed
3753 FROM ttrss_feeds WHERE feed_url = '$feed_url' AND private = false");
3755 $subscribed = db_fetch_result($result, 0, "subscribed");
3757 $icon_file = ICONS_DIR
. "/$feed_id.ico";
3759 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3760 $feed_icon = "<img width=\"16\" height=\"16\"
3761 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
3766 print "<h1>$feed_icon $title</h1>";
3768 print "<table width='100%'>";
3771 print "<tr><td width='30%'>Link</td>
3772 <td><a href=\"$site_url\">$site_url</a>
3773 <a href=\"$feed_url\">(feed)</a></td>
3776 print "<tr><td width='30%'>Feed URL</td>
3777 <td><a href=\"$feed_url\">$feed_url</a></td></tr>";
3779 print "<tr><td>Last updated</td><td>$last_updated</td></tr>";
3780 print "<tr><td>Total articles</td><td>$total</td></tr>";
3781 print "<tr><td>Unread articles</td><td>$unread</td></tr>";
3782 print "<tr><td>Starred articles</td><td>$marked</td></tr>";
3783 print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>";
3787 /* $result = db_query($link, "SELECT title,
3788 SUBSTRING(updated,1,16) AS updated,unread
3789 FROM ttrss_entries,ttrss_user_entries
3790 WHERE ref_id = id AND feed_id = '$feed_id'
3791 ORDER BY date_entered DESC LIMIT 5");
3793 if (db_num_rows($result) > 0) {
3795 print "<h1>Latest headlines</h1>";
3797 print "<ul class=\"nomarks\">";
3799 while ($line = db_fetch_assoc($result)) {
3800 if ($line["unread"] == "t" || $line["unread"] == "1") {
3801 $line["title"] = "<b>" . $line["title"] . "</b>";
3803 print "<li>" . $line["title"].
3804 " <span class=\"insensitive\">(" .
3805 date(get_pref($link, 'SHORT_DATE_FORMAT'),
3806 strtotime($line["updated"])).
3817 print "<div align='center'>
3818 <input type='submit' class='button'
3819 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3822 if ($op == "pref-feed-browser") {
3824 if (!ENABLE_FEED_BROWSER
) {
3825 print "Feed browser is administratively disabled.";
3829 $subop = $_REQUEST["subop"];
3831 if ($subop == "details") {
3832 $id = db_escape_string($_GET["id"]);
3834 print "<div class=\"browserFeedInfo\">";
3835 print "<b>Feed information:</b>";
3836 print "<div class=\"detailsPart\">";
3838 $result = db_query($link, "SELECT
3840 SUBSTRING(last_updated,1,19) AS last_updated
3841 FROM ttrss_feeds WHERE id = '$id'");
3843 $feed_url = db_fetch_result($result, 0, "feed_url");
3844 $site_url = db_fetch_result($result, 0, "site_url");
3845 $last_updated = db_fetch_result($result, 0, "last_updated");
3847 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
3848 $last_updated = smart_date_time(strtotime($last_updated));
3850 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
3851 $last_updated = date($short_date, strtotime($last_updated));
3854 print "Site: <a href='$site_url'>$site_url</a> ".
3855 "(<a href='$feed_url'>feed</a>), ".
3856 "Last updated: $last_updated";
3860 $result = db_query($link, "SELECT
3861 ttrss_entries.title,
3863 substring(date_entered,1,19) as date_entered,
3864 substring(updated,1,19) as updated
3865 FROM ttrss_entries,ttrss_user_entries
3866 WHERE ttrss_entries.id = ref_id AND feed_id = '$id'
3867 ORDER BY updated DESC LIMIT 5");
3869 if (db_num_rows($result) > 0) {
3871 print "<b>Last headlines:</b><br>";
3873 print "<div class=\"detailsPart\">";
3874 print "<ul class=\"compact\">";
3875 while ($line = db_fetch_assoc($result)) {
3877 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
3878 $entry_dt = smart_date_time(strtotime($line["updated"]));
3880 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
3881 $entry_dt = date($short_date, strtotime($line["updated"]));
3884 print "<li>" . $line["title"] .
3885 " <span class=\"insensitive\">($entry_dt)</span></li>";
3887 print "</ul></div>";
3895 print "<p>This panel shows feeds subscribed by other users of this system, just in case you are interested in some of them too.</p>";
3897 $result = db_query($link, "SELECT feed_url,count(id) AS subscribers
3899 WHERE auth_login = '' AND auth_pass = '' AND private = false
3900 GROUP BY feed_url ORDER BY subscribers DESC LIMIT 100");
3902 print "<p>Selection:
3903 <input type='submit' class='button' onclick=\"feedBrowserSubscribe()\"
3904 value=\"Subscribe\">";
3906 print "<ul class='nomarks' id='browseBigFeedList'>";
3910 while ($line = db_fetch_assoc($result)) {
3911 $feed_url = $line["feed_url"];
3912 $subscribers = $line["subscribers"];
3914 $sub_result = db_query($link, "SELECT id
3915 FROM ttrss_feeds WHERE feed_url = '$feed_url' AND owner_uid =" .
3918 if (db_num_rows($sub_result) > 0) {
3919 continue; // already subscribed
3922 $det_result = db_query($link, "SELECT site_url,title,id
3923 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
3925 $details = db_fetch_assoc($det_result);
3927 $icon_file = ICONS_DIR
. "/" . $details["id"] . ".ico";
3929 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3930 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL
.
3931 "/".$details["id"].".ico\">";
3933 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3936 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
3937 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
3939 $class = ($feedctr %
2) ?
"even" : "odd";
3941 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
3944 print "<a href=\"javascript:browserToggleExpand('".$details["id"]."')\">" .
3945 $details["title"] ."</a> " .
3946 "<span class='subscribers'>($subscribers)</span>";
3948 print "<div class=\"browserDetails\" id=\"BRDET-" . $details["id"] . "\">";
3956 if ($feedctr == 0) {
3957 print "<li>No feeds found to subscribe.</li>";
3966 function check_configuration_variables() {
3967 if (!defined('SESSION_EXPIRE_TIME')) {
3968 return "config: SESSION_EXPIRE_TIME is undefined";
3971 if (SESSION_EXPIRE_TIME
< 60) {
3972 return "config: SESSION_EXPIRE_TIME is too low (less than 60)";
3975 if (SESSION_EXPIRE_TIME
< SESSION_COOKIE_LIFETIME_REMEMBER
) {
3976 return "config: SESSION_EXPIRE_TIME should be greater or equal to" .
3977 "SESSION_COOKIE_LIFETIME_REMEMBER";
3980 if (defined('DISABLE_SESSIONS')) {
3981 return "config: you have enabled DISABLE_SESSIONS. Please disable this option.";
3984 if (DATABASE_BACKED_SESSIONS
&& SINGLE_USER_MODE
) {
3985 return "config: DATABASE_BACKED_SESSIONS is incompatible with SINGLE_USER_MODE";
3994 <!-- <?
= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?
> -->