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', 9);
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 == "rss" ||
37 $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
38 header("Content-Type: application/xml");
41 if (!$_SESSION["uid"] && $op != "globalUpdateFeeds" && $op != "rss") {
44 print_error_xml(6); die;
48 <p>Error: Not logged in.</p>
49 <script type=\"text/javascript\">
50 if (parent.window != 'undefined') {
51 parent.window.location = \"login.php\";
53 window.location = \"login.php\";
63 print_error_xml(7); exit;
66 $purge_intervals = array(
73 90 => "3 months old");
75 $update_intervals = array(
77 -1 => "Disable updates",
78 30 => "Each 30 minutes",
80 240 => "Each 4 hours",
81 720 => "Each 12 hours",
85 $access_level_names = array(
87 10 => "Administrator");
89 $script_started = getmicrotime();
91 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
94 if (DB_TYPE == "mysql") {
97 // PG seems to display its own errors just fine by default.
101 if (DB_TYPE == "pgsql") {
102 pg_query("set client_encoding = 'utf-8'");
105 if ($_SESSION["uid"]) {
107 // setcookie('ttrss_vf_refresh', FEEDS_FRAME_REFRESH);
108 // setcookie('ttrss_vf_daemon', ENABLE_UPDATE_DAEMON);
110 /* if (get_pref($link, "ON_CATCHUP_SHOW_NEXT_FEED")) {
111 setcookie('ttrss_vf_catchupnext', 1);
113 setcookie('ttrss_vf_catchupnext', 0);
117 $fetch = $_GET["fetch"];
119 // setcookie("ttrss_icons_url", ICONS_URL);
121 if (!sanity_check($link)) { return; }
123 function outputFeedList($link, $tags = false) {
126 <title>Tiny Tiny RSS : Feedlist</title>
127 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
129 $user_theme = $_SESSION["theme"];
131 print "<link rel=\"stylesheet\" type=\"text/css\"
132 href=\"themes/$user_theme/theme.css\">";
135 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
136 print "<link rel=\"stylesheet\" type=\"text/css\"
137 href=\"tt-rss_compact.css\"/>";
139 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
140 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
143 $script_dt_add = get_script_dt_add();
146 <script type=\"text/javascript\" src=\"prototype.js\"></script>
147 <script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
148 <script type=\"text/javascript\" src=\"feedlist.js?$script_dt_add\"></script>
149 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
150 <!--[if gte IE 5.5000]>
151 <script type=\"text/javascript\" src=\"pngfix.js\"></script>
152 <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
155 <script type=\"text/javascript\">
156 if (document.addEventListener) {
157 document.addEventListener(\"DOMContentLoaded\", init, null);
159 window.onload = init;
162 print "<ul class=\"feedList\" id=\"feedList\">\n";
164 $owner_uid = $_SESSION["uid"];
170 if (get_pref($link, 'ENABLE_FEED_CATS')) {
171 print "<li class=\"feedCat\">Special</li>";
172 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
175 $result = db_query($link, "SELECT count(id) as num_starred
176 FROM ttrss_entries,ttrss_user_entries
177 WHERE marked = true AND
178 ttrss_user_entries.ref_id = ttrss_entries.id AND
179 unread = true AND owner_uid = '$owner_uid'");
180 $num_starred = db_fetch_result($result, 0, "num_starred");
184 if ($num_starred > 0) $class .= "Unread";
186 printFeedEntry(-1, $class, "Starred articles", $num_starred,
187 "images/mark_set.png", $link);
189 if (get_pref($link, 'ENABLE_FEED_CATS')) {
193 if (GLOBAL_ENABLE_LABELS && get_pref($link, 'ENABLE_LABELS')) {
195 $result = db_query($link, "SELECT id,sql_exp,description FROM
196 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
198 if (db_num_rows($result) > 0) {
199 if (get_pref($link, 'ENABLE_FEED_CATS')) {
200 print "<li class=\"feedCat\">Labels</li>";
201 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
203 print "<li><hr></li>";
207 while ($line = db_fetch_assoc($result)) {
211 $tmp_result = db_query($link, "SELECT count(ttrss_entries.id) as count
212 FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
213 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
214 ttrss_user_entries.ref_id = ttrss_entries.id AND
215 ttrss_user_entries.feed_id = ttrss_feeds.id
216 AND ttrss_user_entries.owner_uid = '$owner_uid'");
218 $count = db_fetch_result($tmp_result, 0, "count");
226 error_reporting (DEFAULT_ERROR_LEVEL);
228 printFeedEntry(-$line["id"]-11,
229 $class, db_unescape_string($line["description"]),
230 $count, "images/label.png", $link);
234 if (db_num_rows($result) > 0) {
235 if (get_pref($link, 'ENABLE_FEED_CATS')) {
242 // if (!get_pref($link, 'ENABLE_FEED_CATS')) {
243 print "<li><hr></li>";
246 if (get_pref($link, 'ENABLE_FEED_CATS')) {
247 if (get_pref($link, "FEEDS_SORT_BY_UNREAD")) {
248 $order_by_qpart = "category,unread DESC,title";
250 $order_by_qpart = "category,title";
253 if (get_pref($link, "FEEDS_SORT_BY_UNREAD")) {
254 $order_by_qpart = "unread DESC,title";
256 $order_by_qpart = "title";
260 $result = db_query($link, "SELECT ttrss_feeds.*,
261 SUBSTRING(last_updated,1,19) AS last_updated_noms,
262 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
263 WHERE feed_id = ttrss_feeds.id AND
264 ttrss_user_entries.ref_id = ttrss_entries.id AND
265 owner_uid = '$owner_uid') AS total,
266 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
267 WHERE feed_id = ttrss_feeds.id AND unread = true
268 AND ttrss_user_entries.ref_id = ttrss_entries.id
269 AND owner_uid = '$owner_uid') as unread,
271 ttrss_feed_categories.title AS category,
272 ttrss_feed_categories.collapsed
273 FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
274 ON (ttrss_feed_categories.id = cat_id)
276 ttrss_feeds.owner_uid = '$owner_uid' AND parent_feed IS NULL
277 ORDER BY $order_by_qpart");
279 $actid = $_GET["actid"];
289 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
291 while ($line = db_fetch_assoc($result)) {
293 $feed = db_unescape_string($line["title"]);
294 $feed_id = $line["id"];
296 $subop = $_GET["subop"];
298 $total = $line["total"];
299 $unread = $line["unread"];
301 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
302 $last_updated = smart_date_time(strtotime($line["last_updated_noms"]));
304 $last_updated = date($short_date, strtotime($line["last_updated_noms"]));
307 $rtl_content = sql_bool_to_bool($line["rtl_content"]);
310 $rtl_tag = "dir=\"RTL\"";
315 $tmp_result = db_query($link,
316 "SELECT id,COUNT(unread) AS unread
317 FROM ttrss_feeds LEFT JOIN ttrss_user_entries
318 ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
319 WHERE parent_feed = '$feed_id' AND unread = true
320 GROUP BY ttrss_feeds.id");
322 if (db_num_rows($tmp_result) > 0) {
323 while ($l = db_fetch_assoc($tmp_result)) {
324 $unread += $l["unread"];
328 $cat_id = $line["cat_id"];
330 $tmp_category = $line["category"];
332 if (!$tmp_category) {
333 $tmp_category = "Uncategorized";
336 // $class = ($lnum % 2) ? "even" : "odd";
338 if ($line["last_error"]) {
344 if ($unread > 0) $class .= "Unread";
346 if ($actid == $feed_id) {
347 $class .= "Selected";
350 $total_unread += $unread;
352 if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
358 $category = $tmp_category;
360 $collapsed = $line["collapsed"];
362 // workaround for NULL category
363 if ($category == "Uncategorized") {
364 if ($_COOKIE["ttrss_vf_uclps"] == 1) {
369 if ($collapsed == "t" || $collapsed == "1") {
370 $holder_class = "invisible";
378 $cat_id_qpart = "cat_id = '$cat_id'";
380 $cat_id_qpart = "cat_id IS NULL";
383 $tmp_result = db_query($link, "SELECT count(int_id) AS unread
384 FROM ttrss_user_entries,ttrss_feeds WHERE
386 feed_id = ttrss_feeds.id AND $cat_id_qpart AND
387 ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
389 $cat_unread = db_fetch_result($tmp_result, 0, "unread");
391 $cat_id = sprintf("%d", $cat_id);
393 print "<li class=\"feedCat\" id=\"FCAT-$cat_id\">
394 <a id=\"FCATN-$cat_id\" href=\"javascript:toggleCollapseCat($cat_id)\">$tmp_category</a>
395 <a href=\"javascript:viewCategory($cat_id)\" id=\"FCAP-$cat_id\">
396 <span id=\"FCATCTR-$cat_id\"
397 class=\"$catctr_class\">($cat_unread unread)$ellipsis</span>
400 // !!! NO SPACE before <ul...feedCatList - breaks firstChild DOM function
401 // -> keyboard navigation, etc.
402 print "<li id=\"feedCatHolder\" class=\"$holder_class\"><ul class=\"feedCatList\" id=\"FCATLIST-$cat_id\">";
405 printFeedEntry($feed_id, $class, $feed, $unread,
406 "icons/$feed_id.ico", $link, $rtl_content,
407 $last_updated, $line["last_error"]);
416 /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
417 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
418 post_int_id = ttrss_user_entries.int_id AND
419 unread = true AND ref_id = ttrss_entries.id
420 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
422 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'
423 ORDER BY tag_name"); */
425 $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
426 FROM ttrss_user_entries WHERE int_id = post_int_id
427 AND unread = true)) AS count FROM ttrss_tags
428 WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name");
432 while ($line = db_fetch_assoc($result)) {
433 $tags[$line["tag_name"]] += $line["count"];
436 foreach (array_keys($tags) as $tag) {
438 $unread = $tags[$tag];
446 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
452 if (db_num_rows($result) == 0) {
458 print "<li>No $what to display.</li>";
464 <script type="text/javascript">
466 function statechange() {
467 if (document.readyState == "interactive") init();
470 if (document.readyState) {
471 if (document.readyState == "interactive" || document.readyState == "complete") {
474 document.onreadystatechange = statechange;
477 </script></body></html>';
482 handle_rpc_request($link);
485 if ($op == "feeds") {
487 $tags = $_GET["tags"];
489 $subop = $_GET["subop"];
491 if ($subop == "catchupAll") {
492 db_query($link, "UPDATE ttrss_user_entries SET
493 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
496 if ($subop == "collapse") {
497 $cat_id = db_escape_string($_GET["cid"]);
499 db_query($link, "UPDATE ttrss_feed_categories SET
500 collapsed = NOT collapsed WHERE id = '$cat_id' AND owner_uid = " .
505 outputFeedList($link, $tags);
511 $id = db_escape_string($_GET["id"]);
512 $feed_id = db_escape_string($_GET["feed"]);
514 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
515 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
517 if (db_num_rows($result) == 1) {
518 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
520 $rtl_content = false;
524 $rtl_tag = "dir=\"RTL\"";
531 $result = db_query($link, "UPDATE ttrss_user_entries
532 SET unread = false,last_read = NOW()
533 WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
535 $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
536 SUBSTRING(updated,1,16) as updated,
537 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url,
540 FROM ttrss_entries,ttrss_user_entries
541 WHERE id = '$id' AND ref_id = id AND owner_uid = " . $_SESSION["uid"]);
544 <title>Tiny Tiny RSS : Article $id</title>
545 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
547 $user_theme = $_SESSION["theme"];
549 print "<link rel=\"stylesheet\" type=\"text/css\"
550 href=\"themes/$user_theme/theme.css\">";
553 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
554 print "<link rel=\"stylesheet\" type=\"text/css\"
555 href=\"tt-rss_compact.css\"/>";
557 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
558 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
561 $script_dt_add = get_script_dt_add();
564 <script type=\"text/javascript\" src=\"prototype.js\"></script>
565 <script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
566 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
567 </head><body $rtl_tag>";
573 if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
574 $link_target = "target=\"_new\"";
577 $line = db_fetch_assoc($result);
579 if ($line["icon_url"]) {
580 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
582 $feed_icon = " ";
585 /* if ($line["comments"] && $line["link"] != $line["comments"]) {
586 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
588 $entry_comments = "";
591 $num_comments = $line["num_comments"];
592 $entry_comments = "";
594 if ($num_comments > 0) {
595 if ($line["comments"]) {
596 $comments_url = $line["comments"];
598 $comments_url = $line["link"];
600 $entry_comments = "<a $link_target href=\"$comments_url\">$num_comments comments</a>";
602 if ($line["comments"] && $line["link"] != $line["comments"]) {
603 $entry_comments = "<a $link_target href=\"".$line["comments"]."\">comments</a>";
607 print "<div class=\"postReply\">";
609 print "<div class=\"postHeader\"><table width=\"100%\">";
611 $entry_author = $line["author"];
614 $entry_author = " - by $entry_author";
617 print "<tr><td><a $link_target href=\"" . $line["link"] . "\">" . $line["title"] .
618 "</a>$entry_author</td>";
620 $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
621 strtotime($line["updated"]));
623 print "<td class=\"postDate$rtl_class\">$parsed_updated</td>";
627 $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
628 ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
636 while ($tmp_line = db_fetch_assoc($tmp_result)) {
638 $tag = $tmp_line["tag_name"];
639 $tag_str = "<a href=\"javascript:parent.viewfeed('$tag')\">$tag</a>, ";
641 if ($num_tags == 5) {
642 $tags_str .= "<a href=\"javascript:showBlockElement('allEntryTags')\">...</a>";
643 } else if ($num_tags < 5) {
644 $tags_str .= $tag_str;
646 $f_tags_str .= $tag_str;
649 $tags_str = preg_replace("/, $/", "", $tags_str);
650 $f_tags_str = preg_replace("/, $/", "", $f_tags_str);
652 // $truncated_link = truncate_string($line["link"], 60);
654 if ($tags_str || $entry_comments) {
655 print "<tr><td width='50%'>
657 <td align=\"right\">$tags_str</td></tr>";
660 print "</table></div>";
662 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
663 print "<div class=\"postContent\">";
665 if (db_num_rows($tmp_result) > 5) {
666 print "<div id=\"allEntryTags\">Tags: $f_tags_str</div>";
669 if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
670 $line["content"] = preg_replace("/href=/i", "target=\"_new\" href=", $line["content"]);
673 print $line["content"] . "</div>";
677 print "<script type=\"text/javascript\">
679 parent.update_all_counters('$feed_id');
681 exception_error('view/footer', e);
686 print "</body></html>";
689 if ($op == "viewfeed") {
691 $feed = db_escape_string($_GET["feed"]);
692 $subop = db_escape_string($_GET["subop"]);
693 $view_mode = db_escape_string($_GET["view_mode"]);
694 $limit = db_escape_string($_GET["limit"]);
695 $cat_view = db_escape_string($_GET["cat"]);
696 $next_unread_feed = db_escape_string($_GET["nuf"]);
698 if ($subop == "undefined") $subop = "";
701 <title>Tiny Tiny RSS : Feed $feed</title>
702 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
704 $user_theme = $_SESSION["theme"];
706 print "<link rel=\"stylesheet\" type=\"text/css\"
707 href=\"themes/$user_theme/theme.css\">";
710 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
711 print "<link rel=\"stylesheet\"
712 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
715 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
716 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
719 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
720 update_generic_feed($link, $feed, $cat_view);
723 if ($subop == "MarkAllRead") {
724 catchup_feed($link, $feed, $cat_view);
726 if (get_pref($link, 'ON_CATCHUP_SHOW_NEXT_FEED')) {
727 if ($next_unread_feed) {
728 $feed = $next_unread_feed;
734 $result = db_query($link,
735 "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
737 if (db_num_rows($result) == 0) {
738 print "<div align='center'>
739 Feed not found.</div>";
744 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
746 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
747 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
749 if (db_num_rows($result) == 1) {
750 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
752 $rtl_content = false;
756 $rtl_tag = "dir=\"RTL\"";
762 $rtl_content = false;
765 $script_dt_add = get_script_dt_add();
767 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
768 <script type=\"text/javascript\" src=\"prototype.js\"></script>
769 <script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
770 <script type=\"text/javascript\" src=\"viewfeed.js?$script_dt_add\"></script>
771 <!--[if gte IE 5.5000]>
772 <script type=\"text/javascript\" src=\"pngfix.js\"></script>
773 <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
775 </head><body $rtl_tag>
776 <script type=\"text/javascript\">
777 if (document.addEventListener) {
778 document.addEventListener(\"DOMContentLoaded\", init, null);
780 window.onload = init;
783 /// START /////////////////////////////////////////////////////////////////////////////////
785 $search = db_escape_string($_GET["query"]);
786 $search_mode = db_escape_string($_GET["search_mode"]);
787 $match_on = db_escape_string($_GET["match_on"]);
793 $qfh_ret = queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on);
795 $result = $qfh_ret[0];
796 $feed_title = $qfh_ret[1];
797 $feed_site_url = $qfh_ret[2];
798 $last_error = $qfh_ret[3];
800 /// STOP //////////////////////////////////////////////////////////////////////////////////
802 print "<div id=\"headlinesContainer\">";
805 print "<div align='center'>
806 Could not display feed (query failed). Please check label match syntax or local configuration.</div>";
810 function print_headline_subtoolbar($link, $feed_site_url, $feed_title,
811 $bottom = false, $rtl_content = false, $feed_id = 0,
812 $is_cat = false, $search = false, $match_on = false,
813 $search_mode = false) {
816 $class = "headlinesSubToolbar";
817 $tid = "headlineActionsTop";
819 $class = "invisible";
820 $tid = "headlineActionsBottom";
823 print "<table class=\"$class\" id=\"$tid\"
824 width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
832 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
834 print "<td class=\"headlineActions$rtl_cpart\">
836 <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, '', true)\">All</a>,
837 <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true)\">Unread</a>,
838 <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false)\">None</a>
840 Toggle: <a href='#' onclick=\"javascript:selectionToggleUnread()\">Unread</a>,
841 <a href='#' onclick=\"javascript:selectionToggleMarked()\">Starred</a>";
845 if ($search && $feed_id > 0 && get_pref($link, 'ENABLE_LABELS') && GLOBAL_ENABLE_LABELS) {
846 print "<td class=\"headlineActions$rtl_cpart\">
847 <a href=\"javascript:labelFromSearch('$search', '$search_mode',
848 '$match_on', '$feed_id', '$is_cat');\">
849 Convert this search to label</a></td>";
854 print "<td class=\"headlineActions$rtl_cpart\">
856 <a href=\"#\" onclick=\"javascript:cdmSelectArticles('all')\">All</a>,
857 <a href=\"#\" onclick=\"javascript:cdmSelectArticles('unread')\">Unread</a>,
858 <a href=\"#\" onclick=\"javascript:cdmSelectArticles('none')\">None</a>
860 Toggle: <a href=\"#\" onclick=\"javascript:selectionToggleUnread(true)\">Unread</a>,
861 <a href=\"#\" onclick=\"javascript:selectionToggleMarked(true)\">Starred</a>";
867 print "<td class=\"headlineTitle$rtl_cpart\">";
869 if ($feed_site_url) {
871 $target = "target=\"_blank\"";
873 print "<a $target href=\"$feed_site_url\">$feed_title</a>";
879 $search_q = "&q=$search&m=$match_on&smode=$search_mode";
885 href=\"backend.php?op=rss&id=$feed_id&is_cat=$is_cat$search_q\"
886 <img class=\"noborder\"
887 alt=\"Generated feed\" src=\"images/feed-icon-12x12.png\">
892 print "</tr></table>";
896 if (db_num_rows($result) > 0) {
898 print_headline_subtoolbar($link, $feed_site_url, $feed_title, false,
899 $rtl_content, $feed, $cat_view, $search, $match_on, $search_mode);
901 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
902 print "<table class=\"headlinesList\" id=\"headlinesList\"
903 cellspacing=\"0\" width=\"100%\">";
908 error_reporting (DEFAULT_ERROR_LEVEL);
912 while ($line = db_fetch_assoc($result)) {
914 $class = ($lnum % 2) ? "even" : "odd";
917 $feed_id = $line["feed_id"];
919 if ($line["last_read"] == "" &&
920 ($line["unread"] != "t" && $line["unread"] != "1")) {
922 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
925 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
929 if ($line["unread"] == "t" || $line["unread"] == "1") {
937 if ($line["marked"] == "t" || $line["marked"] == "1") {
938 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
939 alt=\"Reset mark\" onclick='javascript:toggleMark($id)'>";
941 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
942 alt=\"Set mark\" onclick='javascript:toggleMark($id)'>";
945 $content_link = "<a href=\"javascript:view($id,$feed_id);\">" .
946 $line["title"] . "</a>";
948 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
949 $updated_fmt = smart_date_time(strtotime($line["updated"]));
951 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
952 $updated_fmt = date($short_date, strtotime($line["updated"]));
955 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
956 $content_preview = truncate_string(strip_tags($line["content_preview"]),
960 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
962 print "<tr class='$class' id='RROW-$id'>";
964 print "<td class='hlUpdatePic'>$update_pic</td>";
966 print "<td class='hlSelectRow'>
967 <input type=\"checkbox\" onclick=\"toggleSelectRow(this)\"
968 class=\"feedCheckBox\" id=\"RCHK-$id\">
971 print "<td class='hlMarkedPic'>$marked_pic</td>";
973 if ($line["feed_title"]) {
974 print "<td class='hlContent'>$content_link</td>";
975 print "<td class='hlFeed'>
976 <a href='javascript:viewfeed($feed_id)'>".
977 $line["feed_title"]."</a> </td>";
979 print "<td class='hlContent' valign='middle'>";
981 print "<a href=\"javascript:view($id,$feed_id);\">" .
984 if (get_pref($link, 'SHOW_CONTENT_PREVIEW') && !$rtl_tag) {
985 if ($content_preview) {
986 print "<span class=\"contentPreview\"> - $content_preview</span>";
994 print "<td class=\"hlUpdated\"><nobr>$updated_fmt </nobr></td>";
1001 $add_class = "Unread";
1006 print "<div class=\"cdmArticle$add_class\" id=\"RROW-$id\">";
1008 print "<div class=\"cdmHeader\">";
1010 print "<div style=\"float : right\">$updated_fmt,
1011 <a class=\"cdmToggleLink\"
1012 href=\"javascript:toggleUnread($id)\">Toggle unread</a>
1015 print "<a class=\"title\"
1016 onclick=\"javascript:toggleUnread($id, 0)\"
1017 target=\"new\" href=\"".$line["link"]."\">".$line["title"]."</a>";
1019 if ($line["feed_title"]) {
1020 print " (<a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>)";
1025 print "<div class=\"cdmContent\">" . $line["content_preview"] . "</div><br clear=\"all\">";
1027 print "<div style=\"float : right\">$marked_pic</div>
1028 <div lass=\"cdmFooter\">
1029 <input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
1030 'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\"></div>";
1032 # print "<div align=\"center\"><a class=\"cdmToggleLink\"
1033 # href=\"javascript:toggleUnread($id)\">
1034 # Toggle unread</a></div>";
1043 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1047 print_headline_subtoolbar($link,
1048 "javascript:catchupPage()", "Mark page as read", true, $rtl_content);
1052 print "<div width='100%' align='center'>No articles found.</div>";
1058 <script type=\"text/javascript\">
1060 document.onkeydown = hotkey_handler;
1062 parent.update_all_counters(\"$feed\");
1064 // this is workaround against mysterious permission
1065 // denied feature/bug of firefox (ticket #73)
1066 // if call from this context failed - ignore silently
1067 exception_error(\"viewfeed/footer1/counters\", e, true);
1070 exception_error(\"viewfeed/footer1\", e);
1074 function statechange() {
1075 if (document.readyState == \"interactive\") init();
1078 if (document.readyState) {
1079 if (document.readyState == \"interactive\" || document.readyState == \"complete\") {
1082 document.onreadystatechange = statechange;
1087 print "</body></html>";
1090 if ($op == "pref-feeds") {
1092 $subop = $_REQUEST["subop"];
1093 $quiet = $_REQUEST["quiet"];
1095 if ($subop == "massSubscribe") {
1096 $ids = split(",", db_escape_string($_GET["ids"]));
1098 $subscribed = array();
1100 foreach ($ids as $id) {
1101 $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds
1104 $feed_url = db_fetch_result($result, 0, "feed_url");
1105 $title = db_fetch_result($result, 0, "title");
1107 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
1108 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
1110 if (db_num_rows($result) == 0) {
1111 $result = db_query($link,
1112 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
1113 VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)");
1115 array_push($subscribed, $title);
1119 if (count($subscribed) > 0) {
1120 print "<div class=\"notice\">";
1121 print "<b>Subscribed to feeds:</b>";
1122 print "<ul class=\"nomarks\">";
1123 foreach ($subscribed as $title) {
1124 print "<li>$title</li>";
1131 if ($subop == "browse") {
1133 if (!ENABLE_FEED_BROWSER) {
1134 print "Feed browser is administratively disabled.";
1138 print "<div id=\"infoBoxTitle\">Other feeds: Top 25</div>";
1140 print "<div class=\"infoBoxContents\">";
1142 print "<p>Showing top 25 registered feeds, sorted by popularity:</p>";
1144 # $result = db_query($link, "SELECT feed_url,count(id) AS subscribers
1146 # WHERE auth_login = '' AND auth_pass = '' AND private = false
1147 # GROUP BY feed_url ORDER BY subscribers DESC LIMIT 25");
1149 $owner_uid = $_SESSION["uid"];
1151 $result = db_query($link, "SELECT feed_url,COUNT(id) AS subscribers
1152 FROM ttrss_feeds WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
1153 WHERE tf.feed_url = ttrss_feeds.feed_url
1154 AND owner_uid = '$owner_uid') GROUP BY feed_url
1155 ORDER BY subscribers DESC LIMIT 25");
1157 print "<ul class='browseFeedList' id='browseFeedList'>";
1161 while ($line = db_fetch_assoc($result)) {
1162 $feed_url = $line["feed_url"];
1163 $subscribers = $line["subscribers"];
1165 $det_result = db_query($link, "SELECT site_url,title,id
1166 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
1168 $details = db_fetch_assoc($det_result);
1170 $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
1172 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1173 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
1174 "/".$details["id"].".ico\">";
1176 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1179 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
1180 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
1182 $class = ($feedctr % 2) ? "even" : "odd";
1184 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
1185 "$feed_icon " . db_unescape_string($details["title"]) .
1186 " <span class='subscribers'>($subscribers)</span></li>";
1191 if ($feedctr == 0) {
1192 print "<li>No feeds found to subscribe.</li>";
1197 print "<div align='center'>
1198 <input type=\"submit\" class=\"button\"
1199 onclick=\"feedBrowserSubscribe()\" value=\"Subscribe\">
1200 <input type='submit' class='button'
1201 onclick=\"closeInfoBox()\" value=\"Cancel\"></div>";
1207 if ($subop == "editfeed") {
1208 $feed_id = db_escape_string($_REQUEST["id"]);
1210 $result = db_query($link,
1211 "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
1212 owner_uid = " . $_SESSION["uid"]);
1214 $title = htmlspecialchars(db_unescape_string(db_fetch_result($result,
1217 $icon_file = ICONS_DIR . "/$feed_id.ico";
1219 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1220 $feed_icon = "<img width=\"16\" height=\"16\"
1221 src=\"" . ICONS_URL . "/$feed_id.ico\">";
1226 print "<div id=\"infoBoxTitle\">Feed editor</div>";
1228 print "<div class=\"infoBoxContents\">";
1230 print "<form id=\"edit_feed_form\">";
1232 print "<input type=\"hidden\" name=\"id\" value=\"$feed_id\">";
1233 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
1234 print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
1236 print "<table width='100%'>";
1238 print "<tr><td>Title:</td>";
1239 print "<td><input class=\"iedit\" onkeypress=\"return filterCR(event)\"
1240 name=\"title\" value=\"$title\"></td></tr>";
1242 $feed_url = db_fetch_result($result, 0, "feed_url");
1243 $feed_url = htmlspecialchars(db_unescape_string(db_fetch_result($result,
1246 print "<tr><td>Feed URL:</td>";
1247 print "<td><input class=\"iedit\" onkeypress=\"return filterCR(event)\"
1248 name=\"feed_url\" value=\"$feed_url\"></td></tr>";
1250 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1252 $cat_id = db_fetch_result($result, 0, "cat_id");
1254 print "<tr><td>Category:</td>";
1257 print_feed_cat_select($link, "cat_id", $cat_id, "class=\"iedit\"");
1264 $update_interval = db_fetch_result($result, 0, "update_interval");
1266 print "<tr><td>Update Interval:</td>";
1270 print_select_hash("update_interval", $update_interval, $update_intervals,
1275 print "<tr><td>Link to:</td><td>";
1277 $tmp_result = db_query($link, "SELECT COUNT(id) AS count
1278 FROM ttrss_feeds WHERE parent_feed = '$feed_id'");
1280 $linked_count = db_fetch_result($tmp_result, 0, "count");
1282 $parent_feed = db_fetch_result($result, 0, "parent_feed");
1284 if ($linked_count > 0) {
1285 $disabled = "disabled";
1288 print "<select class=\"iedit\" $disabled name=\"parent_feed\">";
1290 print "<option value=\"0\">Not linked</option>";
1292 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1294 $cat_qpart = "AND cat_id = '$cat_id'";
1296 $cat_qpart = "AND cat_id IS NULL";
1300 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
1301 WHERE id != '$feed_id' AND owner_uid = ".$_SESSION["uid"]."
1302 $cat_qpart ORDER BY title");
1304 if (db_num_rows($tmp_result) > 0) {
1305 print "<option disabled>--------</option>";
1308 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1309 if ($tmp_line["id"] == $parent_feed) {
1310 $is_selected = "selected";
1314 printf("<option $is_selected value='%d'>%s</option>",
1315 $tmp_line["id"], $tmp_line["title"]);
1321 $purge_interval = db_fetch_result($result, 0, "purge_interval");
1323 print "<tr><td>Article purging:</td>";
1327 print_select_hash("purge_interval", $purge_interval, $purge_intervals,
1332 $auth_login = db_fetch_result($result, 0, "auth_login");
1334 print "<tr><td>Login:</td>";
1335 print "<td><input class=\"iedit\" onkeypress=\"return filterCR(event)\"
1336 name=\"auth_login\" value=\"$auth_login\"></td></tr>";
1338 $auth_pass = db_fetch_result($result, 0, "auth_pass");
1340 print "<tr><td>Password:</td>";
1341 print "<td><input class=\"iedit\" type=\"password\" name=\"auth_pass\"
1342 onkeypress=\"return filterCR(event)\"
1343 value=\"$auth_pass\"></td></tr>";
1345 $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
1348 $checked = "checked";
1353 print "<tr><td valign='top'>Options:</td>";
1354 print "<td><input type=\"checkbox\" name=\"private\" id=\"private\"
1355 $checked><label for=\"private\">Hide from feed browser</label>";
1357 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
1360 $checked = "checked";
1365 print "<br><input type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
1366 $checked><label for=\"rtl_content\">Right-to-left content</label>";
1376 print "<div align='center'>
1377 <input type=\"submit\" class=\"button\"
1378 onclick=\"return feedEditSave()\" value=\"Save\">
1379 <input type='submit' class='button'
1380 onclick=\"return feedEditCancel()\" value=\"Cancel\"></div>";
1384 if ($subop == "editSave") {
1386 $feed_title = db_escape_string(trim($_POST["title"]));
1387 $feed_link = db_escape_string(trim($_POST["feed_url"]));
1388 $upd_intl = db_escape_string($_POST["update_interval"]);
1389 $purge_intl = db_escape_string($_POST["purge_interval"]);
1390 $feed_id = db_escape_string($_POST["id"]);
1391 $cat_id = db_escape_string($_POST["cat_id"]);
1392 $auth_login = db_escape_string(trim($_POST["auth_login"]));
1393 $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
1394 $parent_feed = db_escape_string($_POST["parent_feed"]);
1395 $private = checkbox_to_sql_bool(db_escape_string($_POST["private"]));
1396 $rtl_content = checkbox_to_sql_bool(db_escape_string($_POST["rtl_content"]));
1398 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1399 if ($cat_id && $cat_id != 0) {
1400 $category_qpart = "cat_id = '$cat_id',";
1402 $category_qpart = 'cat_id = NULL,';
1405 $category_qpart = "";
1408 if ($parent_feed && $parent_feed != 0) {
1409 $parent_qpart = "parent_feed = '$parent_feed',";
1411 $parent_qpart = 'parent_feed = NULL,';
1414 $result = db_query($link, "UPDATE ttrss_feeds SET
1417 title = '$feed_title', feed_url = '$feed_link',
1418 update_interval = '$upd_intl',
1419 purge_interval = '$purge_intl',
1420 auth_login = '$auth_login',
1421 auth_pass = '$auth_pass',
1423 rtl_content = $rtl_content
1424 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
1427 if ($subop == "saveCat") {
1428 $cat_title = db_escape_string(trim($_GET["title"]));
1429 $cat_id = db_escape_string($_GET["id"]);
1431 $result = db_query($link, "UPDATE ttrss_feed_categories SET
1432 title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
1436 if ($subop == "remove") {
1438 if (!WEB_DEMO_MODE) {
1440 $ids = split(",", db_escape_string($_GET["ids"]));
1442 foreach ($ids as $id) {
1446 db_query($link, "DELETE FROM ttrss_feeds
1447 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1449 $icons_dir = ICONS_DIR;
1451 if (file_exists($icons_dir . "/$id.ico")) {
1452 unlink($icons_dir . "/$id.ico");
1454 } else if ($id < -10) {
1456 $label_id = -$id - 11;
1458 db_query($link, "DELETE FROM ttrss_labels
1459 WHERE id = '$label_id' AND owner_uid = " . $_SESSION["uid"]);
1465 if ($subop == "add") {
1467 if (!WEB_DEMO_MODE) {
1469 $feed_url = db_escape_string(trim($_GET["feed_url"]));
1470 $cat_id = db_escape_string($_GET["cat_id"]);
1472 if (subscribe_to_feed($link, $feed_url, $cat_id)) {
1473 print "Added feed.";
1475 print "<div class=\"warning\">
1476 Feed <b>$feed_url</b> already exists in the database.
1482 if ($subop == "addCat") {
1484 if (!WEB_DEMO_MODE) {
1486 $feed_cat = db_escape_string(trim($_GET["cat"]));
1488 $result = db_query($link,
1489 "SELECT id FROM ttrss_feed_categories
1490 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
1492 if (db_num_rows($result) == 0) {
1494 $result = db_query($link,
1495 "INSERT INTO ttrss_feed_categories (owner_uid,title)
1496 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
1500 print "<div class=\"warning\">
1501 Category <b>$feed_cat</b> already exists in the database.
1509 if ($subop == "removeCats") {
1511 if (!WEB_DEMO_MODE) {
1513 $ids = split(",", db_escape_string($_GET["ids"]));
1515 foreach ($ids as $id) {
1517 db_query($link, "BEGIN");
1519 $result = db_query($link,
1520 "SELECT count(id) as num_feeds FROM ttrss_feeds
1521 WHERE cat_id = '$id'");
1523 $num_feeds = db_fetch_result($result, 0, "num_feeds");
1525 if ($num_feeds == 0) {
1526 db_query($link, "DELETE FROM ttrss_feed_categories
1527 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1530 print "<div class=\"warning\">
1531 Unable to delete non empty feed categories.</div>";
1535 db_query($link, "COMMIT");
1540 if ($subop == "categorize") {
1542 if (!WEB_DEMO_MODE) {
1544 $ids = split(",", db_escape_string($_GET["ids"]));
1546 $cat_id = db_escape_string($_GET["cat_id"]);
1549 $cat_id_qpart = 'NULL';
1551 $cat_id_qpart = "'$cat_id'";
1554 db_query($link, "BEGIN");
1556 foreach ($ids as $id) {
1558 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
1559 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1562 db_query($link, "COMMIT");
1569 // print "<h3>Edit Feeds</h3>";
1571 $result = db_query($link, "SELECT id,title,feed_url,last_error
1572 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1574 if (db_num_rows($result) > 0) {
1576 print "<div class=\"warning\">";
1578 // print"<img class=\"closeButton\"
1579 // onclick=\"javascript:hideParentElement(this);\" src=\"images/close.png\">";
1581 print "<a href=\"javascript:showBlockElement('feedUpdateErrors')\">
1582 <b>Some feeds have update errors (click for details)</b></a>";
1584 print "<ul id=\"feedUpdateErrors\" class=\"nomarks\">";
1586 while ($line = db_fetch_assoc($result)) {
1587 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
1588 $line["last_error"];
1596 $feed_search = db_escape_string($_GET["search"]);
1598 if (array_key_exists("search", $_GET)) {
1599 $_SESSION["prefs_feed_search"] = $feed_search;
1601 $feed_search = $_SESSION["prefs_feed_search"];
1604 print "<table width='100%' class=\"prefGenericAddBox\"
1605 cellspacing='0' cellpadding='0'><tr>
1607 <input id=\"fadd_link\"
1608 onkeyup=\"toggleSubmitNotEmpty(this, 'fadd_submit_btn')\"
1610 <input type=\"submit\" class=\"button\"
1611 disabled=\"true\" id=\"fadd_submit_btn\"
1612 onclick=\"addFeed()\" value=\"Subscribe\">";
1614 if (ENABLE_FEED_BROWSER && !SINGLE_USER_MODE) {
1615 print " <input type=\"submit\" class=\"button\"
1616 onclick=\"javascript:browseFeeds()\" value=\"Top 25\">";
1619 print "</td><td align='right'>
1620 <input id=\"feed_search\" size=\"20\"
1621 onchange=\"javascript:updateFeedList()\" value=\"$feed_search\">
1622 <input type=\"submit\" class=\"button\"
1623 onclick=\"javascript:updateFeedList()\" value=\"Search\">
1627 $feeds_sort = db_escape_string($_GET["sort"]);
1629 if (!$feeds_sort || $feeds_sort == "undefined") {
1630 $feeds_sort = $_SESSION["pref_sort_feeds"];
1631 if (!$feeds_sort) $feeds_sort = "title";
1634 $_SESSION["pref_sort_feeds"] = $feeds_sort;
1637 $search_qpart = "(UPPER(F1.title) LIKE UPPER('%$feed_search%') OR
1638 UPPER(F1.feed_url) LIKE UPPER('%$feed_search%')) AND";
1643 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1644 $order_by_qpart = "category,$feeds_sort,title";
1646 $order_by_qpart = "$feeds_sort,title";
1649 $result = db_query($link, "SELECT
1653 substring(F1.last_updated,1,16) AS last_updated,
1658 F2.title AS parent_title,
1659 C1.title AS category
1662 LEFT JOIN ttrss_feeds AS F2
1663 ON (F1.parent_feed = F2.id)
1664 LEFT JOIN ttrss_feed_categories AS C1
1665 ON (F1.cat_id = C1.id)
1667 $search_qpart F1.owner_uid = '".$_SESSION["uid"]."'
1668 ORDER by $order_by_qpart");
1670 if (db_num_rows($result) != 0) {
1672 // print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1674 print "<p><table width=\"100%\" cellspacing=\"0\"
1675 class=\"prefFeedList\" id=\"prefFeedList\">";
1676 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1678 <a href=\"javascript:selectPrefRows('feed', true)\">All</a>,
1679 <a href=\"javascript:selectPrefRows('feed', false)\">None</a>
1682 if (!get_pref($link, 'ENABLE_FEED_CATS')) {
1683 print "<tr class=\"title\">
1684 <td width='5%' align='center'> </td>";
1686 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1687 print "<td width='3%'> </td>";
1691 <td width='40%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
1692 <td width='45%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
1693 <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
1700 while ($line = db_fetch_assoc($result)) {
1702 $feed_id = $line["id"];
1703 $cat_id = $line["cat_id"];
1705 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1706 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
1707 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
1709 if (!$edit_cat) $edit_cat = "Uncategorized";
1711 $last_updated = $line["last_updated"];
1713 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1714 $last_updated = smart_date_time(strtotime($last_updated));
1716 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1717 $last_updated = date($short_date, strtotime($last_updated));
1720 if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
1723 print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>";
1725 print "<tr class=\"title\">
1726 <td width='5%'> </td>";
1728 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1729 print "<td width='3%'> </td>";
1732 print "<td width='40%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
1733 <td width='45%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
1734 <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
1736 $cur_cat_id = $cat_id;
1739 $class = ($lnum % 2) ? "even" : "odd";
1740 $this_row_id = "id=\"FEEDR-$feed_id\"";
1742 print "<tr class=\"$class\" $this_row_id>";
1744 $icon_file = ICONS_DIR . "/$feed_id.ico";
1746 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1747 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/$feed_id.ico\">";
1749 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1752 print "<td class='feedSelect'><input onclick='toggleSelectPrefRow(this, \"feed\");'
1753 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
1755 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1756 print "<td class='feedIcon'>$feed_icon</td>";
1759 $edit_title = truncate_string($edit_title, 40);
1760 $edit_link = truncate_string($edit_link, 60);
1762 $parent_title = $line["parent_title"];
1763 if ($parent_title) {
1764 $parent_title = "<span class='groupPrompt'>(linked to
1765 $parent_title)</span>";
1768 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1769 "$edit_title $parent_title" . "</a></td>";
1771 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1772 $edit_link . "</a></td>";
1774 print "<td align='right'><a href=\"javascript:editFeed($feed_id);\">" .
1775 "$last_updated</a></td>";
1784 print "<p><span id=\"feedOpToolbar\">";
1786 if ($subop == "edit") {
1787 print "Edit feed:
1788 <input type=\"submit\" class=\"button\"
1789 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
1790 <input type=\"submit\" class=\"button\"
1791 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1796 <input type=\"submit\" class=\"button\" disabled=\"true\"
1797 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
1798 <input type=\"submit\" class=\"button\" disabled=\"true\"
1799 onclick=\"javascript:removeSelectedFeeds()\" value=\"Unsubscribe\">";
1801 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1803 print " | ";
1805 print_feed_cat_select($link, "sfeed_set_fcat", "", "disabled");
1807 print " <input type=\"submit\" class=\"button\" disabled=\"true\"
1808 onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Recategorize\">";
1813 All feeds: <input type=\"submit\"
1814 class=\"button\" onclick=\"gotoExportOpml()\"
1815 value=\"Export OPML\">";
1819 print "<p>No feeds defined.</p>";
1823 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1825 print "<h3>Edit Categories</h3>";
1827 print "<div class=\"prefGenericAddBox\">
1828 <input id=\"fadd_cat\"
1829 onkeyup=\"toggleSubmitNotEmpty(this, 'catadd_submit_btn')\"
1832 type=\"submit\" class=\"button\" disabled=\"true\" id=\"catadd_submit_btn\"
1833 onclick=\"javascript:addFeedCat()\" value=\"Create category\"></div>";
1835 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1836 WHERE owner_uid = ".$_SESSION["uid"]."
1839 if (db_num_rows($result) != 0) {
1841 print "<form id=\"feed_cat_edit_form\">";
1843 print "<p><table width=\"100%\" class=\"prefFeedCatList\"
1844 cellspacing=\"0\" id=\"prefFeedCatList\">";
1846 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1848 <a href=\"javascript:selectPrefRows('fcat', true)\">All</a>,
1849 <a href=\"javascript:selectPrefRows('fcat', false)\">None</a>
1852 print "<tr class=\"title\">
1853 <td width=\"5%\"> </td><td width=\"80%\">Title</td>
1858 while ($line = db_fetch_assoc($result)) {
1860 $class = ($lnum % 2) ? "even" : "odd";
1862 $cat_id = $line["id"];
1864 $edit_cat_id = $_GET["id"];
1866 if ($subop == "editCat" && $cat_id != $edit_cat_id) {
1870 $this_row_id = "id=\"FCATR-$cat_id\"";
1873 print "<tr class=\"$class\" $this_row_id>";
1875 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1877 if (!$edit_cat_id || $subop != "editCat") {
1879 print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"fcat\");'
1880 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
1882 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
1883 $edit_title . "</a></td>";
1885 } else if ($cat_id != $edit_cat_id) {
1887 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
1888 id=\"FRCHK-".$line["id"]."\"></td>";
1890 print "<td>$edit_title</td>";
1894 print "<td align='center'><input disabled=\"true\" type=\"checkbox\" checked>";
1896 print "<input type=\"hidden\" name=\"id\" value=\"$cat_id\">";
1897 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
1898 print "<input type=\"hidden\" name=\"subop\" value=\"saveCat\">";
1902 print "<td><input onkeypress=\"return filterCR(event)\"
1903 name=\"title\" class=\"iedit\" value=\"$edit_title\"></td>";
1916 print "<p id=\"catOpToolbar\">";
1918 if ($subop == "editCat") {
1919 print "Edit category:
1920 <input type=\"submit\" class=\"button\"
1921 onclick=\"return feedCatEditSave()\" value=\"Save\">
1922 <input type=\"submit\" class=\"button\"
1923 onclick=\"return feedCatEditCancel()\" value=\"Cancel\">";
1928 <input type=\"submit\" class=\"button\" disabled=\"true\"
1929 onclick=\"return editSelectedFeedCat()\" value=\"Edit\">
1930 <input type=\"submit\" class=\"button\" disabled=\"true\"
1931 onclick=\"return removeSelectedFeedCats()\" value=\"Remove\">";
1936 print "<p>No feed categories defined.</p>";
1940 print "<h3>Import OPML</h3>
1941 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1942 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">
1943 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
1944 type=\"submit\" value=\"Import\">
1949 if ($op == "pref-filters") {
1951 $subop = $_GET["subop"];
1952 $quiet = $_GET["quiet"];
1954 if ($subop == "edit") {
1956 $filter_id = db_escape_string($_GET["id"]);
1958 $result = db_query($link,
1959 "SELECT * FROM ttrss_filters WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
1961 $reg_exp = htmlspecialchars(db_unescape_string(db_fetch_result($result, 0, "reg_exp")));
1962 $filter_type = db_fetch_result($result, 0, "filter_type");
1963 $feed_id = db_fetch_result($result, 0, "feed_id");
1964 $action_id = db_fetch_result($result, 0, "action_id");
1966 print "<div id=\"infoBoxTitle\">Filter editor</div>";
1967 print "<div class=\"infoBoxContents\">";
1969 print "<form id=\"filter_edit_form\">";
1971 print "<input type=\"hidden\" name=\"op\" value=\"pref-filters\">";
1972 print "<input type=\"hidden\" name=\"id\" value=\"$filter_id\">";
1973 print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
1975 // print "<div class=\"notice\"><b>Note:</b> filter will only apply to new articles.</div>";
1977 $result = db_query($link, "SELECT id,description
1978 FROM ttrss_filter_types ORDER BY description");
1980 $filter_types = array();
1982 while ($line = db_fetch_assoc($result)) {
1983 //array_push($filter_types, $line["description"]);
1984 $filter_types[$line["id"]] = $line["description"];
1987 print "<table width='100%'>";
1989 print "<tr><td>Match:</td>
1990 <td><input onkeypress=\"return filterCR(event)\"
1991 onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
1992 name=\"reg_exp\" class=\"iedit\" value=\"$reg_exp\">";
1996 print_select_hash("filter_type", $filter_type, $filter_types, "class=\"iedit\"");
1999 print "<tr><td>Feed:</td><td colspan='2'>";
2001 print_feed_select($link, "feed_id", $feed_id);
2005 print "<tr><td>Action:</td>";
2007 print "<td colspan='2'><select name=\"action_id\">";
2009 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2012 while ($line = db_fetch_assoc($result)) {
2013 $is_sel = ($line["id"] == $action_id) ? "selected" : "";
2014 printf("<option value='%d' $is_sel>%s</option>", $line["id"], $line["description"]);
2019 print "</td></tr></table>";
2023 print "<div align='right'>";
2025 print "<input type=\"submit\"
2026 id=\"infobox_submit\"
2027 class=\"button\" onclick=\"return filterEditSave()\"
2030 print "<input class=\"button\"
2031 type=\"submit\" onclick=\"return filterEditCancel()\"
2040 if ($subop == "editSave") {
2042 $reg_exp = db_escape_string(trim($_GET["reg_exp"]));
2043 $filter_type = db_escape_string(trim($_GET["filter_type"]));
2044 $filter_id = db_escape_string($_GET["id"]);
2045 $feed_id = db_escape_string($_GET["feed_id"]);
2046 $action_id = db_escape_string($_GET["action_id"]);
2051 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2054 $result = db_query($link, "UPDATE ttrss_filters SET
2055 reg_exp = '$reg_exp',
2057 action_id = '$action_id',
2058 filter_type = '$filter_type'
2059 WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
2062 if ($subop == "remove") {
2064 if (!WEB_DEMO_MODE) {
2066 $ids = split(",", db_escape_string($_GET["ids"]));
2068 foreach ($ids as $id) {
2069 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
2075 if ($subop == "add") {
2077 if (!WEB_DEMO_MODE) {
2079 $regexp = db_escape_string(trim($_GET["reg_exp"]));
2080 $filter_type = db_escape_string(trim($_GET["filter_type"]));
2081 $feed_id = db_escape_string($_GET["feed_id"]);
2082 $action_id = db_escape_string($_GET["action_id"]);
2087 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2090 $result = db_query($link,
2091 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
2094 ('$regexp', '$filter_type','".$_SESSION["uid"]."',
2095 $feed_id, '$action_id')");
2101 // print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2103 $result = db_query($link, "SELECT id,description
2104 FROM ttrss_filter_types ORDER BY description");
2106 $filter_types = array();
2108 while ($line = db_fetch_assoc($result)) {
2109 //array_push($filter_types, $line["description"]);
2110 $filter_types[$line["id"]] = $line["description"];
2113 print "<input type=\"submit\"
2115 onclick=\"return displayDlg('quickAddFilter', false)\"
2116 id=\"create_filter_btn\"
2117 value=\"Create filter\">";
2119 $result = db_query($link, "SELECT
2120 ttrss_filters.id AS id,reg_exp,
2121 ttrss_filter_types.name AS filter_type_name,
2122 ttrss_filter_types.description AS filter_type_descr,
2124 ttrss_filter_actions.description AS action_description,
2125 ttrss_feeds.title AS feed_title
2127 ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN
2128 ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id)
2130 filter_type = ttrss_filter_types.id AND
2131 ttrss_filter_actions.id = action_id AND
2132 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
2135 if (db_num_rows($result) != 0) {
2137 print "<form id=\"filter_edit_form\">";
2139 print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\"
2140 id=\"prefFilterList\">";
2142 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2144 <a href=\"javascript:selectPrefRows('filter', true)\">All</a>,
2145 <a href=\"javascript:selectPrefRows('filter', false)\">None</a>
2148 print "<tr class=\"title\">
2149 <td align='center' width=\"5%\"> </td>
2150 <td width=\"20%\">Filter expression</td>
2151 <td width=\"20%\">Feed</td>
2152 <td width=\"15%\">Match</td>
2153 <td width=\"15%\">Action</td>";
2157 while ($line = db_fetch_assoc($result)) {
2159 $class = ($lnum % 2) ? "even" : "odd";
2161 $filter_id = $line["id"];
2162 $edit_filter_id = $_GET["id"];
2164 if ($subop == "edit" && $filter_id != $edit_filter_id) {
2168 $this_row_id = "id=\"FILRR-$filter_id\"";
2171 print "<tr class=\"$class\" $this_row_id>";
2173 $line["reg_exp"] = htmlspecialchars(db_unescape_string($line["reg_exp"]));
2175 if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
2177 $line["feed_title"] = htmlspecialchars(db_unescape_string($line["feed_title"]));
2179 print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"filter\");'
2180 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
2182 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2183 $line["reg_exp"] . "</td>";
2185 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2186 $line["feed_title"] . "</td>";
2188 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2189 $line["filter_type_descr"] . "</td>";
2191 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2192 $line["action_description"] . "</td>";
2200 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
2207 print "<p id=\"filterOpToolbar\">";
2211 <input type=\"submit\" class=\"button\" disabled=\"true\"
2212 onclick=\"return editSelectedFilter()\" value=\"Edit\">
2213 <input type=\"submit\" class=\"button\" disabled=\"true\"
2214 onclick=\"return removeSelectedFilters()\" value=\"Remove\">";
2220 print "<p>No filters defined.</p>";
2225 // We need to accept raw SQL data in label queries, so not everything is escaped
2226 // here, this is by design. If you don't like the whole idea, disable labels
2227 // altogether with GLOBAL_ENABLE_LABELS = false
2229 if ($op == "pref-labels") {
2231 if (!GLOBAL_ENABLE_LABELS) {
2235 $subop = $_GET["subop"];
2237 if ($subop == "test") {
2239 $expr = db_unescape_string(trim($_GET["expr"]));
2240 $descr = db_unescape_string(trim($_GET["descr"]));
2242 print "<div id=\"infoBoxTitle\">Test label: $descr</div>";
2244 print "<div class='infoBoxContents'>";
2246 # print "<h1>Label «$descr»</h1>";
2248 // print "<p><b>Expression</b>: $expr</p>";
2250 $result = db_query($link,
2251 "SELECT count(ttrss_entries.id) AS num_matches
2252 FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
2254 ttrss_user_entries.ref_id = ttrss_entries.id AND
2255 ttrss_user_entries.feed_id = ttrss_feeds.id AND
2256 ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
2258 $num_matches = db_fetch_result($result, 0, "num_matches");;
2260 if ($num_matches > 0) {
2262 print "<p>Query returned <b>$num_matches</b> matches, showing first 15:</p>";
2264 $result = db_query($link,
2265 "SELECT ttrss_entries.title,
2266 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
2267 FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
2269 ttrss_user_entries.ref_id = ttrss_entries.id
2270 AND ttrss_user_entries.feed_id = ttrss_feeds.id
2271 AND ttrss_user_entries.owner_uid = " . $_SESSION["uid"] . "
2272 ORDER BY date_entered DESC LIMIT 15");
2274 print "<ul class=\"filterTestResults\">";
2276 $row_class = "even";
2278 while ($line = db_fetch_assoc($result)) {
2279 $row_class = toggleEvenOdd($row_class);
2281 print "<li class=\"$row_class\">".$line["title"].
2282 " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
2287 print "<p>Query didn't return any matches.</p>";
2292 print "<div align='center'>
2293 <input type='submit' class='button'
2294 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2298 if ($subop == "editSave") {
2300 $sql_exp = trim($_GET["sql_exp"]);
2301 $descr = db_escape_string(trim($_GET["description"]));
2302 $label_id = db_escape_string($_GET["id"]);
2304 $result = db_query($link, "UPDATE ttrss_labels SET
2305 sql_exp = '$sql_exp',
2306 description = '$descr'
2307 WHERE id = '$label_id'");
2310 if ($subop == "remove") {
2312 if (!WEB_DEMO_MODE) {
2314 $ids = split(",", db_escape_string($_GET["ids"]));
2316 foreach ($ids as $id) {
2317 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
2323 if ($subop == "add") {
2325 if (!WEB_DEMO_MODE) {
2327 // no escaping is done here on purpose
2328 $exp = trim($_GET["exp"]);
2330 $result = db_query($link,
2331 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
2332 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
2336 print "<div class=\"prefGenericAddBox\">
2338 onkeyup=\"toggleSubmitNotEmpty(this, 'label_create_btn')\"
2339 id=\"ladd_expr\"> ";
2341 print"<input type=\"submit\" class=\"button\"
2342 disabled=\"true\" id=\"label_create_btn\"
2343 onclick=\"javascript:addLabel()\" value=\"Create label\"></div>";
2345 $result = db_query($link, "SELECT
2346 id,sql_exp,description
2350 owner_uid = ".$_SESSION["uid"]."
2351 ORDER by description");
2353 // print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2355 if (db_num_rows($result) != 0) {
2357 print "<form id=\"label_edit_form\">";
2359 print "<p><table width=\"100%\" cellspacing=\"0\"
2360 class=\"prefLabelList\" id=\"prefLabelList\">";
2362 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2364 <a href=\"javascript:selectPrefRows('label', true)\">All</a>,
2365 <a href=\"javascript:selectPrefRows('label', false)\">None</a>
2368 print "<tr class=\"title\">
2369 <td width=\"5%\"> </td>
2370 <td width=\"40%\">SQL expression
2371 <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a>
2373 <td width=\"40%\">Caption</td></tr>";
2377 while ($line = db_fetch_assoc($result)) {
2379 $class = ($lnum % 2) ? "even" : "odd";
2381 $label_id = $line["id"];
2382 $edit_label_id = $_GET["id"];
2384 if ($subop == "edit" && $label_id != $edit_label_id) {
2388 $this_row_id = "id=\"LILRR-$label_id\"";
2391 print "<tr class=\"$class\" $this_row_id>";
2393 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
2394 $line["description"] = htmlspecialchars($line["description"]);
2396 if (!$edit_label_id || $subop != "edit") {
2398 if (!$line["description"]) $line["description"] = "[No caption]";
2400 print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"label\");'
2401 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
2403 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2404 $line["sql_exp"] . "</td>";
2406 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2407 $line["description"] . "</td>";
2409 } else if ($label_id != $edit_label_id) {
2411 if (!$line["description"]) $line["description"] = "[No description]";
2413 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
2414 id=\"LICHK-".$line["id"]."\"></td>";
2416 print "<td>".$line["sql_exp"]."</td>";
2417 print "<td>".$line["description"]."</td>";
2421 print "<td align='center'><input disabled=\"true\" type=\"checkbox\" checked>";
2423 print "<input type=\"hidden\" name=\"id\" value=\"$label_id\">";
2424 print "<input type=\"hidden\" name=\"op\" value=\"pref-labels\">";
2425 print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
2429 print "<td><input onkeypress=\"return filterCR(event)\"
2430 class=\"iedit\" name=\"sql_exp\" value=\"".$line["sql_exp"]."\"></td>";
2432 print "<td><input onkeypress=\"return filterCR(event)\"
2433 class=\"iedit\" name=\"description\" value=\"".$line["description"]."\"></td>";
2443 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
2450 print "<p id=\"labelOpToolbar\">";
2452 if ($subop == "edit") {
2454 <input type=\"submit\" class=\"button\"
2455 onclick=\"javascript:labelTest()\" value=\"Test\">
2456 <input type=\"submit\" class=\"button\"
2457 onclick=\"javascript:labelEditSave()\" value=\"Save\">
2458 <input type=\"submit\" class=\"button\"
2459 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">";
2464 <input type=\"submit\" class=\"button\" disabled=\"true\"
2465 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
2466 <input type=\"submit\" class=\"button\" disabled=\"true\"
2467 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
2470 print "<p>No labels defined.</p>";
2474 if ($op == "error") {
2475 print "<div width=\"100%\" align='center'>";
2476 $msg = $_GET["msg"];
2481 if ($op == "help") {
2482 if (!$_GET["noheaders"]) {
2484 <title>Tiny Tiny RSS : Help</title>
2485 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2486 <script type=\"text/javascript\" src=\"prototype.js\"></script>
2487 <script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
2488 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2492 $tid = sprintf("%d", $_GET["tid"]);
2494 print "<div id=\"infoBoxTitle\">Help</div>";
2496 print "<div class='infoBoxContents'>";
2498 if (file_exists("help/$tid.php")) {
2499 include("help/$tid.php");
2501 print "<p>Help topic not found.</p>";
2506 print "<div align='center'>
2507 <input type='submit' class='button'
2508 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2510 if (!$_GET["noheaders"]) {
2511 print "</body></html>";
2518 $param = $_GET["param"];
2520 if ($id == "quickAddFeed") {
2522 print "<div id=\"infoBoxTitle\">Subscribe to feed</div>";
2523 print "<div class=\"infoBoxContents\">";
2525 print "<form id='feed_add_form'>";
2527 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
2528 print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
2529 print "<input type=\"hidden\" name=\"subop\" value=\"add\">";
2531 print "<table width='100%'>
2532 <tr><td>Feed URL:</td><td>
2533 <input class=\"iedit\" onblur=\"javascript:enableHotkeys()\"
2534 onkeypress=\"return filterCR(event)\"
2535 onkeyup=\"toggleSubmitNotEmpty(this, 'fadd_submit_btn')\"
2536 onfocus=\"javascript:disableHotkeys()\" name=\"feed_url\"></td></tr>";
2538 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2539 print "<tr><td>Category:</td><td>";
2540 print_feed_cat_select($link, "cat_id");
2547 print "<div align='right'>
2548 <input class=\"button\"
2549 id=\"fadd_submit_btn\" disabled=\"true\"
2550 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Subscribe\">
2551 <input class=\"button\"
2552 type=\"submit\" onclick=\"javascript:closeInfoBox()\"
2553 value=\"Cancel\"></div>";
2557 if ($id == "search") {
2559 print "<div id=\"infoBoxTitle\">Search</div>";
2560 print "<div class=\"infoBoxContents\">";
2562 print "<form id='search_form'>";
2564 #$active_feed_id = db_escape_string($_GET["param"]);
2566 $params = split(":", db_escape_string($_GET["param"]));
2568 $active_feed_id = sprintf("%d", $params[0]);
2569 $is_cat = $params[1] == "true";
2571 print "<table width='100%'><tr><td>Search:</td><td>";
2573 print "<input name=\"query\" class=\"iedit\"
2574 onkeypress=\"return filterCR(event)\"
2575 onkeyup=\"toggleSubmitNotEmpty(this, 'search_submit_btn')\"
2579 print "<tr><td>Where:</td><td>";
2581 print "<select name=\"search_mode\">
2582 <option value=\"all_feeds\">All feeds</option>";
2584 $feed_title = getFeedTitle($link, $active_feed_id);
2587 $feed_cat_title = getFeedCatTitle($link, $active_feed_id);
2589 $feed_cat_title = getCategoryTitle($link, $active_feed_id);
2592 if ($active_feed_id && !$is_cat) {
2593 print "<option selected value=\"this_feed\">This feed ($feed_title)</option>";
2595 print "<option disabled>This feed</option>";
2599 $cat_preselected = "selected";
2602 if (get_pref($link, 'ENABLE_FEED_CATS') && ($active_feed_id > 0 || $is_cat)) {
2603 print "<option $cat_preselected value=\"this_cat\">This category ($feed_cat_title)</option>";
2605 print "<option disabled>This category</option>";
2608 print "</select></td></tr>";
2610 print "<tr><td>Match on:</td><td>";
2612 $search_fields = array(
2614 "content" => "Content",
2615 "both" => "Title or content");
2617 print_select_hash("match_on", 3, $search_fields);
2619 print "</td></tr></table>";
2623 print "<div align=\"right\">
2624 <input type=\"submit\"
2625 class=\"button\" onclick=\"javascript:search()\"
2626 id=\"search_submit_btn\" disabled=\"true\"
2628 <input class=\"button\"
2629 type=\"submit\" onclick=\"javascript:searchCancel()\"
2630 value=\"Cancel\"></div>";
2636 if ($id == "quickAddFilter") {
2638 $active_feed_id = db_escape_string($_GET["param"]);
2640 print "<div id=\"infoBoxTitle\">Create filter</div>";
2641 print "<div class=\"infoBoxContents\">";
2643 print "<form id=\"filter_add_form\">";
2645 print "<input type=\"hidden\" name=\"op\" value=\"pref-filters\">";
2646 print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
2647 print "<input type=\"hidden\" name=\"subop\" value=\"add\">";
2649 // print "<div class=\"notice\"><b>Note:</b> filter will only apply to new articles.</div>";
2651 $result = db_query($link, "SELECT id,description
2652 FROM ttrss_filter_types ORDER BY description");
2654 $filter_types = array();
2656 while ($line = db_fetch_assoc($result)) {
2657 //array_push($filter_types, $line["description"]);
2658 $filter_types[$line["id"]] = $line["description"];
2661 print "<table width='100%'>";
2663 print "<tr><td>Match:</td>
2664 <td><input onkeypress=\"return filterCR(event)\"
2665 onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
2666 name=\"reg_exp\" class=\"iedit\">";
2669 print_select_hash("filter_type", 1, $filter_types, "class=\"iedit\"");
2672 print "<tr><td>Feed:</td><td colspan='2'>";
2674 print_feed_select($link, "feed_id", $active_feed_id);
2678 print "<tr><td>Action:</td>";
2680 print "<td colspan='2'><select name=\"action_id\">";
2682 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2685 while ($line = db_fetch_assoc($result)) {
2686 printf("<option value='%d'>%s</option>", $line["id"], $line["description"]);
2691 print "</td></tr></table>";
2695 print "<div align='right'>";
2697 print "<input type=\"submit\"
2698 id=\"infobox_submit\"
2699 class=\"button\" onclick=\"return qaddFilter()\"
2700 disabled=\"true\" value=\"Create\"> ";
2702 print "<input class=\"button\"
2703 type=\"submit\" onclick=\"return closeInfoBox()\"
2708 // print "</td></tr></table>";
2716 // update feeds of all users, may be used anonymously
2717 if ($op == "globalUpdateFeeds") {
2719 $result = db_query($link, "SELECT id FROM ttrss_users");
2721 while ($line = db_fetch_assoc($result)) {
2722 $user_id = $line["id"];
2723 // print "<!-- updating feeds of uid $user_id -->";
2724 update_all_feeds($link, false, $user_id);
2728 <message msg=\"All feeds updated\"/>
2733 if ($op == "pref-prefs") {
2735 $subop = $_REQUEST["subop"];
2737 if ($subop == "Save configuration") {
2739 if (WEB_DEMO_MODE) {
2740 header("Location: prefs.php");
2744 $_SESSION["prefs_op_result"] = "save-config";
2746 $_SESSION["prefs_cache"] = false;
2748 foreach (array_keys($_POST) as $pref_name) {
2750 $pref_name = db_escape_string($pref_name);
2751 $value = db_escape_string($_POST[$pref_name]);
2753 $result = db_query($link, "SELECT type_name
2754 FROM ttrss_prefs,ttrss_prefs_types
2755 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
2757 if (db_num_rows($result) > 0) {
2759 $type_name = db_fetch_result($result, 0, "type_name");
2761 // print "$pref_name : $type_name : $value<br>";
2763 if ($type_name == "bool") {
2764 if ($value == "1") {
2769 } else if ($type_name == "integer") {
2770 $value = sprintf("%d", $value);
2773 // print "$pref_name : $type_name : $value<br>";
2775 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
2776 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
2780 header("Location: prefs.php");
2784 } else if ($subop == "getHelp") {
2786 $pref_name = db_escape_string($_GET["pn"]);
2788 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
2789 WHERE pref_name = '$pref_name'");
2791 if (db_num_rows($result) > 0) {
2792 $help_text = db_fetch_result($result, 0, "help_text");
2795 print "Unknown option: $pref_name";
2798 } else if ($subop == "Change e-mail") {
2800 if (WEB_DEMO_MODE) {
2801 header("Location: prefs.php");
2805 $email = db_escape_string($_GET["email"]);
2806 $active_uid = $_SESSION["uid"];
2809 db_query($link, "UPDATE ttrss_users SET email = '$email'
2810 WHERE id = '$active_uid'");
2813 header("Location: prefs.php");
2815 } else if ($subop == "Change password") {
2817 if (WEB_DEMO_MODE) {
2818 header("Location: prefs.php");
2822 $old_pw = $_POST["OLD_PASSWORD"];
2823 $new_pw = $_POST["OLD_PASSWORD"];
2825 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
2826 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
2828 $active_uid = $_SESSION["uid"];
2830 if ($old_pw && $new_pw) {
2832 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
2834 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
2835 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
2836 pwd_hash = '$old_pw_hash')");
2838 if (db_num_rows($result) == 1) {
2839 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
2840 WHERE id = '$active_uid'");
2842 $_SESSION["pwd_change_result"] = "ok";
2844 $_SESSION["pwd_change_result"] = "failed";
2848 header("Location: prefs.php");
2850 } else if ($subop == "Reset to defaults") {
2852 if (WEB_DEMO_MODE) {
2853 header("Location: prefs.php");
2857 $_SESSION["prefs_op_result"] = "reset-to-defaults";
2859 if (DB_TYPE == "pgsql") {
2860 db_query($link,"UPDATE ttrss_user_prefs
2861 SET value = ttrss_prefs.def_value
2862 WHERE owner_uid = '".$_SESSION["uid"]."' AND
2863 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
2865 db_query($link, "DELETE FROM ttrss_user_prefs
2866 WHERE owner_uid = ".$_SESSION["uid"]);
2867 initialize_user_prefs($link, $_SESSION["uid"]);
2870 header("Location: prefs.php");
2872 } else if ($subop == "Change theme") {
2874 $theme = db_escape_string($_POST["theme"]);
2876 if ($theme == "Default") {
2877 $theme_qpart = 'NULL';
2879 $theme_qpart = "'$theme'";
2882 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
2883 WHERE theme_name = '$theme'");
2885 if (db_num_rows($result) == 1) {
2886 $theme_id = db_fetch_result($result, 0, "id");
2887 $theme_path = db_fetch_result($result, 0, "theme_path");
2893 db_query($link, "UPDATE ttrss_users SET
2894 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
2896 $_SESSION["theme"] = $theme_path;
2898 header("Location: prefs.php");
2902 if (!SINGLE_USER_MODE) {
2904 $result = db_query($link, "SELECT id,email FROM ttrss_users
2905 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
2906 pwd_hash = 'SHA1:".sha1("password")."')");
2908 if (db_num_rows($result) != 0) {
2909 print "<div class=\"warning\">
2910 Your password is at default value, please change it.
2914 if ($_SESSION["pwd_change_result"] == "failed") {
2915 print "<div class=\"warning\">
2916 There was an error while changing your password.
2920 if ($_SESSION["pwd_change_result"] == "ok") {
2921 print "<div class=\"notice\">
2922 Password changed successfully.
2926 $_SESSION["pwd_change_result"] = "";
2928 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
2929 print "<div class=\"notice\">
2930 Your configuration was reset to defaults.
2934 if ($_SESSION["prefs_op_result"] == "save-config") {
2935 print "<div class=\"notice\">
2936 Your configuration was saved successfully.
2940 $_SESSION["prefs_op_result"] = "";
2942 print "<form action=\"backend.php\" method=\"GET\">";
2944 print "<table width=\"100%\" class=\"prefPrefsList\">";
2945 print "<tr><td colspan='3'><h3>Personal data</h3></tr></td>";
2947 $result = db_query($link, "SELECT email FROM ttrss_users
2948 WHERE id = ".$_SESSION["uid"]);
2950 $email = db_fetch_result($result, 0, "email");
2952 print "<tr><td width=\"40%\">E-mail</td>";
2953 print "<td><input class=\"editbox\" name=\"email\"
2954 value=\"$email\"></td></tr>";
2958 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2960 print "<p><input class=\"button\" type=\"submit\"
2961 value=\"Change e-mail\" name=\"subop\">";
2965 print "<form action=\"backend.php\" method=\"POST\" name=\"changePassForm\">";
2967 print "<table width=\"100%\" class=\"prefPrefsList\">";
2968 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
2970 print "<tr><td width=\"40%\">Old password</td>";
2971 print "<td><input class=\"editbox\" type=\"password\"
2972 name=\"OLD_PASSWORD\"></td></tr>";
2974 print "<tr><td width=\"40%\">New password</td>";
2976 print "<td><input class=\"editbox\" type=\"password\"
2977 name=\"NEW_PASSWORD\"></td></tr>";
2981 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2983 print "<p><input class=\"button\" type=\"submit\"
2984 onclick=\"return validateNewPassword(this.form)\"
2985 value=\"Change password\" name=\"subop\">";
2991 $result = db_query($link, "SELECT
2992 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
2994 $user_theme_id = db_fetch_result($result, 0, "theme_id");
2996 $result = db_query($link, "SELECT
2997 id,theme_name FROM ttrss_themes ORDER BY theme_name");
2999 if (db_num_rows($result) > 0) {
3001 print "<form action=\"backend.php\" method=\"POST\">";
3002 print "<table width=\"100%\" class=\"prefPrefsList\">";
3003 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
3004 print "<tr><td width=\"40%\">Select theme</td>";
3005 print "<td><select name=\"theme\">";
3006 print "<option>Default</option>";
3007 print "<option disabled>--------</option>";
3009 while ($line = db_fetch_assoc($result)) {
3010 if ($line["id"] == $user_theme_id) {
3011 $selected = "selected";
3015 print "<option $selected>" . $line["theme_name"] . "</option>";
3017 print "</select></td></tr>";
3019 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3020 print "<p><input class=\"button\" type=\"submit\"
3021 value=\"Change theme\" name=\"subop\">";
3025 $result = db_query($link, "SELECT
3026 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
3027 section_name,def_value
3028 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
3029 WHERE type_id = ttrss_prefs_types.id AND
3030 section_id = ttrss_prefs_sections.id AND
3031 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
3032 owner_uid = ".$_SESSION["uid"]."
3033 ORDER BY section_id,short_desc");
3035 print "<form action=\"backend.php\" method=\"POST\">";
3039 $active_section = "";
3041 while ($line = db_fetch_assoc($result)) {
3043 if ($active_section != $line["section_name"]) {
3045 if ($active_section != "") {
3049 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
3051 $active_section = $line["section_name"];
3053 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
3054 // print "<tr class=\"title\">
3055 // <td width=\"25%\">Option</td><td>Value</td></tr>";
3060 // $class = ($lnum % 2) ? "even" : "odd";
3064 $type_name = $line["type_name"];
3065 $pref_name = $line["pref_name"];
3066 $value = $line["value"];
3067 $def_value = $line["def_value"];
3068 $help_text = $line["help_text"];
3070 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
3072 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
3078 if ($type_name == "bool") {
3079 // print_select($pref_name, $value, array("true", "false"));
3081 if ($value == "true") {
3087 print_radio($pref_name, $value, array("Yes", "No"));
3090 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
3102 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3104 print "<p><input class=\"button\" type=\"submit\"
3105 name=\"subop\" value=\"Save configuration\">";
3107 print " <input class=\"button\" type=\"submit\"
3108 name=\"subop\" onclick=\"return validatePrefsReset()\"
3109 value=\"Reset to defaults\"></p>";
3117 if ($op == "pref-users") {
3119 $subop = $_GET["subop"];
3121 if ($subop == "edit") {
3123 $id = db_escape_string($_GET["id"]);
3125 print "<div id=\"infoBoxTitle\">User editor</div>";
3127 print "<div class=\"infoBoxContents\">";
3129 print "<form id=\"user_edit_form\">";
3131 print "<input type=\"hidden\" name=\"id\" value=\"$id\">";
3132 print "<input type=\"hidden\" name=\"op\" value=\"pref-users\">";
3133 print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
3135 $result = db_query($link, "SELECT * FROM ttrss_users WHERE id = '$id'");
3137 $login = db_fetch_result($result, 0, "login");
3138 $access_level = db_fetch_result($result, 0, "access_level");
3139 $email = db_fetch_result($result, 0, "email");
3141 print "<table width='100%'>";
3142 print "<tr><td>Login:</td><td>
3143 <input class=\"iedit\" onkeypress=\"return filterCR(event)\"
3144 name=\"login\" value=\"$login\"></td></tr>";
3146 print "<tr><td>Change password:</td><td>
3147 <input class=\"iedit\" onkeypress=\"return filterCR(event)\"
3148 name=\"password\"></td></tr>";
3150 print "<tr><td>E-mail:</td><td>
3151 <input class=\"iedit\" name=\"email\" onkeypress=\"return filterCR(event)\"
3152 value=\"$email\"></td></tr>";
3154 $sel_disabled = ($id == $_SESSION["uid"]) ? "disabled" : "";
3156 print "<tr><td>Access level:</td><td>";
3157 print_select_hash("access_level", $access_level, $access_level_names,
3165 print "<div align='right'>
3166 <input class=\"button\"
3167 type=\"submit\" onclick=\"return userEditSave()\"
3169 <input class=\"button\"
3170 type=\"submit\" onclick=\"return userEditCancel()\"
3171 value=\"Cancel\"></div>";
3178 if ($subop == "editSave") {
3180 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3182 $login = db_escape_string(trim($_GET["login"]));
3183 $uid = db_escape_string($_GET["id"]);
3184 $access_level = sprintf("%d", $_GET["access_level"]);
3185 $email = db_escape_string(trim($_GET["email"]));
3186 $password = db_escape_string(trim($_GET["password"]));
3189 $pwd_hash = 'SHA1:' . sha1($password);
3190 $pass_query_part = "pwd_hash = '$pwd_hash', ";
3191 print "<div class='notice'>Changed password for user <b>$login</b>.</div>";
3193 $pass_query_part = "";
3196 db_query($link, "UPDATE ttrss_users SET $pass_query_part login = '$login',
3197 access_level = '$access_level', email = '$email' WHERE id = '$uid'");
3200 } else if ($subop == "remove") {
3202 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3204 $ids = split(",", db_escape_string($_GET["ids"]));
3206 foreach ($ids as $id) {
3207 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
3211 } else if ($subop == "add") {
3213 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3215 $login = db_escape_string(trim($_GET["login"]));
3216 $tmp_user_pwd = make_password(8);
3217 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3219 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3222 if (db_num_rows($result) == 0) {
3224 db_query($link, "INSERT INTO ttrss_users
3225 (login,pwd_hash,access_level,last_login)
3226 VALUES ('$login', '$pwd_hash', 0, NOW())");
3229 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3230 login = '$login' AND pwd_hash = '$pwd_hash'");
3232 if (db_num_rows($result) == 1) {
3234 $new_uid = db_fetch_result($result, 0, "id");
3236 print "<div class=\"notice\">Added user <b>".$_GET["login"].
3237 "</b> with password <b>$tmp_user_pwd</b>.</div>";
3239 initialize_user($link, $new_uid);
3243 print "<div class=\"warning\">Could not create user <b>".
3244 $_GET["login"]."</b></div>";
3248 print "<div class=\"warning\">User <b>".
3249 $_GET["login"]."</b> already exists.</div>";
3252 } else if ($subop == "resetPass") {
3254 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3256 $uid = db_escape_string($_GET["id"]);
3258 $result = db_query($link, "SELECT login,email
3259 FROM ttrss_users WHERE id = '$uid'");
3261 $login = db_fetch_result($result, 0, "login");
3262 $email = db_fetch_result($result, 0, "email");
3263 $tmp_user_pwd = make_password(8);
3264 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3266 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
3267 WHERE id = '$uid'");
3269 print "<div class=\"notice\">Changed password of
3270 user <b>$login</b> to <b>$tmp_user_pwd</b>.";
3272 if (MAIL_RESET_PASS && $email) {
3273 print " Notifying <b>$email</b>.";
3275 mail("$login <$email>", "Password reset notification",
3278 "Your password for this TT-RSS installation was reset by".
3279 " an administrator.\n".
3281 "Your new password is $tmp_user_pwd, please remember".
3282 " it for later reference.\n".
3284 "Sincerely, TT-RSS Mail Daemon.", "From: " . MAIL_FROM);
3292 print "<div class=\"prefGenericAddBox\">
3293 <input id=\"uadd_box\"
3294 onkeyup=\"toggleSubmitNotEmpty(this, 'user_add_btn')\"
3295 size=\"40\"> ";
3297 print"<input type=\"submit\" class=\"button\"
3298 id=\"user_add_btn\" disabled=\"true\"
3299 onclick=\"javascript:addUser()\" value=\"Create user\"></div>";
3301 $result = db_query($link, "SELECT
3302 id,login,access_level,email,
3303 SUBSTRING(last_login,1,16) as last_login
3308 // print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
3310 print "<p><table width=\"100%\" cellspacing=\"0\"
3311 class=\"prefUserList\" id=\"prefUserList\">";
3313 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
3315 <a href=\"javascript:selectPrefRows('user', true)\">All</a>,
3316 <a href=\"javascript:selectPrefRows('user', false)\">None</a>
3319 print "<tr class=\"title\">
3320 <td align='center' width=\"5%\"> </td>
3321 <td width='40%'>Login</td>
3322 <td width='40%'>Access Level</td>
3323 <td width='30%'>Last login</td></tr>";
3327 while ($line = db_fetch_assoc($result)) {
3329 $class = ($lnum % 2) ? "even" : "odd";
3332 $edit_uid = $_GET["id"];
3334 if ($subop == "edit" && $uid != $edit_uid) {
3338 $this_row_id = "id=\"UMRR-$uid\"";
3341 print "<tr class=\"$class\" $this_row_id>";
3343 $line["login"] = htmlspecialchars($line["login"]);
3345 $line["last_login"] = date(get_pref($link, 'SHORT_DATE_FORMAT'),
3346 strtotime($line["last_login"]));
3348 $access_level_names = array(0 => "User", 10 => "Administrator");
3350 // if (!$edit_uid || $subop != "edit") {
3352 print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"user\");'
3353 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
3355 print "<td><a href=\"javascript:editUser($uid);\">" .
3356 $line["login"] . "</td>";
3358 if (!$line["email"]) $line["email"] = " ";
3360 print "<td><a href=\"javascript:editUser($uid);\">" .
3361 $access_level_names[$line["access_level"]] . "</td>";
3363 /* } else if ($uid != $edit_uid) {
3365 if (!$line["email"]) $line["email"] = " ";
3367 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
3368 id=\"UMCHK-".$line["id"]."\"></td>";
3370 print "<td>".$line["login"]."</td>";
3371 print "<td>".$line["email"]."</td>";
3372 print "<td>".$access_level_names[$line["access_level"]]."</td>";
3376 print "<td align='center'>
3377 <input disabled=\"true\" type=\"checkbox\" checked></td>";
3379 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
3382 print "<td><input id=\"iedit_email\" value=\"".$line["email"].
3386 print "<select id=\"iedit_ulevel\">";
3387 foreach (array_keys($access_level_names) as $al) {
3388 if ($al == $line["access_level"]) {
3389 $selected = "selected";
3393 print "<option $selected id=\"$al\">" .
3394 $access_level_names[$al] . "</option>";
3401 print "<td>".$line["last_login"]."</td>";
3410 print "<p id='userOpToolbar'>";
3412 /* if ($subop == "edit") {
3414 <input type=\"submit\" class=\"button\"
3415 onclick=\"javascript:userEditSave()\" value=\"Save\">
3416 <input type=\"submit\" class=\"button\"
3417 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">";
3423 <input type=\"submit\" class=\"button\" disabled=\"true\"
3424 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
3425 <input type=\"submit\" class=\"button\" disabled=\"true\"
3426 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
3427 <input type=\"submit\" class=\"button\" disabled=\"true\"
3428 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
3429 <input type=\"submit\" class=\"button\" disabled=\"true\"
3430 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
3435 if ($op == "user-details") {
3437 if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
3441 /* print "<html><head>
3442 <title>Tiny Tiny RSS : User Details</title>
3443 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
3444 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
3447 $uid = sprintf("%d", $_GET["id"]);
3449 print "<div id=\"infoBoxTitle\">User details</div>";
3451 print "<div class='infoBoxContents'>";
3453 $result = db_query($link, "SELECT login,
3454 SUBSTRING(last_login,1,16) AS last_login,
3456 (SELECT COUNT(int_id) FROM ttrss_user_entries
3457 WHERE owner_uid = id) AS stored_articles
3459 WHERE id = '$uid'");
3461 if (db_num_rows($result) == 0) {
3462 print "<h1>User not found</h1>";
3466 # print "<h1>User Details</h1>";
3468 $login = db_fetch_result($result, 0, "login");
3470 # print "<h1>$login</h1>";
3472 print "<table width='100%'>";
3474 $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'),
3475 strtotime(db_fetch_result($result, 0, "last_login")));
3476 $access_level = db_fetch_result($result, 0, "access_level");
3477 $stored_articles = db_fetch_result($result, 0, "stored_articles");
3479 # print "<tr><td>Username</td><td>$login</td></tr>";
3480 # print "<tr><td>Access level</td><td>$access_level</td></tr>";
3481 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
3482 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
3484 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
3485 WHERE owner_uid = '$uid'");
3487 $num_feeds = db_fetch_result($result, 0, "num_feeds");
3489 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
3491 /* $result = db_query($link, "SELECT
3492 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
3493 FROM ttrss_user_entries,ttrss_entries
3494 WHERE owner_uid = '$uid' AND ref_id = id");
3496 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
3498 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
3502 print "<h1>Subscribed feeds</h1>";
3504 $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
3505 WHERE owner_uid = '$uid' ORDER BY title");
3507 print "<ul class=\"userFeedList\">";
3511 while ($line = db_fetch_assoc($result)) {
3513 $icon_file = ICONS_URL."/".$line["id"].".ico";
3515 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3516 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
3518 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3521 print "<li class=\"$row_class\">$feed_icon <a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
3523 $row_class = toggleEvenOdd($row_class);
3527 if (db_num_rows($result) < $num_feeds) {
3528 // FIXME - add link to show ALL subscribed feeds here somewhere
3530 class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\"> ...</li>";
3537 print "<div align='center'>
3538 <input type='submit' class='button'
3539 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3541 // print "</body></html>";
3545 if ($op == "pref-feed-browser") {
3547 if (!ENABLE_FEED_BROWSER) {
3548 print "Feed browser is administratively disabled.";
3552 $subop = $_REQUEST["subop"];
3554 if ($subop == "details") {
3555 $id = db_escape_string($_GET["id"]);
3557 print "<div class=\"browserFeedInfo\">";
3558 print "<b>Feed information:</b>";
3559 print "<div class=\"detailsPart\">";
3561 $result = db_query($link, "SELECT
3563 SUBSTRING(last_updated,1,19) AS last_updated
3564 FROM ttrss_feeds WHERE id = '$id'");
3566 $feed_url = db_fetch_result($result, 0, "feed_url");
3567 $site_url = db_fetch_result($result, 0, "site_url");
3568 $last_updated = db_fetch_result($result, 0, "last_updated");
3570 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
3571 $last_updated = smart_date_time(strtotime($last_updated));
3573 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
3574 $last_updated = date($short_date, strtotime($last_updated));
3577 print "Site: <a href='$site_url'>$site_url</a> ".
3578 "(<a href='$feed_url'>feed</a>), ".
3579 "Last updated: $last_updated";
3583 $result = db_query($link, "SELECT
3584 ttrss_entries.title,
3586 substring(date_entered,1,19) as date_entered,
3587 substring(updated,1,19) as updated
3588 FROM ttrss_entries,ttrss_user_entries
3589 WHERE ttrss_entries.id = ref_id AND feed_id = '$id'
3590 ORDER BY updated DESC LIMIT 5");
3592 if (db_num_rows($result) > 0) {
3594 print "<b>Last headlines:</b><br>";
3596 print "<div class=\"detailsPart\">";
3597 print "<ul class=\"compact\">";
3598 while ($line = db_fetch_assoc($result)) {
3600 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
3601 $entry_dt = smart_date_time(strtotime($line["updated"]));
3603 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
3604 $entry_dt = date($short_date, strtotime($line["updated"]));
3607 print "<li>" . $line["title"] .
3608 " <span class=\"insensitive\">($entry_dt)</span></li>";
3610 print "</ul></div>";
3618 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>";
3620 $limit = db_escape_string($_GET["limit"]);
3622 if (!$limit) $limit = 25;
3624 $owner_uid = $_SESSION["uid"];
3626 $result = db_query($link, "SELECT feed_url,COUNT(id) AS subscribers
3627 FROM ttrss_feeds WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
3628 WHERE tf.feed_url = ttrss_feeds.feed_url
3629 AND owner_uid = '$owner_uid') GROUP BY feed_url
3630 ORDER BY subscribers DESC LIMIT $limit");
3633 print "<div style=\"float : right\">
3634 Top <select id=\"feedBrowserLimit\">";
3636 foreach (array(25, 50, 100) as $l) {
3637 $issel = ($l == $limit) ? "selected" : "";
3638 print "<option $issel>$l</option>";
3642 <input type=\"submit\" class=\"button\"
3643 onclick=\"updateBigFeedBrowser()\" value=\"Show\">
3646 print "<p id=\"fbrOpToolbar\">Selection:
3647 <input type='submit' class='button' onclick=\"feedBrowserSubscribe()\"
3648 disabled=\"true\" value=\"Subscribe\">";
3650 print "<ul class='nomarks' id='browseBigFeedList'>";
3654 while ($line = db_fetch_assoc($result)) {
3655 $feed_url = $line["feed_url"];
3656 $subscribers = $line["subscribers"];
3658 $det_result = db_query($link, "SELECT site_url,title,id
3659 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
3661 $details = db_fetch_assoc($det_result);
3663 $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
3665 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3666 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
3667 "/".$details["id"].".ico\">";
3669 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3672 $check_box = "<input onclick='toggleSelectFBListRow(this)' class='feedBrowseCB'
3673 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
3675 $class = ($feedctr % 2) ? "even" : "odd";
3677 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
3680 print "<a href=\"javascript:browserToggleExpand('".$details["id"]."')\">" .
3681 $details["title"] ."</a> " .
3682 "<span class='subscribers'>($subscribers)</span>";
3684 print "<div class=\"browserDetails\" id=\"BRDET-" . $details["id"] . "\">";
3692 if ($feedctr == 0) {
3693 print "<li>No feeds found to subscribe.</li>";
3703 $feed = db_escape_string($_GET["id"]);
3704 $user = db_escape_string($_GET["user"]);
3705 $pass = db_escape_string($_GET["pass"]);
3706 $is_cat = $_GET["is_cat"] != false;
3708 $search = db_escape_string($_GET["q"]);
3709 $match_on = db_escape_string($_GET["m"]);
3710 $search_mode = db_escape_string($_GET["smode"]);
3712 if (!$_SESSION["uid"] && $user && $pass) {
3713 authenticate_user($link, $user, $pass);
3716 if ($_SESSION["uid"] ||
3717 http_authenticate_user($link)) {
3719 generate_syndicated_feed($link, $feed, $is_cat,
3720 $search, $search_mode, $match_on);
3724 function check_configuration_variables() {
3725 if (!defined('SESSION_EXPIRE_TIME')) {
3726 return "config: SESSION_EXPIRE_TIME is undefined";
3729 if (SESSION_EXPIRE_TIME < 60) {
3730 return "config: SESSION_EXPIRE_TIME is too low (less than 60)";
3733 if (SESSION_EXPIRE_TIME < SESSION_COOKIE_LIFETIME_REMEMBER) {
3734 return "config: SESSION_EXPIRE_TIME should be greater or equal to" .
3735 "SESSION_COOKIE_LIFETIME_REMEMBER";
3738 if (defined('DISABLE_SESSIONS')) {
3739 return "config: you have enabled DISABLE_SESSIONS. Please disable this option.";
3742 if (DATABASE_BACKED_SESSIONS && SINGLE_USER_MODE) {
3743 return "config: DATABASE_BACKED_SESSIONS is incompatible with SINGLE_USER_MODE";
3749 if ($op == "labelFromSearch") {
3750 $search = db_escape_string($_GET["search"]);
3751 $search_mode = db_escape_string($_GET["smode"]);
3752 $match_on = db_escape_string($_GET["match"]);
3753 $is_cat = db_escape_string($_GET["is_cat"]);
3754 $title = db_escape_string($_GET["title"]);
3755 $feed = sprintf("%d", $_GET["feed"]);
3757 $label_qparts = array();
3759 $search_expr = getSearchSql($search, $match_on);
3763 $search_expr .= " AND ttrss_feeds.cat_id = $feed ";
3765 $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
3768 if ($search_mode == "all_feeds") {
3770 } else if ($search_mode == "this_cat") {
3772 $tmp_result = db_query($link, "SELECT cat_id
3773 FROM ttrss_feeds WHERE id = '$feed'");
3775 $cat_id = db_fetch_result($tmp_result, 0, "cat_id");
3778 $search_expr .= " AND ttrss_feeds.cat_id = $cat_id ";
3780 $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
3783 $search_expr .= " AND ttrss_feeds.id = $feed ";
3788 $search_expr = db_escape_string($search_expr);
3793 $result = db_query($link,
3794 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
3795 VALUES ('$search_expr', '$title', '".$_SESSION["uid"]."')");
3802 <!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->