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(db_unescape_string($line["sql_exp"]));
2394 $line["description"] = htmlspecialchars(
2395 db_unescape_string($line["description"]));
2397 if (!$edit_label_id ||
$subop != "edit") {
2399 if (!$line["description"]) $line["description"] = "[No caption]";
2401 print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"label\");'
2402 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
2404 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2405 $line["sql_exp"] . "</td>";
2407 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2408 $line["description"] . "</td>";
2410 } else if ($label_id != $edit_label_id) {
2412 if (!$line["description"]) $line["description"] = "[No description]";
2414 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
2415 id=\"LICHK-".$line["id"]."\"></td>";
2417 print "<td>".$line["sql_exp"]."</td>";
2418 print "<td>".$line["description"]."</td>";
2422 print "<td align='center'><input disabled=\"true\" type=\"checkbox\" checked>";
2424 print "<input type=\"hidden\" name=\"id\" value=\"$label_id\">";
2425 print "<input type=\"hidden\" name=\"op\" value=\"pref-labels\">";
2426 print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
2430 print "<td><input onkeypress=\"return filterCR(event)\"
2431 class=\"iedit\" name=\"sql_exp\" value=\"".$line["sql_exp"]."\"></td>";
2433 print "<td><input onkeypress=\"return filterCR(event)\"
2434 class=\"iedit\" name=\"description\" value=\"".$line["description"]."\"></td>";
2444 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
2451 print "<p id=\"labelOpToolbar\">";
2453 if ($subop == "edit") {
2455 <input type=\"submit\" class=\"button\"
2456 onclick=\"javascript:labelTest()\" value=\"Test\">
2457 <input type=\"submit\" class=\"button\"
2458 onclick=\"javascript:labelEditSave()\" value=\"Save\">
2459 <input type=\"submit\" class=\"button\"
2460 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">";
2465 <input type=\"submit\" class=\"button\" disabled=\"true\"
2466 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
2467 <input type=\"submit\" class=\"button\" disabled=\"true\"
2468 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
2471 print "<p>No labels defined.</p>";
2475 if ($op == "error") {
2476 print "<div width=\"100%\" align='center'>";
2477 $msg = $_GET["msg"];
2482 if ($op == "help") {
2483 if (!$_GET["noheaders"]) {
2485 <title>Tiny Tiny RSS : Help</title>
2486 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2487 <script type=\"text/javascript\" src=\"prototype.js\"></script>
2488 <script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
2489 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2493 $tid = sprintf("%d", $_GET["tid"]);
2495 print "<div id=\"infoBoxTitle\">Help</div>";
2497 print "<div class='infoBoxContents'>";
2499 if (file_exists("help/$tid.php")) {
2500 include("help/$tid.php");
2502 print "<p>Help topic not found.</p>";
2507 print "<div align='center'>
2508 <input type='submit' class='button'
2509 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2511 if (!$_GET["noheaders"]) {
2512 print "</body></html>";
2519 $param = $_GET["param"];
2521 if ($id == "quickAddFeed") {
2523 print "<div id=\"infoBoxTitle\">Subscribe to feed</div>";
2524 print "<div class=\"infoBoxContents\">";
2526 print "<form id='feed_add_form'>";
2528 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
2529 print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
2530 print "<input type=\"hidden\" name=\"subop\" value=\"add\">";
2532 print "<table width='100%'>
2533 <tr><td>Feed URL:</td><td>
2534 <input class=\"iedit\" onblur=\"javascript:enableHotkeys()\"
2535 onkeypress=\"return filterCR(event)\"
2536 onkeyup=\"toggleSubmitNotEmpty(this, 'fadd_submit_btn')\"
2537 onfocus=\"javascript:disableHotkeys()\" name=\"feed_url\"></td></tr>";
2539 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2540 print "<tr><td>Category:</td><td>";
2541 print_feed_cat_select($link, "cat_id");
2548 print "<div align='right'>
2549 <input class=\"button\"
2550 id=\"fadd_submit_btn\" disabled=\"true\"
2551 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Subscribe\">
2552 <input class=\"button\"
2553 type=\"submit\" onclick=\"javascript:closeInfoBox()\"
2554 value=\"Cancel\"></div>";
2558 if ($id == "search") {
2560 print "<div id=\"infoBoxTitle\">Search</div>";
2561 print "<div class=\"infoBoxContents\">";
2563 print "<form id='search_form'>";
2565 #$active_feed_id = db_escape_string($_GET["param"]);
2567 $params = split(":", db_escape_string($_GET["param"]));
2569 $active_feed_id = sprintf("%d", $params[0]);
2570 $is_cat = $params[1] == "true";
2572 print "<table width='100%'><tr><td>Search:</td><td>";
2574 print "<input name=\"query\" class=\"iedit\"
2575 onkeypress=\"return filterCR(event)\"
2576 onkeyup=\"toggleSubmitNotEmpty(this, 'search_submit_btn')\"
2580 print "<tr><td>Where:</td><td>";
2582 print "<select name=\"search_mode\">
2583 <option value=\"all_feeds\">All feeds</option>";
2585 $feed_title = getFeedTitle($link, $active_feed_id);
2588 $feed_cat_title = getFeedCatTitle($link, $active_feed_id);
2590 $feed_cat_title = getCategoryTitle($link, $active_feed_id);
2593 if ($active_feed_id && !$is_cat) {
2594 print "<option selected value=\"this_feed\">This feed ($feed_title)</option>";
2596 print "<option disabled>This feed</option>";
2600 $cat_preselected = "selected";
2603 if (get_pref($link, 'ENABLE_FEED_CATS') && ($active_feed_id > 0 ||
$is_cat)) {
2604 print "<option $cat_preselected value=\"this_cat\">This category ($feed_cat_title)</option>";
2606 print "<option disabled>This category</option>";
2609 print "</select></td></tr>";
2611 print "<tr><td>Match on:</td><td>";
2613 $search_fields = array(
2615 "content" => "Content",
2616 "both" => "Title or content");
2618 print_select_hash("match_on", 3, $search_fields);
2620 print "</td></tr></table>";
2624 print "<div align=\"right\">
2625 <input type=\"submit\"
2626 class=\"button\" onclick=\"javascript:search()\"
2627 id=\"search_submit_btn\" disabled=\"true\"
2629 <input class=\"button\"
2630 type=\"submit\" onclick=\"javascript:searchCancel()\"
2631 value=\"Cancel\"></div>";
2637 if ($id == "quickAddFilter") {
2639 $active_feed_id = db_escape_string($_GET["param"]);
2641 print "<div id=\"infoBoxTitle\">Create filter</div>";
2642 print "<div class=\"infoBoxContents\">";
2644 print "<form id=\"filter_add_form\">";
2646 print "<input type=\"hidden\" name=\"op\" value=\"pref-filters\">";
2647 print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
2648 print "<input type=\"hidden\" name=\"subop\" value=\"add\">";
2650 // print "<div class=\"notice\"><b>Note:</b> filter will only apply to new articles.</div>";
2652 $result = db_query($link, "SELECT id,description
2653 FROM ttrss_filter_types ORDER BY description");
2655 $filter_types = array();
2657 while ($line = db_fetch_assoc($result)) {
2658 //array_push($filter_types, $line["description"]);
2659 $filter_types[$line["id"]] = $line["description"];
2662 print "<table width='100%'>";
2664 print "<tr><td>Match:</td>
2665 <td><input onkeypress=\"return filterCR(event)\"
2666 onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
2667 name=\"reg_exp\" class=\"iedit\">";
2670 print_select_hash("filter_type", 1, $filter_types, "class=\"iedit\"");
2673 print "<tr><td>Feed:</td><td colspan='2'>";
2675 print_feed_select($link, "feed_id", $active_feed_id);
2679 print "<tr><td>Action:</td>";
2681 print "<td colspan='2'><select name=\"action_id\">";
2683 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2686 while ($line = db_fetch_assoc($result)) {
2687 printf("<option value='%d'>%s</option>", $line["id"], $line["description"]);
2692 print "</td></tr></table>";
2696 print "<div align='right'>";
2698 print "<input type=\"submit\"
2699 id=\"infobox_submit\"
2700 class=\"button\" onclick=\"return qaddFilter()\"
2701 disabled=\"true\" value=\"Create\"> ";
2703 print "<input class=\"button\"
2704 type=\"submit\" onclick=\"return closeInfoBox()\"
2709 // print "</td></tr></table>";
2717 // update feeds of all users, may be used anonymously
2718 if ($op == "globalUpdateFeeds") {
2720 $result = db_query($link, "SELECT id FROM ttrss_users");
2722 while ($line = db_fetch_assoc($result)) {
2723 $user_id = $line["id"];
2724 // print "<!-- updating feeds of uid $user_id -->";
2725 update_all_feeds($link, false, $user_id);
2729 <message msg=\"All feeds updated\"/>
2734 if ($op == "pref-prefs") {
2736 $subop = $_REQUEST["subop"];
2738 if ($subop == "Save configuration") {
2740 if (WEB_DEMO_MODE
) {
2741 header("Location: prefs.php");
2745 $_SESSION["prefs_op_result"] = "save-config";
2747 $_SESSION["prefs_cache"] = false;
2749 foreach (array_keys($_POST) as $pref_name) {
2751 $pref_name = db_escape_string($pref_name);
2752 $value = db_escape_string($_POST[$pref_name]);
2754 $result = db_query($link, "SELECT type_name
2755 FROM ttrss_prefs,ttrss_prefs_types
2756 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
2758 if (db_num_rows($result) > 0) {
2760 $type_name = db_fetch_result($result, 0, "type_name");
2762 // print "$pref_name : $type_name : $value<br>";
2764 if ($type_name == "bool") {
2765 if ($value == "1") {
2770 } else if ($type_name == "integer") {
2771 $value = sprintf("%d", $value);
2774 // print "$pref_name : $type_name : $value<br>";
2776 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
2777 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
2781 header("Location: prefs.php");
2785 } else if ($subop == "getHelp") {
2787 $pref_name = db_escape_string($_GET["pn"]);
2789 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
2790 WHERE pref_name = '$pref_name'");
2792 if (db_num_rows($result) > 0) {
2793 $help_text = db_fetch_result($result, 0, "help_text");
2796 print "Unknown option: $pref_name";
2799 } else if ($subop == "Change e-mail") {
2801 if (WEB_DEMO_MODE
) {
2802 header("Location: prefs.php");
2806 $email = db_escape_string($_GET["email"]);
2807 $active_uid = $_SESSION["uid"];
2810 db_query($link, "UPDATE ttrss_users SET email = '$email'
2811 WHERE id = '$active_uid'");
2814 header("Location: prefs.php");
2816 } else if ($subop == "Change password") {
2818 if (WEB_DEMO_MODE
) {
2819 header("Location: prefs.php");
2823 $old_pw = $_POST["OLD_PASSWORD"];
2824 $new_pw = $_POST["OLD_PASSWORD"];
2826 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
2827 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
2829 $active_uid = $_SESSION["uid"];
2831 if ($old_pw && $new_pw) {
2833 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
2835 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
2836 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
2837 pwd_hash = '$old_pw_hash')");
2839 if (db_num_rows($result) == 1) {
2840 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
2841 WHERE id = '$active_uid'");
2843 $_SESSION["pwd_change_result"] = "ok";
2845 $_SESSION["pwd_change_result"] = "failed";
2849 header("Location: prefs.php");
2851 } else if ($subop == "Reset to defaults") {
2853 if (WEB_DEMO_MODE
) {
2854 header("Location: prefs.php");
2858 $_SESSION["prefs_op_result"] = "reset-to-defaults";
2860 if (DB_TYPE
== "pgsql") {
2861 db_query($link,"UPDATE ttrss_user_prefs
2862 SET value = ttrss_prefs.def_value
2863 WHERE owner_uid = '".$_SESSION["uid"]."' AND
2864 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
2866 db_query($link, "DELETE FROM ttrss_user_prefs
2867 WHERE owner_uid = ".$_SESSION["uid"]);
2868 initialize_user_prefs($link, $_SESSION["uid"]);
2871 header("Location: prefs.php");
2873 } else if ($subop == "Change theme") {
2875 $theme = db_escape_string($_POST["theme"]);
2877 if ($theme == "Default") {
2878 $theme_qpart = 'NULL';
2880 $theme_qpart = "'$theme'";
2883 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
2884 WHERE theme_name = '$theme'");
2886 if (db_num_rows($result) == 1) {
2887 $theme_id = db_fetch_result($result, 0, "id");
2888 $theme_path = db_fetch_result($result, 0, "theme_path");
2894 db_query($link, "UPDATE ttrss_users SET
2895 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
2897 $_SESSION["theme"] = $theme_path;
2899 header("Location: prefs.php");
2903 if (!SINGLE_USER_MODE
) {
2905 $result = db_query($link, "SELECT id,email FROM ttrss_users
2906 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
2907 pwd_hash = 'SHA1:".sha1("password")."')");
2909 if (db_num_rows($result) != 0) {
2910 print "<div class=\"warning\">
2911 Your password is at default value, please change it.
2915 if ($_SESSION["pwd_change_result"] == "failed") {
2916 print "<div class=\"warning\">
2917 There was an error while changing your password.
2921 if ($_SESSION["pwd_change_result"] == "ok") {
2922 print "<div class=\"notice\">
2923 Password changed successfully.
2927 $_SESSION["pwd_change_result"] = "";
2929 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
2930 print "<div class=\"notice\">
2931 Your configuration was reset to defaults.
2935 if ($_SESSION["prefs_op_result"] == "save-config") {
2936 print "<div class=\"notice\">
2937 Your configuration was saved successfully.
2941 $_SESSION["prefs_op_result"] = "";
2943 print "<form action=\"backend.php\" method=\"GET\">";
2945 print "<table width=\"100%\" class=\"prefPrefsList\">";
2946 print "<tr><td colspan='3'><h3>Personal data</h3></tr></td>";
2948 $result = db_query($link, "SELECT email FROM ttrss_users
2949 WHERE id = ".$_SESSION["uid"]);
2951 $email = db_fetch_result($result, 0, "email");
2953 print "<tr><td width=\"40%\">E-mail</td>";
2954 print "<td><input class=\"editbox\" name=\"email\"
2955 value=\"$email\"></td></tr>";
2959 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2961 print "<p><input class=\"button\" type=\"submit\"
2962 value=\"Change e-mail\" name=\"subop\">";
2966 print "<form action=\"backend.php\" method=\"POST\" name=\"changePassForm\">";
2968 print "<table width=\"100%\" class=\"prefPrefsList\">";
2969 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
2971 print "<tr><td width=\"40%\">Old password</td>";
2972 print "<td><input class=\"editbox\" type=\"password\"
2973 name=\"OLD_PASSWORD\"></td></tr>";
2975 print "<tr><td width=\"40%\">New password</td>";
2977 print "<td><input class=\"editbox\" type=\"password\"
2978 name=\"NEW_PASSWORD\"></td></tr>";
2982 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2984 print "<p><input class=\"button\" type=\"submit\"
2985 onclick=\"return validateNewPassword(this.form)\"
2986 value=\"Change password\" name=\"subop\">";
2992 $result = db_query($link, "SELECT
2993 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
2995 $user_theme_id = db_fetch_result($result, 0, "theme_id");
2997 $result = db_query($link, "SELECT
2998 id,theme_name FROM ttrss_themes ORDER BY theme_name");
3000 if (db_num_rows($result) > 0) {
3002 print "<form action=\"backend.php\" method=\"POST\">";
3003 print "<table width=\"100%\" class=\"prefPrefsList\">";
3004 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
3005 print "<tr><td width=\"40%\">Select theme</td>";
3006 print "<td><select name=\"theme\">";
3007 print "<option>Default</option>";
3008 print "<option disabled>--------</option>";
3010 while ($line = db_fetch_assoc($result)) {
3011 if ($line["id"] == $user_theme_id) {
3012 $selected = "selected";
3016 print "<option $selected>" . $line["theme_name"] . "</option>";
3018 print "</select></td></tr>";
3020 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3021 print "<p><input class=\"button\" type=\"submit\"
3022 value=\"Change theme\" name=\"subop\">";
3026 $result = db_query($link, "SELECT
3027 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
3028 section_name,def_value
3029 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
3030 WHERE type_id = ttrss_prefs_types.id AND
3031 section_id = ttrss_prefs_sections.id AND
3032 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
3033 owner_uid = ".$_SESSION["uid"]."
3034 ORDER BY section_id,short_desc");
3036 print "<form action=\"backend.php\" method=\"POST\">";
3040 $active_section = "";
3042 while ($line = db_fetch_assoc($result)) {
3044 if ($active_section != $line["section_name"]) {
3046 if ($active_section != "") {
3050 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
3052 $active_section = $line["section_name"];
3054 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
3055 // print "<tr class=\"title\">
3056 // <td width=\"25%\">Option</td><td>Value</td></tr>";
3061 // $class = ($lnum % 2) ? "even" : "odd";
3065 $type_name = $line["type_name"];
3066 $pref_name = $line["pref_name"];
3067 $value = $line["value"];
3068 $def_value = $line["def_value"];
3069 $help_text = $line["help_text"];
3071 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
3073 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
3079 if ($type_name == "bool") {
3080 // print_select($pref_name, $value, array("true", "false"));
3082 if ($value == "true") {
3088 print_radio($pref_name, $value, array("Yes", "No"));
3091 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
3103 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3105 print "<p><input class=\"button\" type=\"submit\"
3106 name=\"subop\" value=\"Save configuration\">";
3108 print " <input class=\"button\" type=\"submit\"
3109 name=\"subop\" onclick=\"return validatePrefsReset()\"
3110 value=\"Reset to defaults\"></p>";
3118 if ($op == "pref-users") {
3120 $subop = $_GET["subop"];
3122 if ($subop == "edit") {
3124 $id = db_escape_string($_GET["id"]);
3126 print "<div id=\"infoBoxTitle\">User editor</div>";
3128 print "<div class=\"infoBoxContents\">";
3130 print "<form id=\"user_edit_form\">";
3132 print "<input type=\"hidden\" name=\"id\" value=\"$id\">";
3133 print "<input type=\"hidden\" name=\"op\" value=\"pref-users\">";
3134 print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
3136 $result = db_query($link, "SELECT * FROM ttrss_users WHERE id = '$id'");
3138 $login = db_fetch_result($result, 0, "login");
3139 $access_level = db_fetch_result($result, 0, "access_level");
3140 $email = db_fetch_result($result, 0, "email");
3142 print "<table width='100%'>";
3143 print "<tr><td>Login:</td><td>
3144 <input class=\"iedit\" onkeypress=\"return filterCR(event)\"
3145 name=\"login\" value=\"$login\"></td></tr>";
3147 print "<tr><td>Change password:</td><td>
3148 <input class=\"iedit\" onkeypress=\"return filterCR(event)\"
3149 name=\"password\"></td></tr>";
3151 print "<tr><td>E-mail:</td><td>
3152 <input class=\"iedit\" name=\"email\" onkeypress=\"return filterCR(event)\"
3153 value=\"$email\"></td></tr>";
3155 $sel_disabled = ($id == $_SESSION["uid"]) ?
"disabled" : "";
3157 print "<tr><td>Access level:</td><td>";
3158 print_select_hash("access_level", $access_level, $access_level_names,
3166 print "<div align='right'>
3167 <input class=\"button\"
3168 type=\"submit\" onclick=\"return userEditSave()\"
3170 <input class=\"button\"
3171 type=\"submit\" onclick=\"return userEditCancel()\"
3172 value=\"Cancel\"></div>";
3179 if ($subop == "editSave") {
3181 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3183 $login = db_escape_string(trim($_GET["login"]));
3184 $uid = db_escape_string($_GET["id"]);
3185 $access_level = sprintf("%d", $_GET["access_level"]);
3186 $email = db_escape_string(trim($_GET["email"]));
3187 $password = db_escape_string(trim($_GET["password"]));
3190 $pwd_hash = 'SHA1:' . sha1($password);
3191 $pass_query_part = "pwd_hash = '$pwd_hash', ";
3192 print "<div class='notice'>Changed password for user <b>$login</b>.</div>";
3194 $pass_query_part = "";
3197 db_query($link, "UPDATE ttrss_users SET $pass_query_part login = '$login',
3198 access_level = '$access_level', email = '$email' WHERE id = '$uid'");
3201 } else if ($subop == "remove") {
3203 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3205 $ids = split(",", db_escape_string($_GET["ids"]));
3207 foreach ($ids as $id) {
3208 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
3212 } else if ($subop == "add") {
3214 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3216 $login = db_escape_string(trim($_GET["login"]));
3217 $tmp_user_pwd = make_password(8);
3218 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3220 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3223 if (db_num_rows($result) == 0) {
3225 db_query($link, "INSERT INTO ttrss_users
3226 (login,pwd_hash,access_level,last_login)
3227 VALUES ('$login', '$pwd_hash', 0, NOW())");
3230 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3231 login = '$login' AND pwd_hash = '$pwd_hash'");
3233 if (db_num_rows($result) == 1) {
3235 $new_uid = db_fetch_result($result, 0, "id");
3237 print "<div class=\"notice\">Added user <b>".$_GET["login"].
3238 "</b> with password <b>$tmp_user_pwd</b>.</div>";
3240 initialize_user($link, $new_uid);
3244 print "<div class=\"warning\">Could not create user <b>".
3245 $_GET["login"]."</b></div>";
3249 print "<div class=\"warning\">User <b>".
3250 $_GET["login"]."</b> already exists.</div>";
3253 } else if ($subop == "resetPass") {
3255 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3257 $uid = db_escape_string($_GET["id"]);
3259 $result = db_query($link, "SELECT login,email
3260 FROM ttrss_users WHERE id = '$uid'");
3262 $login = db_fetch_result($result, 0, "login");
3263 $email = db_fetch_result($result, 0, "email");
3264 $tmp_user_pwd = make_password(8);
3265 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3267 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
3268 WHERE id = '$uid'");
3270 print "<div class=\"notice\">Changed password of
3271 user <b>$login</b> to <b>$tmp_user_pwd</b>.";
3273 if (MAIL_RESET_PASS
&& $email) {
3274 print " Notifying <b>$email</b>.";
3276 mail("$login <$email>", "Password reset notification",
3279 "Your password for this TT-RSS installation was reset by".
3280 " an administrator.\n".
3282 "Your new password is $tmp_user_pwd, please remember".
3283 " it for later reference.\n".
3285 "Sincerely, TT-RSS Mail Daemon.", "From: " . MAIL_FROM
);
3293 print "<div class=\"prefGenericAddBox\">
3294 <input id=\"uadd_box\"
3295 onkeyup=\"toggleSubmitNotEmpty(this, 'user_add_btn')\"
3296 size=\"40\"> ";
3298 print"<input type=\"submit\" class=\"button\"
3299 id=\"user_add_btn\" disabled=\"true\"
3300 onclick=\"javascript:addUser()\" value=\"Create user\"></div>";
3302 $result = db_query($link, "SELECT
3303 id,login,access_level,email,
3304 SUBSTRING(last_login,1,16) as last_login
3309 // print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
3311 print "<p><table width=\"100%\" cellspacing=\"0\"
3312 class=\"prefUserList\" id=\"prefUserList\">";
3314 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
3316 <a href=\"javascript:selectPrefRows('user', true)\">All</a>,
3317 <a href=\"javascript:selectPrefRows('user', false)\">None</a>
3320 print "<tr class=\"title\">
3321 <td align='center' width=\"5%\"> </td>
3322 <td width='40%'>Login</td>
3323 <td width='40%'>Access Level</td>
3324 <td width='30%'>Last login</td></tr>";
3328 while ($line = db_fetch_assoc($result)) {
3330 $class = ($lnum %
2) ?
"even" : "odd";
3333 $edit_uid = $_GET["id"];
3335 if ($subop == "edit" && $uid != $edit_uid) {
3339 $this_row_id = "id=\"UMRR-$uid\"";
3342 print "<tr class=\"$class\" $this_row_id>";
3344 $line["login"] = htmlspecialchars($line["login"]);
3346 $line["last_login"] = date(get_pref($link, 'SHORT_DATE_FORMAT'),
3347 strtotime($line["last_login"]));
3349 $access_level_names = array(0 => "User", 10 => "Administrator");
3351 // if (!$edit_uid || $subop != "edit") {
3353 print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"user\");'
3354 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
3356 print "<td><a href=\"javascript:editUser($uid);\">" .
3357 $line["login"] . "</td>";
3359 if (!$line["email"]) $line["email"] = " ";
3361 print "<td><a href=\"javascript:editUser($uid);\">" .
3362 $access_level_names[$line["access_level"]] . "</td>";
3364 /* } else if ($uid != $edit_uid) {
3366 if (!$line["email"]) $line["email"] = " ";
3368 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
3369 id=\"UMCHK-".$line["id"]."\"></td>";
3371 print "<td>".$line["login"]."</td>";
3372 print "<td>".$line["email"]."</td>";
3373 print "<td>".$access_level_names[$line["access_level"]]."</td>";
3377 print "<td align='center'>
3378 <input disabled=\"true\" type=\"checkbox\" checked></td>";
3380 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
3383 print "<td><input id=\"iedit_email\" value=\"".$line["email"].
3387 print "<select id=\"iedit_ulevel\">";
3388 foreach (array_keys($access_level_names) as $al) {
3389 if ($al == $line["access_level"]) {
3390 $selected = "selected";
3394 print "<option $selected id=\"$al\">" .
3395 $access_level_names[$al] . "</option>";
3402 print "<td>".$line["last_login"]."</td>";
3411 print "<p id='userOpToolbar'>";
3413 /* if ($subop == "edit") {
3415 <input type=\"submit\" class=\"button\"
3416 onclick=\"javascript:userEditSave()\" value=\"Save\">
3417 <input type=\"submit\" class=\"button\"
3418 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">";
3424 <input type=\"submit\" class=\"button\" disabled=\"true\"
3425 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
3426 <input type=\"submit\" class=\"button\" disabled=\"true\"
3427 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
3428 <input type=\"submit\" class=\"button\" disabled=\"true\"
3429 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
3430 <input type=\"submit\" class=\"button\" disabled=\"true\"
3431 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
3436 if ($op == "user-details") {
3438 if (WEB_DEMO_MODE ||
$_SESSION["access_level"] < 10) {
3442 /* print "<html><head>
3443 <title>Tiny Tiny RSS : User Details</title>
3444 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
3445 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
3448 $uid = sprintf("%d", $_GET["id"]);
3450 print "<div id=\"infoBoxTitle\">User details</div>";
3452 print "<div class='infoBoxContents'>";
3454 $result = db_query($link, "SELECT login,
3455 SUBSTRING(last_login,1,16) AS last_login,
3457 (SELECT COUNT(int_id) FROM ttrss_user_entries
3458 WHERE owner_uid = id) AS stored_articles
3460 WHERE id = '$uid'");
3462 if (db_num_rows($result) == 0) {
3463 print "<h1>User not found</h1>";
3467 # print "<h1>User Details</h1>";
3469 $login = db_fetch_result($result, 0, "login");
3471 # print "<h1>$login</h1>";
3473 print "<table width='100%'>";
3475 $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'),
3476 strtotime(db_fetch_result($result, 0, "last_login")));
3477 $access_level = db_fetch_result($result, 0, "access_level");
3478 $stored_articles = db_fetch_result($result, 0, "stored_articles");
3480 # print "<tr><td>Username</td><td>$login</td></tr>";
3481 # print "<tr><td>Access level</td><td>$access_level</td></tr>";
3482 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
3483 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
3485 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
3486 WHERE owner_uid = '$uid'");
3488 $num_feeds = db_fetch_result($result, 0, "num_feeds");
3490 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
3492 /* $result = db_query($link, "SELECT
3493 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
3494 FROM ttrss_user_entries,ttrss_entries
3495 WHERE owner_uid = '$uid' AND ref_id = id");
3497 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
3499 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
3503 print "<h1>Subscribed feeds</h1>";
3505 $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
3506 WHERE owner_uid = '$uid' ORDER BY title");
3508 print "<ul class=\"userFeedList\">";
3512 while ($line = db_fetch_assoc($result)) {
3514 $icon_file = ICONS_URL
."/".$line["id"].".ico";
3516 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3517 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
3519 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3522 print "<li class=\"$row_class\">$feed_icon <a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
3524 $row_class = toggleEvenOdd($row_class);
3528 if (db_num_rows($result) < $num_feeds) {
3529 // FIXME - add link to show ALL subscribed feeds here somewhere
3531 class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\"> ...</li>";
3538 print "<div align='center'>
3539 <input type='submit' class='button'
3540 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3542 // print "</body></html>";
3546 if ($op == "pref-feed-browser") {
3548 if (!ENABLE_FEED_BROWSER
) {
3549 print "Feed browser is administratively disabled.";
3553 $subop = $_REQUEST["subop"];
3555 if ($subop == "details") {
3556 $id = db_escape_string($_GET["id"]);
3558 print "<div class=\"browserFeedInfo\">";
3559 print "<b>Feed information:</b>";
3560 print "<div class=\"detailsPart\">";
3562 $result = db_query($link, "SELECT
3564 SUBSTRING(last_updated,1,19) AS last_updated
3565 FROM ttrss_feeds WHERE id = '$id'");
3567 $feed_url = db_fetch_result($result, 0, "feed_url");
3568 $site_url = db_fetch_result($result, 0, "site_url");
3569 $last_updated = db_fetch_result($result, 0, "last_updated");
3571 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
3572 $last_updated = smart_date_time(strtotime($last_updated));
3574 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
3575 $last_updated = date($short_date, strtotime($last_updated));
3578 print "Site: <a href='$site_url'>$site_url</a> ".
3579 "(<a href='$feed_url'>feed</a>), ".
3580 "Last updated: $last_updated";
3584 $result = db_query($link, "SELECT
3585 ttrss_entries.title,
3587 substring(date_entered,1,19) as date_entered,
3588 substring(updated,1,19) as updated
3589 FROM ttrss_entries,ttrss_user_entries
3590 WHERE ttrss_entries.id = ref_id AND feed_id = '$id'
3591 ORDER BY updated DESC LIMIT 5");
3593 if (db_num_rows($result) > 0) {
3595 print "<b>Last headlines:</b><br>";
3597 print "<div class=\"detailsPart\">";
3598 print "<ul class=\"compact\">";
3599 while ($line = db_fetch_assoc($result)) {
3601 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
3602 $entry_dt = smart_date_time(strtotime($line["updated"]));
3604 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
3605 $entry_dt = date($short_date, strtotime($line["updated"]));
3608 print "<li>" . $line["title"] .
3609 " <span class=\"insensitive\">($entry_dt)</span></li>";
3611 print "</ul></div>";
3619 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>";
3621 $limit = db_escape_string($_GET["limit"]);
3623 if (!$limit) $limit = 25;
3625 $owner_uid = $_SESSION["uid"];
3627 $result = db_query($link, "SELECT feed_url,COUNT(id) AS subscribers
3628 FROM ttrss_feeds WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
3629 WHERE tf.feed_url = ttrss_feeds.feed_url
3630 AND owner_uid = '$owner_uid') GROUP BY feed_url
3631 ORDER BY subscribers DESC LIMIT $limit");
3634 print "<div style=\"float : right\">
3635 Top <select id=\"feedBrowserLimit\">";
3637 foreach (array(25, 50, 100) as $l) {
3638 $issel = ($l == $limit) ?
"selected" : "";
3639 print "<option $issel>$l</option>";
3643 <input type=\"submit\" class=\"button\"
3644 onclick=\"updateBigFeedBrowser()\" value=\"Show\">
3647 print "<p id=\"fbrOpToolbar\">Selection:
3648 <input type='submit' class='button' onclick=\"feedBrowserSubscribe()\"
3649 disabled=\"true\" value=\"Subscribe\">";
3651 print "<ul class='nomarks' id='browseBigFeedList'>";
3655 while ($line = db_fetch_assoc($result)) {
3656 $feed_url = $line["feed_url"];
3657 $subscribers = $line["subscribers"];
3659 $det_result = db_query($link, "SELECT site_url,title,id
3660 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
3662 $details = db_fetch_assoc($det_result);
3664 $icon_file = ICONS_DIR
. "/" . $details["id"] . ".ico";
3666 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3667 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL
.
3668 "/".$details["id"].".ico\">";
3670 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3673 $check_box = "<input onclick='toggleSelectFBListRow(this)' class='feedBrowseCB'
3674 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
3676 $class = ($feedctr %
2) ?
"even" : "odd";
3678 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
3681 print "<a href=\"javascript:browserToggleExpand('".$details["id"]."')\">" .
3682 $details["title"] ."</a> " .
3683 "<span class='subscribers'>($subscribers)</span>";
3685 print "<div class=\"browserDetails\" id=\"BRDET-" . $details["id"] . "\">";
3693 if ($feedctr == 0) {
3694 print "<li>No feeds found to subscribe.</li>";
3704 $feed = db_escape_string($_GET["id"]);
3705 $user = db_escape_string($_GET["user"]);
3706 $pass = db_escape_string($_GET["pass"]);
3707 $is_cat = $_GET["is_cat"] != false;
3709 $search = db_escape_string($_GET["q"]);
3710 $match_on = db_escape_string($_GET["m"]);
3711 $search_mode = db_escape_string($_GET["smode"]);
3713 if (!$_SESSION["uid"] && $user && $pass) {
3714 authenticate_user($link, $user, $pass);
3717 if ($_SESSION["uid"] ||
3718 http_authenticate_user($link)) {
3720 generate_syndicated_feed($link, $feed, $is_cat,
3721 $search, $search_mode, $match_on);
3725 function check_configuration_variables() {
3726 if (!defined('SESSION_EXPIRE_TIME')) {
3727 return "config: SESSION_EXPIRE_TIME is undefined";
3730 if (SESSION_EXPIRE_TIME
< 60) {
3731 return "config: SESSION_EXPIRE_TIME is too low (less than 60)";
3734 if (SESSION_EXPIRE_TIME
< SESSION_COOKIE_LIFETIME_REMEMBER
) {
3735 return "config: SESSION_EXPIRE_TIME should be greater or equal to" .
3736 "SESSION_COOKIE_LIFETIME_REMEMBER";
3739 if (defined('DISABLE_SESSIONS')) {
3740 return "config: you have enabled DISABLE_SESSIONS. Please disable this option.";
3743 if (DATABASE_BACKED_SESSIONS
&& SINGLE_USER_MODE
) {
3744 return "config: DATABASE_BACKED_SESSIONS is incompatible with SINGLE_USER_MODE";
3750 if ($op == "labelFromSearch") {
3751 $search = db_escape_string($_GET["search"]);
3752 $search_mode = db_escape_string($_GET["smode"]);
3753 $match_on = db_escape_string($_GET["match"]);
3754 $is_cat = db_escape_string($_GET["is_cat"]);
3755 $title = db_escape_string($_GET["title"]);
3756 $feed = sprintf("%d", $_GET["feed"]);
3758 $label_qparts = array();
3760 $search_expr = getSearchSql($search, $match_on);
3764 $search_expr .= " AND ttrss_feeds.cat_id = $feed ";
3766 $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
3769 if ($search_mode == "all_feeds") {
3771 } else if ($search_mode == "this_cat") {
3773 $tmp_result = db_query($link, "SELECT cat_id
3774 FROM ttrss_feeds WHERE id = '$feed'");
3776 $cat_id = db_fetch_result($tmp_result, 0, "cat_id");
3779 $search_expr .= " AND ttrss_feeds.cat_id = $cat_id ";
3781 $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
3784 $search_expr .= " AND ttrss_feeds.id = $feed ";
3789 $search_expr = db_escape_string($search_expr);
3794 $result = db_query($link,
3795 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
3796 VALUES ('$search_expr', '$title', '".$_SESSION["uid"]."')");
3803 <!-- <?
= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?
> -->