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', 7);
21 require_once "sanity_check.php";
22 require_once "config.php";
24 $err_msg = check_configuration_variables();
27 print "Fatal error: $err_msg";
31 if ((!$op ||
$op == "rpc" ||
$op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
32 header("Content-Type: application/xml");
35 if (!$_SESSION["uid"] && $op != "globalUpdateFeeds") {
38 print "<error error-code=\"6\"/>";
42 <p>Error: Not logged in.</p>
43 <script type=\"text/javascript\">
44 if (parent.window != 'undefined') {
45 parent.window.location = \"login.php\";
47 window.location = \"login.php\";
57 print "<error error-code=\"7\"/>";
61 require_once "db.php";
62 require_once "db-prefs.php";
63 require_once "functions.php";
64 require_once "magpierss/rss_fetch.inc";
66 $purge_intervals = array(
75 $update_intervals = array(
77 -1 => "Disable updates",
85 $script_started = getmicrotime();
87 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
90 if (DB_TYPE
== "mysql") {
93 // PG seems to display its own errors just fine by default.
97 if (DB_TYPE
== "pgsql") {
98 pg_query("set client_encoding = 'utf-8'");
101 if ($_SESSION["uid"]) {
102 if (get_pref($link, "HIDE_READ_FEEDS") == "true") {
103 setcookie("ttrss_vf_hreadf", 1);
105 setcookie("ttrss_vf_hreadf", 0);
108 setcookie('ttrss_vf_refresh', FEEDS_FRAME_REFRESH
);
109 setcookie('ttrss_vf_daemon', ENABLE_UPDATE_DAEMON
);
112 $fetch = $_GET["fetch"];
114 // setcookie("ttrss_icons_url", ICONS_URL);
116 if (!sanity_check($link)) { return; }
118 function outputFeedList($link, $tags = false) {
121 <title>Tiny Tiny RSS : Feedlist</title>
122 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
124 $user_theme = $_SESSION["theme"];
126 print "<link rel=\"stylesheet\" type=\"text/css\"
127 href=\"themes/$user_theme/theme.css\">";
130 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
131 print "<link rel=\"stylesheet\" type=\"text/css\"
132 href=\"tt-rss_compact.css\"/>";
134 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
135 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
138 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
139 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
140 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
141 <!--[if gte IE 5.5000]>
142 <script type=\"text/javascript\" src=\"pngfix.js\"></script>
143 <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
146 <script type=\"text/javascript\">
147 if (document.addEventListener) {
148 document.addEventListener(\"DOMContentLoaded\", init, null);
150 window.onload = init;
153 print "<ul class=\"feedList\" id=\"feedList\">\n";
155 $owner_uid = $_SESSION["uid"];
161 if (get_pref($link, 'ENABLE_FEED_CATS')) {
162 print "<li class=\"feedCat\">Special</li>";
163 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
166 $result = db_query($link, "SELECT count(id) as num_starred
167 FROM ttrss_entries,ttrss_user_entries
168 WHERE marked = true AND
169 ttrss_user_entries.ref_id = ttrss_entries.id AND
170 unread = true AND owner_uid = '$owner_uid'");
171 $num_starred = db_fetch_result($result, 0, "num_starred");
175 if ($num_starred > 0) $class .= "Unread";
177 printFeedEntry(-1, $class, "Starred articles", $num_starred,
178 "images/mark_set.png", $link);
180 if (get_pref($link, 'ENABLE_FEED_CATS')) {
184 if (GLOBAL_ENABLE_LABELS
&& get_pref($link, 'ENABLE_LABELS')) {
186 $result = db_query($link, "SELECT id,sql_exp,description FROM
187 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
189 if (db_num_rows($result) > 0) {
190 if (get_pref($link, 'ENABLE_FEED_CATS')) {
191 print "<li class=\"feedCat\">Labels</li>";
192 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
194 print "<li><hr></li>";
198 while ($line = db_fetch_assoc($result)) {
202 $tmp_result = db_query($link, "SELECT count(id) as count
203 FROM ttrss_entries,ttrss_user_entries
204 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
205 ttrss_user_entries.ref_id = ttrss_entries.id
206 AND owner_uid = '$owner_uid'");
208 $count = db_fetch_result($tmp_result, 0, "count");
216 error_reporting (DEFAULT_ERROR_LEVEL
);
218 printFeedEntry(-$line["id"]-11,
219 $class, $line["description"], $count, "images/label.png", $link);
223 if (db_num_rows($result) > 0) {
224 if (get_pref($link, 'ENABLE_FEED_CATS')) {
231 // if (!get_pref($link, 'ENABLE_FEED_CATS')) {
232 print "<li><hr></li>";
235 if (get_pref($link, 'ENABLE_FEED_CATS')) {
236 $order_by_qpart = "category,title";
238 $order_by_qpart = "title";
241 $result = db_query($link, "SELECT ttrss_feeds.*,
242 SUBSTRING(last_updated,1,19) AS last_updated_noms,
243 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
244 WHERE feed_id = ttrss_feeds.id AND
245 ttrss_user_entries.ref_id = ttrss_entries.id AND
246 owner_uid = '$owner_uid') AS total,
247 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
248 WHERE feed_id = ttrss_feeds.id AND unread = true
249 AND ttrss_user_entries.ref_id = ttrss_entries.id
250 AND owner_uid = '$owner_uid') as unread,
252 ttrss_feed_categories.title AS category,
253 ttrss_feed_categories.collapsed
254 FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
255 ON (ttrss_feed_categories.id = cat_id)
257 ttrss_feeds.owner_uid = '$owner_uid' AND parent_feed IS NULL
258 ORDER BY $order_by_qpart");
260 $actid = $_GET["actid"];
270 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
272 while ($line = db_fetch_assoc($result)) {
274 $feed = db_unescape_string($line["title"]);
275 $feed_id = $line["id"];
277 $subop = $_GET["subop"];
279 $total = $line["total"];
280 $unread = $line["unread"];
282 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
283 $last_updated = smart_date_time(strtotime($line["last_updated_noms"]));
285 $last_updated = date($short_date, strtotime($line["last_updated_noms"]));
288 $rtl_content = sql_bool_to_bool($line["rtl_content"]);
291 $rtl_tag = "dir=\"RTL\"";
296 $tmp_result = db_query($link,
297 "SELECT id,COUNT(unread) AS unread
298 FROM ttrss_feeds LEFT JOIN ttrss_user_entries
299 ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
300 WHERE parent_feed = '$feed_id' AND unread = true
301 GROUP BY ttrss_feeds.id");
303 if (db_num_rows($tmp_result) > 0) {
304 while ($l = db_fetch_assoc($tmp_result)) {
305 $unread +
= $l["unread"];
309 $cat_id = $line["cat_id"];
311 $tmp_category = $line["category"];
313 if (!$tmp_category) {
314 $tmp_category = "Uncategorized";
317 // $class = ($lnum % 2) ? "even" : "odd";
319 if ($line["last_error"]) {
325 if ($unread > 0) $class .= "Unread";
327 if ($actid == $feed_id) {
328 $class .= "Selected";
331 $total_unread +
= $unread;
333 if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
339 $category = $tmp_category;
341 $collapsed = $line["collapsed"];
343 // workaround for NULL category
344 if ($category == "Uncategorized") {
345 if ($_COOKIE["ttrss_vf_uclps"] == 1) {
350 if ($collapsed == "t" ||
$collapsed == "1") {
351 $holder_class = "invisible";
359 $cat_id_qpart = "cat_id = '$cat_id'";
361 $cat_id_qpart = "cat_id IS NULL";
364 $tmp_result = db_query($link, "SELECT count(int_id) AS unread
365 FROM ttrss_user_entries,ttrss_feeds WHERE
367 feed_id = ttrss_feeds.id AND $cat_id_qpart AND
368 ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
370 $cat_unread = db_fetch_result($tmp_result, 0, "unread");
372 $cat_id = sprintf("%d", $cat_id);
374 print "<li class=\"feedCat\" id=\"FCAT-$cat_id\">
375 <a href=\"javascript:toggleCollapseCat($cat_id)\">$tmp_category</a>
376 <a href=\"javascript:viewCategory($cat_id)\" id=\"FCAP-$cat_id\">
377 <span id=\"FCATCTR-$cat_id\"
378 class=\"$catctr_class\">($cat_unread unread)$ellipsis</span>
381 // !!! NO SPACE before <ul...feedCatList - breaks firstChild DOM function
382 // -> keyboard navigation, etc.
383 print "<li id=\"feedCatHolder\" class=\"$holder_class\"><ul class=\"feedCatList\" id=\"FCATLIST-$cat_id\">";
386 printFeedEntry($feed_id, $class, $feed, $unread,
387 "icons/$feed_id.ico", $link, $rtl_content,
388 $last_updated, $line["last_error"]);
397 /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
398 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
399 post_int_id = ttrss_user_entries.int_id AND
400 unread = true AND ref_id = ttrss_entries.id
401 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
403 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'
404 ORDER BY tag_name"); */
406 $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
407 FROM ttrss_user_entries WHERE int_id = post_int_id
408 AND unread = true)) AS count FROM ttrss_tags
409 WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name");
413 while ($line = db_fetch_assoc($result)) {
414 $tags[$line["tag_name"]] +
= $line["count"];
417 foreach (array_keys($tags) as $tag) {
419 $unread = $tags[$tag];
427 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
433 if (db_num_rows($result) == 0) {
439 print "<li>No $what to display.</li>";
445 <script type="text/javascript">
447 function statechange() {
448 if (document.readyState == "interactive") init();
451 if (document.readyState) {
452 if (document.readyState == "interactive" || document.readyState == "complete") {
455 document.onreadystatechange = statechange;
458 </script></body></html>';
463 handle_rpc_request($link);
466 if ($op == "feeds") {
468 $tags = $_GET["tags"];
470 $subop = $_GET["subop"];
472 if ($subop == "catchupAll") {
473 db_query($link, "UPDATE ttrss_user_entries SET
474 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
477 if ($subop == "collapse") {
478 $cat_id = db_escape_string($_GET["cid"]);
480 db_query($link, "UPDATE ttrss_feed_categories SET
481 collapsed = NOT collapsed WHERE id = '$cat_id' AND owner_uid = " .
486 outputFeedList($link, $tags);
492 $id = db_escape_string($_GET["id"]);
493 $feed_id = db_escape_string($_GET["feed"]);
495 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
496 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
498 if (db_num_rows($result) == 1) {
499 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
501 $rtl_content = false;
505 $rtl_tag = "dir=\"RTL\"";
512 $result = db_query($link, "UPDATE ttrss_user_entries
513 SET unread = false,last_read = NOW()
514 WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
516 $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
517 SUBSTRING(updated,1,16) as updated,
518 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url,
521 FROM ttrss_entries,ttrss_user_entries
522 WHERE id = '$id' AND ref_id = id");
525 <title>Tiny Tiny RSS : Article $id</title>
526 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
528 $user_theme = $_SESSION["theme"];
530 print "<link rel=\"stylesheet\" type=\"text/css\"
531 href=\"themes/$user_theme/theme.css\">";
534 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
535 print "<link rel=\"stylesheet\" type=\"text/css\"
536 href=\"tt-rss_compact.css\"/>";
538 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
539 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
542 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
543 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
544 </head><body $rtl_tag>";
548 $line = db_fetch_assoc($result);
550 if ($line["icon_url"]) {
551 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
553 $feed_icon = " ";
556 /* if ($line["comments"] && $line["link"] != $line["comments"]) {
557 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
559 $entry_comments = "";
562 $num_comments = $line["num_comments"];
563 $entry_comments = "";
565 if ($num_comments > 0) {
566 if ($line["comments"]) {
567 $comments_url = $line["comments"];
569 $comments_url = $line["link"];
571 $entry_comments = "<a href=\"$comments_url\">$num_comments comments</a>";
573 if ($line["comments"] && $line["link"] != $line["comments"]) {
574 $entry_comments = "<a href=\"".$line["comments"]."\">comments</a>";
578 print "<div class=\"postReply\">";
580 print "<div class=\"postHeader\"><table width=\"100%\">";
582 $entry_author = $line["author"];
585 $entry_author = " - by $entry_author";
588 print "<tr><td><a href=\"" . $line["link"] . "\">" . $line["title"] .
589 "</a>$entry_author</td>";
591 $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
592 strtotime($line["updated"]));
594 print "<td class=\"postDate$rtl_class\">$parsed_updated</td>";
598 $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
599 ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
607 while ($tmp_line = db_fetch_assoc($tmp_result)) {
609 $tag = $tmp_line["tag_name"];
610 $tag_str = "<a href=\"javascript:parent.viewfeed('$tag')\">$tag</a>, ";
612 if ($num_tags == 5) {
613 $tags_str .= "<a href=\"javascript:showBlockElement('allEntryTags')\">...</a>";
614 } else if ($num_tags < 5) {
615 $tags_str .= $tag_str;
617 $f_tags_str .= $tag_str;
620 $tags_str = preg_replace("/, $/", "", $tags_str);
621 $f_tags_str = preg_replace("/, $/", "", $f_tags_str);
623 // $truncated_link = truncate_string($line["link"], 60);
625 if ($tags_str ||
$entry_comments) {
626 print "<tr><td width='50%'>
628 <td align=\"right\">$tags_str</td></tr>";
631 print "</table></div>";
633 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
634 print "<div class=\"postContent\">";
636 if (db_num_rows($tmp_result) > 5) {
637 print "<div id=\"allEntryTags\">Tags: $f_tags_str</div>";
640 if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
641 $line["content"] = preg_replace("/href=/i", "target=\"_new\" href=", $line["content"]);
644 print $line["content"] . "</div>";
648 print "<script type=\"text/javascript\">
649 update_all_counters('$feed_id');
653 print "</body></html>";
656 if ($op == "viewfeed") {
658 $feed = db_escape_string($_GET["feed"]);
659 $skip = db_escape_string($_GET["skip"]);
660 $subop = db_escape_string($_GET["subop"]);
661 $view_mode = db_escape_string($_GET["view"]);
662 $limit = db_escape_string($_GET["limit"]);
663 $cat_view = db_escape_string($_GET["cat"]);
665 if (!$skip) $skip = 0;
667 if ($subop == "undefined") $subop = "";
670 <title>Tiny Tiny RSS : Feed $feed</title>
671 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
673 $user_theme = $_SESSION["theme"];
675 print "<link rel=\"stylesheet\" type=\"text/css\"
676 href=\"themes/$user_theme/theme.css\">";
679 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
680 print "<link rel=\"stylesheet\"
681 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
684 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
685 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
688 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
690 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
691 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
693 if (db_num_rows($result) == 1) {
694 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
696 $rtl_content = false;
700 $rtl_tag = "dir=\"RTL\"";
706 $rtl_content = false;
709 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
710 <script type=\"text/javascript\" src=\"functions.js\"></script>
711 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
712 <!--[if gte IE 5.5000]>
713 <script type=\"text/javascript\" src=\"pngfix.js\"></script>
714 <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
716 </head><body $rtl_tag>
717 <script type=\"text/javascript\">
718 if (document.addEventListener) {
719 document.addEventListener(\"DOMContentLoaded\", init, null);
721 window.onload = init;
724 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
725 update_generic_feed($link, $feed, $cat_view);
728 if ($subop == "MarkAllRead") {
729 catchup_feed($link, $feed, $cat_view);
732 $search = db_escape_string($_GET["search"]);
733 $search_mode = db_escape_string($_GET["smode"]);
736 $search_query_part = "(upper(ttrss_entries.title) LIKE upper('%$search%')
737 OR ttrss_entries.content LIKE '%$search%') AND";
739 $search_query_part = "";
742 $view_query_part = "";
744 if ($view_mode == "Adaptive") {
746 $view_query_part = " ";
747 } else if ($feed != -1) {
748 $unread = getFeedUnread($link, $feed);
750 $view_query_part = " unread = true AND ";
755 if ($view_mode == "Starred") {
756 $view_query_part = " marked = true AND ";
759 if ($view_mode == "Unread") {
760 $view_query_part = " unread = true AND ";
763 if ($limit && $limit != "All") {
764 $limit_query_part = "LIMIT " . $limit;
767 $vfeed_query_part = "";
769 // override query strategy and enable feed display when searching globally
770 if ($search && $search_mode == "All feeds") {
771 $query_strategy_part = "ttrss_entries.id > 0";
772 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
773 } else if (preg_match("/^-?[0-9][0-9]*$/", $feed) == false) {
774 $query_strategy_part = "ttrss_entries.id > 0";
775 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
776 id = feed_id) as feed_title,";
777 } else if ($feed >= 0 && $search && $search_mode == "This category") {
779 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
781 $tmp_result = db_query($link, "SELECT id
782 FROM ttrss_feeds WHERE cat_id =
783 (SELECT cat_id FROM ttrss_feeds WHERE id = '$feed') AND id != '$feed'");
785 $cat_siblings = array();
787 if (db_num_rows($tmp_result) > 0) {
788 while ($p = db_fetch_assoc($tmp_result)) {
789 array_push($cat_siblings, "feed_id = " . $p["id"]);
792 $query_strategy_part = sprintf("(feed_id = %d OR %s)",
793 $feed, implode(" OR ", $cat_siblings));
796 $query_strategy_part = "ttrss_entries.id > 0";
799 } else if ($feed >= 0) {
804 $query_strategy_part = "cat_id = '$feed'";
806 $query_strategy_part = "cat_id IS NULL";
809 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
812 $tmp_result = db_query($link, "SELECT id
813 FROM ttrss_feeds WHERE parent_feed = '$feed'
814 ORDER BY cat_id,title");
816 $parent_ids = array();
818 if (db_num_rows($tmp_result) > 0) {
819 while ($p = db_fetch_assoc($tmp_result)) {
820 array_push($parent_ids, "feed_id = " . $p["id"]);
823 $query_strategy_part = sprintf("(feed_id = %d OR %s)",
824 $feed, implode(" OR ", $parent_ids));
826 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
828 $query_strategy_part = "feed_id = '$feed'";
831 } else if ($feed == -1) { // starred virtual feed
832 $query_strategy_part = "marked = true";
833 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
834 } else if ($feed <= -10) { // labels
835 $label_id = -$feed - 11;
837 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
838 WHERE id = '$label_id'");
840 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
842 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
844 $query_strategy_part = "id > 0"; // dumb
847 $order_by = "updated DESC";
849 // if ($feed < -10) {
850 // $order_by = "feed_id,updated DESC";
855 if ($search && $search_mode == "All feeds") {
856 $feed_title = "Global search results ($search)";
857 } else if ($search && preg_match('/^-?[0-9][0-9]*$/', $feed) == false) {
858 $feed_title = "Feed search results ($search, $feed)";
859 } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) == false) {
861 } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) != false && $feed >= 0) {
866 $result = db_query($link, "SELECT title FROM ttrss_feed_categories
867 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
868 $feed_title = db_fetch_result($result, 0, "title");
870 $feed_title = "Uncategorized";
874 $result = db_query($link, "SELECT title,site_url,last_error FROM ttrss_feeds
875 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
877 $feed_title = db_fetch_result($result, 0, "title");
878 $feed_site_url = db_fetch_result($result, 0, "site_url");
879 $last_error = db_fetch_result($result, 0, "last_error");
883 } else if ($feed == -1) {
884 $feed_title = "Starred articles";
885 } else if ($feed < -10) {
886 $label_id = -$feed - 11;
887 $result = db_query($link, "SELECT description FROM ttrss_labels
888 WHERE id = '$label_id'");
889 $feed_title = db_fetch_result($result, 0, "description");
894 if ($feed < -10) error_reporting (0);
896 print "<div id=\"headlinesContainer\">";
898 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
901 $feed_kind = "Feeds";
903 $feed_kind = "Labels";
906 // if (!$vfeed_query_part) {
907 $content_query_part = "content as content_preview,";
909 // $content_query_part = "";
913 ttrss_entries.id,ttrss_entries.title,
914 SUBSTRING(updated,1,16) as updated,
915 unread,feed_id,marked,link,last_read,
916 SUBSTRING(last_read,1,19) as last_read_noms,
919 SUBSTRING(updated,1,19) as updated_noms
921 ttrss_entries,ttrss_user_entries,ttrss_feeds
923 ttrss_user_entries.feed_id = ttrss_feeds.id AND
924 ttrss_user_entries.ref_id = ttrss_entries.id AND
925 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
928 $query_strategy_part ORDER BY $order_by
931 $result = db_query($link, $query);
933 if ($_GET["debug"]) print $query;
940 $result = db_query($link, "SELECT
941 ttrss_entries.id as id,title,
942 SUBSTRING(updated,1,16) as updated,
944 marked,link,last_read,
945 SUBSTRING(last_read,1,19) as last_read_noms,
948 SUBSTRING(updated,1,19) as updated_noms
950 ttrss_entries,ttrss_user_entries,ttrss_tags
952 ref_id = ttrss_entries.id AND
953 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
954 post_int_id = int_id AND tag_name = '$feed' AND
957 $query_strategy_part ORDER BY $order_by
962 print "<div align='center'>
963 Could not display feed (query failed). Please check label match syntax or local configuration.</div>";
967 function print_headline_subtoolbar($link, $feed_site_url, $feed_title,
968 $bottom = false, $rtl_content = false) {
971 $class = "headlinesSubToolbar";
972 $tid = "headlineActionsTop";
974 $class = "invisible";
975 $tid = "headlineActionsBottom";
978 print "<table class=\"$class\" id=\"$tid\"
979 width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
987 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
989 print "<td class=\"headlineActions$rtl_cpart\">
991 <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, '', true)\">All</a>,
992 <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true)\">Unread</a>,
993 <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false)\">None</a>
995 Toggle: <a href='#' onclick=\"javascript:selectionToggleUnread()\">Unread</a>,
996 <a href='#' onclick=\"javascript:selectionToggleMarked()\">Starred</a>";
1001 print "<td class=\"headlineActions$rtl_cpart\">
1003 <a href=\"#\" onclick=\"javascript:cdmSelectArticles('all')\">All</a>,
1004 <a href=\"#\" onclick=\"javascript:cdmSelectArticles('unread')\">Unread</a>,
1005 <a href=\"#\" onclick=\"javascript:cdmSelectArticles('none')\">None</a>
1007 Toggle: <a href=\"#\" onclick=\"javascript:selectionToggleUnread(true)\">Unread</a>,
1008 <a href=\"#\" onclick=\"javascript:selectionToggleMarked(true)\">Starred</a>";
1014 print "<td class=\"headlineTitle$rtl_cpart\">";
1016 if ($feed_site_url) {
1018 $target = "target=\"_blank\"";
1020 print "<a $target href=\"$feed_site_url\">$feed_title</a>";
1026 print "</tr></table>";
1030 if (db_num_rows($result) > 0) {
1032 print_headline_subtoolbar($link, $feed_site_url, $feed_title, false,
1035 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1036 print "<table class=\"headlinesList\" id=\"headlinesList\"
1037 cellspacing=\"0\" width=\"100%\">";
1042 error_reporting (DEFAULT_ERROR_LEVEL
);
1046 while ($line = db_fetch_assoc($result)) {
1048 $class = ($lnum %
2) ?
"even" : "odd";
1051 $feed_id = $line["feed_id"];
1053 if ($line["last_read"] == "" &&
1054 ($line["unread"] != "t" && $line["unread"] != "1")) {
1056 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
1059 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
1063 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
1071 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
1072 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
1073 alt=\"Reset mark\" onclick='javascript:toggleMark($id)'>";
1075 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
1076 alt=\"Set mark\" onclick='javascript:toggleMark($id)'>";
1079 $content_link = "<a href=\"javascript:view($id,$feed_id);\">" .
1080 $line["title"] . "</a>";
1082 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1083 $updated_fmt = smart_date_time(strtotime($line["updated"]));
1085 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1086 $updated_fmt = date($short_date, strtotime($line["updated"]));
1089 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
1090 $content_preview = truncate_string(strip_tags($line["content_preview"]),
1094 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1096 print "<tr class='$class' id='RROW-$id'>";
1098 print "<td class='hlUpdatePic'>$update_pic</td>";
1100 print "<td class='hlSelectRow'>
1101 <input type=\"checkbox\" onclick=\"toggleSelectRow(this)\"
1102 class=\"feedCheckBox\" id=\"RCHK-$id\">
1105 print "<td class='hlMarkedPic'>$marked_pic</td>";
1107 if ($line["feed_title"]) {
1108 print "<td class='hlContent'>$content_link</td>";
1109 print "<td class='hlFeed'>
1110 <a href='javascript:viewfeed($feed_id)'>".
1111 $line["feed_title"]."</a> </td>";
1113 print "<td class='hlContent' valign='middle'>";
1115 print "<a href=\"javascript:view($id,$feed_id);\">" .
1118 if (get_pref($link, 'SHOW_CONTENT_PREVIEW') && !$rtl_tag) {
1119 if ($content_preview) {
1120 print "<span class=\"contentPreview\"> - $content_preview</span>";
1128 print "<td class=\"hlUpdated\"><nobr>$updated_fmt </nobr></td>";
1135 $add_class = "Unread";
1140 print "<div class=\"cdmArticle$add_class\" id=\"RROW-$id\">";
1142 print "<div class=\"cdmHeader\">";
1144 print "<div style=\"float : right\">$updated_fmt</div>";
1146 print "<a target=\"new\" href=\"".$line["link"]."\">".$line["title"]."</a>";
1148 if ($line["feed_title"]) {
1149 print " (<a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>)";
1154 print "<div class=\"cdmContent\">" . $line["content_preview"] . "</div>";
1156 print "<div style=\"float : right\">$marked_pic</div>
1157 <div class=\"cdmFooter\">
1158 <input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
1159 'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\"></div>";
1168 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1172 print_headline_subtoolbar($link,
1173 "javascript:catchupPage()", "Mark page as read", true, $rtl_content);
1177 print "<div width='100%' align='center'>No articles found.</div>";
1182 print "<script type=\"text/javascript\">
1183 document.onkeydown = hotkey_handler;
1184 // if (parent.daemon_enabled) parent.updateTitle('$feed_title');
1185 update_all_counters('$feed');
1189 <script type="text/javascript">
1191 function statechange() {
1192 if (document.readyState == "interactive") init();
1195 if (document.readyState) {
1196 if (document.readyState == "interactive" || document.readyState == "complete") {
1199 document.onreadystatechange = statechange;
1204 print "</body></html>";
1207 if ($op == "pref-rpc") {
1209 $subop = $_GET["subop"];
1211 if ($subop == "unread") {
1212 $ids = split(",", db_escape_string($_GET["ids"]));
1213 foreach ($ids as $id) {
1214 db_query($link, "UPDATE ttrss_user_entries SET unread = true
1215 WHERE feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
1218 print "Marked selected feeds as unread.";
1221 if ($subop == "read") {
1222 $ids = split(",", db_escape_string($_GET["ids"]));
1223 foreach ($ids as $id) {
1224 db_query($link, "UPDATE ttrss_user_entries
1225 SET unread = false,last_read = NOW() WHERE
1226 feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
1229 print "Marked selected feeds as read.";
1235 if ($op == "pref-feeds") {
1237 $subop = $_REQUEST["subop"];
1238 $quiet = $_REQUEST["quiet"];
1240 if ($subop == "massSubscribe") {
1241 $ids = split(",", db_escape_string($_GET["ids"]));
1243 $subscribed = array();
1245 foreach ($ids as $id) {
1246 $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds
1249 $feed_url = db_fetch_result($result, 0, "feed_url");
1250 $title = db_fetch_result($result, 0, "title");
1252 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
1253 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
1255 if (db_num_rows($result) == 0) {
1256 $result = db_query($link,
1257 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
1258 VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)");
1260 array_push($subscribed, $title);
1264 if (count($subscribed) > 0) {
1265 print "<div class=\"notice\">";
1266 print "<b>Subscribed to feeds:</b>";
1267 print "<ul class=\"nomarks\">";
1268 foreach ($subscribed as $title) {
1269 print "<li>$title</li>";
1276 if ($subop == "browse") {
1278 if (!ENABLE_FEED_BROWSER
) {
1279 print "Feed browser is administratively disabled.";
1283 print "<div class=\"infoBoxContents\">";
1285 print "<h1>Feed browser</h1>";
1287 print "<p>Showing top 50 registered feeds, sorted by popularity:</p>";
1289 $result = db_query($link, "SELECT feed_url,count(id) AS subscribers
1291 WHERE auth_login = '' AND auth_pass = '' AND private = false
1292 GROUP BY feed_url ORDER BY subscribers DESC LIMIT 50");
1294 print "<ul class='browseFeedList' id='browseFeedList'>";
1298 while ($line = db_fetch_assoc($result)) {
1299 $feed_url = $line["feed_url"];
1300 $subscribers = $line["subscribers"];
1302 $sub_result = db_query($link, "SELECT id
1303 FROM ttrss_feeds WHERE feed_url = '$feed_url' AND owner_uid =" .
1306 if (db_num_rows($sub_result) > 0) {
1307 continue; // already subscribed
1310 $det_result = db_query($link, "SELECT site_url,title,id
1311 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
1313 $details = db_fetch_assoc($det_result);
1315 $icon_file = ICONS_DIR
. "/" . $details["id"] . ".ico";
1317 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1318 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL
.
1319 "/".$details["id"].".ico\">";
1321 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1324 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
1325 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
1327 $class = ($feedctr %
2) ?
"even" : "odd";
1329 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
1330 "$feed_icon " . db_unescape_string($details["title"]) .
1331 " <span class='subscribers'>($subscribers)</span></li>";
1336 if ($feedctr == 0) {
1337 print "<li>No feeds found to subscribe.</li>";
1342 print "<div align='center'>
1343 <input type=\"submit\" class=\"button\"
1344 onclick=\"feedBrowserSubscribe()\" value=\"Subscribe\">
1345 <input type='submit' class='button'
1346 onclick=\"closeInfoBox()\" value=\"Cancel\"></div>";
1352 if ($subop == "editfeed") {
1353 $feed_id = db_escape_string($_GET["id"]);
1355 $result = db_query($link,
1356 "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
1357 owner_uid = " . $_SESSION["uid"]);
1359 $title = htmlspecialchars(db_unescape_string(db_fetch_result($result,
1362 print "<div class=\"infoBoxContents\">";
1364 $icon_file = ICONS_DIR
. "/$feed_id.ico";
1366 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1367 $feed_icon = "<img width=\"16\" height=\"16\"
1368 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
1373 print "<h1>$feed_icon $title</h1>";
1375 print "<table width='100%'>";
1379 print "<tr class='$row_class'><td>Title:</td>";
1380 print "<td><input id=\"iedit_title\" value=\"$title\"></td></tr>";
1382 $feed_url = db_fetch_result($result, 0, "feed_url");
1383 $feed_url = htmlspecialchars(db_unescape_string(db_fetch_result($result,
1385 $row_class = toggleEvenOdd($row_class);
1387 print "<tr class='$row_class'><td>Feed URL:</td>";
1388 print "<td><input id=\"iedit_link\" value=\"$feed_url\"></td></tr>";
1390 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1392 $cat_id = db_fetch_result($result, 0, "cat_id");
1394 $row_class = toggleEvenOdd($row_class);
1396 print "<tr class='$row_class'><td>Category:</td>";
1398 print "<select id=\"iedit_fcat\">";
1399 print "<option id=\"0\">Uncategorized</option>";
1401 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feed_categories
1402 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1404 if (db_num_rows($tmp_result) > 0) {
1405 print "<option disabled>--------</option>";
1408 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1409 if ($tmp_line["id"] == $cat_id) {
1410 $is_selected = "selected";
1414 printf("<option $is_selected id='%d'>%s</option>",
1415 $tmp_line["id"], $tmp_line["title"]);
1418 print "</select></td>";
1423 $update_interval = db_fetch_result($result, 0, "update_interval");
1424 $row_class = toggleEvenOdd($row_class);
1426 print "<tr class='$row_class'><td>Update Interval:</td>";
1427 // print "<td><input id=\"iedit_updintl\"
1428 // value=\"$update_interval\"></td></tr>";
1432 print "<select id=\"iedit_updintl\">";
1434 foreach (array_keys($update_intervals) as $i) {
1436 if ($i == $update_interval) {
1437 $selected = "selected";
1441 print "<option $selected id=\"$i\">" . $update_intervals[$i] . "</option>";
1448 $row_class = toggleEvenOdd($row_class);
1449 print "<tr class='$row_class'><td>Link to:</td>";
1451 $tmp_result = db_query($link, "SELECT COUNT(id) AS count
1452 FROM ttrss_feeds WHERE parent_feed = '$feed_id'");
1454 $linked_count = db_fetch_result($tmp_result, 0, "count");
1456 $parent_feed = db_fetch_result($result, 0, "parent_feed");
1458 if ($linked_count > 0) {
1459 $disabled = "disabled";
1462 print "<select $disabled id=\"iedit_parent_feed\">";
1464 print "<option id=\"0\">Not linked</option>";
1466 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1468 $cat_qpart = "AND cat_id = '$cat_id'";
1470 $cat_qpart = "AND cat_id IS NULL";
1474 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
1475 WHERE id != '$feed_id' AND owner_uid = ".$_SESSION["uid"]."
1476 $cat_qpart ORDER BY title");
1478 if (db_num_rows($tmp_result) > 0) {
1479 print "<option disabled>--------</option>";
1482 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1483 if ($tmp_line["id"] == $parent_feed) {
1484 $is_selected = "selected";
1488 printf("<option $is_selected id='%d'>%s</option>",
1489 $tmp_line["id"], $tmp_line["title"]);
1492 print "</select></td>";
1495 $purge_interval = db_fetch_result($result, 0, "purge_interval");
1496 $row_class = toggleEvenOdd($row_class);
1498 print "<tr class='$row_class'><td>Purge Days:</td>";
1499 // print "<td><input id=\"iedit_purgintl\"
1500 // value=\"$purge_interval\"></td></tr>";
1504 print "<select id=\"iedit_purgintl\">";
1506 foreach (array_keys($purge_intervals) as $i) {
1508 if ($i == $purge_interval) {
1509 $selected = "selected";
1513 print "<option $selected id=\"$i\">" . $purge_intervals[$i] . "</option>";
1520 // print "<tr><td colspan=\"2\"><b>Authentication</b></td></tr>";
1522 $row_class = toggleEvenOdd($row_class);
1523 $auth_login = db_fetch_result($result, 0, "auth_login");
1525 print "<tr class='$row_class'><td>Login:</td>";
1526 print "<td><input id=\"iedit_login\"
1527 value=\"$auth_login\"></td></tr>";
1529 $row_class = toggleEvenOdd($row_class);
1530 $auth_pass = db_fetch_result($result, 0, "auth_pass");
1532 print "<tr class='$row_class'><td>Password:</td>";
1533 print "<td><input type=\"password\" id=\"iedit_pass\"
1534 value=\"$auth_pass\"></td></tr>";
1536 $row_class = toggleEvenOdd($row_class);
1537 $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
1540 $checked = "checked";
1545 print "<tr class='$row_class'><td valign='top'>Options:</td>";
1546 print "<td><input type=\"checkbox\" id=\"iedit_private\"
1547 $checked><label for=\"iedit_private\">Hide from feed browser</label>";
1549 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
1552 $checked = "checked";
1557 print "<br><input type=\"checkbox\" id=\"iedit_rtl\"
1558 $checked><label for=\"iedit_rtl\">Right-to-left content</label>";
1565 print "<div align='center'>
1566 <input type=\"submit\" class=\"button\"
1567 onclick=\"feedEditSave()\" value=\"Save\">
1568 <input type='submit' class='button'
1569 onclick=\"feedEditCancel()\" value=\"Cancel\"></div>";
1573 if ($subop == "editSave") {
1574 $feed_title = db_escape_string($_POST["t"]);
1575 $feed_link = db_escape_string($_POST["l"]);
1576 $upd_intl = db_escape_string($_POST["ui"]);
1577 $purge_intl = db_escape_string($_POST["pi"]);
1578 $feed_id = db_escape_string($_POST["id"]);
1579 $cat_id = db_escape_string($_POST["catid"]);
1580 $auth_login = db_escape_string($_POST["login"]);
1581 $auth_pass = db_escape_string($_POST["pass"]);
1582 $parent_feed = db_escape_string($_POST["pfeed"]);
1583 $private = db_escape_string($_POST["is_pvt"]);
1584 $rtl_content = db_escape_string($_POST["is_rtl"]);
1586 if (strtoupper($upd_intl) == "DEFAULT")
1589 if (strtoupper($upd_intl) == "DISABLED")
1592 if (strtoupper($purge_intl) == "DEFAULT")
1595 if (strtoupper($purge_intl) == "DISABLED")
1599 $category_qpart = "cat_id = '$cat_id'";
1601 $category_qpart = 'cat_id = NULL';
1604 if ($parent_feed != 0) {
1605 $parent_qpart = "parent_feed = '$parent_feed'";
1607 $parent_qpart = 'parent_feed = NULL';
1610 $result = db_query($link, "UPDATE ttrss_feeds SET
1613 title = '$feed_title', feed_url = '$feed_link',
1614 update_interval = '$upd_intl',
1615 purge_interval = '$purge_intl',
1616 auth_login = '$auth_login',
1617 auth_pass = '$auth_pass',
1619 rtl_content = $rtl_content
1620 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
1623 if ($subop == "saveCat") {
1624 $cat_title = db_escape_string($_GET["title"]);
1625 $cat_id = db_escape_string($_GET["id"]);
1627 $result = db_query($link, "UPDATE ttrss_feed_categories SET
1628 title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
1632 if ($subop == "remove") {
1634 if (!WEB_DEMO_MODE
) {
1636 $ids = split(",", db_escape_string($_GET["ids"]));
1638 foreach ($ids as $id) {
1639 db_query($link, "DELETE FROM ttrss_feeds
1640 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1642 $icons_dir = ICONS_DIR
;
1644 if (file_exists($icons_dir . "/$id.ico")) {
1645 unlink($icons_dir . "/$id.ico");
1651 if ($subop == "add") {
1653 if (!WEB_DEMO_MODE
) {
1655 $feed_link = db_escape_string(trim($_GET["link"]));
1656 $cat_id = db_escape_string($_GET["cid"]);
1658 if ($cat_id == "0" ||
!$cat_id) {
1659 $cat_qpart = "NULL";
1661 $cat_qpart = "'$cat_id'";
1664 $result = db_query($link,
1665 "SELECT id FROM ttrss_feeds
1666 WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]);
1668 if (db_num_rows($result) == 0) {
1670 $result = db_query($link,
1671 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
1672 VALUES ('".$_SESSION["uid"]."', '$feed_link',
1673 '[Unknown]', $cat_qpart)");
1675 $result = db_query($link,
1676 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'
1677 AND owner_uid = " . $_SESSION["uid"]);
1679 $feed_id = db_fetch_result($result, 0, "id");
1682 update_rss_feed($link, $feed_link, $feed_id, true);
1686 print "<div class=\"warning\">
1687 Feed <b>$feed_link</b> already exists in the database.
1693 if ($subop == "addCat") {
1695 if (!WEB_DEMO_MODE
) {
1697 $feed_cat = db_escape_string(trim($_GET["cat"]));
1699 $result = db_query($link,
1700 "SELECT id FROM ttrss_feed_categories
1701 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
1703 if (db_num_rows($result) == 0) {
1705 $result = db_query($link,
1706 "INSERT INTO ttrss_feed_categories (owner_uid,title)
1707 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
1711 print "<div class=\"warning\">
1712 Category <b>$feed_cat</b> already exists in the database.
1720 if ($subop == "removeCats") {
1722 if (!WEB_DEMO_MODE
) {
1724 $ids = split(",", db_escape_string($_GET["ids"]));
1726 foreach ($ids as $id) {
1728 db_query($link, "BEGIN");
1730 $result = db_query($link,
1731 "SELECT count(id) as num_feeds FROM ttrss_feeds
1732 WHERE cat_id = '$id'");
1734 $num_feeds = db_fetch_result($result, 0, "num_feeds");
1736 if ($num_feeds == 0) {
1737 db_query($link, "DELETE FROM ttrss_feed_categories
1738 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1741 print "<div class=\"warning\">
1742 Unable to delete non empty feed categories.</div>";
1746 db_query($link, "COMMIT");
1751 if ($subop == "categorize") {
1753 if (!WEB_DEMO_MODE
) {
1755 $ids = split(",", db_escape_string($_GET["ids"]));
1757 $cat_id = db_escape_string($_GET["cat_id"]);
1760 $cat_id_qpart = 'NULL';
1762 $cat_id_qpart = "'$cat_id'";
1765 db_query($link, "BEGIN");
1767 foreach ($ids as $id) {
1769 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
1770 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1773 db_query($link, "COMMIT");
1780 // print "<h3>Edit Feeds</h3>";
1782 $result = db_query($link, "SELECT id,title,feed_url,last_error
1783 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1785 if (db_num_rows($result) > 0) {
1787 print "<div class=\"warning\">";
1789 // print"<img class=\"closeButton\"
1790 // onclick=\"javascript:hideParentElement(this);\" src=\"images/close.png\">";
1792 print "<a href=\"javascript:showBlockElement('feedUpdateErrors')\">
1793 <b>Feeds with update errors</b> (click to expand)</a>";
1795 print "<ul id=\"feedUpdateErrors\" class=\"nomarks\">";
1797 while ($line = db_fetch_assoc($result)) {
1798 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
1799 $line["last_error"];
1807 $feed_search = db_escape_string($_GET["search"]);
1809 if (array_key_exists("search", $_GET)) {
1810 $_SESSION["prefs_feed_search"] = $feed_search;
1812 $feed_search = $_SESSION["prefs_feed_search"];
1815 print "<table width='100%' class=\"prefGenericAddBox\"
1816 cellspacing='0' cellpadding='0'><tr>
1818 <input id=\"fadd_link\"
1819 onchange=\"javascript:addFeed()\"
1821 <input type=\"submit\" class=\"button\"
1822 onclick=\"javascript:addFeed()\" value=\"Add feed\">";
1824 if (ENABLE_FEED_BROWSER
) {
1825 print " (<a href='javascript:browseFeeds()'>Top 50</a>)";
1828 print "</td><td align='right'>
1829 <input id=\"feed_search\" size=\"20\"
1830 onchange=\"javascript:updateFeedList()\"
1831 value=\"$feed_search\">
1832 <input type=\"submit\" class=\"button\"
1833 onclick=\"javascript:updateFeedList()\" value=\"Search\">
1837 $feeds_sort = db_escape_string($_GET["sort"]);
1839 if (!$feeds_sort ||
$feeds_sort == "undefined") {
1840 $feeds_sort = $_SESSION["pref_sort_feeds"];
1841 if (!$feeds_sort) $feeds_sort = "title";
1844 $_SESSION["pref_sort_feeds"] = $feeds_sort;
1847 $search_qpart = "(UPPER(F1.title) LIKE UPPER('%$feed_search%') OR
1848 UPPER(F1.feed_url) LIKE UPPER('%$feed_search%')) AND";
1853 $result = db_query($link, "SELECT
1857 substring(F1.last_updated,1,16) AS last_updated,
1862 F2.title AS parent_title,
1863 C1.title AS category
1866 LEFT JOIN ttrss_feeds AS F2
1867 ON (F1.parent_feed = F2.id)
1868 LEFT JOIN ttrss_feed_categories AS C1
1869 ON (F1.cat_id = C1.id)
1871 $search_qpart F1.owner_uid = '".$_SESSION["uid"]."'
1872 ORDER by category,$feeds_sort,title");
1874 if (db_num_rows($result) != 0) {
1876 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1878 print "<p><table width=\"100%\" cellspacing=\"0\"
1879 class=\"prefFeedList\" id=\"prefFeedList\">";
1880 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1882 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
1883 'FEEDR-', 'FRCHK-', true)\">All</a>,
1884 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
1885 'FEEDR-', 'FRCHK-', false)\">None</a>
1888 if (!get_pref($link, 'ENABLE_FEED_CATS')) {
1889 print "<tr class=\"title\">
1890 <td width='5%' align='center'> </td>
1891 <td width='40%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
1892 <td width='45%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
1893 <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
1900 while ($line = db_fetch_assoc($result)) {
1902 $feed_id = $line["id"];
1903 $cat_id = $line["cat_id"];
1905 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1906 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
1907 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
1909 if (!$edit_cat) $edit_cat = "Uncategorized";
1911 $last_updated = $line["last_updated"];
1913 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1914 $last_updated = smart_date_time(strtotime($last_updated));
1916 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1917 $last_updated = date($short_date, strtotime($last_updated));
1920 if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
1923 print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>";
1925 print "<tr class=\"title\">
1926 <td width='5%' align='center'> </td>
1927 <td width='40%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
1928 <td width='45%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
1929 <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
1931 $cur_cat_id = $cat_id;
1934 $class = ($lnum %
2) ?
"even" : "odd";
1935 $this_row_id = "id=\"FEEDR-$feed_id\"";
1937 print "<tr class=\"$class\" $this_row_id>";
1939 $icon_file = ICONS_DIR
. "/$feed_id.ico";
1941 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1942 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL
. "/$feed_id.ico\">";
1944 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1946 // print "<td class='feedIcon'>$feed_icon</td>";
1948 print "<td class='feedSelect'><input onclick='toggleSelectRow(this);'
1949 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
1951 $edit_title = truncate_string($edit_title, 40);
1952 $edit_link = truncate_string($edit_link, 60);
1954 $parent_title = $line["parent_title"];
1955 if ($parent_title) {
1956 $parent_title = "<span class='groupPrompt'>(linked to
1957 $parent_title)</span>";
1960 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1961 "$feed_icon $edit_title $parent_title" . "</a></td>";
1963 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1964 $edit_link . "</a></td>";
1966 /* if (get_pref($link, 'ENABLE_FEED_CATS')) {
1967 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1968 $edit_cat . "</a></td>";
1971 /* print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1972 $update_intervals[$line["update_interval"]] . "</a></td>";
1974 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1975 $purge_intervals[$line["purge_interval"]] . "</a></td>"; */
1977 print "<td align='right'><a href=\"javascript:editFeed($feed_id);\">" .
1978 "$last_updated</a></td>";
1989 if ($subop == "edit") {
1990 print "Edit feed:
1991 <input type=\"submit\" class=\"button\"
1992 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
1993 <input type=\"submit\" class=\"button\"
1994 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1999 <input type=\"submit\" class=\"button\"
2000 onclick=\"javascript:selectedFeedDetails()\" value=\"Details\">
2001 <input type=\"submit\" class=\"button\"
2002 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
2003 <input type=\"submit\" class=\"button\"
2004 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
2006 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2008 print " ";
2010 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2011 WHERE owner_uid = ".$_SESSION["uid"]."
2014 print "<select id=\"sfeed_set_fcat\">";
2015 print "<option id=\"0\">Uncategorized</option>";
2017 if (db_num_rows($result) != 0) {
2019 print "<option disabled>--------</option>";
2021 while ($line = db_fetch_assoc($result)) {
2022 printf("<option id='%d'>%s</option>",
2023 $line["id"], $line["title"]);
2029 print " <input type=\"submit\" class=\"button\"
2030 onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Set category\">";
2035 All feeds: <input type=\"submit\"
2036 class=\"button\" onclick=\"gotoExportOpml()\"
2037 value=\"Export OPML\">";
2041 print "<p>No feeds defined.</p>";
2045 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2047 print "<h3>Edit Categories</h3>";
2049 // print "<h3>Categories</h3>";
2051 print "<div class=\"prefGenericAddBox\">
2052 <input id=\"fadd_cat\"
2053 onchange=\"javascript:addFeedCat()\"
2056 type=\"submit\" class=\"button\"
2057 onclick=\"javascript:addFeedCat()\" value=\"Add category\"></div>";
2059 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2060 WHERE owner_uid = ".$_SESSION["uid"]."
2063 if (db_num_rows($result) != 0) {
2065 print "<p><table width=\"100%\" class=\"prefFeedCatList\"
2066 cellspacing=\"0\" id=\"prefFeedCatList\">";
2068 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2070 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
2071 'FCATR-', 'FCCHK-', true)\">All</a>,
2072 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
2073 'FCATR-', 'FCCHK-', false)\">None</a>
2076 print "<tr class=\"title\">
2077 <td width=\"5%\"></td><td width=\"80%\">Title</td>
2082 while ($line = db_fetch_assoc($result)) {
2084 $class = ($lnum %
2) ?
"even" : "odd";
2086 $cat_id = $line["id"];
2088 $edit_cat_id = $_GET["id"];
2090 if ($subop == "editCat" && $cat_id != $edit_cat_id) {
2094 $this_row_id = "id=\"FCATR-$cat_id\"";
2097 print "<tr class=\"$class\" $this_row_id>";
2099 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
2101 if (!$edit_cat_id ||
$subop != "editCat") {
2103 print "<td align='center'><input onclick='toggleSelectRow(this);'
2104 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
2106 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
2107 $edit_title . "</a></td>";
2109 } else if ($cat_id != $edit_cat_id) {
2111 print "<td><input disabled=\"true\" type=\"checkbox\"
2112 id=\"FRCHK-".$line["id"]."\"></td>";
2114 print "<td>$edit_title</td>";
2118 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2120 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
2133 if ($subop == "editCat") {
2134 print "Edit category:
2135 <input type=\"submit\" class=\"button\"
2136 onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\">
2137 <input type=\"submit\" class=\"button\"
2138 onclick=\"javascript:feedCatEditSave()\" value=\"Save\">";
2143 <input type=\"submit\" class=\"button\"
2144 onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\">
2145 <input type=\"submit\" class=\"button\"
2146 onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">";
2151 print "<p>No feed categories defined.</p>";
2155 print "<h3>Import OPML</h3>
2156 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
2157 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">
2158 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
2159 type=\"submit\" value=\"Import\">
2164 if ($op == "pref-filters") {
2166 $subop = $_GET["subop"];
2167 $quiet = $_GET["quiet"];
2169 if ($subop == "editSave") {
2171 $regexp = db_escape_string($_GET["r"]);
2172 $match = db_escape_string($_GET["m"]);
2173 $filter_id = db_escape_string($_GET["id"]);
2174 $feed_id = db_escape_string($_GET["fid"]);
2175 $action_id = db_escape_string($_GET["aid"]);
2180 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2183 $result = db_query($link, "UPDATE ttrss_filters SET
2184 reg_exp = '$regexp',
2186 action_id = '$action_id',
2187 filter_type = (SELECT id FROM ttrss_filter_types WHERE
2188 description = '$match')
2189 WHERE id = '$filter_id'");
2192 if ($subop == "remove") {
2194 if (!WEB_DEMO_MODE
) {
2196 $ids = split(",", db_escape_string($_GET["ids"]));
2198 foreach ($ids as $id) {
2199 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
2205 if ($subop == "add") {
2207 if (!WEB_DEMO_MODE
) {
2209 $regexp = db_escape_string(trim($_GET["regexp"]));
2210 $match = db_escape_string(trim($_GET["match"]));
2211 $feed_id = db_escape_string($_GET["fid"]);
2212 $action_id = db_escape_string($_GET["aid"]);
2217 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2220 $result = db_query($link,
2221 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
2224 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
2225 description = '$match'),'".$_SESSION["uid"]."',
2226 $feed_id, '$action_id')");
2232 $result = db_query($link, "SELECT description
2233 FROM ttrss_filter_types ORDER BY description");
2235 $filter_types = array();
2237 while ($line = db_fetch_assoc($result)) {
2238 array_push($filter_types, $line["description"]);
2241 print "<div class=\"prefGenericAddBox\">
2242 <input id=\"fadd_regexp\" size=\"40\"> ";
2244 print_select("fadd_match", "Title", $filter_types);
2246 print " <select id=\"fadd_feed\">";
2248 print "<option selected id=\"0\">All feeds</option>";
2250 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
2251 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2253 if (db_num_rows($result) > 0) {
2254 print "<option disabled>--------</option>";
2257 while ($line = db_fetch_assoc($result)) {
2258 printf("<option id='%d'>%s</option>", $line["id"], $line["title"]);
2261 print "</select> ";
2263 print " Action: ";
2265 print "<select id=\"fadd_action\">";
2267 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2270 while ($line = db_fetch_assoc($result)) {
2271 printf("<option id='%d'>%s</option>", $line["id"], $line["description"]);
2274 print "</select> ";
2276 /* print "<input type=\"submit\"
2277 class=\"button\" onclick=\"javascript:testFilter()\"
2278 value=\"Test filter\"> "; */
2280 print "<input type=\"submit\"
2281 class=\"button\" onclick=\"javascript:addFilter()\"
2282 value=\"Add filter\">";
2286 $result = db_query($link, "SELECT
2287 ttrss_filters.id AS id,reg_exp,
2288 ttrss_filter_types.name AS filter_type_name,
2289 ttrss_filter_types.description AS filter_type_descr,
2291 ttrss_filter_actions.description AS action_description,
2292 ttrss_feeds.title AS feed_title
2294 ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN
2295 ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id)
2297 filter_type = ttrss_filter_types.id AND
2298 ttrss_filter_actions.id = action_id AND
2299 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
2302 if (db_num_rows($result) != 0) {
2304 print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\"
2305 id=\"prefFilterList\">";
2307 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2309 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
2310 'FILRR-', 'FICHK-', true)\">All</a>,
2311 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
2312 'FILRR-', 'FICHK-', false)\">None</a>
2315 print "<tr class=\"title\">
2316 <td align='center' width=\"5%\"> </td>
2317 <td width=\"20%\">Filter expression</td>
2318 <td width=\"20%\">Feed</td>
2319 <td width=\"15%\">Match</td>
2320 <td width=\"15%\">Action</td>";
2324 while ($line = db_fetch_assoc($result)) {
2326 $class = ($lnum %
2) ?
"even" : "odd";
2328 $filter_id = $line["id"];
2329 $edit_filter_id = $_GET["id"];
2331 if ($subop == "edit" && $filter_id != $edit_filter_id) {
2335 $this_row_id = "id=\"FILRR-$filter_id\"";
2338 print "<tr class=\"$class\" $this_row_id>";
2340 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
2342 if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
2344 if (!$edit_filter_id ||
$subop != "edit") {
2346 print "<td align='center'><input onclick='toggleSelectRow(this);'
2347 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
2349 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2350 $line["reg_exp"] . "</td>";
2352 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2353 $line["feed_title"] . "</td>";
2355 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2356 $line["filter_type_descr"] . "</td>";
2358 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2359 $line["action_description"] . "</td>";
2361 } else if ($filter_id != $edit_filter_id) {
2363 if (!$line["description"]) $line["description"] = "[No description]";
2365 print "<td><input disabled=\"true\" type=\"checkbox\"
2366 id=\"FICHK-".$line["id"]."\"></td>";
2368 print "<td>".$line["reg_exp"]."</td>";
2369 print "<td>".$line["feed_title"]."</td>";
2370 print "<td>".$line["filter_type_descr"]."</td>";
2371 print "<td>".$line["action_description"]."</td>";
2375 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2377 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
2381 print "<select id=\"iedit_feed\">";
2382 print "<option id=\"0\">All feeds</option>";
2384 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
2385 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2387 if (db_num_rows($tmp_result) > 0) {
2388 print "<option disabled>--------</option>";
2391 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2392 if ($tmp_line["id"] == $line["feed_id"]) {
2393 $is_selected = "selected";
2397 printf("<option $is_selected id='%d'>%s</option>",
2398 $tmp_line["id"], $tmp_line["title"]);
2401 print "</select></td>";
2404 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
2408 print "<select id=\"iedit_filter_action\">";
2410 $tmp_result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2411 ORDER BY description");
2413 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2414 if ($tmp_line["description"] == $line["action_description"]) {
2415 $is_selected = "selected";
2419 printf("<option $is_selected id='%d'>%s</option>",
2420 $tmp_line["id"], $tmp_line["description"]);
2423 print "</select></td>";
2434 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
2441 if ($subop == "edit") {
2443 <input type=\"submit\" class=\"button\"
2444 onclick=\"javascript:filterEditSave()\" value=\"Save\">
2445 <input type=\"submit\" class=\"button\"
2446 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">";
2452 <input type=\"submit\" class=\"button\"
2453 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
2454 <input type=\"submit\" class=\"button\"
2455 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
2460 print "<p>No filters defined.</p>";
2465 // We need to accept raw SQL data in label queries, so not everything is escaped
2466 // here, this is by design. If you don't like the whole idea, disable labels
2467 // altogether with GLOBAL_ENABLE_LABELS = false
2469 if ($op == "pref-labels") {
2471 if (!GLOBAL_ENABLE_LABELS
) {
2475 $subop = $_GET["subop"];
2477 if ($subop == "test") {
2479 $expr = $_GET["expr"];
2480 $descr = $_GET["descr"];
2482 print "<div class='infoBoxContents'>";
2484 print "<h1>Label «$descr»</h1>";
2486 // print "<p><b>Expression</b>: $expr</p>";
2488 $result = db_query($link,
2489 "SELECT count(id) AS num_matches
2490 FROM ttrss_entries,ttrss_user_entries
2492 ttrss_user_entries.ref_id = ttrss_entries.id AND
2493 owner_uid = " . $_SESSION["uid"]);
2495 $num_matches = db_fetch_result($result, 0, "num_matches");;
2497 if ($num_matches > 0) {
2499 print "<p>Query returned <b>$num_matches</b> matches, first 5 follow:</p>";
2501 $result = db_query($link,
2503 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
2504 FROM ttrss_entries,ttrss_user_entries
2506 ttrss_user_entries.ref_id = ttrss_entries.id
2507 AND owner_uid = " . $_SESSION["uid"] . "
2508 ORDER BY date_entered DESC LIMIT 5");
2510 print "<ul class=\"nomarks\">";
2511 while ($line = db_fetch_assoc($result)) {
2512 print "<li>".$line["title"].
2513 " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
2518 print "<p>Query didn't return any matches.</p>";
2523 print "<div align='center'>
2524 <input type='submit' class='button'
2525 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2529 if ($subop == "editSave") {
2531 $sql_exp = $_GET["s"];
2532 $descr = $_GET["d"];
2533 $label_id = db_escape_string($_GET["id"]);
2535 // print "$sql_exp : $descr : $label_id";
2537 $result = db_query($link, "UPDATE ttrss_labels SET
2538 sql_exp = '$sql_exp',
2539 description = '$descr'
2540 WHERE id = '$label_id'");
2543 if ($subop == "remove") {
2545 if (!WEB_DEMO_MODE
) {
2547 $ids = split(",", db_escape_string($_GET["ids"]));
2549 foreach ($ids as $id) {
2550 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
2556 if ($subop == "add") {
2558 if (!WEB_DEMO_MODE
) {
2560 // no escaping is done here on purpose
2561 $exp = trim($_GET["exp"]);
2563 $result = db_query($link,
2564 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
2565 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
2569 print "<div class=\"prefGenericAddBox\">
2570 <input size=\"40\" id=\"ladd_expr\"> ";
2572 print"<input type=\"submit\" class=\"button\"
2573 onclick=\"javascript:addLabel()\" value=\"Add label\"></div>";
2575 $result = db_query($link, "SELECT
2576 id,sql_exp,description
2580 owner_uid = ".$_SESSION["uid"]."
2581 ORDER by description");
2583 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2585 if (db_num_rows($result) != 0) {
2587 print "<p><table width=\"100%\" cellspacing=\"0\"
2588 class=\"prefLabelList\" id=\"prefLabelList\">";
2590 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2592 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2593 'LILRR-', 'LICHK-', true)\">All</a>,
2594 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2595 'LILRR-', 'LICHK-', false)\">None</a>
2598 print "<tr class=\"title\">
2599 <td align='center' width=\"5%\"> </td>
2600 <td width=\"40%\">SQL expression
2601 <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a>
2603 <td width=\"40%\">Caption</td></tr>";
2607 while ($line = db_fetch_assoc($result)) {
2609 $class = ($lnum %
2) ?
"even" : "odd";
2611 $label_id = $line["id"];
2612 $edit_label_id = $_GET["id"];
2614 if ($subop == "edit" && $label_id != $edit_label_id) {
2618 $this_row_id = "id=\"LILRR-$label_id\"";
2621 print "<tr class=\"$class\" $this_row_id>";
2623 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
2624 $line["description"] = htmlspecialchars($line["description"]);
2626 if (!$edit_label_id ||
$subop != "edit") {
2628 if (!$line["description"]) $line["description"] = "[No caption]";
2630 print "<td align='center'><input onclick='toggleSelectRow(this);'
2631 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
2633 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2634 $line["sql_exp"] . "</td>";
2636 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2637 $line["description"] . "</td>";
2639 } else if ($label_id != $edit_label_id) {
2641 if (!$line["description"]) $line["description"] = "[No description]";
2643 print "<td><input disabled=\"true\" type=\"checkbox\"
2644 id=\"LICHK-".$line["id"]."\"></td>";
2646 print "<td>".$line["sql_exp"]."</td>";
2647 print "<td>".$line["description"]."</td>";
2651 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2653 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
2656 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2668 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
2675 if ($subop == "edit") {
2677 <input type=\"submit\" class=\"button\"
2678 onclick=\"javascript:labelTest()\" value=\"Test\">
2679 <input type=\"submit\" class=\"button\"
2680 onclick=\"javascript:labelEditSave()\" value=\"Save\">
2681 <input type=\"submit\" class=\"button\"
2682 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">";
2688 <input type=\"submit\" class=\"button\"
2689 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
2690 <input type=\"submit\" class=\"button\"
2691 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
2694 print "<p>No labels defined.</p>";
2698 if ($op == "error") {
2699 print "<div width=\"100%\" align='center'>";
2700 $msg = $_GET["msg"];
2705 if ($op == "help") {
2706 if (!$_GET["noheaders"]) {
2708 <title>Tiny Tiny RSS : Help</title>
2709 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2710 <script type=\"text/javascript\" src=\"functions.js\"></script>
2711 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2715 $tid = sprintf("%d", $_GET["tid"]);
2717 print "<div class='infoBoxContents'>";
2719 if (file_exists("help/$tid.php")) {
2720 include("help/$tid.php");
2722 print "<p>Help topic not found.</p>";
2727 print "<div align='center'>
2728 <input type='submit' class='button'
2729 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2731 if (!$_GET["noheaders"]) {
2732 print "</body></html>";
2739 $param = $_GET["param"];
2741 if ($id == "quickAddFeed") {
2744 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2747 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2748 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2749 WHERE owner_uid = ".$_SESSION["uid"]."
2752 print " <select id=\"qafCat\">";
2753 print "<option id=\"0\">Uncategorized</option>";
2755 if (db_num_rows($result) != 0) {
2757 print "<option disabled>--------</option>";
2759 while ($line = db_fetch_assoc($result)) {
2760 printf("<option id='%d'>%s</option>",
2761 $line["id"], $line["title"]);
2768 print " <input class=\"button\"
2769 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
2770 <input class=\"button\"
2771 type=\"submit\" onclick=\"javascript:closeDlg()\"
2775 if ($id == "quickDelFeed") {
2777 $param = db_escape_string($param);
2779 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
2783 $f_title = db_fetch_result($result, 0, "title");
2785 print "Remove current feed (<b>$f_title</b>)?
2786 <input class=\"button\"
2787 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
2788 <input class=\"button\"
2789 type=\"submit\" onclick=\"javascript:closeDlg()\"
2792 print "Error: Feed $param not found.
2793 <input class=\"button\"
2794 type=\"submit\" onclick=\"javascript:closeDlg()\"
2799 if ($id == "search") {
2801 $active_feed_id = db_escape_string($_GET["param"]);
2803 print "<input id=\"searchbox\" class=\"extSearch\"
2804 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2805 onchange=\"javascript:search()\">
2806 <select id=\"searchmodebox\">
2807 <option selected>All feeds</option>";
2809 if ($active_feed_id) {
2810 print "<option>This feed</option>";
2812 print "<option disabled>This feed</option>";
2815 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2816 print "<option>This category</option>";
2820 <input type=\"submit\"
2821 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
2822 <input class=\"button\"
2823 type=\"submit\" onclick=\"javascript:closeDlg()\"
2828 if ($id == "quickAddFilter") {
2830 $result = db_query($link, "SELECT description
2831 FROM ttrss_filter_types ORDER BY description");
2833 $filter_types = array();
2835 while ($line = db_fetch_assoc($result)) {
2836 array_push($filter_types, $line["description"]);
2841 print "<tr><td>Match:</td><td><input id=\"fadd_regexp\" size=\"40\"> ";
2843 print_select("fadd_match", "Title", $filter_types);
2846 print "<tr><td>Feed:</td><td><select id=\"fadd_feed\">";
2848 print "<option selected id=\"0\">All feeds</option>";
2850 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
2851 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2853 if (db_num_rows($result) > 0) {
2854 print "<option disabled>--------</option>";
2857 while ($line = db_fetch_assoc($result)) {
2858 if ($param == $line["id"]) {
2859 $selected = "selected";
2863 printf("<option id='%d' %s>%s</option>", $line["id"], $selected, $line["title"]);
2866 print "</select></td></tr>";
2868 print "<tr><td>Action:</td>";
2870 print "<td><select id=\"fadd_action\">";
2872 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2875 while ($line = db_fetch_assoc($result)) {
2876 printf("<option id='%d'>%s</option>", $line["id"], $line["description"]);
2881 print "</td></tr><tr><td colspan=\"2\" align=\"right\">";
2883 print "<input type=\"submit\"
2884 class=\"button\" onclick=\"javascript:qaddFilter()\"
2885 value=\"Add filter\"> ";
2887 print "<input class=\"button\"
2888 type=\"submit\" onclick=\"javascript:closeDlg()\"
2891 print "</td></tr></table>";
2895 // update feeds of all users, may be used anonymously
2896 if ($op == "globalUpdateFeeds") {
2898 $result = db_query($link, "SELECT id FROM ttrss_users");
2900 while ($line = db_fetch_assoc($result)) {
2901 $user_id = $line["id"];
2902 // print "<!-- updating feeds of uid $user_id -->";
2903 update_all_feeds($link, false, $user_id);
2907 <message msg=\"All feeds updated\"/>
2912 if ($op == "pref-prefs") {
2914 $subop = $_REQUEST["subop"];
2916 if ($subop == "Save configuration") {
2918 if (WEB_DEMO_MODE
) {
2919 header("Location: prefs.php");
2923 $_SESSION["prefs_op_result"] = "save-config";
2925 $_SESSION["prefs_cache"] = false;
2927 foreach (array_keys($_POST) as $pref_name) {
2929 $pref_name = db_escape_string($pref_name);
2930 $value = db_escape_string($_POST[$pref_name]);
2932 $result = db_query($link, "SELECT type_name
2933 FROM ttrss_prefs,ttrss_prefs_types
2934 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
2936 if (db_num_rows($result) > 0) {
2938 $type_name = db_fetch_result($result, 0, "type_name");
2940 // print "$pref_name : $type_name : $value<br>";
2942 if ($type_name == "bool") {
2943 if ($value == "1") {
2948 } else if ($type_name == "integer") {
2949 $value = sprintf("%d", $value);
2952 // print "$pref_name : $type_name : $value<br>";
2954 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
2955 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
2959 header("Location: prefs.php");
2963 } else if ($subop == "getHelp") {
2965 $pref_name = db_escape_string($_GET["pn"]);
2967 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
2968 WHERE pref_name = '$pref_name'");
2970 if (db_num_rows($result) > 0) {
2971 $help_text = db_fetch_result($result, 0, "help_text");
2974 print "Unknown option: $pref_name";
2977 } else if ($subop == "Change e-mail") {
2979 if (WEB_DEMO_MODE
) {
2980 header("Location: prefs.php");
2984 $email = db_escape_string($_GET["email"]);
2985 $active_uid = $_SESSION["uid"];
2988 db_query($link, "UPDATE ttrss_users SET email = '$email'
2989 WHERE id = '$active_uid'");
2992 header("Location: prefs.php");
2994 } else if ($subop == "Change password") {
2996 if (WEB_DEMO_MODE
) {
2997 header("Location: prefs.php");
3001 $old_pw = $_POST["OLD_PASSWORD"];
3002 $new_pw = $_POST["OLD_PASSWORD"];
3004 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
3005 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
3007 $active_uid = $_SESSION["uid"];
3009 if ($old_pw && $new_pw) {
3011 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
3013 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3014 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
3015 pwd_hash = '$old_pw_hash')");
3017 if (db_num_rows($result) == 1) {
3018 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
3019 WHERE id = '$active_uid'");
3021 $_SESSION["pwd_change_result"] = "ok";
3023 $_SESSION["pwd_change_result"] = "failed";
3027 header("Location: prefs.php");
3029 } else if ($subop == "Reset to defaults") {
3031 if (WEB_DEMO_MODE
) {
3032 header("Location: prefs.php");
3036 $_SESSION["prefs_op_result"] = "reset-to-defaults";
3038 if (DB_TYPE
== "pgsql") {
3039 db_query($link,"UPDATE ttrss_user_prefs
3040 SET value = ttrss_prefs.def_value
3041 WHERE owner_uid = '".$_SESSION["uid"]."' AND
3042 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
3044 db_query($link, "DELETE FROM ttrss_user_prefs
3045 WHERE owner_uid = ".$_SESSION["uid"]);
3046 initialize_user_prefs($link, $_SESSION["uid"]);
3049 header("Location: prefs.php");
3051 } else if ($subop == "Change theme") {
3053 $theme = db_escape_string($_POST["theme"]);
3055 if ($theme == "Default") {
3056 $theme_qpart = 'NULL';
3058 $theme_qpart = "'$theme'";
3061 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
3062 WHERE theme_name = '$theme'");
3064 if (db_num_rows($result) == 1) {
3065 $theme_id = db_fetch_result($result, 0, "id");
3066 $theme_path = db_fetch_result($result, 0, "theme_path");
3072 db_query($link, "UPDATE ttrss_users SET
3073 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
3075 $_SESSION["theme"] = $theme_path;
3077 header("Location: prefs.php");
3081 if (!SINGLE_USER_MODE
) {
3083 $result = db_query($link, "SELECT id,email FROM ttrss_users
3084 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
3085 pwd_hash = 'SHA1:".sha1("password")."')");
3087 if (db_num_rows($result) != 0) {
3088 print "<div class=\"warning\">
3089 Your password is at default value, please change it.
3093 if ($_SESSION["pwd_change_result"] == "failed") {
3094 print "<div class=\"warning\">
3095 There was an error while changing your password.
3099 if ($_SESSION["pwd_change_result"] == "ok") {
3100 print "<div class=\"notice\">
3101 Password changed successfully.
3105 $_SESSION["pwd_change_result"] = "";
3107 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
3108 print "<div class=\"notice\">
3109 Your configuration was reset to defaults.
3113 if ($_SESSION["prefs_op_result"] == "save-config") {
3114 print "<div class=\"notice\">
3115 Your configuration was saved successfully.
3119 $_SESSION["prefs_op_result"] = "";
3121 print "<form action=\"backend.php\" method=\"GET\">";
3123 print "<table width=\"100%\" class=\"prefPrefsList\">";
3124 print "<tr><td colspan='3'><h3>Personal data</h3></tr></td>";
3126 $result = db_query($link, "SELECT email FROM ttrss_users
3127 WHERE id = ".$_SESSION["uid"]);
3129 $email = db_fetch_result($result, 0, "email");
3131 print "<tr><td width=\"40%\">E-mail</td>";
3132 print "<td><input class=\"editbox\" name=\"email\"
3133 value=\"$email\"></td></tr>";
3137 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3139 print "<p><input class=\"button\" type=\"submit\"
3140 value=\"Change e-mail\" name=\"subop\">";
3144 print "<form action=\"backend.php\" method=\"POST\">";
3146 print "<table width=\"100%\" class=\"prefPrefsList\">";
3147 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
3149 print "<tr><td width=\"40%\">Old password</td>";
3150 print "<td><input class=\"editbox\" type=\"password\"
3151 name=\"OLD_PASSWORD\"></td></tr>";
3153 print "<tr><td width=\"40%\">New password</td>";
3155 print "<td><input class=\"editbox\" type=\"password\"
3156 name=\"NEW_PASSWORD\"></td></tr>";
3160 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3162 print "<p><input class=\"button\" type=\"submit\"
3163 value=\"Change password\" name=\"subop\">";
3169 $result = db_query($link, "SELECT
3170 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
3172 $user_theme_id = db_fetch_result($result, 0, "theme_id");
3174 $result = db_query($link, "SELECT
3175 id,theme_name FROM ttrss_themes ORDER BY theme_name");
3177 if (db_num_rows($result) > 0) {
3179 print "<form action=\"backend.php\" method=\"POST\">";
3180 print "<table width=\"100%\" class=\"prefPrefsList\">";
3181 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
3182 print "<tr><td width=\"40%\">Select theme</td>";
3183 print "<td><select name=\"theme\">";
3184 print "<option>Default</option>";
3185 print "<option disabled>--------</option>";
3187 while ($line = db_fetch_assoc($result)) {
3188 if ($line["id"] == $user_theme_id) {
3189 $selected = "selected";
3193 print "<option $selected>" . $line["theme_name"] . "</option>";
3195 print "</select></td></tr>";
3197 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3198 print "<p><input class=\"button\" type=\"submit\"
3199 value=\"Change theme\" name=\"subop\">";
3203 $result = db_query($link, "SELECT
3204 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
3205 section_name,def_value
3206 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
3207 WHERE type_id = ttrss_prefs_types.id AND
3208 section_id = ttrss_prefs_sections.id AND
3209 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
3210 owner_uid = ".$_SESSION["uid"]."
3211 ORDER BY section_id,short_desc");
3213 print "<form action=\"backend.php\" method=\"POST\">";
3217 $active_section = "";
3219 while ($line = db_fetch_assoc($result)) {
3221 if ($active_section != $line["section_name"]) {
3223 if ($active_section != "") {
3227 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
3229 $active_section = $line["section_name"];
3231 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
3232 // print "<tr class=\"title\">
3233 // <td width=\"25%\">Option</td><td>Value</td></tr>";
3238 // $class = ($lnum % 2) ? "even" : "odd";
3242 $type_name = $line["type_name"];
3243 $pref_name = $line["pref_name"];
3244 $value = $line["value"];
3245 $def_value = $line["def_value"];
3246 $help_text = $line["help_text"];
3248 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
3250 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
3256 if ($type_name == "bool") {
3257 // print_select($pref_name, $value, array("true", "false"));
3259 if ($value == "true") {
3265 print_radio($pref_name, $value, array("Yes", "No"));
3268 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
3280 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3282 print "<p><input class=\"button\" type=\"submit\"
3283 name=\"subop\" value=\"Save configuration\">";
3285 print " <input class=\"button\" type=\"submit\"
3286 name=\"subop\" onclick=\"return validatePrefsReset()\"
3287 value=\"Reset to defaults\"></p>";
3295 if ($op == "pref-users") {
3297 $subop = $_GET["subop"];
3299 if ($subop == "editSave") {
3301 if (!WEB_DEMO_MODE
) {
3303 $login = db_escape_string($_GET["l"]);
3304 $uid = db_escape_string($_GET["id"]);
3305 $access_level = sprintf("%d", $_GET["al"]);
3306 $email = db_escape_string($_GET["e"]);
3308 db_query($link, "UPDATE ttrss_users SET login = '$login',
3309 access_level = '$access_level', email = '$email' WHERE id = '$uid'");
3312 } else if ($subop == "remove") {
3314 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3316 $ids = split(",", db_escape_string($_GET["ids"]));
3318 foreach ($ids as $id) {
3319 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
3323 } else if ($subop == "add") {
3325 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3327 $login = db_escape_string(trim($_GET["login"]));
3328 $tmp_user_pwd = make_password(8);
3329 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3331 db_query($link, "INSERT INTO ttrss_users
3332 (login,pwd_hash,access_level,last_login)
3333 VALUES ('$login', '$pwd_hash', 0, NOW())");
3336 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3337 login = '$login' AND pwd_hash = '$pwd_hash'");
3339 if (db_num_rows($result) == 1) {
3341 $new_uid = db_fetch_result($result, 0, "id");
3343 print "<div class=\"notice\">Added user <b>".$_GET["login"].
3344 "</b> with password <b>$tmp_user_pwd</b>.</div>";
3346 initialize_user($link, $new_uid);
3350 print "<div class=\"warning\">Error while adding user <b>".
3351 $_GET["login"].".</b></div>";
3355 } else if ($subop == "resetPass") {
3357 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3359 $uid = db_escape_string($_GET["id"]);
3361 $result = db_query($link, "SELECT login,email
3362 FROM ttrss_users WHERE id = '$uid'");
3364 $login = db_fetch_result($result, 0, "login");
3365 $email = db_fetch_result($result, 0, "email");
3366 $tmp_user_pwd = make_password(8);
3367 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3369 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
3370 WHERE id = '$uid'");
3372 print "<div class=\"notice\">Changed password of
3373 user <b>$login</b> to <b>$tmp_user_pwd</b>.";
3375 if (MAIL_RESET_PASS
&& $email) {
3376 print " Notifying <b>$email</b>.";
3378 mail("$login <$email>", "Password reset notification",
3381 "Your password for this TT-RSS installation was reset by".
3382 " an administrator.\n".
3384 "Your new password is $tmp_user_pwd, please remember".
3385 " it for later reference.\n".
3387 "Sincerely, TT-RSS Mail Daemon.", "From: " . MAIL_FROM
);
3395 print "<div class=\"prefGenericAddBox\">
3396 <input id=\"uadd_box\" onchange=\"javascript:addUser()\" size=\"40\"> ";
3398 print"<input type=\"submit\" class=\"button\"
3399 onclick=\"javascript:addUser()\" value=\"Add user\"></div>";
3401 $result = db_query($link, "SELECT
3402 id,login,access_level,email,
3403 SUBSTRING(last_login,1,16) as last_login
3408 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
3410 print "<p><table width=\"100%\" cellspacing=\"0\"
3411 class=\"prefUserList\" id=\"prefUserList\">";
3413 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
3415 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3416 'UMRR-', 'UMCHK-', true)\">All</a>,
3417 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3418 'UMRR-', 'UMCHK-', false)\">None</a>
3421 print "<tr class=\"title\">
3422 <td align='center' width=\"5%\"> </td>
3423 <td width='20%'>Username</td>
3424 <td width='20%'>E-mail</td>
3425 <td width='20%'>Access Level</td>
3426 <td width='20%'>Last login</td></tr>";
3430 while ($line = db_fetch_assoc($result)) {
3432 $class = ($lnum %
2) ?
"even" : "odd";
3435 $edit_uid = $_GET["id"];
3437 if ($subop == "edit" && $uid != $edit_uid) {
3441 $this_row_id = "id=\"UMRR-$uid\"";
3444 print "<tr class=\"$class\" $this_row_id>";
3446 $line["login"] = htmlspecialchars($line["login"]);
3448 $line["last_login"] = date(get_pref($link, 'SHORT_DATE_FORMAT'),
3449 strtotime($line["last_login"]));
3451 $access_level_names = array(0 => "User", 10 => "Administrator");
3453 /* if ($uid == $_SESSION["uid"]) {
3455 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
3456 id=\"UMCHK-".$line["id"]."\"></td>";
3458 print "<td>".$line["login"]."</td>";
3459 print "<td>".$line["email"]."</td>";
3460 print "<td>".$line["access_level"]."</td>";
3462 } else */ if (!$edit_uid ||
$subop != "edit") {
3464 print "<td align='center'><input onclick='toggleSelectRow(this);'
3465 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
3467 print "<td><a href=\"javascript:editUser($uid);\">" .
3468 $line["login"] . "</td>";
3470 print "<td><a href=\"javascript:editUser($uid);\">" .
3471 $line["email"] . "</td>";
3473 print "<td><a href=\"javascript:editUser($uid);\">" .
3474 $access_level_names[$line["access_level"]] . "</td>";
3476 } else if ($uid != $edit_uid) {
3478 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
3479 id=\"UMCHK-".$line["id"]."\"></td>";
3481 print "<td>".$line["login"]."</td>";
3482 print "<td>".$line["email"]."</td>";
3483 print "<td>".$access_level_names[$line["access_level"]]."</td>";
3487 print "<td align='center'>
3488 <input disabled=\"true\" type=\"checkbox\" checked></td>";
3490 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
3493 print "<td><input id=\"iedit_email\" value=\"".$line["email"].
3496 // print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
3500 print "<select id=\"iedit_ulevel\">";
3501 foreach (array_keys($access_level_names) as $al) {
3502 if ($al == $line["access_level"]) {
3503 $selected = "selected";
3507 print "<option $selected id=\"$al\">" .
3508 $access_level_names[$al] . "</option>";
3515 print "<td>".$line["last_login"]."</td>";
3526 if ($subop == "edit") {
3528 <input type=\"submit\" class=\"button\"
3529 onclick=\"javascript:userEditSave()\" value=\"Save\">
3530 <input type=\"submit\" class=\"button\"
3531 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">";
3537 <input type=\"submit\" class=\"button\"
3538 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
3539 <input type=\"submit\" class=\"button\"
3540 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
3541 <input type=\"submit\" class=\"button\"
3542 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
3543 <input type=\"submit\" class=\"button\"
3544 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
3549 if ($op == "user-details") {
3551 if (WEB_DEMO_MODE ||
$_SESSION["access_level"] < 10) {
3555 /* print "<html><head>
3556 <title>Tiny Tiny RSS : User Details</title>
3557 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
3558 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
3561 $uid = sprintf("%d", $_GET["id"]);
3563 print "<div class='infoBoxContents'>";
3565 $result = db_query($link, "SELECT login,
3566 SUBSTRING(last_login,1,16) AS last_login,
3568 (SELECT COUNT(int_id) FROM ttrss_user_entries
3569 WHERE owner_uid = id) AS stored_articles
3571 WHERE id = '$uid'");
3573 if (db_num_rows($result) == 0) {
3574 print "<h1>User not found</h1>";
3578 print "<h1>User Details</h1>";
3580 print "<table width='100%'>";
3582 $login = db_fetch_result($result, 0, "login");
3583 $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'),
3584 strtotime(db_fetch_result($result, 0, "last_login")));
3585 $access_level = db_fetch_result($result, 0, "access_level");
3586 $stored_articles = db_fetch_result($result, 0, "stored_articles");
3588 print "<tr><td>Username</td><td>$login</td></tr>";
3589 print "<tr><td>Access level</td><td>$access_level</td></tr>";
3590 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
3591 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
3593 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
3594 WHERE owner_uid = '$uid'");
3596 $num_feeds = db_fetch_result($result, 0, "num_feeds");
3598 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
3600 /* $result = db_query($link, "SELECT
3601 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
3602 FROM ttrss_user_entries,ttrss_entries
3603 WHERE owner_uid = '$uid' AND ref_id = id");
3605 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
3607 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
3611 print "<h1>Subscribed feeds</h1>";
3613 $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
3614 WHERE owner_uid = '$uid' ORDER BY title");
3616 print "<ul class=\"userFeedList\">";
3618 while ($line = db_fetch_assoc($result)) {
3620 $icon_file = ICONS_URL
."/".$line["id"].".ico";
3622 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3623 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
3625 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3628 print "<li>$feed_icon <a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
3631 if (db_num_rows($result) < $num_feeds) {
3632 // FIXME - add link to show ALL subscribed feeds here somewhere
3634 class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\"> ...</li>";
3641 print "<div align='center'>
3642 <input type='submit' class='button'
3643 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3645 // print "</body></html>";
3649 if ($op == "feed-details") {
3651 // $feed_id = $_GET["id"];
3653 $feed_ids = split(",", db_escape_string($_GET["id"]));
3655 print "<div class=\"infoBoxContents\">";
3657 foreach ($feed_ids as $feed_id) {
3659 $result = db_query($link,
3662 SUBSTRING(last_updated,1,16) as last_updated,
3664 (SELECT COUNT(int_id) FROM ttrss_user_entries
3665 WHERE feed_id = id) AS total,
3666 (SELECT COUNT(int_id) FROM ttrss_user_entries
3667 WHERE feed_id = id AND unread = true) AS unread,
3668 (SELECT COUNT(int_id) FROM ttrss_user_entries
3669 WHERE feed_id = id AND marked = true) AS marked
3671 WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]);
3673 if (db_num_rows($result) == 0) return;
3675 $title = db_unescape_string(db_fetch_result($result, 0, "title"));
3676 $last_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
3677 strtotime(db_fetch_result($result, 0, "last_updated")));
3678 $feed_url = db_fetch_result($result, 0, "feed_url");
3679 $icon_url = db_fetch_result($result, 0, "icon_url");
3680 $total = db_fetch_result($result, 0, "total");
3681 $unread = db_fetch_result($result, 0, "unread");
3682 $marked = db_fetch_result($result, 0, "marked");
3683 $site_url = db_fetch_result($result, 0, "site_url");
3685 $result = db_query($link, "SELECT COUNT(id) AS subscribed
3686 FROM ttrss_feeds WHERE feed_url = '$feed_url' AND private = false");
3688 $subscribed = db_fetch_result($result, 0, "subscribed");
3690 $icon_file = ICONS_DIR
. "/$feed_id.ico";
3692 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3693 $feed_icon = "<img width=\"16\" height=\"16\"
3694 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
3699 print "<h1>$feed_icon $title</h1>";
3701 print "<table width='100%'>";
3704 print "<tr><td width='30%'>Link</td>
3705 <td><a href=\"$site_url\">$site_url</a>
3706 <a href=\"$feed_url\">(feed)</a></td>
3709 print "<tr><td width='30%'>Feed URL</td>
3710 <td><a href=\"$feed_url\">$feed_url</a></td></tr>";
3712 print "<tr><td>Last updated</td><td>$last_updated</td></tr>";
3713 print "<tr><td>Total articles</td><td>$total</td></tr>";
3714 print "<tr><td>Unread articles</td><td>$unread</td></tr>";
3715 print "<tr><td>Starred articles</td><td>$marked</td></tr>";
3716 print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>";
3720 /* $result = db_query($link, "SELECT title,
3721 SUBSTRING(updated,1,16) AS updated,unread
3722 FROM ttrss_entries,ttrss_user_entries
3723 WHERE ref_id = id AND feed_id = '$feed_id'
3724 ORDER BY date_entered DESC LIMIT 5");
3726 if (db_num_rows($result) > 0) {
3728 print "<h1>Latest headlines</h1>";
3730 print "<ul class=\"nomarks\">";
3732 while ($line = db_fetch_assoc($result)) {
3733 if ($line["unread"] == "t" || $line["unread"] == "1") {
3734 $line["title"] = "<b>" . $line["title"] . "</b>";
3736 print "<li>" . $line["title"].
3737 " <span class=\"insensitive\">(" .
3738 date(get_pref($link, 'SHORT_DATE_FORMAT'),
3739 strtotime($line["updated"])).
3750 print "<div align='center'>
3751 <input type='submit' class='button'
3752 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3755 if ($op == "pref-feed-browser") {
3757 if (!ENABLE_FEED_BROWSER
) {
3758 print "Feed browser is administratively disabled.";
3762 $subop = $_REQUEST["subop"];
3764 if ($subop == "details") {
3765 $id = db_escape_string($_GET["id"]);
3767 print "<div class=\"browserFeedInfo\">";
3768 print "<b>Feed information:</b>";
3769 print "<div class=\"detailsPart\">";
3771 $result = db_query($link, "SELECT
3773 SUBSTRING(last_updated,1,19) AS last_updated
3774 FROM ttrss_feeds WHERE id = '$id'");
3776 $feed_url = db_fetch_result($result, 0, "feed_url");
3777 $site_url = db_fetch_result($result, 0, "site_url");
3778 $last_updated = db_fetch_result($result, 0, "last_updated");
3780 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
3781 $last_updated = smart_date_time(strtotime($last_updated));
3783 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
3784 $last_updated = date($short_date, strtotime($last_updated));
3787 print "Site: <a href='$site_url'>$site_url</a> ".
3788 "(<a href='$feed_url'>feed</a>), ".
3789 "Last updated: $last_updated";
3793 $result = db_query($link, "SELECT
3794 ttrss_entries.title,
3796 substring(date_entered,1,19) as date_entered,
3797 substring(updated,1,19) as updated
3798 FROM ttrss_entries,ttrss_user_entries
3799 WHERE ttrss_entries.id = ref_id AND feed_id = '$id'
3800 ORDER BY updated DESC LIMIT 5");
3802 if (db_num_rows($result) > 0) {
3804 print "<b>Last headlines:</b><br>";
3806 print "<div class=\"detailsPart\">";
3807 print "<ul class=\"compact\">";
3808 while ($line = db_fetch_assoc($result)) {
3810 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
3811 $entry_dt = smart_date_time(strtotime($line["updated"]));
3813 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
3814 $entry_dt = date($short_date, strtotime($line["updated"]));
3817 print "<li>" . $line["title"] .
3818 " <span class=\"insensitive\">($entry_dt)</span></li>";
3820 print "</ul></div>";
3828 $result = db_query($link, "SELECT feed_url,count(id) AS subscribers
3830 WHERE auth_login = '' AND auth_pass = '' AND private = false
3831 GROUP BY feed_url ORDER BY subscribers DESC LIMIT 100");
3833 print "<ul class='nomarks' id='browseBigFeedList'>";
3837 while ($line = db_fetch_assoc($result)) {
3838 $feed_url = $line["feed_url"];
3839 $subscribers = $line["subscribers"];
3841 $sub_result = db_query($link, "SELECT id
3842 FROM ttrss_feeds WHERE feed_url = '$feed_url' AND owner_uid =" .
3845 if (db_num_rows($sub_result) > 0) {
3846 continue; // already subscribed
3849 $det_result = db_query($link, "SELECT site_url,title,id
3850 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
3852 $details = db_fetch_assoc($det_result);
3854 $icon_file = ICONS_DIR
. "/" . $details["id"] . ".ico";
3856 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3857 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL
.
3858 "/".$details["id"].".ico\">";
3860 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3863 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
3864 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
3866 $class = ($feedctr %
2) ?
"even" : "odd";
3868 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
3871 print "<a href=\"javascript:browserToggleExpand('".$details["id"]."')\">" .
3872 $details["title"] ."</a> " .
3873 "<span class='subscribers'>($subscribers)</span>";
3875 print "<div class=\"browserDetails\" id=\"BRDET-" . $details["id"] . "\">";
3883 if ($feedctr == 0) {
3884 print "<li>No feeds found to subscribe.</li>";
3889 print "<p>Selection:
3890 <input type='submit' class='button' onclick=\"feedBrowserSubscribe()\"
3891 value=\"Subscribe\"></p>";
3897 function check_configuration_variables() {
3898 if (!defined('SESSION_EXPIRE_TIME')) {
3899 return "config: SESSION_EXPIRE_TIME is undefined";
3902 if (SESSION_EXPIRE_TIME
< 60) {
3903 return "config: SESSION_EXPIRE_TIME is too low (less than 60)";
3906 if (SESSION_EXPIRE_TIME
< SESSION_COOKIE_LIFETIME_REMEMBER
) {
3907 return "config: SESSION_EXPIRE_TIME should be greater or equal to" .
3908 "SESSION_COOKIE_LIFETIME_REMEMBER";
3911 if (defined('DISABLE_SESSIONS') && DISABLE_SESSIONS
) {
3912 return "config: you have enabled DISABLE_SESSIONS. Please disable this option.";
3921 <!-- <?
= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?
> -->