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 require_once "db.php";
25 require_once "db-prefs.php";
26 require_once "functions.php";
27 require_once "magpierss/rss_fetch.inc";
29 $err_msg = check_configuration_variables();
32 header("Content-Type: application/xml");
33 print_error_xml(9, $err_msg); die;
36 if ((!$op ||
$op == "rpc" ||
$op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
37 header("Content-Type: application/xml");
40 if (!$_SESSION["uid"] && $op != "globalUpdateFeeds") {
43 print_error_xml(6); die;
47 <p>Error: Not logged in.</p>
48 <script type=\"text/javascript\">
49 if (parent.window != 'undefined') {
50 parent.window.location = \"login.php\";
52 window.location = \"login.php\";
62 print_error_xml(7); exit;
65 $purge_intervals = array(
74 $update_intervals = array(
76 -1 => "Disable updates",
84 $script_started = getmicrotime();
86 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
89 if (DB_TYPE
== "mysql") {
92 // PG seems to display its own errors just fine by default.
96 if (DB_TYPE
== "pgsql") {
97 pg_query("set client_encoding = 'utf-8'");
100 if ($_SESSION["uid"]) {
101 if (get_pref($link, "HIDE_READ_FEEDS") == "true") {
102 setcookie("ttrss_vf_hreadf", 1);
104 setcookie("ttrss_vf_hreadf", 0);
107 setcookie('ttrss_vf_refresh', FEEDS_FRAME_REFRESH
);
108 setcookie('ttrss_vf_daemon', ENABLE_UPDATE_DAEMON
);
111 $fetch = $_GET["fetch"];
113 // setcookie("ttrss_icons_url", ICONS_URL);
115 if (!sanity_check($link)) { return; }
117 function outputFeedList($link, $tags = false) {
120 <title>Tiny Tiny RSS : Feedlist</title>
121 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
123 $user_theme = $_SESSION["theme"];
125 print "<link rel=\"stylesheet\" type=\"text/css\"
126 href=\"themes/$user_theme/theme.css\">";
129 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
130 print "<link rel=\"stylesheet\" type=\"text/css\"
131 href=\"tt-rss_compact.css\"/>";
133 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
134 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
137 $script_dt_add = get_script_dt_add();
139 print "<script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
140 <script type=\"text/javascript\" src=\"feedlist.js?$script_dt_add\"></script>
141 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
142 <!--[if gte IE 5.5000]>
143 <script type=\"text/javascript\" src=\"pngfix.js\"></script>
144 <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
147 <script type=\"text/javascript\">
148 if (document.addEventListener) {
149 document.addEventListener(\"DOMContentLoaded\", init, null);
151 window.onload = init;
154 print "<ul class=\"feedList\" id=\"feedList\">\n";
156 $owner_uid = $_SESSION["uid"];
162 if (get_pref($link, 'ENABLE_FEED_CATS')) {
163 print "<li class=\"feedCat\">Special</li>";
164 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
167 $result = db_query($link, "SELECT count(id) as num_starred
168 FROM ttrss_entries,ttrss_user_entries
169 WHERE marked = true AND
170 ttrss_user_entries.ref_id = ttrss_entries.id AND
171 unread = true AND owner_uid = '$owner_uid'");
172 $num_starred = db_fetch_result($result, 0, "num_starred");
176 if ($num_starred > 0) $class .= "Unread";
178 printFeedEntry(-1, $class, "Starred articles", $num_starred,
179 "images/mark_set.png", $link);
181 if (get_pref($link, 'ENABLE_FEED_CATS')) {
185 if (GLOBAL_ENABLE_LABELS
&& get_pref($link, 'ENABLE_LABELS')) {
187 $result = db_query($link, "SELECT id,sql_exp,description FROM
188 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
190 if (db_num_rows($result) > 0) {
191 if (get_pref($link, 'ENABLE_FEED_CATS')) {
192 print "<li class=\"feedCat\">Labels</li>";
193 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
195 print "<li><hr></li>";
199 while ($line = db_fetch_assoc($result)) {
203 $tmp_result = db_query($link, "SELECT count(id) as count
204 FROM ttrss_entries,ttrss_user_entries
205 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
206 ttrss_user_entries.ref_id = ttrss_entries.id
207 AND owner_uid = '$owner_uid'");
209 $count = db_fetch_result($tmp_result, 0, "count");
217 error_reporting (DEFAULT_ERROR_LEVEL
);
219 printFeedEntry(-$line["id"]-11,
220 $class, $line["description"], $count, "images/label.png", $link);
224 if (db_num_rows($result) > 0) {
225 if (get_pref($link, 'ENABLE_FEED_CATS')) {
232 // if (!get_pref($link, 'ENABLE_FEED_CATS')) {
233 print "<li><hr></li>";
236 if (get_pref($link, 'ENABLE_FEED_CATS')) {
237 $order_by_qpart = "category,title";
239 $order_by_qpart = "title";
242 $result = db_query($link, "SELECT ttrss_feeds.*,
243 SUBSTRING(last_updated,1,19) AS last_updated_noms,
244 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
245 WHERE feed_id = ttrss_feeds.id AND
246 ttrss_user_entries.ref_id = ttrss_entries.id AND
247 owner_uid = '$owner_uid') AS total,
248 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
249 WHERE feed_id = ttrss_feeds.id AND unread = true
250 AND ttrss_user_entries.ref_id = ttrss_entries.id
251 AND owner_uid = '$owner_uid') as unread,
253 ttrss_feed_categories.title AS category,
254 ttrss_feed_categories.collapsed
255 FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
256 ON (ttrss_feed_categories.id = cat_id)
258 ttrss_feeds.owner_uid = '$owner_uid' AND parent_feed IS NULL
259 ORDER BY $order_by_qpart");
261 $actid = $_GET["actid"];
271 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
273 while ($line = db_fetch_assoc($result)) {
275 $feed = db_unescape_string($line["title"]);
276 $feed_id = $line["id"];
278 $subop = $_GET["subop"];
280 $total = $line["total"];
281 $unread = $line["unread"];
283 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
284 $last_updated = smart_date_time(strtotime($line["last_updated_noms"]));
286 $last_updated = date($short_date, strtotime($line["last_updated_noms"]));
289 $rtl_content = sql_bool_to_bool($line["rtl_content"]);
292 $rtl_tag = "dir=\"RTL\"";
297 $tmp_result = db_query($link,
298 "SELECT id,COUNT(unread) AS unread
299 FROM ttrss_feeds LEFT JOIN ttrss_user_entries
300 ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
301 WHERE parent_feed = '$feed_id' AND unread = true
302 GROUP BY ttrss_feeds.id");
304 if (db_num_rows($tmp_result) > 0) {
305 while ($l = db_fetch_assoc($tmp_result)) {
306 $unread +
= $l["unread"];
310 $cat_id = $line["cat_id"];
312 $tmp_category = $line["category"];
314 if (!$tmp_category) {
315 $tmp_category = "Uncategorized";
318 // $class = ($lnum % 2) ? "even" : "odd";
320 if ($line["last_error"]) {
326 if ($unread > 0) $class .= "Unread";
328 if ($actid == $feed_id) {
329 $class .= "Selected";
332 $total_unread +
= $unread;
334 if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
340 $category = $tmp_category;
342 $collapsed = $line["collapsed"];
344 // workaround for NULL category
345 if ($category == "Uncategorized") {
346 if ($_COOKIE["ttrss_vf_uclps"] == 1) {
351 if ($collapsed == "t" ||
$collapsed == "1") {
352 $holder_class = "invisible";
360 $cat_id_qpart = "cat_id = '$cat_id'";
362 $cat_id_qpart = "cat_id IS NULL";
365 $tmp_result = db_query($link, "SELECT count(int_id) AS unread
366 FROM ttrss_user_entries,ttrss_feeds WHERE
368 feed_id = ttrss_feeds.id AND $cat_id_qpart AND
369 ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
371 $cat_unread = db_fetch_result($tmp_result, 0, "unread");
373 $cat_id = sprintf("%d", $cat_id);
375 print "<li class=\"feedCat\" id=\"FCAT-$cat_id\">
376 <a href=\"javascript:toggleCollapseCat($cat_id)\">$tmp_category</a>
377 <a href=\"javascript:viewCategory($cat_id)\" id=\"FCAP-$cat_id\">
378 <span id=\"FCATCTR-$cat_id\"
379 class=\"$catctr_class\">($cat_unread unread)$ellipsis</span>
382 // !!! NO SPACE before <ul...feedCatList - breaks firstChild DOM function
383 // -> keyboard navigation, etc.
384 print "<li id=\"feedCatHolder\" class=\"$holder_class\"><ul class=\"feedCatList\" id=\"FCATLIST-$cat_id\">";
387 printFeedEntry($feed_id, $class, $feed, $unread,
388 "icons/$feed_id.ico", $link, $rtl_content,
389 $last_updated, $line["last_error"]);
398 /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
399 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
400 post_int_id = ttrss_user_entries.int_id AND
401 unread = true AND ref_id = ttrss_entries.id
402 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
404 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'
405 ORDER BY tag_name"); */
407 $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
408 FROM ttrss_user_entries WHERE int_id = post_int_id
409 AND unread = true)) AS count FROM ttrss_tags
410 WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name");
414 while ($line = db_fetch_assoc($result)) {
415 $tags[$line["tag_name"]] +
= $line["count"];
418 foreach (array_keys($tags) as $tag) {
420 $unread = $tags[$tag];
428 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
434 if (db_num_rows($result) == 0) {
440 print "<li>No $what to display.</li>";
446 <script type="text/javascript">
448 function statechange() {
449 if (document.readyState == "interactive") init();
452 if (document.readyState) {
453 if (document.readyState == "interactive" || document.readyState == "complete") {
456 document.onreadystatechange = statechange;
459 </script></body></html>';
464 handle_rpc_request($link);
467 if ($op == "feeds") {
469 $tags = $_GET["tags"];
471 $subop = $_GET["subop"];
473 if ($subop == "catchupAll") {
474 db_query($link, "UPDATE ttrss_user_entries SET
475 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
478 if ($subop == "collapse") {
479 $cat_id = db_escape_string($_GET["cid"]);
481 db_query($link, "UPDATE ttrss_feed_categories SET
482 collapsed = NOT collapsed WHERE id = '$cat_id' AND owner_uid = " .
487 outputFeedList($link, $tags);
493 $id = db_escape_string($_GET["id"]);
494 $feed_id = db_escape_string($_GET["feed"]);
496 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
497 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
499 if (db_num_rows($result) == 1) {
500 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
502 $rtl_content = false;
506 $rtl_tag = "dir=\"RTL\"";
513 $result = db_query($link, "UPDATE ttrss_user_entries
514 SET unread = false,last_read = NOW()
515 WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
517 $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
518 SUBSTRING(updated,1,16) as updated,
519 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url,
522 FROM ttrss_entries,ttrss_user_entries
523 WHERE id = '$id' AND ref_id = id AND owner_uid = " . $_SESSION["uid"]);
526 <title>Tiny Tiny RSS : Article $id</title>
527 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
529 $user_theme = $_SESSION["theme"];
531 print "<link rel=\"stylesheet\" type=\"text/css\"
532 href=\"themes/$user_theme/theme.css\">";
535 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
536 print "<link rel=\"stylesheet\" type=\"text/css\"
537 href=\"tt-rss_compact.css\"/>";
539 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
540 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
543 $script_dt_add = get_script_dt_add();
545 print "<script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
546 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
547 </head><body $rtl_tag>";
551 $line = db_fetch_assoc($result);
553 if ($line["icon_url"]) {
554 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
556 $feed_icon = " ";
559 /* if ($line["comments"] && $line["link"] != $line["comments"]) {
560 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
562 $entry_comments = "";
565 $num_comments = $line["num_comments"];
566 $entry_comments = "";
568 if ($num_comments > 0) {
569 if ($line["comments"]) {
570 $comments_url = $line["comments"];
572 $comments_url = $line["link"];
574 $entry_comments = "<a href=\"$comments_url\">$num_comments comments</a>";
576 if ($line["comments"] && $line["link"] != $line["comments"]) {
577 $entry_comments = "<a href=\"".$line["comments"]."\">comments</a>";
581 print "<div class=\"postReply\">";
583 print "<div class=\"postHeader\"><table width=\"100%\">";
585 $entry_author = $line["author"];
588 $entry_author = " - by $entry_author";
591 print "<tr><td><a href=\"" . $line["link"] . "\">" . $line["title"] .
592 "</a>$entry_author</td>";
594 $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
595 strtotime($line["updated"]));
597 print "<td class=\"postDate$rtl_class\">$parsed_updated</td>";
601 $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
602 ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
610 while ($tmp_line = db_fetch_assoc($tmp_result)) {
612 $tag = $tmp_line["tag_name"];
613 $tag_str = "<a href=\"javascript:parent.viewfeed('$tag')\">$tag</a>, ";
615 if ($num_tags == 5) {
616 $tags_str .= "<a href=\"javascript:showBlockElement('allEntryTags')\">...</a>";
617 } else if ($num_tags < 5) {
618 $tags_str .= $tag_str;
620 $f_tags_str .= $tag_str;
623 $tags_str = preg_replace("/, $/", "", $tags_str);
624 $f_tags_str = preg_replace("/, $/", "", $f_tags_str);
626 // $truncated_link = truncate_string($line["link"], 60);
628 if ($tags_str ||
$entry_comments) {
629 print "<tr><td width='50%'>
631 <td align=\"right\">$tags_str</td></tr>";
634 print "</table></div>";
636 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
637 print "<div class=\"postContent\">";
639 if (db_num_rows($tmp_result) > 5) {
640 print "<div id=\"allEntryTags\">Tags: $f_tags_str</div>";
643 if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
644 $line["content"] = preg_replace("/href=/i", "target=\"_new\" href=", $line["content"]);
647 print $line["content"] . "</div>";
651 print "<script type=\"text/javascript\">
652 update_all_counters('$feed_id');
656 print "</body></html>";
659 if ($op == "viewfeed") {
661 $feed = db_escape_string($_GET["feed"]);
662 $skip = db_escape_string($_GET["skip"]);
663 $subop = db_escape_string($_GET["subop"]);
664 $view_mode = db_escape_string($_GET["view"]);
665 $limit = db_escape_string($_GET["limit"]);
666 $cat_view = db_escape_string($_GET["cat"]);
668 if (!$skip) $skip = 0;
670 if ($subop == "undefined") $subop = "";
673 <title>Tiny Tiny RSS : Feed $feed</title>
674 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
676 $user_theme = $_SESSION["theme"];
678 print "<link rel=\"stylesheet\" type=\"text/css\"
679 href=\"themes/$user_theme/theme.css\">";
682 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
683 print "<link rel=\"stylesheet\"
684 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
687 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
688 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
691 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
693 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
694 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
696 if (db_num_rows($result) == 1) {
697 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
699 $rtl_content = false;
703 $rtl_tag = "dir=\"RTL\"";
709 $rtl_content = false;
712 $script_dt_add = get_script_dt_add();
714 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
715 <script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
716 <script type=\"text/javascript\" src=\"viewfeed.js?$script_dt_add\"></script>
717 <!--[if gte IE 5.5000]>
718 <script type=\"text/javascript\" src=\"pngfix.js\"></script>
719 <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
721 </head><body $rtl_tag>
722 <script type=\"text/javascript\">
723 if (document.addEventListener) {
724 document.addEventListener(\"DOMContentLoaded\", init, null);
726 window.onload = init;
729 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
730 update_generic_feed($link, $feed, $cat_view);
733 if ($subop == "MarkAllRead") {
734 catchup_feed($link, $feed, $cat_view);
737 $search = db_escape_string($_GET["search"]);
738 $search_mode = db_escape_string($_GET["smode"]);
741 $search_query_part = "(upper(ttrss_entries.title) LIKE upper('%$search%')
742 OR ttrss_entries.content LIKE '%$search%') AND";
744 $search_query_part = "";
747 $view_query_part = "";
749 if ($view_mode == "Adaptive") {
751 $view_query_part = " ";
752 } else if ($feed != -1) {
753 $unread = getFeedUnread($link, $feed);
755 $view_query_part = " unread = true AND ";
760 if ($view_mode == "Starred") {
761 $view_query_part = " marked = true AND ";
764 if ($view_mode == "Unread") {
765 $view_query_part = " unread = true AND ";
768 if ($limit && $limit != "All") {
769 $limit_query_part = "LIMIT " . $limit;
772 $vfeed_query_part = "";
774 // override query strategy and enable feed display when searching globally
775 if ($search && $search_mode == "All feeds") {
776 $query_strategy_part = "ttrss_entries.id > 0";
777 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
778 } else if (preg_match("/^-?[0-9][0-9]*$/", $feed) == false) {
779 $query_strategy_part = "ttrss_entries.id > 0";
780 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
781 id = feed_id) as feed_title,";
782 } else if ($feed >= 0 && $search && $search_mode == "This category") {
784 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
786 $tmp_result = db_query($link, "SELECT id
787 FROM ttrss_feeds WHERE cat_id =
788 (SELECT cat_id FROM ttrss_feeds WHERE id = '$feed') AND id != '$feed'");
790 $cat_siblings = array();
792 if (db_num_rows($tmp_result) > 0) {
793 while ($p = db_fetch_assoc($tmp_result)) {
794 array_push($cat_siblings, "feed_id = " . $p["id"]);
797 $query_strategy_part = sprintf("(feed_id = %d OR %s)",
798 $feed, implode(" OR ", $cat_siblings));
801 $query_strategy_part = "ttrss_entries.id > 0";
804 } else if ($feed >= 0) {
809 $query_strategy_part = "cat_id = '$feed'";
811 $query_strategy_part = "cat_id IS NULL";
814 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
817 $tmp_result = db_query($link, "SELECT id
818 FROM ttrss_feeds WHERE parent_feed = '$feed'
819 ORDER BY cat_id,title");
821 $parent_ids = array();
823 if (db_num_rows($tmp_result) > 0) {
824 while ($p = db_fetch_assoc($tmp_result)) {
825 array_push($parent_ids, "feed_id = " . $p["id"]);
828 $query_strategy_part = sprintf("(feed_id = %d OR %s)",
829 $feed, implode(" OR ", $parent_ids));
831 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
833 $query_strategy_part = "feed_id = '$feed'";
836 } else if ($feed == -1) { // starred virtual feed
837 $query_strategy_part = "marked = true";
838 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
839 } else if ($feed <= -10) { // labels
840 $label_id = -$feed - 11;
842 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
843 WHERE id = '$label_id'");
845 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
847 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
849 $query_strategy_part = "id > 0"; // dumb
852 $order_by = "updated DESC";
854 // if ($feed < -10) {
855 // $order_by = "feed_id,updated DESC";
860 if ($search && $search_mode == "All feeds") {
861 $feed_title = "Global search results ($search)";
862 } else if ($search && preg_match('/^-?[0-9][0-9]*$/', $feed) == false) {
863 $feed_title = "Feed search results ($search, $feed)";
864 } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) == false) {
866 } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) != false && $feed >= 0) {
871 $result = db_query($link, "SELECT title FROM ttrss_feed_categories
872 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
873 $feed_title = db_fetch_result($result, 0, "title");
875 $feed_title = "Uncategorized";
879 $result = db_query($link, "SELECT title,site_url,last_error FROM ttrss_feeds
880 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
882 $feed_title = db_fetch_result($result, 0, "title");
883 $feed_site_url = db_fetch_result($result, 0, "site_url");
884 $last_error = db_fetch_result($result, 0, "last_error");
888 } else if ($feed == -1) {
889 $feed_title = "Starred articles";
890 } else if ($feed < -10) {
891 $label_id = -$feed - 11;
892 $result = db_query($link, "SELECT description FROM ttrss_labels
893 WHERE id = '$label_id'");
894 $feed_title = db_fetch_result($result, 0, "description");
899 $feed_title = db_unescape_string($feed_title);
901 if ($feed < -10) error_reporting (0);
903 print "<div id=\"headlinesContainer\">";
905 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
908 $feed_kind = "Feeds";
910 $feed_kind = "Labels";
913 // if (!$vfeed_query_part) {
914 $content_query_part = "content as content_preview,";
916 // $content_query_part = "";
920 ttrss_entries.id,ttrss_entries.title,
921 SUBSTRING(updated,1,16) as updated,
922 unread,feed_id,marked,link,last_read,
923 SUBSTRING(last_read,1,19) as last_read_noms,
926 SUBSTRING(updated,1,19) as updated_noms
928 ttrss_entries,ttrss_user_entries,ttrss_feeds
930 ttrss_user_entries.feed_id = ttrss_feeds.id AND
931 ttrss_user_entries.ref_id = ttrss_entries.id AND
932 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
935 $query_strategy_part ORDER BY $order_by
938 $result = db_query($link, $query);
940 if ($_GET["debug"]) print $query;
947 $result = db_query($link, "SELECT
948 ttrss_entries.id as id,title,
949 SUBSTRING(updated,1,16) as updated,
951 marked,link,last_read,
952 SUBSTRING(last_read,1,19) as last_read_noms,
955 SUBSTRING(updated,1,19) as updated_noms
957 ttrss_entries,ttrss_user_entries,ttrss_tags
959 ref_id = ttrss_entries.id AND
960 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
961 post_int_id = int_id AND tag_name = '$feed' AND
964 $query_strategy_part ORDER BY $order_by
969 print "<div align='center'>
970 Could not display feed (query failed). Please check label match syntax or local configuration.</div>";
974 function print_headline_subtoolbar($link, $feed_site_url, $feed_title,
975 $bottom = false, $rtl_content = false) {
978 $class = "headlinesSubToolbar";
979 $tid = "headlineActionsTop";
981 $class = "invisible";
982 $tid = "headlineActionsBottom";
985 print "<table class=\"$class\" id=\"$tid\"
986 width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
994 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
996 print "<td class=\"headlineActions$rtl_cpart\">
998 <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, '', true)\">All</a>,
999 <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true)\">Unread</a>,
1000 <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false)\">None</a>
1002 Toggle: <a href='#' onclick=\"javascript:selectionToggleUnread()\">Unread</a>,
1003 <a href='#' onclick=\"javascript:selectionToggleMarked()\">Starred</a>";
1008 print "<td class=\"headlineActions$rtl_cpart\">
1010 <a href=\"#\" onclick=\"javascript:cdmSelectArticles('all')\">All</a>,
1011 <a href=\"#\" onclick=\"javascript:cdmSelectArticles('unread')\">Unread</a>,
1012 <a href=\"#\" onclick=\"javascript:cdmSelectArticles('none')\">None</a>
1014 Toggle: <a href=\"#\" onclick=\"javascript:selectionToggleUnread(true)\">Unread</a>,
1015 <a href=\"#\" onclick=\"javascript:selectionToggleMarked(true)\">Starred</a>";
1021 print "<td class=\"headlineTitle$rtl_cpart\">";
1023 if ($feed_site_url) {
1025 $target = "target=\"_blank\"";
1027 print "<a $target href=\"$feed_site_url\">$feed_title</a>";
1033 print "</tr></table>";
1037 if (db_num_rows($result) > 0) {
1039 print_headline_subtoolbar($link, $feed_site_url, $feed_title, false,
1042 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1043 print "<table class=\"headlinesList\" id=\"headlinesList\"
1044 cellspacing=\"0\" width=\"100%\">";
1049 error_reporting (DEFAULT_ERROR_LEVEL
);
1053 while ($line = db_fetch_assoc($result)) {
1055 $class = ($lnum %
2) ?
"even" : "odd";
1058 $feed_id = $line["feed_id"];
1060 if ($line["last_read"] == "" &&
1061 ($line["unread"] != "t" && $line["unread"] != "1")) {
1063 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
1066 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
1070 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
1078 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
1079 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
1080 alt=\"Reset mark\" onclick='javascript:toggleMark($id)'>";
1082 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
1083 alt=\"Set mark\" onclick='javascript:toggleMark($id)'>";
1086 $content_link = "<a href=\"javascript:view($id,$feed_id);\">" .
1087 $line["title"] . "</a>";
1089 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1090 $updated_fmt = smart_date_time(strtotime($line["updated"]));
1092 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1093 $updated_fmt = date($short_date, strtotime($line["updated"]));
1096 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
1097 $content_preview = truncate_string(strip_tags($line["content_preview"]),
1101 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1103 print "<tr class='$class' id='RROW-$id'>";
1105 print "<td class='hlUpdatePic'>$update_pic</td>";
1107 print "<td class='hlSelectRow'>
1108 <input type=\"checkbox\" onclick=\"toggleSelectRow(this)\"
1109 class=\"feedCheckBox\" id=\"RCHK-$id\">
1112 print "<td class='hlMarkedPic'>$marked_pic</td>";
1114 if ($line["feed_title"]) {
1115 print "<td class='hlContent'>$content_link</td>";
1116 print "<td class='hlFeed'>
1117 <a href='javascript:viewfeed($feed_id)'>".
1118 $line["feed_title"]."</a> </td>";
1120 print "<td class='hlContent' valign='middle'>";
1122 print "<a href=\"javascript:view($id,$feed_id);\">" .
1125 if (get_pref($link, 'SHOW_CONTENT_PREVIEW') && !$rtl_tag) {
1126 if ($content_preview) {
1127 print "<span class=\"contentPreview\"> - $content_preview</span>";
1135 print "<td class=\"hlUpdated\"><nobr>$updated_fmt </nobr></td>";
1142 $add_class = "Unread";
1147 print "<div class=\"cdmArticle$add_class\" id=\"RROW-$id\">";
1149 print "<div class=\"cdmHeader\">";
1151 print "<div style=\"float : right\">$updated_fmt,
1152 <a class=\"cdmToggleLink\"
1153 href=\"javascript:toggleUnread($id)\">Toggle unread</a>
1156 print "<a class=\"title\"
1157 onclick=\"javascript:toggleUnread($id, 0)\"
1158 target=\"new\" href=\"".$line["link"]."\">".$line["title"]."</a>";
1160 if ($line["feed_title"]) {
1161 print " (<a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>)";
1166 print "<div class=\"cdmContent\">" . $line["content_preview"] . "</div>";
1168 print "<div style=\"float : right\">$marked_pic</div>
1169 <div lass=\"cdmFooter\">
1170 <input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
1171 'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\"></div>";
1173 # print "<div align=\"center\"><a class=\"cdmToggleLink\"
1174 # href=\"javascript:toggleUnread($id)\">
1175 # Toggle unread</a></div>";
1184 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1188 print_headline_subtoolbar($link,
1189 "javascript:catchupPage()", "Mark page as read", true, $rtl_content);
1193 print "<div width='100%' align='center'>No articles found.</div>";
1198 print "<script type=\"text/javascript\">
1199 document.onkeydown = hotkey_handler;
1200 // if (parent.daemon_enabled) parent.updateTitle('$feed_title');
1201 update_all_counters('$feed');
1205 <script type="text/javascript">
1207 function statechange() {
1208 if (document.readyState == "interactive") init();
1211 if (document.readyState) {
1212 if (document.readyState == "interactive" || document.readyState == "complete") {
1215 document.onreadystatechange = statechange;
1220 print "</body></html>";
1223 if ($op == "pref-rpc") {
1225 $subop = $_GET["subop"];
1227 if ($subop == "unread") {
1228 $ids = split(",", db_escape_string($_GET["ids"]));
1229 foreach ($ids as $id) {
1230 db_query($link, "UPDATE ttrss_user_entries SET unread = true
1231 WHERE feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
1234 print "Marked selected feeds as unread.";
1237 if ($subop == "read") {
1238 $ids = split(",", db_escape_string($_GET["ids"]));
1239 foreach ($ids as $id) {
1240 db_query($link, "UPDATE ttrss_user_entries
1241 SET unread = false,last_read = NOW() WHERE
1242 feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
1245 print "Marked selected feeds as read.";
1251 if ($op == "pref-feeds") {
1253 $subop = $_REQUEST["subop"];
1254 $quiet = $_REQUEST["quiet"];
1256 if ($subop == "massSubscribe") {
1257 $ids = split(",", db_escape_string($_GET["ids"]));
1259 $subscribed = array();
1261 foreach ($ids as $id) {
1262 $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds
1265 $feed_url = db_fetch_result($result, 0, "feed_url");
1266 $title = db_fetch_result($result, 0, "title");
1268 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
1269 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
1271 if (db_num_rows($result) == 0) {
1272 $result = db_query($link,
1273 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
1274 VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)");
1276 array_push($subscribed, $title);
1280 if (count($subscribed) > 0) {
1281 print "<div class=\"notice\">";
1282 print "<b>Subscribed to feeds:</b>";
1283 print "<ul class=\"nomarks\">";
1284 foreach ($subscribed as $title) {
1285 print "<li>$title</li>";
1292 if ($subop == "browse") {
1294 if (!ENABLE_FEED_BROWSER
) {
1295 print "Feed browser is administratively disabled.";
1299 print "<div class=\"infoBoxContents\">";
1301 print "<h1>Feed browser</h1>";
1303 print "<p>Showing top 50 registered feeds, sorted by popularity:</p>";
1305 $result = db_query($link, "SELECT feed_url,count(id) AS subscribers
1307 WHERE auth_login = '' AND auth_pass = '' AND private = false
1308 GROUP BY feed_url ORDER BY subscribers DESC LIMIT 50");
1310 print "<ul class='browseFeedList' id='browseFeedList'>";
1314 while ($line = db_fetch_assoc($result)) {
1315 $feed_url = $line["feed_url"];
1316 $subscribers = $line["subscribers"];
1318 $sub_result = db_query($link, "SELECT id
1319 FROM ttrss_feeds WHERE feed_url = '$feed_url' AND owner_uid =" .
1322 if (db_num_rows($sub_result) > 0) {
1323 continue; // already subscribed
1326 $det_result = db_query($link, "SELECT site_url,title,id
1327 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
1329 $details = db_fetch_assoc($det_result);
1331 $icon_file = ICONS_DIR
. "/" . $details["id"] . ".ico";
1333 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1334 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL
.
1335 "/".$details["id"].".ico\">";
1337 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1340 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
1341 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
1343 $class = ($feedctr %
2) ?
"even" : "odd";
1345 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
1346 "$feed_icon " . db_unescape_string($details["title"]) .
1347 " <span class='subscribers'>($subscribers)</span></li>";
1352 if ($feedctr == 0) {
1353 print "<li>No feeds found to subscribe.</li>";
1358 print "<div align='center'>
1359 <input type=\"submit\" class=\"button\"
1360 onclick=\"feedBrowserSubscribe()\" value=\"Subscribe\">
1361 <input type='submit' class='button'
1362 onclick=\"closeInfoBox()\" value=\"Cancel\"></div>";
1368 if ($subop == "editfeed") {
1369 $feed_id = db_escape_string($_GET["id"]);
1371 $result = db_query($link,
1372 "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
1373 owner_uid = " . $_SESSION["uid"]);
1375 $title = htmlspecialchars(db_unescape_string(db_fetch_result($result,
1378 print "<div class=\"infoBoxContents\">";
1380 $icon_file = ICONS_DIR
. "/$feed_id.ico";
1382 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1383 $feed_icon = "<img width=\"16\" height=\"16\"
1384 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
1389 print "<h1>$feed_icon $title</h1>";
1391 print "<table width='100%'>";
1395 print "<tr class='$row_class'><td>Title:</td>";
1396 print "<td><input id=\"iedit_title\" value=\"$title\"></td></tr>";
1398 $feed_url = db_fetch_result($result, 0, "feed_url");
1399 $feed_url = htmlspecialchars(db_unescape_string(db_fetch_result($result,
1401 $row_class = toggleEvenOdd($row_class);
1403 print "<tr class='$row_class'><td>Feed URL:</td>";
1404 print "<td><input id=\"iedit_link\" value=\"$feed_url\"></td></tr>";
1406 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1408 $cat_id = db_fetch_result($result, 0, "cat_id");
1410 $row_class = toggleEvenOdd($row_class);
1412 print "<tr class='$row_class'><td>Category:</td>";
1414 print "<select id=\"iedit_fcat\">";
1415 print "<option id=\"0\">Uncategorized</option>";
1417 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feed_categories
1418 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1420 if (db_num_rows($tmp_result) > 0) {
1421 print "<option disabled>--------</option>";
1424 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1425 if ($tmp_line["id"] == $cat_id) {
1426 $is_selected = "selected";
1430 printf("<option $is_selected id='%d'>%s</option>",
1431 $tmp_line["id"], $tmp_line["title"]);
1434 print "</select></td>";
1439 $update_interval = db_fetch_result($result, 0, "update_interval");
1440 $row_class = toggleEvenOdd($row_class);
1442 print "<tr class='$row_class'><td>Update Interval:</td>";
1443 // print "<td><input id=\"iedit_updintl\"
1444 // value=\"$update_interval\"></td></tr>";
1448 print "<select id=\"iedit_updintl\">";
1450 foreach (array_keys($update_intervals) as $i) {
1452 if ($i == $update_interval) {
1453 $selected = "selected";
1457 print "<option $selected id=\"$i\">" . $update_intervals[$i] . "</option>";
1464 $row_class = toggleEvenOdd($row_class);
1465 print "<tr class='$row_class'><td>Link to:</td>";
1467 $tmp_result = db_query($link, "SELECT COUNT(id) AS count
1468 FROM ttrss_feeds WHERE parent_feed = '$feed_id'");
1470 $linked_count = db_fetch_result($tmp_result, 0, "count");
1472 $parent_feed = db_fetch_result($result, 0, "parent_feed");
1474 if ($linked_count > 0) {
1475 $disabled = "disabled";
1478 print "<select $disabled id=\"iedit_parent_feed\">";
1480 print "<option id=\"0\">Not linked</option>";
1482 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1484 $cat_qpart = "AND cat_id = '$cat_id'";
1486 $cat_qpart = "AND cat_id IS NULL";
1490 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
1491 WHERE id != '$feed_id' AND owner_uid = ".$_SESSION["uid"]."
1492 $cat_qpart ORDER BY title");
1494 if (db_num_rows($tmp_result) > 0) {
1495 print "<option disabled>--------</option>";
1498 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1499 if ($tmp_line["id"] == $parent_feed) {
1500 $is_selected = "selected";
1504 printf("<option $is_selected id='%d'>%s</option>",
1505 $tmp_line["id"], $tmp_line["title"]);
1508 print "</select></td>";
1511 $purge_interval = db_fetch_result($result, 0, "purge_interval");
1512 $row_class = toggleEvenOdd($row_class);
1514 print "<tr class='$row_class'><td>Purge Days:</td>";
1515 // print "<td><input id=\"iedit_purgintl\"
1516 // value=\"$purge_interval\"></td></tr>";
1520 print "<select id=\"iedit_purgintl\">";
1522 foreach (array_keys($purge_intervals) as $i) {
1524 if ($i == $purge_interval) {
1525 $selected = "selected";
1529 print "<option $selected id=\"$i\">" . $purge_intervals[$i] . "</option>";
1536 // print "<tr><td colspan=\"2\"><b>Authentication</b></td></tr>";
1538 $row_class = toggleEvenOdd($row_class);
1539 $auth_login = db_fetch_result($result, 0, "auth_login");
1541 print "<tr class='$row_class'><td>Login:</td>";
1542 print "<td><input id=\"iedit_login\"
1543 value=\"$auth_login\"></td></tr>";
1545 $row_class = toggleEvenOdd($row_class);
1546 $auth_pass = db_fetch_result($result, 0, "auth_pass");
1548 print "<tr class='$row_class'><td>Password:</td>";
1549 print "<td><input type=\"password\" id=\"iedit_pass\"
1550 value=\"$auth_pass\"></td></tr>";
1552 $row_class = toggleEvenOdd($row_class);
1553 $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
1556 $checked = "checked";
1561 print "<tr class='$row_class'><td valign='top'>Options:</td>";
1562 print "<td><input type=\"checkbox\" id=\"iedit_private\"
1563 $checked><label for=\"iedit_private\">Hide from feed browser</label>";
1565 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
1568 $checked = "checked";
1573 print "<br><input type=\"checkbox\" id=\"iedit_rtl\"
1574 $checked><label for=\"iedit_rtl\">Right-to-left content</label>";
1581 print "<div align='center'>
1582 <input type=\"submit\" class=\"button\"
1583 onclick=\"feedEditSave()\" value=\"Save\">
1584 <input type='submit' class='button'
1585 onclick=\"feedEditCancel()\" value=\"Cancel\"></div>";
1589 if ($subop == "editSave") {
1590 $feed_title = db_escape_string($_POST["t"]);
1591 $feed_link = db_escape_string($_POST["l"]);
1592 $upd_intl = db_escape_string($_POST["ui"]);
1593 $purge_intl = db_escape_string($_POST["pi"]);
1594 $feed_id = db_escape_string($_POST["id"]);
1595 $cat_id = db_escape_string($_POST["catid"]);
1596 $auth_login = db_escape_string($_POST["login"]);
1597 $auth_pass = db_escape_string($_POST["pass"]);
1598 $parent_feed = db_escape_string($_POST["pfeed"]);
1599 $private = db_escape_string($_POST["is_pvt"]);
1600 $rtl_content = db_escape_string($_POST["is_rtl"]);
1602 if (strtoupper($upd_intl) == "DEFAULT")
1605 if (strtoupper($upd_intl) == "DISABLED")
1608 if (strtoupper($purge_intl) == "DEFAULT")
1611 if (strtoupper($purge_intl) == "DISABLED")
1615 $category_qpart = "cat_id = '$cat_id'";
1617 $category_qpart = 'cat_id = NULL';
1620 if ($parent_feed != 0) {
1621 $parent_qpart = "parent_feed = '$parent_feed'";
1623 $parent_qpart = 'parent_feed = NULL';
1626 $result = db_query($link, "UPDATE ttrss_feeds SET
1629 title = '$feed_title', feed_url = '$feed_link',
1630 update_interval = '$upd_intl',
1631 purge_interval = '$purge_intl',
1632 auth_login = '$auth_login',
1633 auth_pass = '$auth_pass',
1635 rtl_content = $rtl_content
1636 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
1639 if ($subop == "saveCat") {
1640 $cat_title = db_escape_string($_GET["title"]);
1641 $cat_id = db_escape_string($_GET["id"]);
1643 $result = db_query($link, "UPDATE ttrss_feed_categories SET
1644 title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
1648 if ($subop == "remove") {
1650 if (!WEB_DEMO_MODE
) {
1652 $ids = split(",", db_escape_string($_GET["ids"]));
1654 foreach ($ids as $id) {
1655 db_query($link, "DELETE FROM ttrss_feeds
1656 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1658 $icons_dir = ICONS_DIR
;
1660 if (file_exists($icons_dir . "/$id.ico")) {
1661 unlink($icons_dir . "/$id.ico");
1667 if ($subop == "add") {
1669 if (!WEB_DEMO_MODE
) {
1671 $feed_link = db_escape_string(trim($_GET["link"]));
1672 $cat_id = db_escape_string($_GET["cid"]);
1674 if (subscribe_to_feed($link, $feed_link, $cat_id)) {
1675 print "Added feed.";
1677 print "<div class=\"warning\">
1678 Feed <b>$feed_link</b> already exists in the database.
1684 if ($subop == "addCat") {
1686 if (!WEB_DEMO_MODE
) {
1688 $feed_cat = db_escape_string(trim($_GET["cat"]));
1690 $result = db_query($link,
1691 "SELECT id FROM ttrss_feed_categories
1692 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
1694 if (db_num_rows($result) == 0) {
1696 $result = db_query($link,
1697 "INSERT INTO ttrss_feed_categories (owner_uid,title)
1698 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
1702 print "<div class=\"warning\">
1703 Category <b>$feed_cat</b> already exists in the database.
1711 if ($subop == "removeCats") {
1713 if (!WEB_DEMO_MODE
) {
1715 $ids = split(",", db_escape_string($_GET["ids"]));
1717 foreach ($ids as $id) {
1719 db_query($link, "BEGIN");
1721 $result = db_query($link,
1722 "SELECT count(id) as num_feeds FROM ttrss_feeds
1723 WHERE cat_id = '$id'");
1725 $num_feeds = db_fetch_result($result, 0, "num_feeds");
1727 if ($num_feeds == 0) {
1728 db_query($link, "DELETE FROM ttrss_feed_categories
1729 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1732 print "<div class=\"warning\">
1733 Unable to delete non empty feed categories.</div>";
1737 db_query($link, "COMMIT");
1742 if ($subop == "categorize") {
1744 if (!WEB_DEMO_MODE
) {
1746 $ids = split(",", db_escape_string($_GET["ids"]));
1748 $cat_id = db_escape_string($_GET["cat_id"]);
1751 $cat_id_qpart = 'NULL';
1753 $cat_id_qpart = "'$cat_id'";
1756 db_query($link, "BEGIN");
1758 foreach ($ids as $id) {
1760 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
1761 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1764 db_query($link, "COMMIT");
1771 // print "<h3>Edit Feeds</h3>";
1773 $result = db_query($link, "SELECT id,title,feed_url,last_error
1774 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1776 if (db_num_rows($result) > 0) {
1778 print "<div class=\"warning\">";
1780 // print"<img class=\"closeButton\"
1781 // onclick=\"javascript:hideParentElement(this);\" src=\"images/close.png\">";
1783 print "<a href=\"javascript:showBlockElement('feedUpdateErrors')\">
1784 <b>Feeds with update errors</b> (click to expand)</a>";
1786 print "<ul id=\"feedUpdateErrors\" class=\"nomarks\">";
1788 while ($line = db_fetch_assoc($result)) {
1789 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
1790 $line["last_error"];
1798 $feed_search = db_escape_string($_GET["search"]);
1800 if (array_key_exists("search", $_GET)) {
1801 $_SESSION["prefs_feed_search"] = $feed_search;
1803 $feed_search = $_SESSION["prefs_feed_search"];
1806 print "<table width='100%' class=\"prefGenericAddBox\"
1807 cellspacing='0' cellpadding='0'><tr>
1809 <input id=\"fadd_link\"
1810 onchange=\"javascript:addFeed()\"
1812 <input type=\"submit\" class=\"button\"
1813 onclick=\"javascript:addFeed()\" value=\"Add feed\">";
1815 if (ENABLE_FEED_BROWSER
&& !SINGLE_USER_MODE
) {
1816 print " (<a href='javascript:browseFeeds()'>Top 50</a>)";
1819 print "</td><td align='right'>
1820 <input id=\"feed_search\" size=\"20\"
1821 onchange=\"javascript:updateFeedList()\"
1822 value=\"$feed_search\">
1823 <input type=\"submit\" class=\"button\"
1824 onclick=\"javascript:updateFeedList()\" value=\"Search\">
1828 $feeds_sort = db_escape_string($_GET["sort"]);
1830 if (!$feeds_sort ||
$feeds_sort == "undefined") {
1831 $feeds_sort = $_SESSION["pref_sort_feeds"];
1832 if (!$feeds_sort) $feeds_sort = "title";
1835 $_SESSION["pref_sort_feeds"] = $feeds_sort;
1838 $search_qpart = "(UPPER(F1.title) LIKE UPPER('%$feed_search%') OR
1839 UPPER(F1.feed_url) LIKE UPPER('%$feed_search%')) AND";
1844 $result = db_query($link, "SELECT
1848 substring(F1.last_updated,1,16) AS last_updated,
1853 F2.title AS parent_title,
1854 C1.title AS category
1857 LEFT JOIN ttrss_feeds AS F2
1858 ON (F1.parent_feed = F2.id)
1859 LEFT JOIN ttrss_feed_categories AS C1
1860 ON (F1.cat_id = C1.id)
1862 $search_qpart F1.owner_uid = '".$_SESSION["uid"]."'
1863 ORDER by category,$feeds_sort,title");
1865 if (db_num_rows($result) != 0) {
1867 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1869 print "<p><table width=\"100%\" cellspacing=\"0\"
1870 class=\"prefFeedList\" id=\"prefFeedList\">";
1871 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1873 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
1874 'FEEDR-', 'FRCHK-', true)\">All</a>,
1875 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
1876 'FEEDR-', 'FRCHK-', false)\">None</a>
1879 if (!get_pref($link, 'ENABLE_FEED_CATS')) {
1880 print "<tr class=\"title\">
1881 <td width='5%' align='center'> </td>
1882 <td width='40%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
1883 <td width='45%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
1884 <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
1891 while ($line = db_fetch_assoc($result)) {
1893 $feed_id = $line["id"];
1894 $cat_id = $line["cat_id"];
1896 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1897 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
1898 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
1900 if (!$edit_cat) $edit_cat = "Uncategorized";
1902 $last_updated = $line["last_updated"];
1904 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1905 $last_updated = smart_date_time(strtotime($last_updated));
1907 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1908 $last_updated = date($short_date, strtotime($last_updated));
1911 if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
1914 print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>";
1916 print "<tr class=\"title\">
1917 <td width='5%' align='center'> </td>
1918 <td width='40%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
1919 <td width='45%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
1920 <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
1922 $cur_cat_id = $cat_id;
1925 $class = ($lnum %
2) ?
"even" : "odd";
1926 $this_row_id = "id=\"FEEDR-$feed_id\"";
1928 print "<tr class=\"$class\" $this_row_id>";
1930 $icon_file = ICONS_DIR
. "/$feed_id.ico";
1932 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1933 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL
. "/$feed_id.ico\">";
1935 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1937 // print "<td class='feedIcon'>$feed_icon</td>";
1939 print "<td class='feedSelect'><input onclick='toggleSelectRow(this);'
1940 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
1942 $edit_title = truncate_string($edit_title, 40);
1943 $edit_link = truncate_string($edit_link, 60);
1945 $parent_title = $line["parent_title"];
1946 if ($parent_title) {
1947 $parent_title = "<span class='groupPrompt'>(linked to
1948 $parent_title)</span>";
1951 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1952 "$feed_icon $edit_title $parent_title" . "</a></td>";
1954 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1955 $edit_link . "</a></td>";
1957 /* if (get_pref($link, 'ENABLE_FEED_CATS')) {
1958 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1959 $edit_cat . "</a></td>";
1962 /* print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1963 $update_intervals[$line["update_interval"]] . "</a></td>";
1965 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1966 $purge_intervals[$line["purge_interval"]] . "</a></td>"; */
1968 print "<td align='right'><a href=\"javascript:editFeed($feed_id);\">" .
1969 "$last_updated</a></td>";
1980 if ($subop == "edit") {
1981 print "Edit feed:
1982 <input type=\"submit\" class=\"button\"
1983 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
1984 <input type=\"submit\" class=\"button\"
1985 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1990 <input type=\"submit\" class=\"button\"
1991 onclick=\"javascript:selectedFeedDetails()\" value=\"Details\">
1992 <input type=\"submit\" class=\"button\"
1993 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
1994 <input type=\"submit\" class=\"button\"
1995 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
1997 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1999 print " ";
2001 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2002 WHERE owner_uid = ".$_SESSION["uid"]."
2005 print "<select id=\"sfeed_set_fcat\">";
2006 print "<option id=\"0\">Uncategorized</option>";
2008 if (db_num_rows($result) != 0) {
2010 print "<option disabled>--------</option>";
2012 while ($line = db_fetch_assoc($result)) {
2013 printf("<option id='%d'>%s</option>",
2014 $line["id"], $line["title"]);
2020 print " <input type=\"submit\" class=\"button\"
2021 onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Set category\">";
2026 All feeds: <input type=\"submit\"
2027 class=\"button\" onclick=\"gotoExportOpml()\"
2028 value=\"Export OPML\">";
2032 print "<p>No feeds defined.</p>";
2036 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2038 print "<h3>Edit Categories</h3>";
2040 // print "<h3>Categories</h3>";
2042 print "<div class=\"prefGenericAddBox\">
2043 <input id=\"fadd_cat\"
2044 onchange=\"javascript:addFeedCat()\"
2047 type=\"submit\" class=\"button\"
2048 onclick=\"javascript:addFeedCat()\" value=\"Add category\"></div>";
2050 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2051 WHERE owner_uid = ".$_SESSION["uid"]."
2054 if (db_num_rows($result) != 0) {
2056 print "<p><table width=\"100%\" class=\"prefFeedCatList\"
2057 cellspacing=\"0\" id=\"prefFeedCatList\">";
2059 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2061 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
2062 'FCATR-', 'FCCHK-', true)\">All</a>,
2063 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
2064 'FCATR-', 'FCCHK-', false)\">None</a>
2067 print "<tr class=\"title\">
2068 <td width=\"5%\"> </td><td width=\"80%\">Title</td>
2073 while ($line = db_fetch_assoc($result)) {
2075 $class = ($lnum %
2) ?
"even" : "odd";
2077 $cat_id = $line["id"];
2079 $edit_cat_id = $_GET["id"];
2081 if ($subop == "editCat" && $cat_id != $edit_cat_id) {
2085 $this_row_id = "id=\"FCATR-$cat_id\"";
2088 print "<tr class=\"$class\" $this_row_id>";
2090 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
2092 if (!$edit_cat_id ||
$subop != "editCat") {
2094 print "<td align='center'><input onclick='toggleSelectRow(this);'
2095 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
2097 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
2098 $edit_title . "</a></td>";
2100 } else if ($cat_id != $edit_cat_id) {
2102 print "<td><input disabled=\"true\" type=\"checkbox\"
2103 id=\"FRCHK-".$line["id"]."\"></td>";
2105 print "<td>$edit_title</td>";
2109 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2111 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
2124 if ($subop == "editCat") {
2125 print "Edit category:
2126 <input type=\"submit\" class=\"button\"
2127 onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\">
2128 <input type=\"submit\" class=\"button\"
2129 onclick=\"javascript:feedCatEditSave()\" value=\"Save\">";
2134 <input type=\"submit\" class=\"button\"
2135 onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\">
2136 <input type=\"submit\" class=\"button\"
2137 onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">";
2142 print "<p>No feed categories defined.</p>";
2146 print "<h3>Import OPML</h3>
2147 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
2148 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">
2149 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
2150 type=\"submit\" value=\"Import\">
2155 if ($op == "pref-filters") {
2157 $subop = $_GET["subop"];
2158 $quiet = $_GET["quiet"];
2160 if ($subop == "editSave") {
2162 $regexp = db_escape_string($_GET["r"]);
2163 $match = db_escape_string($_GET["m"]);
2164 $filter_id = db_escape_string($_GET["id"]);
2165 $feed_id = db_escape_string($_GET["fid"]);
2166 $action_id = db_escape_string($_GET["aid"]);
2171 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2174 $result = db_query($link, "UPDATE ttrss_filters SET
2175 reg_exp = '$regexp',
2177 action_id = '$action_id',
2178 filter_type = (SELECT id FROM ttrss_filter_types WHERE
2179 description = '$match')
2180 WHERE id = '$filter_id'");
2183 if ($subop == "remove") {
2185 if (!WEB_DEMO_MODE
) {
2187 $ids = split(",", db_escape_string($_GET["ids"]));
2189 foreach ($ids as $id) {
2190 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
2196 if ($subop == "add") {
2198 if (!WEB_DEMO_MODE
) {
2200 $regexp = db_escape_string(trim($_GET["regexp"]));
2201 $match = db_escape_string(trim($_GET["match"]));
2202 $feed_id = db_escape_string($_GET["fid"]);
2203 $action_id = db_escape_string($_GET["aid"]);
2208 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2211 $result = db_query($link,
2212 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
2215 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
2216 description = '$match'),'".$_SESSION["uid"]."',
2217 $feed_id, '$action_id')");
2223 $result = db_query($link, "SELECT description
2224 FROM ttrss_filter_types ORDER BY description");
2226 $filter_types = array();
2228 while ($line = db_fetch_assoc($result)) {
2229 array_push($filter_types, $line["description"]);
2232 print "<div class=\"prefGenericAddBox\">
2233 <input id=\"fadd_regexp\" size=\"40\"> ";
2235 print_select("fadd_match", "Title", $filter_types);
2237 print " <select id=\"fadd_feed\">";
2239 print "<option selected id=\"0\">All feeds</option>";
2241 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
2242 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2244 if (db_num_rows($result) > 0) {
2245 print "<option disabled>--------</option>";
2248 while ($line = db_fetch_assoc($result)) {
2249 printf("<option id='%d'>%s</option>", $line["id"],
2250 db_unescape_string($line["title"]));
2253 print "</select> ";
2255 print " Action: ";
2257 print "<select id=\"fadd_action\">";
2259 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2262 while ($line = db_fetch_assoc($result)) {
2263 printf("<option id='%d'>%s</option>", $line["id"], $line["description"]);
2266 print "</select> ";
2268 /* print "<input type=\"submit\"
2269 class=\"button\" onclick=\"javascript:testFilter()\"
2270 value=\"Test filter\"> "; */
2272 print "<input type=\"submit\"
2273 class=\"button\" onclick=\"javascript:addFilter()\"
2274 value=\"Add filter\">";
2278 $result = db_query($link, "SELECT
2279 ttrss_filters.id AS id,reg_exp,
2280 ttrss_filter_types.name AS filter_type_name,
2281 ttrss_filter_types.description AS filter_type_descr,
2283 ttrss_filter_actions.description AS action_description,
2284 ttrss_feeds.title AS feed_title
2286 ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN
2287 ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id)
2289 filter_type = ttrss_filter_types.id AND
2290 ttrss_filter_actions.id = action_id AND
2291 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
2294 if (db_num_rows($result) != 0) {
2296 print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\"
2297 id=\"prefFilterList\">";
2299 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2301 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
2302 'FILRR-', 'FICHK-', true)\">All</a>,
2303 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
2304 'FILRR-', 'FICHK-', false)\">None</a>
2307 print "<tr class=\"title\">
2308 <td align='center' width=\"5%\"> </td>
2309 <td width=\"20%\">Filter expression</td>
2310 <td width=\"20%\">Feed</td>
2311 <td width=\"15%\">Match</td>
2312 <td width=\"15%\">Action</td>";
2316 while ($line = db_fetch_assoc($result)) {
2318 $class = ($lnum %
2) ?
"even" : "odd";
2320 $filter_id = $line["id"];
2321 $edit_filter_id = $_GET["id"];
2323 if ($subop == "edit" && $filter_id != $edit_filter_id) {
2327 $this_row_id = "id=\"FILRR-$filter_id\"";
2330 print "<tr class=\"$class\" $this_row_id>";
2332 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
2334 if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
2336 if (!$edit_filter_id ||
$subop != "edit") {
2338 print "<td align='center'><input onclick='toggleSelectRow(this);'
2339 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
2341 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2342 $line["reg_exp"] . "</td>";
2344 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2345 $line["feed_title"] . "</td>";
2347 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2348 $line["filter_type_descr"] . "</td>";
2350 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2351 $line["action_description"] . "</td>";
2353 } else if ($filter_id != $edit_filter_id) {
2355 if (!$line["description"]) $line["description"] = "[No description]";
2357 print "<td><input disabled=\"true\" type=\"checkbox\"
2358 id=\"FICHK-".$line["id"]."\"></td>";
2360 print "<td>".$line["reg_exp"]."</td>";
2361 print "<td>".$line["feed_title"]."</td>";
2362 print "<td>".$line["filter_type_descr"]."</td>";
2363 print "<td>".$line["action_description"]."</td>";
2367 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2369 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
2373 print "<select id=\"iedit_feed\">";
2374 print "<option id=\"0\">All feeds</option>";
2376 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
2377 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2379 if (db_num_rows($tmp_result) > 0) {
2380 print "<option disabled>--------</option>";
2383 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2384 if ($tmp_line["id"] == $line["feed_id"]) {
2385 $is_selected = "selected";
2389 printf("<option $is_selected id='%d'>%s</option>",
2390 $tmp_line["id"], db_unescape_string($tmp_line["title"]));
2393 print "</select></td>";
2396 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
2400 print "<select id=\"iedit_filter_action\">";
2402 $tmp_result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2403 ORDER BY description");
2405 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2406 if ($tmp_line["description"] == $line["action_description"]) {
2407 $is_selected = "selected";
2411 printf("<option $is_selected id='%d'>%s</option>",
2412 $tmp_line["id"], $tmp_line["description"]);
2415 print "</select></td>";
2426 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
2433 if ($subop == "edit") {
2435 <input type=\"submit\" class=\"button\"
2436 onclick=\"javascript:filterEditSave()\" value=\"Save\">
2437 <input type=\"submit\" class=\"button\"
2438 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">";
2444 <input type=\"submit\" class=\"button\"
2445 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
2446 <input type=\"submit\" class=\"button\"
2447 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
2452 print "<p>No filters defined.</p>";
2457 // We need to accept raw SQL data in label queries, so not everything is escaped
2458 // here, this is by design. If you don't like the whole idea, disable labels
2459 // altogether with GLOBAL_ENABLE_LABELS = false
2461 if ($op == "pref-labels") {
2463 if (!GLOBAL_ENABLE_LABELS
) {
2467 $subop = $_GET["subop"];
2469 if ($subop == "test") {
2471 $expr = $_GET["expr"];
2472 $descr = $_GET["descr"];
2474 print "<div class='infoBoxContents'>";
2476 print "<h1>Label «$descr»</h1>";
2478 // print "<p><b>Expression</b>: $expr</p>";
2480 $result = db_query($link,
2481 "SELECT count(id) AS num_matches
2482 FROM ttrss_entries,ttrss_user_entries
2484 ttrss_user_entries.ref_id = ttrss_entries.id AND
2485 owner_uid = " . $_SESSION["uid"]);
2487 $num_matches = db_fetch_result($result, 0, "num_matches");;
2489 if ($num_matches > 0) {
2491 print "<p>Query returned <b>$num_matches</b> matches, first 5 follow:</p>";
2493 $result = db_query($link,
2495 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
2496 FROM ttrss_entries,ttrss_user_entries
2498 ttrss_user_entries.ref_id = ttrss_entries.id
2499 AND owner_uid = " . $_SESSION["uid"] . "
2500 ORDER BY date_entered DESC LIMIT 5");
2502 print "<ul class=\"nomarks\">";
2503 while ($line = db_fetch_assoc($result)) {
2504 print "<li>".$line["title"].
2505 " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
2510 print "<p>Query didn't return any matches.</p>";
2515 print "<div align='center'>
2516 <input type='submit' class='button'
2517 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2521 if ($subop == "editSave") {
2523 $sql_exp = $_GET["s"];
2524 $descr = $_GET["d"];
2525 $label_id = db_escape_string($_GET["id"]);
2527 // print "$sql_exp : $descr : $label_id";
2529 $result = db_query($link, "UPDATE ttrss_labels SET
2530 sql_exp = '$sql_exp',
2531 description = '$descr'
2532 WHERE id = '$label_id'");
2535 if ($subop == "remove") {
2537 if (!WEB_DEMO_MODE
) {
2539 $ids = split(",", db_escape_string($_GET["ids"]));
2541 foreach ($ids as $id) {
2542 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
2548 if ($subop == "add") {
2550 if (!WEB_DEMO_MODE
) {
2552 // no escaping is done here on purpose
2553 $exp = trim($_GET["exp"]);
2555 $result = db_query($link,
2556 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
2557 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
2561 print "<div class=\"prefGenericAddBox\">
2562 <input size=\"40\" id=\"ladd_expr\"> ";
2564 print"<input type=\"submit\" class=\"button\"
2565 onclick=\"javascript:addLabel()\" value=\"Add label\"></div>";
2567 $result = db_query($link, "SELECT
2568 id,sql_exp,description
2572 owner_uid = ".$_SESSION["uid"]."
2573 ORDER by description");
2575 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2577 if (db_num_rows($result) != 0) {
2579 print "<p><table width=\"100%\" cellspacing=\"0\"
2580 class=\"prefLabelList\" id=\"prefLabelList\">";
2582 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2584 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2585 'LILRR-', 'LICHK-', true)\">All</a>,
2586 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2587 'LILRR-', 'LICHK-', false)\">None</a>
2590 print "<tr class=\"title\">
2591 <td align='center' width=\"5%\"> </td>
2592 <td width=\"40%\">SQL expression
2593 <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a>
2595 <td width=\"40%\">Caption</td></tr>";
2599 while ($line = db_fetch_assoc($result)) {
2601 $class = ($lnum %
2) ?
"even" : "odd";
2603 $label_id = $line["id"];
2604 $edit_label_id = $_GET["id"];
2606 if ($subop == "edit" && $label_id != $edit_label_id) {
2610 $this_row_id = "id=\"LILRR-$label_id\"";
2613 print "<tr class=\"$class\" $this_row_id>";
2615 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
2616 $line["description"] = htmlspecialchars($line["description"]);
2618 if (!$edit_label_id ||
$subop != "edit") {
2620 if (!$line["description"]) $line["description"] = "[No caption]";
2622 print "<td align='center'><input onclick='toggleSelectRow(this);'
2623 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
2625 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2626 $line["sql_exp"] . "</td>";
2628 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2629 $line["description"] . "</td>";
2631 } else if ($label_id != $edit_label_id) {
2633 if (!$line["description"]) $line["description"] = "[No description]";
2635 print "<td><input disabled=\"true\" type=\"checkbox\"
2636 id=\"LICHK-".$line["id"]."\"></td>";
2638 print "<td>".$line["sql_exp"]."</td>";
2639 print "<td>".$line["description"]."</td>";
2643 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2645 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
2648 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2660 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
2667 if ($subop == "edit") {
2669 <input type=\"submit\" class=\"button\"
2670 onclick=\"javascript:labelTest()\" value=\"Test\">
2671 <input type=\"submit\" class=\"button\"
2672 onclick=\"javascript:labelEditSave()\" value=\"Save\">
2673 <input type=\"submit\" class=\"button\"
2674 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">";
2680 <input type=\"submit\" class=\"button\"
2681 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
2682 <input type=\"submit\" class=\"button\"
2683 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
2686 print "<p>No labels defined.</p>";
2690 if ($op == "error") {
2691 print "<div width=\"100%\" align='center'>";
2692 $msg = $_GET["msg"];
2697 if ($op == "help") {
2698 if (!$_GET["noheaders"]) {
2700 <title>Tiny Tiny RSS : Help</title>
2701 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2702 <script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
2703 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2707 $tid = sprintf("%d", $_GET["tid"]);
2709 print "<div class='infoBoxContents'>";
2711 if (file_exists("help/$tid.php")) {
2712 include("help/$tid.php");
2714 print "<p>Help topic not found.</p>";
2719 print "<div align='center'>
2720 <input type='submit' class='button'
2721 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2723 if (!$_GET["noheaders"]) {
2724 print "</body></html>";
2731 $param = $_GET["param"];
2733 if ($id == "quickAddFeed") {
2736 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2739 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2740 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2741 WHERE owner_uid = ".$_SESSION["uid"]."
2744 print " <select id=\"qafCat\">";
2745 print "<option id=\"0\">Uncategorized</option>";
2747 if (db_num_rows($result) != 0) {
2749 print "<option disabled>--------</option>";
2751 while ($line = db_fetch_assoc($result)) {
2752 printf("<option id='%d'>%s</option>",
2753 $line["id"], $line["title"]);
2760 print " <input class=\"button\"
2761 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
2762 <input class=\"button\"
2763 type=\"submit\" onclick=\"javascript:closeDlg()\"
2767 if ($id == "quickDelFeed") {
2769 $param = db_escape_string($param);
2771 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
2775 $f_title = db_fetch_result($result, 0, "title");
2777 print "Remove current feed (<b>$f_title</b>)?
2778 <input class=\"button\"
2779 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
2780 <input class=\"button\"
2781 type=\"submit\" onclick=\"javascript:closeDlg()\"
2784 print "Error: Feed $param not found.
2785 <input class=\"button\"
2786 type=\"submit\" onclick=\"javascript:closeDlg()\"
2791 if ($id == "search") {
2793 $active_feed_id = db_escape_string($_GET["param"]);
2795 print "<input id=\"searchbox\" class=\"extSearch\"
2796 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2797 onchange=\"javascript:search()\">
2798 <select id=\"searchmodebox\">
2799 <option selected>All feeds</option>";
2801 if ($active_feed_id) {
2802 print "<option>This feed</option>";
2804 print "<option disabled>This feed</option>";
2807 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2808 print "<option>This category</option>";
2812 <input type=\"submit\"
2813 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
2814 <input class=\"button\"
2815 type=\"submit\" onclick=\"javascript:closeDlg()\"
2820 if ($id == "quickAddFilter") {
2822 $result = db_query($link, "SELECT description
2823 FROM ttrss_filter_types ORDER BY description");
2825 $filter_types = array();
2827 while ($line = db_fetch_assoc($result)) {
2828 array_push($filter_types, $line["description"]);
2833 print "<tr><td>Match:</td><td><input id=\"fadd_regexp\" size=\"40\"> ";
2835 print_select("fadd_match", "Title", $filter_types);
2838 print "<tr><td>Feed:</td><td><select id=\"fadd_feed\">";
2840 print "<option selected id=\"0\">All feeds</option>";
2842 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
2843 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2845 if (db_num_rows($result) > 0) {
2846 print "<option disabled>--------</option>";
2849 while ($line = db_fetch_assoc($result)) {
2850 if ($param == $line["id"]) {
2851 $selected = "selected";
2855 printf("<option id='%d' %s>%s</option>", $line["id"], $selected, $line["title"]);
2858 print "</select></td></tr>";
2860 print "<tr><td>Action:</td>";
2862 print "<td><select id=\"fadd_action\">";
2864 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2867 while ($line = db_fetch_assoc($result)) {
2868 printf("<option id='%d'>%s</option>", $line["id"], $line["description"]);
2873 print "</td></tr><tr><td colspan=\"2\" align=\"right\">";
2875 print "<input type=\"submit\"
2876 class=\"button\" onclick=\"javascript:qaddFilter()\"
2877 value=\"Add filter\"> ";
2879 print "<input class=\"button\"
2880 type=\"submit\" onclick=\"javascript:closeDlg()\"
2883 print "</td></tr></table>";
2887 // update feeds of all users, may be used anonymously
2888 if ($op == "globalUpdateFeeds") {
2890 $result = db_query($link, "SELECT id FROM ttrss_users");
2892 while ($line = db_fetch_assoc($result)) {
2893 $user_id = $line["id"];
2894 // print "<!-- updating feeds of uid $user_id -->";
2895 update_all_feeds($link, false, $user_id);
2899 <message msg=\"All feeds updated\"/>
2904 if ($op == "pref-prefs") {
2906 $subop = $_REQUEST["subop"];
2908 if ($subop == "Save configuration") {
2910 if (WEB_DEMO_MODE
) {
2911 header("Location: prefs.php");
2915 $_SESSION["prefs_op_result"] = "save-config";
2917 $_SESSION["prefs_cache"] = false;
2919 foreach (array_keys($_POST) as $pref_name) {
2921 $pref_name = db_escape_string($pref_name);
2922 $value = db_escape_string($_POST[$pref_name]);
2924 $result = db_query($link, "SELECT type_name
2925 FROM ttrss_prefs,ttrss_prefs_types
2926 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
2928 if (db_num_rows($result) > 0) {
2930 $type_name = db_fetch_result($result, 0, "type_name");
2932 // print "$pref_name : $type_name : $value<br>";
2934 if ($type_name == "bool") {
2935 if ($value == "1") {
2940 } else if ($type_name == "integer") {
2941 $value = sprintf("%d", $value);
2944 // print "$pref_name : $type_name : $value<br>";
2946 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
2947 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
2951 header("Location: prefs.php");
2955 } else if ($subop == "getHelp") {
2957 $pref_name = db_escape_string($_GET["pn"]);
2959 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
2960 WHERE pref_name = '$pref_name'");
2962 if (db_num_rows($result) > 0) {
2963 $help_text = db_fetch_result($result, 0, "help_text");
2966 print "Unknown option: $pref_name";
2969 } else if ($subop == "Change e-mail") {
2971 if (WEB_DEMO_MODE
) {
2972 header("Location: prefs.php");
2976 $email = db_escape_string($_GET["email"]);
2977 $active_uid = $_SESSION["uid"];
2980 db_query($link, "UPDATE ttrss_users SET email = '$email'
2981 WHERE id = '$active_uid'");
2984 header("Location: prefs.php");
2986 } else if ($subop == "Change password") {
2988 if (WEB_DEMO_MODE
) {
2989 header("Location: prefs.php");
2993 $old_pw = $_POST["OLD_PASSWORD"];
2994 $new_pw = $_POST["OLD_PASSWORD"];
2996 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
2997 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
2999 $active_uid = $_SESSION["uid"];
3001 if ($old_pw && $new_pw) {
3003 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
3005 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3006 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
3007 pwd_hash = '$old_pw_hash')");
3009 if (db_num_rows($result) == 1) {
3010 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
3011 WHERE id = '$active_uid'");
3013 $_SESSION["pwd_change_result"] = "ok";
3015 $_SESSION["pwd_change_result"] = "failed";
3019 header("Location: prefs.php");
3021 } else if ($subop == "Reset to defaults") {
3023 if (WEB_DEMO_MODE
) {
3024 header("Location: prefs.php");
3028 $_SESSION["prefs_op_result"] = "reset-to-defaults";
3030 if (DB_TYPE
== "pgsql") {
3031 db_query($link,"UPDATE ttrss_user_prefs
3032 SET value = ttrss_prefs.def_value
3033 WHERE owner_uid = '".$_SESSION["uid"]."' AND
3034 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
3036 db_query($link, "DELETE FROM ttrss_user_prefs
3037 WHERE owner_uid = ".$_SESSION["uid"]);
3038 initialize_user_prefs($link, $_SESSION["uid"]);
3041 header("Location: prefs.php");
3043 } else if ($subop == "Change theme") {
3045 $theme = db_escape_string($_POST["theme"]);
3047 if ($theme == "Default") {
3048 $theme_qpart = 'NULL';
3050 $theme_qpart = "'$theme'";
3053 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
3054 WHERE theme_name = '$theme'");
3056 if (db_num_rows($result) == 1) {
3057 $theme_id = db_fetch_result($result, 0, "id");
3058 $theme_path = db_fetch_result($result, 0, "theme_path");
3064 db_query($link, "UPDATE ttrss_users SET
3065 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
3067 $_SESSION["theme"] = $theme_path;
3069 header("Location: prefs.php");
3073 if (!SINGLE_USER_MODE
) {
3075 $result = db_query($link, "SELECT id,email FROM ttrss_users
3076 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
3077 pwd_hash = 'SHA1:".sha1("password")."')");
3079 if (db_num_rows($result) != 0) {
3080 print "<div class=\"warning\">
3081 Your password is at default value, please change it.
3085 if ($_SESSION["pwd_change_result"] == "failed") {
3086 print "<div class=\"warning\">
3087 There was an error while changing your password.
3091 if ($_SESSION["pwd_change_result"] == "ok") {
3092 print "<div class=\"notice\">
3093 Password changed successfully.
3097 $_SESSION["pwd_change_result"] = "";
3099 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
3100 print "<div class=\"notice\">
3101 Your configuration was reset to defaults.
3105 if ($_SESSION["prefs_op_result"] == "save-config") {
3106 print "<div class=\"notice\">
3107 Your configuration was saved successfully.
3111 $_SESSION["prefs_op_result"] = "";
3113 print "<form action=\"backend.php\" method=\"GET\">";
3115 print "<table width=\"100%\" class=\"prefPrefsList\">";
3116 print "<tr><td colspan='3'><h3>Personal data</h3></tr></td>";
3118 $result = db_query($link, "SELECT email FROM ttrss_users
3119 WHERE id = ".$_SESSION["uid"]);
3121 $email = db_fetch_result($result, 0, "email");
3123 print "<tr><td width=\"40%\">E-mail</td>";
3124 print "<td><input class=\"editbox\" name=\"email\"
3125 value=\"$email\"></td></tr>";
3129 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3131 print "<p><input class=\"button\" type=\"submit\"
3132 value=\"Change e-mail\" name=\"subop\">";
3136 print "<form action=\"backend.php\" method=\"POST\">";
3138 print "<table width=\"100%\" class=\"prefPrefsList\">";
3139 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
3141 print "<tr><td width=\"40%\">Old password</td>";
3142 print "<td><input class=\"editbox\" type=\"password\"
3143 name=\"OLD_PASSWORD\"></td></tr>";
3145 print "<tr><td width=\"40%\">New password</td>";
3147 print "<td><input class=\"editbox\" type=\"password\"
3148 name=\"NEW_PASSWORD\"></td></tr>";
3152 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3154 print "<p><input class=\"button\" type=\"submit\"
3155 value=\"Change password\" name=\"subop\">";
3161 $result = db_query($link, "SELECT
3162 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
3164 $user_theme_id = db_fetch_result($result, 0, "theme_id");
3166 $result = db_query($link, "SELECT
3167 id,theme_name FROM ttrss_themes ORDER BY theme_name");
3169 if (db_num_rows($result) > 0) {
3171 print "<form action=\"backend.php\" method=\"POST\">";
3172 print "<table width=\"100%\" class=\"prefPrefsList\">";
3173 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
3174 print "<tr><td width=\"40%\">Select theme</td>";
3175 print "<td><select name=\"theme\">";
3176 print "<option>Default</option>";
3177 print "<option disabled>--------</option>";
3179 while ($line = db_fetch_assoc($result)) {
3180 if ($line["id"] == $user_theme_id) {
3181 $selected = "selected";
3185 print "<option $selected>" . $line["theme_name"] . "</option>";
3187 print "</select></td></tr>";
3189 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3190 print "<p><input class=\"button\" type=\"submit\"
3191 value=\"Change theme\" name=\"subop\">";
3195 $result = db_query($link, "SELECT
3196 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
3197 section_name,def_value
3198 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
3199 WHERE type_id = ttrss_prefs_types.id AND
3200 section_id = ttrss_prefs_sections.id AND
3201 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
3202 owner_uid = ".$_SESSION["uid"]."
3203 ORDER BY section_id,short_desc");
3205 print "<form action=\"backend.php\" method=\"POST\">";
3209 $active_section = "";
3211 while ($line = db_fetch_assoc($result)) {
3213 if ($active_section != $line["section_name"]) {
3215 if ($active_section != "") {
3219 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
3221 $active_section = $line["section_name"];
3223 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
3224 // print "<tr class=\"title\">
3225 // <td width=\"25%\">Option</td><td>Value</td></tr>";
3230 // $class = ($lnum % 2) ? "even" : "odd";
3234 $type_name = $line["type_name"];
3235 $pref_name = $line["pref_name"];
3236 $value = $line["value"];
3237 $def_value = $line["def_value"];
3238 $help_text = $line["help_text"];
3240 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
3242 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
3248 if ($type_name == "bool") {
3249 // print_select($pref_name, $value, array("true", "false"));
3251 if ($value == "true") {
3257 print_radio($pref_name, $value, array("Yes", "No"));
3260 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
3272 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3274 print "<p><input class=\"button\" type=\"submit\"
3275 name=\"subop\" value=\"Save configuration\">";
3277 print " <input class=\"button\" type=\"submit\"
3278 name=\"subop\" onclick=\"return validatePrefsReset()\"
3279 value=\"Reset to defaults\"></p>";
3287 if ($op == "pref-users") {
3289 $subop = $_GET["subop"];
3291 if ($subop == "editSave") {
3293 if (!WEB_DEMO_MODE
) {
3295 $login = db_escape_string($_GET["l"]);
3296 $uid = db_escape_string($_GET["id"]);
3297 $access_level = sprintf("%d", $_GET["al"]);
3298 $email = db_escape_string($_GET["e"]);
3300 db_query($link, "UPDATE ttrss_users SET login = '$login',
3301 access_level = '$access_level', email = '$email' WHERE id = '$uid'");
3304 } else if ($subop == "remove") {
3306 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3308 $ids = split(",", db_escape_string($_GET["ids"]));
3310 foreach ($ids as $id) {
3311 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
3315 } else if ($subop == "add") {
3317 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3319 $login = db_escape_string(trim($_GET["login"]));
3320 $tmp_user_pwd = make_password(8);
3321 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3323 db_query($link, "INSERT INTO ttrss_users
3324 (login,pwd_hash,access_level,last_login)
3325 VALUES ('$login', '$pwd_hash', 0, NOW())");
3328 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3329 login = '$login' AND pwd_hash = '$pwd_hash'");
3331 if (db_num_rows($result) == 1) {
3333 $new_uid = db_fetch_result($result, 0, "id");
3335 print "<div class=\"notice\">Added user <b>".$_GET["login"].
3336 "</b> with password <b>$tmp_user_pwd</b>.</div>";
3338 initialize_user($link, $new_uid);
3342 print "<div class=\"warning\">Error while adding user <b>".
3343 $_GET["login"].".</b></div>";
3347 } else if ($subop == "resetPass") {
3349 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3351 $uid = db_escape_string($_GET["id"]);
3353 $result = db_query($link, "SELECT login,email
3354 FROM ttrss_users WHERE id = '$uid'");
3356 $login = db_fetch_result($result, 0, "login");
3357 $email = db_fetch_result($result, 0, "email");
3358 $tmp_user_pwd = make_password(8);
3359 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3361 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
3362 WHERE id = '$uid'");
3364 print "<div class=\"notice\">Changed password of
3365 user <b>$login</b> to <b>$tmp_user_pwd</b>.";
3367 if (MAIL_RESET_PASS
&& $email) {
3368 print " Notifying <b>$email</b>.";
3370 mail("$login <$email>", "Password reset notification",
3373 "Your password for this TT-RSS installation was reset by".
3374 " an administrator.\n".
3376 "Your new password is $tmp_user_pwd, please remember".
3377 " it for later reference.\n".
3379 "Sincerely, TT-RSS Mail Daemon.", "From: " . MAIL_FROM
);
3387 print "<div class=\"prefGenericAddBox\">
3388 <input id=\"uadd_box\" onchange=\"javascript:addUser()\" size=\"40\"> ";
3390 print"<input type=\"submit\" class=\"button\"
3391 onclick=\"javascript:addUser()\" value=\"Add user\"></div>";
3393 $result = db_query($link, "SELECT
3394 id,login,access_level,email,
3395 SUBSTRING(last_login,1,16) as last_login
3400 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
3402 print "<p><table width=\"100%\" cellspacing=\"0\"
3403 class=\"prefUserList\" id=\"prefUserList\">";
3405 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
3407 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3408 'UMRR-', 'UMCHK-', true)\">All</a>,
3409 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3410 'UMRR-', 'UMCHK-', false)\">None</a>
3413 print "<tr class=\"title\">
3414 <td align='center' width=\"5%\"> </td>
3415 <td width='20%'>Login</td>
3416 <td width='20%'>E-mail</td>
3417 <td width='20%'>Access Level</td>
3418 <td width='20%'>Last login</td></tr>";
3422 while ($line = db_fetch_assoc($result)) {
3424 $class = ($lnum %
2) ?
"even" : "odd";
3427 $edit_uid = $_GET["id"];
3429 if ($subop == "edit" && $uid != $edit_uid) {
3433 $this_row_id = "id=\"UMRR-$uid\"";
3436 print "<tr class=\"$class\" $this_row_id>";
3438 $line["login"] = htmlspecialchars($line["login"]);
3440 $line["last_login"] = date(get_pref($link, 'SHORT_DATE_FORMAT'),
3441 strtotime($line["last_login"]));
3443 $access_level_names = array(0 => "User", 10 => "Administrator");
3445 /* if ($uid == $_SESSION["uid"]) {
3447 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
3448 id=\"UMCHK-".$line["id"]."\"></td>";
3450 print "<td>".$line["login"]."</td>";
3451 print "<td>".$line["email"]."</td>";
3452 print "<td>".$line["access_level"]."</td>";
3454 } else */ if (!$edit_uid ||
$subop != "edit") {
3456 print "<td align='center'><input onclick='toggleSelectRow(this);'
3457 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
3459 print "<td><a href=\"javascript:editUser($uid);\">" .
3460 $line["login"] . "</td>";
3462 if (!$line["email"]) $line["email"] = " ";
3464 print "<td><a href=\"javascript:editUser($uid);\">" .
3465 $line["email"] . "</td>";
3467 print "<td><a href=\"javascript:editUser($uid);\">" .
3468 $access_level_names[$line["access_level"]] . "</td>";
3470 } else if ($uid != $edit_uid) {
3472 if (!$line["email"]) $line["email"] = " ";
3474 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
3475 id=\"UMCHK-".$line["id"]."\"></td>";
3477 print "<td>".$line["login"]."</td>";
3478 print "<td>".$line["email"]."</td>";
3479 print "<td>".$access_level_names[$line["access_level"]]."</td>";
3483 print "<td align='center'>
3484 <input disabled=\"true\" type=\"checkbox\" checked></td>";
3486 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
3489 print "<td><input id=\"iedit_email\" value=\"".$line["email"].
3492 // print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
3496 print "<select id=\"iedit_ulevel\">";
3497 foreach (array_keys($access_level_names) as $al) {
3498 if ($al == $line["access_level"]) {
3499 $selected = "selected";
3503 print "<option $selected id=\"$al\">" .
3504 $access_level_names[$al] . "</option>";
3511 print "<td>".$line["last_login"]."</td>";
3522 if ($subop == "edit") {
3524 <input type=\"submit\" class=\"button\"
3525 onclick=\"javascript:userEditSave()\" value=\"Save\">
3526 <input type=\"submit\" class=\"button\"
3527 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">";
3533 <input type=\"submit\" class=\"button\"
3534 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
3535 <input type=\"submit\" class=\"button\"
3536 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
3537 <input type=\"submit\" class=\"button\"
3538 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
3539 <input type=\"submit\" class=\"button\"
3540 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
3545 if ($op == "user-details") {
3547 if (WEB_DEMO_MODE ||
$_SESSION["access_level"] < 10) {
3551 /* print "<html><head>
3552 <title>Tiny Tiny RSS : User Details</title>
3553 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
3554 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
3557 $uid = sprintf("%d", $_GET["id"]);
3559 print "<div class='infoBoxContents'>";
3561 $result = db_query($link, "SELECT login,
3562 SUBSTRING(last_login,1,16) AS last_login,
3564 (SELECT COUNT(int_id) FROM ttrss_user_entries
3565 WHERE owner_uid = id) AS stored_articles
3567 WHERE id = '$uid'");
3569 if (db_num_rows($result) == 0) {
3570 print "<h1>User not found</h1>";
3574 print "<h1>User Details</h1>";
3576 print "<table width='100%'>";
3578 $login = db_fetch_result($result, 0, "login");
3579 $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'),
3580 strtotime(db_fetch_result($result, 0, "last_login")));
3581 $access_level = db_fetch_result($result, 0, "access_level");
3582 $stored_articles = db_fetch_result($result, 0, "stored_articles");
3584 print "<tr><td>Username</td><td>$login</td></tr>";
3585 print "<tr><td>Access level</td><td>$access_level</td></tr>";
3586 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
3587 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
3589 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
3590 WHERE owner_uid = '$uid'");
3592 $num_feeds = db_fetch_result($result, 0, "num_feeds");
3594 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
3596 /* $result = db_query($link, "SELECT
3597 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
3598 FROM ttrss_user_entries,ttrss_entries
3599 WHERE owner_uid = '$uid' AND ref_id = id");
3601 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
3603 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
3607 print "<h1>Subscribed feeds</h1>";
3609 $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
3610 WHERE owner_uid = '$uid' ORDER BY title");
3612 print "<ul class=\"userFeedList\">";
3614 while ($line = db_fetch_assoc($result)) {
3616 $icon_file = ICONS_URL
."/".$line["id"].".ico";
3618 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3619 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
3621 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3624 print "<li>$feed_icon <a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
3627 if (db_num_rows($result) < $num_feeds) {
3628 // FIXME - add link to show ALL subscribed feeds here somewhere
3630 class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\"> ...</li>";
3637 print "<div align='center'>
3638 <input type='submit' class='button'
3639 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3641 // print "</body></html>";
3645 if ($op == "feed-details") {
3647 // $feed_id = $_GET["id"];
3649 $feed_ids = split(",", db_escape_string($_GET["id"]));
3651 print "<div class=\"infoBoxContents\">";
3653 foreach ($feed_ids as $feed_id) {
3655 $result = db_query($link,
3658 SUBSTRING(last_updated,1,16) as last_updated,
3660 (SELECT COUNT(int_id) FROM ttrss_user_entries
3661 WHERE feed_id = id) AS total,
3662 (SELECT COUNT(int_id) FROM ttrss_user_entries
3663 WHERE feed_id = id AND unread = true) AS unread,
3664 (SELECT COUNT(int_id) FROM ttrss_user_entries
3665 WHERE feed_id = id AND marked = true) AS marked
3667 WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]);
3669 if (db_num_rows($result) == 0) return;
3671 $title = db_unescape_string(db_fetch_result($result, 0, "title"));
3672 $last_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
3673 strtotime(db_fetch_result($result, 0, "last_updated")));
3674 $feed_url = db_fetch_result($result, 0, "feed_url");
3675 $icon_url = db_fetch_result($result, 0, "icon_url");
3676 $total = db_fetch_result($result, 0, "total");
3677 $unread = db_fetch_result($result, 0, "unread");
3678 $marked = db_fetch_result($result, 0, "marked");
3679 $site_url = db_fetch_result($result, 0, "site_url");
3681 $result = db_query($link, "SELECT COUNT(id) AS subscribed
3682 FROM ttrss_feeds WHERE feed_url = '$feed_url' AND private = false");
3684 $subscribed = db_fetch_result($result, 0, "subscribed");
3686 $icon_file = ICONS_DIR
. "/$feed_id.ico";
3688 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3689 $feed_icon = "<img width=\"16\" height=\"16\"
3690 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
3695 print "<h1>$feed_icon $title</h1>";
3697 print "<table width='100%'>";
3700 print "<tr><td width='30%'>Link</td>
3701 <td><a href=\"$site_url\">$site_url</a>
3702 <a href=\"$feed_url\">(feed)</a></td>
3705 print "<tr><td width='30%'>Feed URL</td>
3706 <td><a href=\"$feed_url\">$feed_url</a></td></tr>";
3708 print "<tr><td>Last updated</td><td>$last_updated</td></tr>";
3709 print "<tr><td>Total articles</td><td>$total</td></tr>";
3710 print "<tr><td>Unread articles</td><td>$unread</td></tr>";
3711 print "<tr><td>Starred articles</td><td>$marked</td></tr>";
3712 print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>";
3716 /* $result = db_query($link, "SELECT title,
3717 SUBSTRING(updated,1,16) AS updated,unread
3718 FROM ttrss_entries,ttrss_user_entries
3719 WHERE ref_id = id AND feed_id = '$feed_id'
3720 ORDER BY date_entered DESC LIMIT 5");
3722 if (db_num_rows($result) > 0) {
3724 print "<h1>Latest headlines</h1>";
3726 print "<ul class=\"nomarks\">";
3728 while ($line = db_fetch_assoc($result)) {
3729 if ($line["unread"] == "t" || $line["unread"] == "1") {
3730 $line["title"] = "<b>" . $line["title"] . "</b>";
3732 print "<li>" . $line["title"].
3733 " <span class=\"insensitive\">(" .
3734 date(get_pref($link, 'SHORT_DATE_FORMAT'),
3735 strtotime($line["updated"])).
3746 print "<div align='center'>
3747 <input type='submit' class='button'
3748 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3751 if ($op == "pref-feed-browser") {
3753 print "<p>This panel shows feeds subscribed by other users of this system, just in case you are interested in some of them too.</p>";
3755 if (!ENABLE_FEED_BROWSER
) {
3756 print "Feed browser is administratively disabled.";
3760 $subop = $_REQUEST["subop"];
3762 if ($subop == "details") {
3763 $id = db_escape_string($_GET["id"]);
3765 print "<div class=\"browserFeedInfo\">";
3766 print "<b>Feed information:</b>";
3767 print "<div class=\"detailsPart\">";
3769 $result = db_query($link, "SELECT
3771 SUBSTRING(last_updated,1,19) AS last_updated
3772 FROM ttrss_feeds WHERE id = '$id'");
3774 $feed_url = db_fetch_result($result, 0, "feed_url");
3775 $site_url = db_fetch_result($result, 0, "site_url");
3776 $last_updated = db_fetch_result($result, 0, "last_updated");
3778 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
3779 $last_updated = smart_date_time(strtotime($last_updated));
3781 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
3782 $last_updated = date($short_date, strtotime($last_updated));
3785 print "Site: <a href='$site_url'>$site_url</a> ".
3786 "(<a href='$feed_url'>feed</a>), ".
3787 "Last updated: $last_updated";
3791 $result = db_query($link, "SELECT
3792 ttrss_entries.title,
3794 substring(date_entered,1,19) as date_entered,
3795 substring(updated,1,19) as updated
3796 FROM ttrss_entries,ttrss_user_entries
3797 WHERE ttrss_entries.id = ref_id AND feed_id = '$id'
3798 ORDER BY updated DESC LIMIT 5");
3800 if (db_num_rows($result) > 0) {
3802 print "<b>Last headlines:</b><br>";
3804 print "<div class=\"detailsPart\">";
3805 print "<ul class=\"compact\">";
3806 while ($line = db_fetch_assoc($result)) {
3808 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
3809 $entry_dt = smart_date_time(strtotime($line["updated"]));
3811 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
3812 $entry_dt = date($short_date, strtotime($line["updated"]));
3815 print "<li>" . $line["title"] .
3816 " <span class=\"insensitive\">($entry_dt)</span></li>";
3818 print "</ul></div>";
3826 $result = db_query($link, "SELECT feed_url,count(id) AS subscribers
3828 WHERE auth_login = '' AND auth_pass = '' AND private = false
3829 GROUP BY feed_url ORDER BY subscribers DESC LIMIT 100");
3831 print "<p>Selection:
3832 <input type='submit' class='button' onclick=\"feedBrowserSubscribe()\"
3833 value=\"Subscribe\">";
3835 print "<ul class='nomarks' id='browseBigFeedList'>";
3839 while ($line = db_fetch_assoc($result)) {
3840 $feed_url = $line["feed_url"];
3841 $subscribers = $line["subscribers"];
3843 $sub_result = db_query($link, "SELECT id
3844 FROM ttrss_feeds WHERE feed_url = '$feed_url' AND owner_uid =" .
3847 if (db_num_rows($sub_result) > 0) {
3848 continue; // already subscribed
3851 $det_result = db_query($link, "SELECT site_url,title,id
3852 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
3854 $details = db_fetch_assoc($det_result);
3856 $icon_file = ICONS_DIR
. "/" . $details["id"] . ".ico";
3858 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3859 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL
.
3860 "/".$details["id"].".ico\">";
3862 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3865 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
3866 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
3868 $class = ($feedctr %
2) ?
"even" : "odd";
3870 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
3873 print "<a href=\"javascript:browserToggleExpand('".$details["id"]."')\">" .
3874 $details["title"] ."</a> " .
3875 "<span class='subscribers'>($subscribers)</span>";
3877 print "<div class=\"browserDetails\" id=\"BRDET-" . $details["id"] . "\">";
3885 if ($feedctr == 0) {
3886 print "<li>No feeds found to subscribe.</li>";
3895 function check_configuration_variables() {
3896 if (!defined('SESSION_EXPIRE_TIME')) {
3897 return "config: SESSION_EXPIRE_TIME is undefined";
3900 if (SESSION_EXPIRE_TIME
< 60) {
3901 return "config: SESSION_EXPIRE_TIME is too low (less than 60)";
3904 if (SESSION_EXPIRE_TIME
< SESSION_COOKIE_LIFETIME_REMEMBER
) {
3905 return "config: SESSION_EXPIRE_TIME should be greater or equal to" .
3906 "SESSION_COOKIE_LIFETIME_REMEMBER";
3909 if (defined('DISABLE_SESSIONS')) {
3910 return "config: you have enabled DISABLE_SESSIONS. Please disable this option.";
3913 if (DATABASE_BACKED_SESSIONS
&& SINGLE_USER_MODE
) {
3914 return "config: DATABASE_BACKED_SESSIONS is incompatible with SINGLE_USER_MODE";
3923 <!-- <?
= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?
> -->