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', 11);
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";
28 $err_msg = check_configuration_variables();
30 $print_exec_time = true;
33 header("Content-Type: application/xml");
34 print_error_xml(9, $err_msg); die;
37 if ((!$op ||
$op == "rpc" ||
$op == "rss" ||
$op == "digestSend" ||
38 $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
39 header("Content-Type: application/xml");
43 header("Content-Type: application/xml");
44 print_error_xml(7); exit;
47 if (!$_SESSION["uid"] && $op != "globalUpdateFeeds" && $op != "rss" && $op != "getUnread") {
50 print_error_xml(6); die;
54 <p>Error: Not logged in.</p>
55 <script type=\"text/javascript\">
56 if (parent.window != 'undefined') {
57 parent.window.location = \"login.php\";
59 window.location = \"login.php\";
68 $purge_intervals = array(
75 90 => "3 months old");
77 $update_intervals = array(
79 -1 => "Disable updates",
80 30 => "Each 30 minutes",
82 240 => "Each 4 hours",
83 720 => "Each 12 hours",
87 $access_level_names = array(
89 10 => "Administrator");
91 $script_started = getmicrotime();
93 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
96 if (DB_TYPE
== "mysql") {
99 // PG seems to display its own errors just fine by default.
103 if (DB_TYPE
== "pgsql") {
104 pg_query("set client_encoding = 'utf-8'");
107 if ($_SESSION["uid"]) {
109 // setcookie('ttrss_vf_refresh', FEEDS_FRAME_REFRESH);
110 // setcookie('ttrss_vf_daemon', ENABLE_UPDATE_DAEMON);
112 /* if (get_pref($link, "ON_CATCHUP_SHOW_NEXT_FEED")) {
113 setcookie('ttrss_vf_catchupnext', 1);
115 setcookie('ttrss_vf_catchupnext', 0);
119 $fetch = $_GET["fetch"];
121 // setcookie("ttrss_icons_url", ICONS_URL);
123 if (!sanity_check($link)) { return; }
125 function outputFeedList($link, $tags = false) {
127 print "<ul class=\"feedList\" id=\"feedList\">\n";
129 $owner_uid = $_SESSION["uid"];
135 if (get_pref($link, 'ENABLE_FEED_CATS')) {
136 print "<li class=\"feedCat\">Special</li>";
137 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
140 $num_starred = getFeedUnread($link, -1);
144 if ($num_starred > 0) $class .= "Unread";
146 printFeedEntry(-1, $class, "Starred articles", $num_starred,
147 "images/mark_set.png", $link);
149 if (get_pref($link, 'ENABLE_FEED_CATS')) {
153 if (GLOBAL_ENABLE_LABELS
&& get_pref($link, 'ENABLE_LABELS')) {
155 $result = db_query($link, "SELECT id,sql_exp,description FROM
156 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
158 if (db_num_rows($result) > 0) {
159 if (get_pref($link, 'ENABLE_FEED_CATS')) {
160 print "<li class=\"feedCat\">Labels</li>";
161 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
163 print "<li><hr></li>";
167 while ($line = db_fetch_assoc($result)) {
171 $label_id = -$line['id'] - 11;
172 $count = getFeedUnread($link, $label_id);
180 error_reporting (DEFAULT_ERROR_LEVEL
);
182 printFeedEntry($label_id,
183 $class, db_unescape_string($line["description"]),
184 $count, "images/label.png", $link);
188 if (db_num_rows($result) > 0) {
189 if (get_pref($link, 'ENABLE_FEED_CATS')) {
196 // if (!get_pref($link, 'ENABLE_FEED_CATS')) {
197 print "<li><hr></li>";
200 if (get_pref($link, 'ENABLE_FEED_CATS')) {
201 if (get_pref($link, "FEEDS_SORT_BY_UNREAD")) {
202 $order_by_qpart = "category,unread DESC,title";
204 $order_by_qpart = "category,title";
207 if (get_pref($link, "FEEDS_SORT_BY_UNREAD")) {
208 $order_by_qpart = "unread DESC,title";
210 $order_by_qpart = "title";
214 $result = db_query($link, "SELECT ttrss_feeds.*,
215 SUBSTRING(last_updated,1,19) AS last_updated_noms,
216 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
217 WHERE feed_id = ttrss_feeds.id AND
218 ttrss_user_entries.ref_id = ttrss_entries.id AND
219 owner_uid = '$owner_uid') AS total,
220 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
221 WHERE feed_id = ttrss_feeds.id AND unread = true
222 AND ttrss_user_entries.ref_id = ttrss_entries.id
223 AND owner_uid = '$owner_uid') as unread,
225 ttrss_feed_categories.title AS category,
226 ttrss_feed_categories.collapsed
227 FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
228 ON (ttrss_feed_categories.id = cat_id)
230 ttrss_feeds.hidden = false AND
231 ttrss_feeds.owner_uid = '$owner_uid' AND parent_feed IS NULL
232 ORDER BY $order_by_qpart");
234 $actid = $_GET["actid"];
244 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
246 while ($line = db_fetch_assoc($result)) {
248 $feed = db_unescape_string($line["title"]);
249 $feed_id = $line["id"];
251 $subop = $_GET["subop"];
253 $total = $line["total"];
254 $unread = $line["unread"];
256 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
257 $last_updated = smart_date_time(strtotime($line["last_updated_noms"]));
259 $last_updated = date($short_date, strtotime($line["last_updated_noms"]));
262 $rtl_content = sql_bool_to_bool($line["rtl_content"]);
265 $rtl_tag = "dir=\"RTL\"";
270 $tmp_result = db_query($link,
271 "SELECT id,COUNT(unread) AS unread
272 FROM ttrss_feeds LEFT JOIN ttrss_user_entries
273 ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
274 WHERE parent_feed = '$feed_id' AND unread = true
275 GROUP BY ttrss_feeds.id");
277 if (db_num_rows($tmp_result) > 0) {
278 while ($l = db_fetch_assoc($tmp_result)) {
279 $unread +
= $l["unread"];
283 $cat_id = $line["cat_id"];
285 $tmp_category = $line["category"];
287 if (!$tmp_category) {
288 $tmp_category = "Uncategorized";
291 // $class = ($lnum % 2) ? "even" : "odd";
293 if ($line["last_error"]) {
299 if ($unread > 0) $class .= "Unread";
301 if ($actid == $feed_id) {
302 $class .= "Selected";
305 $total_unread +
= $unread;
307 if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
313 $category = $tmp_category;
315 $collapsed = $line["collapsed"];
317 // workaround for NULL category
318 if ($category == "Uncategorized") {
319 if ($_COOKIE["ttrss_vf_uclps"] == 1) {
324 if ($collapsed == "t" ||
$collapsed == "1") {
325 $holder_class = "invisible";
332 $cat_id = sprintf("%d", $cat_id);
334 $cat_unread = getCategoryUnread($link, $cat_id);
336 print "<li class=\"feedCat\" id=\"FCAT-$cat_id\">
337 <a id=\"FCATN-$cat_id\" href=\"javascript:toggleCollapseCat($cat_id)\">$tmp_category</a>
338 <a href=\"javascript:viewCategory($cat_id)\" id=\"FCAP-$cat_id\">
339 <span id=\"FCATCTR-$cat_id\"
340 class=\"$catctr_class\">($cat_unread unread)$ellipsis</span>
343 // !!! NO SPACE before <ul...feedCatList - breaks firstChild DOM function
344 // -> keyboard navigation, etc.
345 print "<li id=\"feedCatHolder\" class=\"$holder_class\"><ul class=\"feedCatList\" id=\"FCATLIST-$cat_id\">";
348 printFeedEntry($feed_id, $class, $feed, $unread,
349 "icons/$feed_id.ico", $link, $rtl_content,
350 $last_updated, $line["last_error"]);
359 /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
360 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
361 post_int_id = ttrss_user_entries.int_id AND
362 unread = true AND ref_id = ttrss_entries.id
363 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
365 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'
366 ORDER BY tag_name"); */
368 $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
369 FROM ttrss_user_entries WHERE int_id = post_int_id
370 AND unread = true)) AS count FROM ttrss_tags
371 WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name");
375 while ($line = db_fetch_assoc($result)) {
376 $tags[$line["tag_name"]] +
= $line["count"];
379 foreach (array_keys($tags) as $tag) {
381 $unread = $tags[$tag];
389 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
395 if (db_num_rows($result) == 0) {
401 print "<li>No $what to display.</li>";
410 handle_rpc_request($link);
413 if ($op == "feeds") {
415 $tags = $_GET["tags"];
417 $subop = $_GET["subop"];
419 if ($subop == "catchupAll") {
420 db_query($link, "UPDATE ttrss_user_entries SET
421 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
424 if ($subop == "collapse") {
425 $cat_id = db_escape_string($_GET["cid"]);
427 db_query($link, "UPDATE ttrss_feed_categories SET
428 collapsed = NOT collapsed WHERE id = '$cat_id' AND owner_uid = " .
433 outputFeedList($link, $tags);
439 $id = db_escape_string($_GET["id"]);
440 $feed_id = db_escape_string($_GET["feed"]);
442 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
443 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
445 if (db_num_rows($result) == 1) {
446 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
448 $rtl_content = false;
452 $rtl_tag = "dir=\"RTL\"";
459 $result = db_query($link, "UPDATE ttrss_user_entries
460 SET unread = false,last_read = NOW()
461 WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
463 $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
464 SUBSTRING(updated,1,16) as updated,
465 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url,
468 FROM ttrss_entries,ttrss_user_entries
469 WHERE id = '$id' AND ref_id = id AND owner_uid = " . $_SESSION["uid"]);
475 if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
476 $link_target = "target=\"_new\"";
479 $line = db_fetch_assoc($result);
481 if ($line["icon_url"]) {
482 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
484 $feed_icon = " ";
487 /* if ($line["comments"] && $line["link"] != $line["comments"]) {
488 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
490 $entry_comments = "";
493 $num_comments = $line["num_comments"];
494 $entry_comments = "";
496 if ($num_comments > 0) {
497 if ($line["comments"]) {
498 $comments_url = $line["comments"];
500 $comments_url = $line["link"];
502 $entry_comments = "<a $link_target href=\"$comments_url\">$num_comments comments</a>";
504 if ($line["comments"] && $line["link"] != $line["comments"]) {
505 $entry_comments = "<a $link_target href=\"".$line["comments"]."\">comments</a>";
509 print "<div class=\"postReply\">";
511 print "<div class=\"postHeader\"><table width=\"100%\">";
513 $entry_author = $line["author"];
516 $entry_author = " - by $entry_author";
520 print "<tr><td><a $link_target href=\"" . $line["link"] . "\">" .
521 $line["title"] . "</a>$entry_author</td>";
523 print "<tr><td>" . $line["title"] . "$entry_author</td>";
526 $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
527 strtotime($line["updated"]));
529 print "<td class=\"postDate$rtl_class\">$parsed_updated</td>";
533 $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
534 ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
542 while ($tmp_line = db_fetch_assoc($tmp_result)) {
544 $tag = $tmp_line["tag_name"];
545 $tag_str = "<a href=\"javascript:parent.viewfeed('$tag')\">$tag</a>, ";
547 if ($num_tags == 5) {
548 $tags_str .= "<a href=\"javascript:showBlockElement('allEntryTags')\">...</a>";
549 } else if ($num_tags < 5) {
550 $tags_str .= $tag_str;
552 $f_tags_str .= $tag_str;
555 $tags_str = preg_replace("/, $/", "", $tags_str);
556 $f_tags_str = preg_replace("/, $/", "", $f_tags_str);
558 // $truncated_link = truncate_string($line["link"], 60);
560 if ($tags_str ||
$entry_comments) {
561 print "<tr><td width='50%'>
563 <td align=\"right\">$tags_str</td></tr>";
566 print "</table></div>";
568 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
569 print "<div class=\"postContent\">";
571 if (db_num_rows($tmp_result) > 5) {
572 print "<div id=\"allEntryTags\">Tags: $f_tags_str</div>";
575 if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
576 $line["content"] = preg_replace("/href=/i", "target=\"_new\" href=", $line["content"]);
579 $line["content"] = sanitize_rss($line["content"]);
581 print $line["content"] . "</div>";
588 if ($op == "viewfeed") {
590 $feed = db_escape_string($_GET["feed"]);
591 $subop = db_escape_string($_GET["subop"]);
592 $view_mode = db_escape_string($_GET["view_mode"]);
593 $limit = db_escape_string($_GET["limit"]);
594 $cat_view = db_escape_string($_GET["cat"]);
595 $next_unread_feed = db_escape_string($_GET["nuf"]);
597 if ($subop == "undefined") $subop = "";
599 if ($subop == "CatchupSelected") {
600 $ids = split(",", db_escape_string($_GET["ids"]));
601 $cmode = sprintf("%d", $_GET["cmode"]);
603 catchupArticlesById($link, $ids, $cmode);
606 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
607 update_generic_feed($link, $feed, $cat_view);
610 if ($subop == "MarkAllRead") {
611 catchup_feed($link, $feed, $cat_view);
613 if (get_pref($link, 'ON_CATCHUP_SHOW_NEXT_FEED')) {
614 if ($next_unread_feed) {
615 $feed = $next_unread_feed;
621 $result = db_query($link,
622 "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
624 if (db_num_rows($result) == 0) {
625 print "<div align='center'>
626 Feed not found.</div>";
631 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
633 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
634 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
636 if (db_num_rows($result) == 1) {
637 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
639 $rtl_content = false;
643 $rtl_tag = "dir=\"RTL\"";
649 $rtl_content = false;
652 $script_dt_add = get_script_dt_add();
654 /* print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
655 <script type=\"text/javascript\" src=\"prototype.js\"></script>
656 <script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
657 <script type=\"text/javascript\" src=\"viewfeed.js?$script_dt_add\"></script>
658 <!--[if gte IE 5.5000]>
659 <script type=\"text/javascript\" src=\"pngfix.js\"></script>
660 <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
662 </head><body $rtl_tag>
663 <script type=\"text/javascript\">
664 if (document.addEventListener) {
665 document.addEventListener(\"DOMContentLoaded\", init, null);
667 window.onload = init;
670 /// START /////////////////////////////////////////////////////////////////////////////////
672 $search = db_escape_string($_GET["query"]);
673 $search_mode = db_escape_string($_GET["search_mode"]);
674 $match_on = db_escape_string($_GET["match_on"]);
680 $qfh_ret = queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view, $search, $search_mode, $match_on);
682 $result = $qfh_ret[0];
683 $feed_title = $qfh_ret[1];
684 $feed_site_url = $qfh_ret[2];
685 $last_error = $qfh_ret[3];
687 /// STOP //////////////////////////////////////////////////////////////////////////////////
689 print "<div id=\"headlinesContainer\" $rtl_tag>";
692 print "<div align='center'>
693 Could not display feed (query failed). Please check label match syntax or local configuration.</div>";
697 if (db_num_rows($result) > 0) {
699 print_headline_subtoolbar($link, $feed_site_url, $feed_title, false,
700 $rtl_content, $feed, $cat_view, $search, $match_on, $search_mode);
702 print "<div id=\"headlinesInnerContainer\">";
704 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
705 print "<table class=\"headlinesList\" id=\"headlinesList\"
706 cellspacing=\"0\" width=\"100%\">";
711 error_reporting (DEFAULT_ERROR_LEVEL
);
715 while ($line = db_fetch_assoc($result)) {
717 $class = ($lnum %
2) ?
"even" : "odd";
720 $feed_id = $line["feed_id"];
722 if ($line["last_read"] == "" &&
723 ($line["unread"] != "t" && $line["unread"] != "1")) {
725 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
728 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
732 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
740 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
741 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
742 alt=\"Reset mark\" onclick='javascript:toggleMark($id)'>";
744 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
745 alt=\"Set mark\" onclick='javascript:toggleMark($id)'>";
748 # $content_link = "<a target=\"_new\" href=\"".$line["link"]."\">" .
749 # $line["title"] . "</a>";
751 $content_link = "<a href=\"javascript:view($id,$feed_id);\">" .
752 $line["title"] . "</a>";
754 # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
755 # $line["title"] . "</a>";
757 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
758 $updated_fmt = smart_date_time(strtotime($line["updated"]));
760 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
761 $updated_fmt = date($short_date, strtotime($line["updated"]));
764 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
765 $content_preview = truncate_string(strip_tags($line["content_preview"]),
769 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
771 print "<tr class='$class' id='RROW-$id'>";
773 print "<td class='hlUpdatePic'>$update_pic</td>";
775 print "<td class='hlSelectRow'>
776 <input type=\"checkbox\" onclick=\"toggleSelectRow(this)\"
777 class=\"feedCheckBox\" id=\"RCHK-$id\">
780 print "<td class='hlMarkedPic'>$marked_pic</td>";
782 if ($line["feed_title"]) {
783 print "<td class='hlContent'>$content_link</td>";
784 print "<td class='hlFeed'>
785 <a href='javascript:viewfeed($feed_id)'>".
786 $line["feed_title"]."</a> </td>";
788 print "<td class='hlContent' valign='middle'>";
790 print "<a href=\"javascript:view($id,$feed_id);\">" .
793 if (get_pref($link, 'SHOW_CONTENT_PREVIEW') && !$rtl_tag) {
794 if ($content_preview) {
795 print "<span class=\"contentPreview\"> - $content_preview</span>";
803 print "<td class=\"hlUpdated\"><nobr>$updated_fmt </nobr></td>";
810 $add_class = "Unread";
815 print "<div class=\"cdmArticle$add_class\" id=\"RROW-$id\">";
817 print "<div class=\"cdmHeader\">";
819 print "<div style=\"float : right\">$updated_fmt,
820 <a class=\"cdmToggleLink\"
821 href=\"javascript:toggleUnread($id)\">Toggle unread</a>
824 print "<a class=\"title\"
825 onclick=\"javascript:toggleUnread($id, 0)\"
826 target=\"new\" href=\"".$line["link"]."\">".$line["title"]."</a>";
828 if ($line["feed_title"]) {
829 print " (<a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>)";
834 print "<div class=\"cdmContent\">" . $line["content_preview"] . "</div><br clear=\"all\">";
836 print "<div style=\"float : right\">$marked_pic</div>
837 <div lass=\"cdmFooter\">
838 <input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
839 'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\"></div>";
841 # print "<div align=\"center\"><a class=\"cdmToggleLink\"
842 # href=\"javascript:toggleUnread($id)\">
843 # Toggle unread</a></div>";
852 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
858 // print_headline_subtoolbar($link,
859 // "javascript:catchupPage()", "Mark page as read", true, $rtl_content);
863 print "<div width='100%' align='center'>No articles found.</div>";
869 if ($op == "pref-feeds") {
871 $subop = $_REQUEST["subop"];
872 $quiet = $_REQUEST["quiet"];
874 if ($subop == "massSubscribe") {
875 $ids = split(",", db_escape_string($_GET["ids"]));
877 $subscribed = array();
879 foreach ($ids as $id) {
880 $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds
883 $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url"));
884 $title = db_escape_string(db_fetch_result($result, 0, "title"));
886 $title_orig = db_fetch_result($result, 0, "title");
888 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
889 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
891 if (db_num_rows($result) == 0) {
892 $result = db_query($link,
893 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
894 VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)");
896 array_push($subscribed, $title_orig);
900 if (count($subscribed) > 0) {
901 print "<div class=\"notice\">";
902 print "<b>Subscribed to feeds:</b>";
903 print "<ul class=\"nomarks\">";
904 foreach ($subscribed as $title) {
905 print "<li>$title</li>";
912 if ($subop == "browse") {
914 if (!ENABLE_FEED_BROWSER
) {
915 print "Feed browser is administratively disabled.";
919 print "<div id=\"infoBoxTitle\">Other feeds: Top 25</div>";
921 print "<div class=\"infoBoxContents\">";
923 print "<p>Showing top 25 registered feeds, sorted by popularity:</p>";
925 # $result = db_query($link, "SELECT feed_url,count(id) AS subscribers
927 # WHERE auth_login = '' AND auth_pass = '' AND private = false
928 # GROUP BY feed_url ORDER BY subscribers DESC LIMIT 25");
930 $owner_uid = $_SESSION["uid"];
932 $result = db_query($link, "SELECT feed_url,COUNT(id) AS subscribers
933 FROM ttrss_feeds WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
934 WHERE tf.feed_url = ttrss_feeds.feed_url
935 AND owner_uid = '$owner_uid') GROUP BY feed_url
936 ORDER BY subscribers DESC LIMIT 25");
938 print "<ul class='browseFeedList' id='browseFeedList'>";
942 while ($line = db_fetch_assoc($result)) {
943 $feed_url = $line["feed_url"];
944 $subscribers = $line["subscribers"];
946 $det_result = db_query($link, "SELECT site_url,title,id
947 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
949 $details = db_fetch_assoc($det_result);
951 $icon_file = ICONS_DIR
. "/" . $details["id"] . ".ico";
953 if (file_exists($icon_file) && filesize($icon_file) > 0) {
954 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL
.
955 "/".$details["id"].".ico\">";
957 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
960 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
961 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
963 $class = ($feedctr %
2) ?
"even" : "odd";
965 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
966 "$feed_icon " . db_unescape_string($details["title"]) .
967 " <span class='subscribers'>($subscribers)</span></li>";
973 print "<li>No feeds found to subscribe.</li>";
978 print "<div align='center'>
979 <input type=\"submit\" class=\"button\"
980 onclick=\"feedBrowserSubscribe()\" value=\"Subscribe\">
981 <input type='submit' class='button'
982 onclick=\"closeInfoBox()\" value=\"Cancel\"></div>";
988 if ($subop == "editfeed") {
989 $feed_id = db_escape_string($_REQUEST["id"]);
991 $result = db_query($link,
992 "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
993 owner_uid = " . $_SESSION["uid"]);
995 $title = htmlspecialchars(db_unescape_string(db_fetch_result($result,
998 $icon_file = ICONS_DIR
. "/$feed_id.ico";
1000 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1001 $feed_icon = "<img width=\"16\" height=\"16\"
1002 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
1007 print "<div id=\"infoBoxTitle\">Feed editor</div>";
1009 print "<div class=\"infoBoxContents\">";
1011 print "<form id=\"edit_feed_form\">";
1013 print "<input type=\"hidden\" name=\"id\" value=\"$feed_id\">";
1014 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
1015 print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
1017 print "<table width='100%'>";
1019 print "<tr><td>Title:</td>";
1020 print "<td><input class=\"iedit\" onkeypress=\"return filterCR(event)\"
1021 name=\"title\" value=\"$title\"></td></tr>";
1023 $feed_url = db_fetch_result($result, 0, "feed_url");
1024 $feed_url = htmlspecialchars(db_unescape_string(db_fetch_result($result,
1027 print "<tr><td>Feed URL:</td>";
1028 print "<td><input class=\"iedit\" onkeypress=\"return filterCR(event)\"
1029 name=\"feed_url\" value=\"$feed_url\"></td></tr>";
1031 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1033 $cat_id = db_fetch_result($result, 0, "cat_id");
1035 print "<tr><td>Category:</td>";
1038 $parent_feed = db_fetch_result($result, 0, "parent_feed");
1040 if (sprintf("%d", $parent_feed) > 0) {
1041 $disabled = "disabled";
1046 print_feed_cat_select($link, "cat_id", $cat_id, "class=\"iedit\" $disabled");
1053 $update_interval = db_fetch_result($result, 0, "update_interval");
1055 print "<tr><td>Update Interval:</td>";
1059 print_select_hash("update_interval", $update_interval, $update_intervals,
1064 print "<tr><td>Link to:</td><td>";
1066 $tmp_result = db_query($link, "SELECT COUNT(id) AS count
1067 FROM ttrss_feeds WHERE parent_feed = '$feed_id'");
1069 $linked_count = db_fetch_result($tmp_result, 0, "count");
1071 $parent_feed = db_fetch_result($result, 0, "parent_feed");
1073 if ($linked_count > 0) {
1074 $disabled = "disabled";
1079 print "<select class=\"iedit\" $disabled name=\"parent_feed\">";
1081 print "<option value=\"0\">Not linked</option>";
1083 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1085 $cat_qpart = "AND cat_id = '$cat_id'";
1087 $cat_qpart = "AND cat_id IS NULL";
1091 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
1092 WHERE id != '$feed_id' AND owner_uid = ".$_SESSION["uid"]." AND
1093 (SELECT COUNT(id) FROM ttrss_feeds AS T2 WHERE T2.id = ttrss_feeds.parent_feed) = 0
1094 $cat_qpart ORDER BY title");
1096 if (db_num_rows($tmp_result) > 0) {
1097 print "<option disabled>--------</option>";
1100 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1101 if ($tmp_line["id"] == $parent_feed) {
1102 $is_selected = "selected";
1106 printf("<option $is_selected value='%d'>%s</option>",
1107 $tmp_line["id"], $tmp_line["title"]);
1113 $purge_interval = db_fetch_result($result, 0, "purge_interval");
1115 print "<tr><td>Article purging:</td>";
1119 print_select_hash("purge_interval", $purge_interval, $purge_intervals,
1124 $auth_login = escape_for_form(db_fetch_result($result, 0, "auth_login"));
1126 print "<tr><td>Login:</td>";
1127 print "<td><input class=\"iedit\" onkeypress=\"return filterCR(event)\"
1128 name=\"auth_login\" value=\"$auth_login\"></td></tr>";
1130 $auth_pass = escape_for_form(db_fetch_result($result, 0, "auth_pass"));
1132 print "<tr><td>Password:</td>";
1133 print "<td><input class=\"iedit\" type=\"password\" name=\"auth_pass\"
1134 onkeypress=\"return filterCR(event)\"
1135 value=\"$auth_pass\"></td></tr>";
1137 $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
1140 $checked = "checked";
1145 print "<tr><td valign='top'>Options:</td>";
1146 print "<td><input type=\"checkbox\" name=\"private\" id=\"private\"
1147 $checked><label for=\"private\">Hide from \"Other Feeds\"</label>";
1149 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
1152 $checked = "checked";
1157 print "<br><input type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
1158 $checked><label for=\"rtl_content\">Right-to-left content</label>";
1160 $hidden = sql_bool_to_bool(db_fetch_result($result, 0, "hidden"));
1163 $checked = "checked";
1168 print "<br><input type=\"checkbox\" id=\"hidden\" name=\"hidden\"
1169 $checked><label for=\"hidden\">Hide from my feed list</label>";
1171 $include_in_digest = sql_bool_to_bool(db_fetch_result($result, 0, "include_in_digest"));
1173 if ($include_in_digest) {
1174 $checked = "checked";
1179 print "<br><input type=\"checkbox\" id=\"include_in_digest\"
1180 name=\"include_in_digest\"
1181 $checked><label for=\"include_in_digest\">Include in e-mail digest</label>";
1189 print "<div align='right'>
1190 <input type=\"submit\" class=\"button\"
1191 onclick=\"return feedEditSave()\" value=\"Save\">
1192 <input type='submit' class='button'
1193 onclick=\"return feedEditCancel()\" value=\"Cancel\"></div>";
1200 if ($subop == "editSave") {
1202 $feed_title = db_escape_string(trim($_POST["title"]));
1203 $feed_link = db_escape_string(trim($_POST["feed_url"]));
1204 $upd_intl = db_escape_string($_POST["update_interval"]);
1205 $purge_intl = db_escape_string($_POST["purge_interval"]);
1206 $feed_id = db_escape_string($_POST["id"]);
1207 $cat_id = db_escape_string($_POST["cat_id"]);
1208 $auth_login = db_escape_string(trim($_POST["auth_login"]));
1209 $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
1210 $parent_feed = db_escape_string($_POST["parent_feed"]);
1211 $private = checkbox_to_sql_bool(db_escape_string($_POST["private"]));
1212 $rtl_content = checkbox_to_sql_bool(db_escape_string($_POST["rtl_content"]));
1213 $hidden = checkbox_to_sql_bool(db_escape_string($_POST["hidden"]));
1214 $include_in_digest = checkbox_to_sql_bool(
1215 db_escape_string($_POST["include_in_digest"]));
1217 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1218 if ($cat_id && $cat_id != 0) {
1219 $category_qpart = "cat_id = '$cat_id',";
1220 $category_qpart_nocomma = "cat_id = '$cat_id'";
1222 $category_qpart = 'cat_id = NULL,';
1223 $category_qpart_nocomma = 'cat_id = NULL';
1226 $category_qpart = "";
1227 $category_qpart_nocomma = "";
1230 if ($parent_feed && $parent_feed != 0) {
1231 $parent_qpart = "parent_feed = '$parent_feed'";
1233 $parent_qpart = 'parent_feed = NULL';
1236 $result = db_query($link, "UPDATE ttrss_feeds SET
1237 $category_qpart $parent_qpart,
1238 title = '$feed_title', feed_url = '$feed_link',
1239 update_interval = '$upd_intl',
1240 purge_interval = '$purge_intl',
1241 auth_login = '$auth_login',
1242 auth_pass = '$auth_pass',
1244 rtl_content = $rtl_content,
1246 include_in_digest = $include_in_digest
1247 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
1249 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1250 # update linked feed categories
1251 $result = db_query($link, "UPDATE ttrss_feeds SET
1252 $category_qpart_nocomma WHERE parent_feed = '$feed_id' AND
1253 owner_uid = " . $_SESSION["uid"]);
1257 if ($subop == "saveCat") {
1258 $cat_title = db_escape_string(trim($_GET["title"]));
1259 $cat_id = db_escape_string($_GET["id"]);
1261 $result = db_query($link, "UPDATE ttrss_feed_categories SET
1262 title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
1266 if ($subop == "remove") {
1268 if (!WEB_DEMO_MODE
) {
1270 $ids = split(",", db_escape_string($_GET["ids"]));
1272 foreach ($ids as $id) {
1276 db_query($link, "DELETE FROM ttrss_feeds
1277 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1279 $icons_dir = ICONS_DIR
;
1281 if (file_exists($icons_dir . "/$id.ico")) {
1282 unlink($icons_dir . "/$id.ico");
1284 } else if ($id < -10) {
1286 $label_id = -$id - 11;
1288 db_query($link, "DELETE FROM ttrss_labels
1289 WHERE id = '$label_id' AND owner_uid = " . $_SESSION["uid"]);
1295 if ($subop == "add") {
1297 if (!WEB_DEMO_MODE
) {
1299 $feed_url = db_escape_string(trim($_GET["feed_url"]));
1300 $cat_id = db_escape_string($_GET["cat_id"]);
1302 if (subscribe_to_feed($link, $feed_url, $cat_id)) {
1303 print "Added feed.";
1305 print "<div class=\"warning\">
1306 Feed <b>$feed_url</b> already exists in the database.
1312 if ($subop == "addCat") {
1314 if (!WEB_DEMO_MODE
) {
1316 $feed_cat = db_escape_string(trim($_GET["cat"]));
1318 $result = db_query($link,
1319 "SELECT id FROM ttrss_feed_categories
1320 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
1322 if (db_num_rows($result) == 0) {
1324 $result = db_query($link,
1325 "INSERT INTO ttrss_feed_categories (owner_uid,title)
1326 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
1330 print "<div class=\"warning\">
1331 Category <b>$feed_cat</b> already exists in the database.
1339 if ($subop == "removeCats") {
1341 if (!WEB_DEMO_MODE
) {
1343 $ids = split(",", db_escape_string($_GET["ids"]));
1345 foreach ($ids as $id) {
1347 db_query($link, "BEGIN");
1349 $result = db_query($link,
1350 "SELECT count(id) as num_feeds FROM ttrss_feeds
1351 WHERE cat_id = '$id'");
1353 $num_feeds = db_fetch_result($result, 0, "num_feeds");
1355 if ($num_feeds == 0) {
1356 db_query($link, "DELETE FROM ttrss_feed_categories
1357 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1360 print "<div class=\"warning\">
1361 Unable to delete non empty feed categories.</div>";
1365 db_query($link, "COMMIT");
1370 if ($subop == "categorize") {
1372 if (!WEB_DEMO_MODE
) {
1374 $ids = split(",", db_escape_string($_GET["ids"]));
1376 $cat_id = db_escape_string($_GET["cat_id"]);
1379 $cat_id_qpart = 'NULL';
1381 $cat_id_qpart = "'$cat_id'";
1384 db_query($link, "BEGIN");
1386 foreach ($ids as $id) {
1388 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
1389 WHERE id = '$id' AND parent_feed IS NULL
1390 AND owner_uid = " . $_SESSION["uid"]);
1392 # update linked feed categories
1393 db_query($link, "UPDATE ttrss_feeds SET
1394 cat_id = $cat_id_qpart WHERE parent_feed = '$id' AND
1395 owner_uid = " . $_SESSION["uid"]);
1399 db_query($link, "COMMIT");
1406 // print "<h3>Edit Feeds</h3>";
1408 $result = db_query($link, "SELECT id,title,feed_url,last_error
1409 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1411 if (db_num_rows($result) > 0) {
1413 print "<div class=\"warning\">";
1415 // print"<img class=\"closeButton\"
1416 // onclick=\"javascript:hideParentElement(this);\" src=\"images/close.png\">";
1418 print "<a href=\"javascript:showBlockElement('feedUpdateErrors')\">
1419 <b>Some feeds have update errors (click for details)</b></a>";
1421 print "<ul id=\"feedUpdateErrors\" class=\"nomarks\">";
1423 while ($line = db_fetch_assoc($result)) {
1424 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
1425 $line["last_error"];
1433 $feed_search = db_escape_string($_GET["search"]);
1435 if (array_key_exists("search", $_GET)) {
1436 $_SESSION["prefs_feed_search"] = $feed_search;
1438 $feed_search = $_SESSION["prefs_feed_search"];
1441 print "<table width='100%' class=\"prefGenericAddBox\"
1442 cellspacing='0' cellpadding='0'><tr>
1444 <input id=\"fadd_link\"
1445 onkeyup=\"toggleSubmitNotEmpty(this, 'fadd_submit_btn')\"
1447 <input type=\"submit\" class=\"button\"
1448 disabled=\"true\" id=\"fadd_submit_btn\"
1449 onclick=\"addFeed()\" value=\"Subscribe\">";
1451 if (ENABLE_FEED_BROWSER
&& !SINGLE_USER_MODE
) {
1452 print " <input type=\"submit\" class=\"button\"
1453 onclick=\"javascript:browseFeeds()\" value=\"Top 25\">";
1456 print "</td><td align='right'>
1457 <input id=\"feed_search\" size=\"20\"
1458 onchange=\"javascript:updateFeedList()\" value=\"$feed_search\">
1459 <input type=\"submit\" class=\"button\"
1460 onclick=\"javascript:updateFeedList()\" value=\"Search\">
1464 $feeds_sort = db_escape_string($_GET["sort"]);
1466 if (!$feeds_sort ||
$feeds_sort == "undefined") {
1467 $feeds_sort = $_SESSION["pref_sort_feeds"];
1468 if (!$feeds_sort) $feeds_sort = "title";
1471 $_SESSION["pref_sort_feeds"] = $feeds_sort;
1474 $search_qpart = "(UPPER(F1.title) LIKE UPPER('%$feed_search%') OR
1475 UPPER(F1.feed_url) LIKE UPPER('%$feed_search%')) AND";
1480 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1481 $order_by_qpart = "category,$feeds_sort,title";
1483 $order_by_qpart = "$feeds_sort,title";
1486 $result = db_query($link, "SELECT
1490 substring(F1.last_updated,1,16) AS last_updated,
1495 F2.title AS parent_title,
1496 C1.title AS category,
1498 F1.include_in_digest
1501 LEFT JOIN ttrss_feeds AS F2
1502 ON (F1.parent_feed = F2.id)
1503 LEFT JOIN ttrss_feed_categories AS C1
1504 ON (F1.cat_id = C1.id)
1506 $search_qpart F1.owner_uid = '".$_SESSION["uid"]."'
1507 ORDER by $order_by_qpart");
1509 if (db_num_rows($result) != 0) {
1511 // print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1513 print "<p><table width=\"100%\" cellspacing=\"0\"
1514 class=\"prefFeedList\" id=\"prefFeedList\">";
1515 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1517 <a href=\"javascript:selectPrefRows('feed', true)\">All</a>,
1518 <a href=\"javascript:selectPrefRows('feed', false)\">None</a>
1521 if (!get_pref($link, 'ENABLE_FEED_CATS')) {
1522 print "<tr class=\"title\">
1523 <td width='5%' align='center'> </td>";
1525 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1526 print "<td width='3%'> </td>";
1530 <td width='40%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
1531 <td width='45%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
1532 <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
1539 while ($line = db_fetch_assoc($result)) {
1541 $feed_id = $line["id"];
1542 $cat_id = $line["cat_id"];
1544 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1545 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
1546 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
1548 $hidden = sql_bool_to_bool($line["hidden"]);
1550 if (!$edit_cat) $edit_cat = "Uncategorized";
1552 $last_updated = $line["last_updated"];
1554 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1555 $last_updated = smart_date_time(strtotime($last_updated));
1557 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1558 $last_updated = date($short_date, strtotime($last_updated));
1561 if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
1564 print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>";
1566 print "<tr class=\"title\">
1567 <td width='5%'> </td>";
1569 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1570 print "<td width='3%'> </td>";
1573 print "<td width='40%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
1574 <td width='45%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
1575 <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
1577 $cur_cat_id = $cat_id;
1580 $class = ($lnum %
2) ?
"even" : "odd";
1581 $this_row_id = "id=\"FEEDR-$feed_id\"";
1583 print "<tr class=\"$class\" $this_row_id>";
1585 $icon_file = ICONS_DIR
. "/$feed_id.ico";
1587 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1588 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL
. "/$feed_id.ico\">";
1590 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1593 print "<td class='feedSelect'><input onclick='toggleSelectPrefRow(this, \"feed\");'
1594 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
1596 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1597 print "<td class='feedIcon'>$feed_icon</td>";
1600 $edit_title = truncate_string($edit_title, 40);
1601 $edit_link = truncate_string($edit_link, 60);
1604 $edit_title = "<span class=\"insensitive\">$edit_title (Hidden)</span>";
1605 $edit_link = "<span class=\"insensitive\">$edit_link</span>";
1606 $last_updated = "<span class=\"insensitive\">$last_updated</span>";
1609 $parent_title = $line["parent_title"];
1610 if ($parent_title) {
1611 $parent_title = "<span class='groupPrompt'>(linked to
1612 $parent_title)</span>";
1615 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1616 "$edit_title $parent_title" . "</a></td>";
1618 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1619 $edit_link . "</a></td>";
1621 print "<td align='right'><a href=\"javascript:editFeed($feed_id);\">" .
1622 "$last_updated</a></td>";
1631 print "<p><span id=\"feedOpToolbar\">";
1633 if ($subop == "edit") {
1634 print "Edit feed:
1635 <input type=\"submit\" class=\"button\"
1636 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
1637 <input type=\"submit\" class=\"button\"
1638 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1643 <input type=\"submit\" class=\"button\" disabled=\"true\"
1644 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
1645 <input type=\"submit\" class=\"button\" disabled=\"true\"
1646 onclick=\"javascript:removeSelectedFeeds()\" value=\"Unsubscribe\">";
1648 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1650 print " | ";
1652 print_feed_cat_select($link, "sfeed_set_fcat", "", "disabled");
1654 print " <input type=\"submit\" class=\"button\" disabled=\"true\"
1655 onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Recategorize\">";
1660 All feeds: <input type=\"submit\"
1661 class=\"button\" onclick=\"gotoExportOpml()\"
1662 value=\"Export OPML\">";
1666 print "<p>No feeds defined.</p>";
1670 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1672 print "<h3>Edit Categories</h3>";
1674 print "<div class=\"prefGenericAddBox\">
1675 <input id=\"fadd_cat\"
1676 onkeyup=\"toggleSubmitNotEmpty(this, 'catadd_submit_btn')\"
1679 type=\"submit\" class=\"button\" disabled=\"true\" id=\"catadd_submit_btn\"
1680 onclick=\"javascript:addFeedCat()\" value=\"Create category\"></div>";
1682 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1683 WHERE owner_uid = ".$_SESSION["uid"]."
1686 if (db_num_rows($result) != 0) {
1688 print "<form id=\"feed_cat_edit_form\">";
1690 print "<p><table width=\"100%\" class=\"prefFeedCatList\"
1691 cellspacing=\"0\" id=\"prefFeedCatList\">";
1693 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1695 <a href=\"javascript:selectPrefRows('fcat', true)\">All</a>,
1696 <a href=\"javascript:selectPrefRows('fcat', false)\">None</a>
1699 print "<tr class=\"title\">
1700 <td width=\"5%\"> </td><td width=\"80%\">Title</td>
1705 while ($line = db_fetch_assoc($result)) {
1707 $class = ($lnum %
2) ?
"even" : "odd";
1709 $cat_id = $line["id"];
1711 $edit_cat_id = $_GET["id"];
1713 if ($subop == "editCat" && $cat_id != $edit_cat_id) {
1717 $this_row_id = "id=\"FCATR-$cat_id\"";
1720 print "<tr class=\"$class\" $this_row_id>";
1722 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1724 if (!$edit_cat_id ||
$subop != "editCat") {
1726 print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"fcat\");'
1727 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
1729 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
1730 $edit_title . "</a></td>";
1732 } else if ($cat_id != $edit_cat_id) {
1734 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
1735 id=\"FRCHK-".$line["id"]."\"></td>";
1737 print "<td>$edit_title</td>";
1741 print "<td align='center'><input disabled=\"true\" type=\"checkbox\" checked>";
1743 print "<input type=\"hidden\" name=\"id\" value=\"$cat_id\">";
1744 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
1745 print "<input type=\"hidden\" name=\"subop\" value=\"saveCat\">";
1749 print "<td><input onkeypress=\"return filterCR(event)\"
1750 name=\"title\" class=\"iedit\" value=\"$edit_title\"></td>";
1763 print "<p id=\"catOpToolbar\">";
1765 if ($subop == "editCat") {
1766 print "Edit category:
1767 <input type=\"submit\" class=\"button\"
1768 onclick=\"return feedCatEditSave()\" value=\"Save\">
1769 <input type=\"submit\" class=\"button\"
1770 onclick=\"return feedCatEditCancel()\" value=\"Cancel\">";
1775 <input type=\"submit\" class=\"button\" disabled=\"true\"
1776 onclick=\"return editSelectedFeedCat()\" value=\"Edit\">
1777 <input type=\"submit\" class=\"button\" disabled=\"true\"
1778 onclick=\"return removeSelectedFeedCats()\" value=\"Remove\">";
1783 print "<p>No feed categories defined.</p>";
1787 print "<h3>Import OPML</h3>
1788 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1789 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">
1790 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
1791 type=\"submit\" value=\"Import\">
1796 if ($op == "pref-filters") {
1798 $subop = $_GET["subop"];
1799 $quiet = $_GET["quiet"];
1801 if ($subop == "edit") {
1803 $filter_id = db_escape_string($_GET["id"]);
1805 $result = db_query($link,
1806 "SELECT * FROM ttrss_filters WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
1808 $reg_exp = htmlspecialchars(db_unescape_string(db_fetch_result($result, 0, "reg_exp")));
1809 $filter_type = db_fetch_result($result, 0, "filter_type");
1810 $feed_id = db_fetch_result($result, 0, "feed_id");
1811 $action_id = db_fetch_result($result, 0, "action_id");
1813 $enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled"));
1815 print "<div id=\"infoBoxTitle\">Filter editor</div>";
1816 print "<div class=\"infoBoxContents\">";
1818 print "<form id=\"filter_edit_form\">";
1820 print "<input type=\"hidden\" name=\"op\" value=\"pref-filters\">";
1821 print "<input type=\"hidden\" name=\"id\" value=\"$filter_id\">";
1822 print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
1824 // print "<div class=\"notice\"><b>Note:</b> filter will only apply to new articles.</div>";
1826 $result = db_query($link, "SELECT id,description
1827 FROM ttrss_filter_types ORDER BY description");
1829 $filter_types = array();
1831 while ($line = db_fetch_assoc($result)) {
1832 //array_push($filter_types, $line["description"]);
1833 $filter_types[$line["id"]] = $line["description"];
1836 print "<table width='100%'>";
1838 print "<tr><td>Match:</td>
1839 <td><input onkeypress=\"return filterCR(event)\"
1840 onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
1841 name=\"reg_exp\" class=\"iedit\" value=\"$reg_exp\">";
1845 print_select_hash("filter_type", $filter_type, $filter_types, "class=\"iedit\"");
1848 print "<tr><td>Feed:</td><td colspan='2'>";
1850 print_feed_select($link, "feed_id", $feed_id);
1854 print "<tr><td>Action:</td>";
1856 print "<td colspan='2'><select name=\"action_id\">";
1858 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
1861 while ($line = db_fetch_assoc($result)) {
1862 $is_sel = ($line["id"] == $action_id) ?
"selected" : "";
1863 printf("<option value='%d' $is_sel>%s</option>", $line["id"], $line["description"]);
1871 $checked = "checked";
1876 print "<tr><td>Options:</td><td>
1877 <input type=\"checkbox\" name=\"enabled\" id=\"enabled\" $checked>
1878 <label for=\"enabled\">Enabled</label>";
1880 print "</td></tr></table>";
1884 print "<div align='right'>";
1886 print "<input type=\"submit\"
1887 id=\"infobox_submit\"
1888 class=\"button\" onclick=\"return filterEditSave()\"
1891 print "<input class=\"button\"
1892 type=\"submit\" onclick=\"return filterEditCancel()\"
1901 if ($subop == "editSave") {
1903 $reg_exp = db_escape_string(trim($_GET["reg_exp"]));
1904 $filter_type = db_escape_string(trim($_GET["filter_type"]));
1905 $filter_id = db_escape_string($_GET["id"]);
1906 $feed_id = db_escape_string($_GET["feed_id"]);
1907 $action_id = db_escape_string($_GET["action_id"]);
1908 $enabled = checkbox_to_sql_bool(db_escape_string($_GET["enabled"]));
1913 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
1916 $result = db_query($link, "UPDATE ttrss_filters SET
1917 reg_exp = '$reg_exp',
1919 action_id = '$action_id',
1920 filter_type = '$filter_type',
1922 WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
1925 if ($subop == "remove") {
1927 if (!WEB_DEMO_MODE
) {
1929 $ids = split(",", db_escape_string($_GET["ids"]));
1931 foreach ($ids as $id) {
1932 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
1938 if ($subop == "add") {
1940 if (!WEB_DEMO_MODE
) {
1942 $regexp = db_escape_string(trim($_GET["reg_exp"]));
1943 $filter_type = db_escape_string(trim($_GET["filter_type"]));
1944 $feed_id = db_escape_string($_GET["feed_id"]);
1945 $action_id = db_escape_string($_GET["action_id"]);
1950 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
1953 $result = db_query($link,
1954 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
1957 ('$regexp', '$filter_type','".$_SESSION["uid"]."',
1958 $feed_id, '$action_id')");
1964 $sort = db_escape_string($_GET["sort"]);
1966 if (!$sort ||
$sort == "undefined") {
1970 // print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1972 $result = db_query($link, "SELECT id,description
1973 FROM ttrss_filter_types ORDER BY description");
1975 $filter_types = array();
1977 while ($line = db_fetch_assoc($result)) {
1978 //array_push($filter_types, $line["description"]);
1979 $filter_types[$line["id"]] = $line["description"];
1982 print "<input type=\"submit\"
1984 onclick=\"return displayDlg('quickAddFilter', false)\"
1985 id=\"create_filter_btn\"
1986 value=\"Create filter\">";
1988 $result = db_query($link, "SELECT
1989 ttrss_filters.id AS id,reg_exp,
1990 ttrss_filter_types.name AS filter_type_name,
1991 ttrss_filter_types.description AS filter_type_descr,
1994 ttrss_filter_actions.description AS action_description,
1995 ttrss_feeds.title AS feed_title
1997 ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN
1998 ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id)
2000 filter_type = ttrss_filter_types.id AND
2001 ttrss_filter_actions.id = action_id AND
2002 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
2005 if (db_num_rows($result) != 0) {
2007 print "<form id=\"filter_edit_form\">";
2009 print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\"
2010 id=\"prefFilterList\">";
2012 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2014 <a href=\"javascript:selectPrefRows('filter', true)\">All</a>,
2015 <a href=\"javascript:selectPrefRows('filter', false)\">None</a>
2018 print "<tr class=\"title\">
2019 <td align='center' width=\"5%\"> </td>
2020 <td width=\"20%\"><a href=\"javascript:updateFilterList('reg_exp')\">Filter expression</a></td>
2021 <td width=\"20%\"><a href=\"javascript:updateFilterList('feed_title')\">Feed</a></td>
2022 <td width=\"15%\"><a href=\"javascript:updateFilterList('filter_type')\">Match</a></td>
2023 <td width=\"15%\"><a href=\"javascript:updateFilterList('action_description')\">Action</a></td>";
2027 while ($line = db_fetch_assoc($result)) {
2029 $class = ($lnum %
2) ?
"even" : "odd";
2031 $filter_id = $line["id"];
2032 $edit_filter_id = $_GET["id"];
2034 $enabled = sql_bool_to_bool($line["enabled"]);
2036 if ($subop == "edit" && $filter_id != $edit_filter_id) {
2040 $this_row_id = "id=\"FILRR-$filter_id\"";
2043 print "<tr class=\"$class\" $this_row_id>";
2045 $line["reg_exp"] = htmlspecialchars(db_unescape_string($line["reg_exp"]));
2047 if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
2049 $line["feed_title"] = htmlspecialchars(db_unescape_string($line["feed_title"]));
2051 print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"filter\");'
2052 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
2055 $line["reg_exp"] = "<span class=\"insensitive\">" .
2056 $line["reg_exp"] . " (Disabled)</span>";
2057 $line["feed_title"] = "<span class=\"insensitive\">" .
2058 $line["feed_title"] . "</span>";
2059 $line["filter_type_descr"] = "<span class=\"insensitive\">" .
2060 $line["filter_type_descr"] . "</span>";
2061 $line["action_description"] = "<span class=\"insensitive\">" .
2062 $line["action_description"] . "</span>";
2065 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2066 $line["reg_exp"] . "</td>";
2068 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2069 $line["feed_title"] . "</td>";
2071 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2072 $line["filter_type_descr"] . "</td>";
2074 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2075 $line["action_description"] . "</td>";
2083 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
2090 print "<p id=\"filterOpToolbar\">";
2094 <input type=\"submit\" class=\"button\" disabled=\"true\"
2095 onclick=\"return editSelectedFilter()\" value=\"Edit\">
2096 <input type=\"submit\" class=\"button\" disabled=\"true\"
2097 onclick=\"return removeSelectedFilters()\" value=\"Remove\">";
2103 print "<p>No filters defined.</p>";
2108 // We need to accept raw SQL data in label queries, so not everything is escaped
2109 // here, this is by design. If you don't like the whole idea, disable labels
2110 // altogether with GLOBAL_ENABLE_LABELS = false
2112 if ($op == "pref-labels") {
2114 if (!GLOBAL_ENABLE_LABELS
) {
2116 print "<p>Sorry, labels have been administratively disabled for this installation. Please contact instance owner or edit configuration file to enable this functionality.</p>";
2120 $subop = $_GET["subop"];
2122 if ($subop == "edit") {
2124 $label_id = db_escape_string($_GET["id"]);
2126 $result = db_query($link, "SELECT sql_exp,description FROM ttrss_labels WHERE
2127 owner_uid = ".$_SESSION["uid"]." AND id = '$label_id' ORDER by description");
2129 $line = db_fetch_assoc($result);
2131 $sql_exp = htmlspecialchars(db_unescape_string($line["sql_exp"]));
2132 $description = htmlspecialchars(db_unescape_string($line["description"]));
2134 print "<div id=\"infoBoxTitle\">Label editor</div>";
2135 print "<div class=\"infoBoxContents\">";
2137 print "<form id=\"label_edit_form\">";
2139 print "<input type=\"hidden\" name=\"op\" value=\"pref-labels\">";
2140 print "<input type=\"hidden\" name=\"id\" value=\"$label_id\">";
2141 print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
2143 print "<table width='100%'>";
2145 print "<tr><td>Caption:</td>
2146 <td><input onkeypress=\"return filterCR(event)\"
2147 onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
2148 name=\"description\" class=\"iedit\" value=\"$description\">";
2152 print "<tr><td colspan=\"2\">
2153 <p>SQL Expression:</p>";
2155 print "<textarea onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
2156 rows=\"4\" name=\"sql_exp\" class=\"iedit\">$sql_exp</textarea>";
2158 print "</td></tr></table>";
2162 print "<div style=\"display : none\" id=\"label_test_result\"></div>";
2164 print "<div align='right'>";
2166 $is_disabled = (strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== FALSE) ?
"disabled" : "";
2168 print "<input $is_disabled type=\"submit\" onclick=\"return labelTest()\" value=\"Test\">
2171 print "<input type=\"submit\"
2172 id=\"infobox_submit\"
2173 class=\"button\" onclick=\"return labelEditSave()\"
2176 print "<input class=\"button\"
2177 type=\"submit\" onclick=\"return labelEditCancel()\"
2185 if ($subop == "test") {
2187 $expr = db_unescape_string(trim($_GET["expr"]));
2188 $descr = db_unescape_string(trim($_GET["descr"]));
2195 $result = db_query($link,
2196 "SELECT count(ttrss_entries.id) AS num_matches
2197 FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
2199 ttrss_user_entries.ref_id = ttrss_entries.id AND
2200 ttrss_user_entries.feed_id = ttrss_feeds.id AND
2201 ttrss_user_entries.owner_uid = " . $_SESSION["uid"], false);
2203 error_reporting (DEFAULT_ERROR_LEVEL
);
2206 print "<p>" . db_last_error($link) . "</p>";
2211 $num_matches = db_fetch_result($result, 0, "num_matches");;
2213 if ($num_matches > 0) {
2215 if ($num_matches > 10) {
2216 $showing_msg = ", showing first 10";
2219 print "<p>Query returned <b>$num_matches</b> matches$showing_msg:</p>";
2221 $result = db_query($link,
2222 "SELECT ttrss_entries.title,
2223 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
2224 FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
2226 ttrss_user_entries.ref_id = ttrss_entries.id
2227 AND ttrss_user_entries.feed_id = ttrss_feeds.id
2228 AND ttrss_user_entries.owner_uid = " . $_SESSION["uid"] . "
2229 ORDER BY date_entered DESC LIMIT 10", false);
2231 print "<ul class=\"labelTestResults\">";
2233 $row_class = "even";
2235 while ($line = db_fetch_assoc($result)) {
2236 $row_class = toggleEvenOdd($row_class);
2238 print "<li class=\"$row_class\">".$line["title"].
2239 " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
2244 print "<p>Query didn't return any matches.</p>";
2252 if ($subop == "editSave") {
2254 $sql_exp = trim($_GET["sql_exp"]);
2255 $descr = db_escape_string(trim($_GET["description"]));
2256 $label_id = db_escape_string($_GET["id"]);
2258 $result = db_query($link, "UPDATE ttrss_labels SET
2259 sql_exp = '$sql_exp',
2260 description = '$descr'
2261 WHERE id = '$label_id'");
2264 if ($subop == "remove") {
2266 if (!WEB_DEMO_MODE
) {
2268 $ids = split(",", db_escape_string($_GET["ids"]));
2270 foreach ($ids as $id) {
2271 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
2277 if ($subop == "add") {
2279 if (!WEB_DEMO_MODE
) {
2281 // no escaping is done here on purpose
2282 $sql_exp = trim($_GET["sql_exp"]);
2283 $description = db_escape_string($_GET["description"]);
2285 $result = db_query($link,
2286 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
2287 VALUES ('$sql_exp', '$description', '".$_SESSION["uid"]."')");
2291 $sort = db_escape_string($_GET["sort"]);
2293 if (!$sort ||
$sort == "undefined") {
2294 $sort = "description";
2297 print "<div class=\"prefGenericAddBox\">";
2299 print"<input type=\"submit\" class=\"button\"
2300 id=\"label_create_btn\"
2301 onclick=\"return displayDlg('quickAddLabel', false)\"
2302 value=\"Create label\"></div>";
2304 $result = db_query($link, "SELECT
2305 id,sql_exp,description
2309 owner_uid = ".$_SESSION["uid"]."
2312 // print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2314 if (db_num_rows($result) != 0) {
2316 print "<form id=\"label_edit_form\">";
2318 print "<p><table width=\"100%\" cellspacing=\"0\"
2319 class=\"prefLabelList\" id=\"prefLabelList\">";
2321 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2323 <a href=\"javascript:selectPrefRows('label', true)\">All</a>,
2324 <a href=\"javascript:selectPrefRows('label', false)\">None</a>
2327 print "<tr class=\"title\">
2328 <td width=\"5%\"> </td>
2329 <td width=\"30%\"><a href=\"javascript:updateLabelList('description')\">Caption</a></td>
2330 <td width=\"50%\"><a href=\"javascript:updateLabelList('sql_exp')\">SQL Expression</a>
2331 <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a>
2337 while ($line = db_fetch_assoc($result)) {
2339 $class = ($lnum %
2) ?
"even" : "odd";
2341 $label_id = $line["id"];
2342 $edit_label_id = $_GET["id"];
2344 if ($subop == "edit" && $label_id != $edit_label_id) {
2348 $this_row_id = "id=\"LILRR-$label_id\"";
2351 print "<tr class=\"$class\" $this_row_id>";
2353 $line["sql_exp"] = htmlspecialchars(db_unescape_string($line["sql_exp"]));
2354 $line["description"] = htmlspecialchars(
2355 db_unescape_string($line["description"]));
2357 if (!$line["description"]) $line["description"] = "[No caption]";
2359 print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"label\");'
2360 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
2362 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2363 $line["description"] . "</td>";
2365 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2366 $line["sql_exp"] . "</td>";
2374 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
2381 print "<p id=\"labelOpToolbar\">";
2385 <input type=\"submit\" class=\"button\" disabled=\"true\"
2386 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
2387 <input type=\"submit\" class=\"button\" disabled=\"true\"
2388 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
2391 print "<p>No labels defined.</p>";
2395 if ($op == "error") {
2396 print "<div width=\"100%\" align='center'>";
2397 $msg = $_GET["msg"];
2402 if ($op == "help") {
2403 if (!$_GET["noheaders"]) {
2405 <title>Tiny Tiny RSS : Help</title>
2406 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2407 <script type=\"text/javascript\" src=\"prototype.js\"></script>
2408 <script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
2409 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2413 $tid = sprintf("%d", $_GET["tid"]);
2415 print "<div id=\"infoBoxTitle\">Help</div>";
2417 print "<div class='infoBoxContents'>";
2419 if (file_exists("help/$tid.php")) {
2420 include("help/$tid.php");
2422 print "<p>Help topic not found.</p>";
2427 print "<div align='center'>
2428 <input type='submit' class='button'
2429 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2431 if (!$_GET["noheaders"]) {
2432 print "</body></html>";
2439 $param = $_GET["param"];
2441 if ($id == "quickAddFeed") {
2443 print "<div id=\"infoBoxTitle\">Subscribe to feed</div>";
2444 print "<div class=\"infoBoxContents\">";
2446 print "<form id='feed_add_form'>";
2448 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
2449 print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
2450 print "<input type=\"hidden\" name=\"subop\" value=\"add\">";
2452 print "<table width='100%'>
2453 <tr><td>Feed URL:</td><td>
2454 <input class=\"iedit\" onblur=\"javascript:enableHotkeys()\"
2455 onkeypress=\"return filterCR(event)\"
2456 onkeyup=\"toggleSubmitNotEmpty(this, 'fadd_submit_btn')\"
2457 onfocus=\"javascript:disableHotkeys()\" name=\"feed_url\"></td></tr>";
2459 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2460 print "<tr><td>Category:</td><td>";
2461 print_feed_cat_select($link, "cat_id");
2468 print "<div align='right'>
2469 <input class=\"button\"
2470 id=\"fadd_submit_btn\" disabled=\"true\"
2471 type=\"submit\" onclick=\"return qafAdd()\" value=\"Subscribe\">
2472 <input class=\"button\"
2473 type=\"submit\" onclick=\"return closeInfoBox()\"
2474 value=\"Cancel\"></div>";
2477 if ($id == "search") {
2479 print "<div id=\"infoBoxTitle\">Search</div>";
2480 print "<div class=\"infoBoxContents\">";
2482 print "<form id='search_form'>";
2484 #$active_feed_id = db_escape_string($_GET["param"]);
2486 $params = split(":", db_escape_string($_GET["param"]));
2488 $active_feed_id = sprintf("%d", $params[0]);
2489 $is_cat = $params[1] == "true";
2491 print "<table width='100%'><tr><td>Search:</td><td>";
2493 print "<input name=\"query\" class=\"iedit\"
2494 onkeypress=\"return filterCR(event)\"
2495 onkeyup=\"toggleSubmitNotEmpty(this, 'search_submit_btn')\"
2499 print "<tr><td>Where:</td><td>";
2501 print "<select name=\"search_mode\">
2502 <option value=\"all_feeds\">All feeds</option>";
2504 $feed_title = getFeedTitle($link, $active_feed_id);
2507 $feed_cat_title = getFeedCatTitle($link, $active_feed_id);
2509 $feed_cat_title = getCategoryTitle($link, $active_feed_id);
2512 if ($active_feed_id && !$is_cat) {
2513 print "<option selected value=\"this_feed\">This feed ($feed_title)</option>";
2515 print "<option disabled>This feed</option>";
2519 $cat_preselected = "selected";
2522 if (get_pref($link, 'ENABLE_FEED_CATS') && ($active_feed_id > 0 ||
$is_cat)) {
2523 print "<option $cat_preselected value=\"this_cat\">This category ($feed_cat_title)</option>";
2525 print "<option disabled>This category</option>";
2528 print "</select></td></tr>";
2530 print "<tr><td>Match on:</td><td>";
2532 $search_fields = array(
2534 "content" => "Content",
2535 "both" => "Title or content");
2537 print_select_hash("match_on", 3, $search_fields);
2539 print "</td></tr></table>";
2543 print "<div align=\"right\">
2544 <input type=\"submit\"
2545 class=\"button\" onclick=\"javascript:search()\"
2546 id=\"search_submit_btn\" disabled=\"true\"
2548 <input class=\"button\"
2549 type=\"submit\" onclick=\"javascript:searchCancel()\"
2550 value=\"Cancel\"></div>";
2556 if ($id == "quickAddLabel") {
2557 print "<div id=\"infoBoxTitle\">Create label</div>";
2558 print "<div class=\"infoBoxContents\">";
2560 print "<form id=\"label_edit_form\">";
2562 print "<input type=\"hidden\" name=\"op\" value=\"pref-labels\">";
2563 print "<input type=\"hidden\" name=\"subop\" value=\"add\">";
2565 print "<table width='100%'>";
2567 print "<tr><td>Caption:</td>
2568 <td><input onkeypress=\"return filterCR(event)\"
2569 onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
2570 name=\"description\" class=\"iedit\">";
2574 print "<tr><td colspan=\"2\">
2575 <p>SQL Expression:</p>";
2577 print "<textarea onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
2578 rows=\"4\" name=\"sql_exp\" class=\"iedit\"></textarea>";
2580 print "</td></tr></table>";
2584 print "<div style=\"display : none\" id=\"label_test_result\"></div>";
2586 print "<div align='right'>";
2588 print "<input type=\"submit\" onclick=\"labelTest()\" value=\"Test\">
2591 print "<input type=\"submit\"
2592 id=\"infobox_submit\"
2594 class=\"button\" onclick=\"return addLabel()\"
2595 value=\"Create\"> ";
2597 print "<input class=\"button\"
2598 type=\"submit\" onclick=\"return labelEditCancel()\"
2602 if ($id == "quickAddFilter") {
2604 $active_feed_id = db_escape_string($_GET["param"]);
2606 print "<div id=\"infoBoxTitle\">Create filter</div>";
2607 print "<div class=\"infoBoxContents\">";
2609 print "<form id=\"filter_add_form\">";
2611 print "<input type=\"hidden\" name=\"op\" value=\"pref-filters\">";
2612 print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
2613 print "<input type=\"hidden\" name=\"subop\" value=\"add\">";
2615 // print "<div class=\"notice\"><b>Note:</b> filter will only apply to new articles.</div>";
2617 $result = db_query($link, "SELECT id,description
2618 FROM ttrss_filter_types ORDER BY description");
2620 $filter_types = array();
2622 while ($line = db_fetch_assoc($result)) {
2623 //array_push($filter_types, $line["description"]);
2624 $filter_types[$line["id"]] = $line["description"];
2627 print "<table width='100%'>";
2629 print "<tr><td>Match:</td>
2630 <td><input onkeypress=\"return filterCR(event)\"
2631 onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
2632 name=\"reg_exp\" class=\"iedit\">";
2635 print_select_hash("filter_type", 1, $filter_types, "class=\"iedit\"");
2638 print "<tr><td>Feed:</td><td colspan='2'>";
2640 print_feed_select($link, "feed_id", $active_feed_id);
2644 print "<tr><td>Action:</td>";
2646 print "<td colspan='2'><select name=\"action_id\">";
2648 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2651 while ($line = db_fetch_assoc($result)) {
2652 printf("<option value='%d'>%s</option>", $line["id"], $line["description"]);
2657 print "</td></tr></table>";
2661 print "<div align='right'>";
2663 print "<input type=\"submit\"
2664 id=\"infobox_submit\"
2665 class=\"button\" onclick=\"return qaddFilter()\"
2666 disabled=\"true\" value=\"Create\"> ";
2668 print "<input class=\"button\"
2669 type=\"submit\" onclick=\"return closeInfoBox()\"
2674 // print "</td></tr></table>";
2682 // update feeds of all users, may be used anonymously
2683 if ($op == "globalUpdateFeeds") {
2685 $result = db_query($link, "SELECT id FROM ttrss_users");
2687 while ($line = db_fetch_assoc($result)) {
2688 $user_id = $line["id"];
2689 // print "<!-- updating feeds of uid $user_id -->";
2690 update_all_feeds($link, false, $user_id);
2694 <message msg=\"All feeds updated\"/>
2699 if ($op == "pref-prefs") {
2701 $subop = $_REQUEST["subop"];
2703 if ($subop == "Save configuration") {
2705 if (WEB_DEMO_MODE
) {
2706 header("Location: prefs.php");
2710 $_SESSION["prefs_op_result"] = "save-config";
2712 $_SESSION["prefs_cache"] = false;
2714 foreach (array_keys($_POST) as $pref_name) {
2716 $pref_name = db_escape_string($pref_name);
2717 $value = db_escape_string($_POST[$pref_name]);
2719 $result = db_query($link, "SELECT type_name
2720 FROM ttrss_prefs,ttrss_prefs_types
2721 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
2723 if (db_num_rows($result) > 0) {
2725 $type_name = db_fetch_result($result, 0, "type_name");
2727 // print "$pref_name : $type_name : $value<br>";
2729 if ($type_name == "bool") {
2730 if ($value == "1") {
2735 } else if ($type_name == "integer") {
2736 $value = sprintf("%d", $value);
2739 // print "$pref_name : $type_name : $value<br>";
2741 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
2742 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
2746 header("Location: prefs.php");
2750 } else if ($subop == "getHelp") {
2752 $pref_name = db_escape_string($_GET["pn"]);
2754 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
2755 WHERE pref_name = '$pref_name'");
2757 if (db_num_rows($result) > 0) {
2758 $help_text = db_fetch_result($result, 0, "help_text");
2761 print "Unknown option: $pref_name";
2764 } else if ($subop == "Change e-mail") {
2766 if (WEB_DEMO_MODE
) {
2767 header("Location: prefs.php");
2771 $email = db_escape_string($_GET["email"]);
2772 $active_uid = $_SESSION["uid"];
2775 db_query($link, "UPDATE ttrss_users SET email = '$email'
2776 WHERE id = '$active_uid'");
2779 header("Location: prefs.php");
2781 } else if ($subop == "Change password") {
2783 if (WEB_DEMO_MODE
) {
2784 header("Location: prefs.php");
2788 $old_pw = $_POST["OLD_PASSWORD"];
2789 $new_pw = $_POST["OLD_PASSWORD"];
2791 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
2792 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
2794 $active_uid = $_SESSION["uid"];
2796 if ($old_pw && $new_pw) {
2798 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
2800 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
2801 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
2802 pwd_hash = '$old_pw_hash')");
2804 if (db_num_rows($result) == 1) {
2805 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
2806 WHERE id = '$active_uid'");
2808 $_SESSION["pwd_change_result"] = "ok";
2810 $_SESSION["pwd_change_result"] = "failed";
2814 header("Location: prefs.php");
2816 } else if ($subop == "Reset to defaults") {
2818 if (WEB_DEMO_MODE
) {
2819 header("Location: prefs.php");
2823 $_SESSION["prefs_op_result"] = "reset-to-defaults";
2825 if (DB_TYPE
== "pgsql") {
2826 db_query($link,"UPDATE ttrss_user_prefs
2827 SET value = ttrss_prefs.def_value
2828 WHERE owner_uid = '".$_SESSION["uid"]."' AND
2829 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
2831 db_query($link, "DELETE FROM ttrss_user_prefs
2832 WHERE owner_uid = ".$_SESSION["uid"]);
2833 initialize_user_prefs($link, $_SESSION["uid"]);
2836 header("Location: prefs.php");
2838 } else if ($subop == "Change theme") {
2840 $theme = db_escape_string($_POST["theme"]);
2842 if ($theme == "Default") {
2843 $theme_qpart = 'NULL';
2845 $theme_qpart = "'$theme'";
2848 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
2849 WHERE theme_name = '$theme'");
2851 if (db_num_rows($result) == 1) {
2852 $theme_id = db_fetch_result($result, 0, "id");
2853 $theme_path = db_fetch_result($result, 0, "theme_path");
2859 db_query($link, "UPDATE ttrss_users SET
2860 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
2862 $_SESSION["theme"] = $theme_path;
2864 header("Location: prefs.php");
2868 print check_for_update($link);
2870 if (!SINGLE_USER_MODE
) {
2872 $result = db_query($link, "SELECT id,email FROM ttrss_users
2873 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
2874 pwd_hash = 'SHA1:".sha1("password")."')");
2876 if (db_num_rows($result) != 0) {
2877 print "<div class=\"warning\">
2878 Your password is at default value, please change it.
2882 if ($_SESSION["pwd_change_result"] == "failed") {
2883 print "<div class=\"warning\">
2884 There was an error while changing your password.
2888 if ($_SESSION["pwd_change_result"] == "ok") {
2889 print "<div class=\"notice\">
2890 Password changed successfully.
2894 $_SESSION["pwd_change_result"] = "";
2896 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
2897 print "<div class=\"notice\">
2898 Your configuration was reset to defaults.
2902 if ($_SESSION["prefs_op_result"] == "save-config") {
2903 print "<div class=\"notice\">
2904 Your configuration was saved successfully.
2908 $_SESSION["prefs_op_result"] = "";
2910 print "<form action=\"backend.php\" method=\"GET\">";
2912 print "<table width=\"100%\" class=\"prefPrefsList\">";
2913 print "<tr><td colspan='3'><h3>Personal data</h3></tr></td>";
2915 $result = db_query($link, "SELECT email FROM ttrss_users
2916 WHERE id = ".$_SESSION["uid"]);
2918 $email = db_fetch_result($result, 0, "email");
2920 print "<tr><td width=\"40%\">E-mail</td>";
2921 print "<td><input class=\"editbox\" name=\"email\"
2922 value=\"$email\"></td></tr>";
2926 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2928 print "<p><input class=\"button\" type=\"submit\"
2929 value=\"Change e-mail\" name=\"subop\">";
2933 print "<form action=\"backend.php\" method=\"POST\" name=\"changePassForm\">";
2935 print "<table width=\"100%\" class=\"prefPrefsList\">";
2936 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
2938 print "<tr><td width=\"40%\">Old password</td>";
2939 print "<td><input class=\"editbox\" type=\"password\"
2940 name=\"OLD_PASSWORD\"></td></tr>";
2942 print "<tr><td width=\"40%\">New password</td>";
2944 print "<td><input class=\"editbox\" type=\"password\"
2945 name=\"NEW_PASSWORD\"></td></tr>";
2949 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2951 print "<p><input class=\"button\" type=\"submit\"
2952 onclick=\"return validateNewPassword(this.form)\"
2953 value=\"Change password\" name=\"subop\">";
2959 $result = db_query($link, "SELECT
2960 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
2962 $user_theme_id = db_fetch_result($result, 0, "theme_id");
2964 $result = db_query($link, "SELECT
2965 id,theme_name FROM ttrss_themes ORDER BY theme_name");
2967 if (db_num_rows($result) > 0) {
2969 print "<form action=\"backend.php\" method=\"POST\">";
2970 print "<table width=\"100%\" class=\"prefPrefsList\">";
2971 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
2972 print "<tr><td width=\"40%\">Select theme</td>";
2973 print "<td><select name=\"theme\">";
2974 print "<option>Default</option>";
2975 print "<option disabled>--------</option>";
2977 while ($line = db_fetch_assoc($result)) {
2978 if ($line["id"] == $user_theme_id) {
2979 $selected = "selected";
2983 print "<option $selected>" . $line["theme_name"] . "</option>";
2985 print "</select></td></tr>";
2987 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2988 print "<p><input class=\"button\" type=\"submit\"
2989 value=\"Change theme\" name=\"subop\">";
2993 initialize_user_prefs($link, $_SESSION["uid"]);
2995 $result = db_query($link, "SELECT
2996 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
2997 section_name,def_value
2998 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
2999 WHERE type_id = ttrss_prefs_types.id AND
3000 section_id = ttrss_prefs_sections.id AND
3001 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
3002 owner_uid = ".$_SESSION["uid"]."
3003 ORDER BY section_id,short_desc");
3005 print "<form action=\"backend.php\" method=\"POST\">";
3009 $active_section = "";
3011 while ($line = db_fetch_assoc($result)) {
3013 if ($active_section != $line["section_name"]) {
3015 if ($active_section != "") {
3019 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
3021 $active_section = $line["section_name"];
3023 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
3024 // print "<tr class=\"title\">
3025 // <td width=\"25%\">Option</td><td>Value</td></tr>";
3030 // $class = ($lnum % 2) ? "even" : "odd";
3034 $type_name = $line["type_name"];
3035 $pref_name = $line["pref_name"];
3036 $value = $line["value"];
3037 $def_value = $line["def_value"];
3038 $help_text = $line["help_text"];
3040 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
3042 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
3048 if ($type_name == "bool") {
3049 // print_select($pref_name, $value, array("true", "false"));
3051 if ($value == "true") {
3057 print_radio($pref_name, $value, array("Yes", "No"));
3060 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
3072 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3074 print "<p><input class=\"button\" type=\"submit\"
3075 name=\"subop\" value=\"Save configuration\">";
3077 print " <input class=\"button\" type=\"submit\"
3078 name=\"subop\" onclick=\"return validatePrefsReset()\"
3079 value=\"Reset to defaults\"></p>";
3087 if ($op == "pref-users") {
3089 $subop = $_GET["subop"];
3091 if ($subop == "edit") {
3093 $id = db_escape_string($_GET["id"]);
3095 print "<div id=\"infoBoxTitle\">User editor</div>";
3097 print "<div class=\"infoBoxContents\">";
3099 print "<form id=\"user_edit_form\">";
3101 print "<input type=\"hidden\" name=\"id\" value=\"$id\">";
3102 print "<input type=\"hidden\" name=\"op\" value=\"pref-users\">";
3103 print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
3105 $result = db_query($link, "SELECT * FROM ttrss_users WHERE id = '$id'");
3107 $login = db_fetch_result($result, 0, "login");
3108 $access_level = db_fetch_result($result, 0, "access_level");
3109 $email = db_fetch_result($result, 0, "email");
3111 print "<table width='100%'>";
3112 print "<tr><td>Login:</td><td>
3113 <input class=\"iedit\" onkeypress=\"return filterCR(event)\"
3114 name=\"login\" value=\"$login\"></td></tr>";
3116 print "<tr><td>Change password:</td><td>
3117 <input class=\"iedit\" onkeypress=\"return filterCR(event)\"
3118 name=\"password\"></td></tr>";
3120 print "<tr><td>E-mail:</td><td>
3121 <input class=\"iedit\" name=\"email\" onkeypress=\"return filterCR(event)\"
3122 value=\"$email\"></td></tr>";
3124 $sel_disabled = ($id == $_SESSION["uid"]) ?
"disabled" : "";
3126 print "<tr><td>Access level:</td><td>";
3127 print_select_hash("access_level", $access_level, $access_level_names,
3135 print "<div align='right'>
3136 <input class=\"button\"
3137 type=\"submit\" onclick=\"return userEditSave()\"
3139 <input class=\"button\"
3140 type=\"submit\" onclick=\"return userEditCancel()\"
3141 value=\"Cancel\"></div>";
3148 if ($subop == "editSave") {
3150 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3152 $login = db_escape_string(trim($_GET["login"]));
3153 $uid = db_escape_string($_GET["id"]);
3154 $access_level = sprintf("%d", $_GET["access_level"]);
3155 $email = db_escape_string(trim($_GET["email"]));
3156 $password = db_escape_string(trim($_GET["password"]));
3159 $pwd_hash = 'SHA1:' . sha1($password);
3160 $pass_query_part = "pwd_hash = '$pwd_hash', ";
3161 print "<div class='notice'>Changed password for user <b>$login</b>.</div>";
3163 $pass_query_part = "";
3166 db_query($link, "UPDATE ttrss_users SET $pass_query_part login = '$login',
3167 access_level = '$access_level', email = '$email' WHERE id = '$uid'");
3170 } else if ($subop == "remove") {
3172 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3174 $ids = split(",", db_escape_string($_GET["ids"]));
3176 foreach ($ids as $id) {
3177 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
3181 } else if ($subop == "add") {
3183 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3185 $login = db_escape_string(trim($_GET["login"]));
3186 $tmp_user_pwd = make_password(8);
3187 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3189 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3192 if (db_num_rows($result) == 0) {
3194 db_query($link, "INSERT INTO ttrss_users
3195 (login,pwd_hash,access_level,last_login)
3196 VALUES ('$login', '$pwd_hash', 0, NOW())");
3199 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3200 login = '$login' AND pwd_hash = '$pwd_hash'");
3202 if (db_num_rows($result) == 1) {
3204 $new_uid = db_fetch_result($result, 0, "id");
3206 print "<div class=\"notice\">Added user <b>".$_GET["login"].
3207 "</b> with password <b>$tmp_user_pwd</b>.</div>";
3209 initialize_user($link, $new_uid);
3213 print "<div class=\"warning\">Could not create user <b>".
3214 $_GET["login"]."</b></div>";
3218 print "<div class=\"warning\">User <b>".
3219 $_GET["login"]."</b> already exists.</div>";
3222 } else if ($subop == "resetPass") {
3224 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3226 $uid = db_escape_string($_GET["id"]);
3228 $result = db_query($link, "SELECT login,email
3229 FROM ttrss_users WHERE id = '$uid'");
3231 $login = db_fetch_result($result, 0, "login");
3232 $email = db_fetch_result($result, 0, "email");
3233 $tmp_user_pwd = make_password(8);
3234 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3236 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
3237 WHERE id = '$uid'");
3239 print "<div class=\"notice\">Changed password of
3240 user <b>$login</b> to <b>$tmp_user_pwd</b>.";
3242 if (MAIL_RESET_PASS
&& $email) {
3243 print " Notifying <b>$email</b>.";
3245 mail("$login <$email>", "Password reset notification",
3248 "Your password for this TT-RSS installation was reset by".
3249 " an administrator.\n".
3251 "Your new password is $tmp_user_pwd, please remember".
3252 " it for later reference.\n".
3254 "Sincerely, TT-RSS Mail Daemon.", "From: " . MAIL_FROM
);
3262 $sort = db_escape_string($_GET["sort"]);
3264 if (!$sort ||
$sort == "undefined") {
3268 print "<div class=\"prefGenericAddBox\">
3269 <input id=\"uadd_box\"
3270 onkeyup=\"toggleSubmitNotEmpty(this, 'user_add_btn')\"
3271 size=\"40\"> ";
3273 print"<input type=\"submit\" class=\"button\"
3274 id=\"user_add_btn\" disabled=\"true\"
3275 onclick=\"javascript:addUser()\" value=\"Create user\"></div>";
3277 $result = db_query($link, "SELECT
3278 id,login,access_level,email,
3279 SUBSTRING(last_login,1,16) as last_login
3284 // print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
3286 print "<p><table width=\"100%\" cellspacing=\"0\"
3287 class=\"prefUserList\" id=\"prefUserList\">";
3289 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
3291 <a href=\"javascript:selectPrefRows('user', true)\">All</a>,
3292 <a href=\"javascript:selectPrefRows('user', false)\">None</a>
3295 print "<tr class=\"title\">
3296 <td align='center' width=\"5%\"> </td>
3297 <td width='40%'><a href=\"javascript:updateUsersList('login')\">Login</a></td>
3298 <td width='40%'><a href=\"javascript:updateUsersList('access_level')\">Access Level</a></td>
3299 <td width='30%'><a href=\"javascript:updateUsersList('last_login')\">Last login</a></td></tr>";
3303 while ($line = db_fetch_assoc($result)) {
3305 $class = ($lnum %
2) ?
"even" : "odd";
3308 $edit_uid = $_GET["id"];
3310 if ($subop == "edit" && $uid != $edit_uid) {
3314 $this_row_id = "id=\"UMRR-$uid\"";
3317 print "<tr class=\"$class\" $this_row_id>";
3319 $line["login"] = htmlspecialchars($line["login"]);
3321 $line["last_login"] = date(get_pref($link, 'SHORT_DATE_FORMAT'),
3322 strtotime($line["last_login"]));
3324 $access_level_names = array(0 => "User", 10 => "Administrator");
3326 // if (!$edit_uid || $subop != "edit") {
3328 print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"user\");'
3329 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
3331 print "<td><a href=\"javascript:editUser($uid);\">" .
3332 $line["login"] . "</td>";
3334 if (!$line["email"]) $line["email"] = " ";
3336 print "<td><a href=\"javascript:editUser($uid);\">" .
3337 $access_level_names[$line["access_level"]] . "</td>";
3339 /* } else if ($uid != $edit_uid) {
3341 if (!$line["email"]) $line["email"] = " ";
3343 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
3344 id=\"UMCHK-".$line["id"]."\"></td>";
3346 print "<td>".$line["login"]."</td>";
3347 print "<td>".$line["email"]."</td>";
3348 print "<td>".$access_level_names[$line["access_level"]]."</td>";
3352 print "<td align='center'>
3353 <input disabled=\"true\" type=\"checkbox\" checked></td>";
3355 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
3358 print "<td><input id=\"iedit_email\" value=\"".$line["email"].
3362 print "<select id=\"iedit_ulevel\">";
3363 foreach (array_keys($access_level_names) as $al) {
3364 if ($al == $line["access_level"]) {
3365 $selected = "selected";
3369 print "<option $selected id=\"$al\">" .
3370 $access_level_names[$al] . "</option>";
3377 print "<td>".$line["last_login"]."</td>";
3386 print "<p id='userOpToolbar'>";
3388 /* if ($subop == "edit") {
3390 <input type=\"submit\" class=\"button\"
3391 onclick=\"javascript:userEditSave()\" value=\"Save\">
3392 <input type=\"submit\" class=\"button\"
3393 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">";
3399 <input type=\"submit\" class=\"button\" disabled=\"true\"
3400 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
3401 <input type=\"submit\" class=\"button\" disabled=\"true\"
3402 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
3403 <input type=\"submit\" class=\"button\" disabled=\"true\"
3404 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
3405 <input type=\"submit\" class=\"button\" disabled=\"true\"
3406 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
3411 if ($op == "user-details") {
3413 if (WEB_DEMO_MODE ||
$_SESSION["access_level"] < 10) {
3417 /* print "<html><head>
3418 <title>Tiny Tiny RSS : User Details</title>
3419 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
3420 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
3423 $uid = sprintf("%d", $_GET["id"]);
3425 print "<div id=\"infoBoxTitle\">User details</div>";
3427 print "<div class='infoBoxContents'>";
3429 $result = db_query($link, "SELECT login,
3430 SUBSTRING(last_login,1,16) AS last_login,
3432 (SELECT COUNT(int_id) FROM ttrss_user_entries
3433 WHERE owner_uid = id) AS stored_articles
3435 WHERE id = '$uid'");
3437 if (db_num_rows($result) == 0) {
3438 print "<h1>User not found</h1>";
3442 # print "<h1>User Details</h1>";
3444 $login = db_fetch_result($result, 0, "login");
3446 # print "<h1>$login</h1>";
3448 print "<table width='100%'>";
3450 $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'),
3451 strtotime(db_fetch_result($result, 0, "last_login")));
3452 $access_level = db_fetch_result($result, 0, "access_level");
3453 $stored_articles = db_fetch_result($result, 0, "stored_articles");
3455 # print "<tr><td>Username</td><td>$login</td></tr>";
3456 # print "<tr><td>Access level</td><td>$access_level</td></tr>";
3457 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
3458 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
3460 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
3461 WHERE owner_uid = '$uid'");
3463 $num_feeds = db_fetch_result($result, 0, "num_feeds");
3465 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
3467 /* $result = db_query($link, "SELECT
3468 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
3469 FROM ttrss_user_entries,ttrss_entries
3470 WHERE owner_uid = '$uid' AND ref_id = id");
3472 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
3474 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
3478 print "<h1>Subscribed feeds</h1>";
3480 $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
3481 WHERE owner_uid = '$uid' ORDER BY title");
3483 print "<ul class=\"userFeedList\">";
3487 while ($line = db_fetch_assoc($result)) {
3489 $icon_file = ICONS_URL
."/".$line["id"].".ico";
3491 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3492 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
3494 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3497 print "<li class=\"$row_class\">$feed_icon <a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
3499 $row_class = toggleEvenOdd($row_class);
3503 if (db_num_rows($result) < $num_feeds) {
3504 // FIXME - add link to show ALL subscribed feeds here somewhere
3506 class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\"> ...</li>";
3513 print "<div align='center'>
3514 <input type='submit' class='button'
3515 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3517 // print "</body></html>";
3521 if ($op == "pref-feed-browser") {
3523 if (!ENABLE_FEED_BROWSER
) {
3524 print "Feed browser is administratively disabled.";
3528 $subop = $_REQUEST["subop"];
3530 if ($subop == "details") {
3531 $id = db_escape_string($_GET["id"]);
3533 print "<div class=\"browserFeedInfo\">";
3534 print "<b>Feed information:</b>";
3535 print "<div class=\"detailsPart\">";
3537 $result = db_query($link, "SELECT
3539 SUBSTRING(last_updated,1,19) AS last_updated
3540 FROM ttrss_feeds WHERE id = '$id'");
3542 $feed_url = db_fetch_result($result, 0, "feed_url");
3543 $site_url = db_fetch_result($result, 0, "site_url");
3544 $last_updated = db_fetch_result($result, 0, "last_updated");
3546 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
3547 $last_updated = smart_date_time(strtotime($last_updated));
3549 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
3550 $last_updated = date($short_date, strtotime($last_updated));
3553 print "Site: <a target=\"_new\" href='$site_url'>$site_url</a> ".
3554 "(<a target=\"_new\" href='$feed_url'>feed</a>), ".
3555 "Last updated: $last_updated";
3559 $result = db_query($link, "SELECT
3560 ttrss_entries.title,
3562 substring(date_entered,1,19) as date_entered,
3563 substring(updated,1,19) as updated
3564 FROM ttrss_entries,ttrss_user_entries
3565 WHERE ttrss_entries.id = ref_id AND feed_id = '$id'
3566 ORDER BY updated DESC LIMIT 5");
3568 if (db_num_rows($result) > 0) {
3570 print "<b>Last headlines:</b><br>";
3572 print "<div class=\"detailsPart\">";
3573 print "<ul class=\"compact\">";
3574 while ($line = db_fetch_assoc($result)) {
3576 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
3577 $entry_dt = smart_date_time(strtotime($line["updated"]));
3579 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
3580 $entry_dt = date($short_date, strtotime($line["updated"]));
3583 print "<li><a target=\"_new\" href=\"" . $line["link"] . "\">" . $line["title"] . "</a>" .
3584 " <span class=\"insensitive\">($entry_dt)</span></li>";
3586 print "</ul></div>";
3594 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>";
3596 $limit = db_escape_string($_GET["limit"]);
3598 if (!$limit) $limit = 25;
3600 $owner_uid = $_SESSION["uid"];
3602 $result = db_query($link, "SELECT feed_url,COUNT(id) AS subscribers
3603 FROM ttrss_feeds WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
3604 WHERE tf.feed_url = ttrss_feeds.feed_url
3605 AND owner_uid = '$owner_uid') GROUP BY feed_url
3606 ORDER BY subscribers DESC LIMIT $limit");
3609 print "<div style=\"float : right\">
3610 Top <select id=\"feedBrowserLimit\">";
3612 foreach (array(25, 50, 100) as $l) {
3613 $issel = ($l == $limit) ?
"selected" : "";
3614 print "<option $issel>$l</option>";
3618 <input type=\"submit\" class=\"button\"
3619 onclick=\"updateBigFeedBrowser()\" value=\"Show\">
3622 print "<p id=\"fbrOpToolbar\">Selection:
3623 <input type='submit' class='button' onclick=\"feedBrowserSubscribe()\"
3624 disabled=\"true\" value=\"Subscribe\">";
3626 print "<ul class='nomarks' id='browseBigFeedList'>";
3630 while ($line = db_fetch_assoc($result)) {
3631 $feed_url = $line["feed_url"];
3632 $subscribers = $line["subscribers"];
3634 $det_result = db_query($link, "SELECT site_url,title,id
3635 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
3637 $details = db_fetch_assoc($det_result);
3639 $icon_file = ICONS_DIR
. "/" . $details["id"] . ".ico";
3641 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3642 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL
.
3643 "/".$details["id"].".ico\">";
3645 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3648 $check_box = "<input onclick='toggleSelectFBListRow(this)' class='feedBrowseCB'
3649 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
3651 $class = ($feedctr %
2) ?
"even" : "odd";
3653 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
3656 print "<a href=\"javascript:browserToggleExpand('".$details["id"]."')\">" .
3657 $details["title"] ."</a> " .
3658 "<span class='subscribers'>($subscribers)</span>";
3660 print "<div class=\"browserDetails\" id=\"BRDET-" . $details["id"] . "\">";
3668 if ($feedctr == 0) {
3669 print "<li>No feeds found to subscribe.</li>";
3679 $feed = db_escape_string($_GET["id"]);
3680 $user = db_escape_string($_GET["user"]);
3681 $pass = db_escape_string($_GET["pass"]);
3682 $is_cat = $_GET["is_cat"] != false;
3684 $search = db_escape_string($_GET["q"]);
3685 $match_on = db_escape_string($_GET["m"]);
3686 $search_mode = db_escape_string($_GET["smode"]);
3688 if (!$_SESSION["uid"] && $user && $pass) {
3689 authenticate_user($link, $user, $pass);
3692 if ($_SESSION["uid"] ||
3693 http_authenticate_user($link)) {
3695 generate_syndicated_feed($link, $feed, $is_cat,
3696 $search, $search_mode, $match_on);
3700 function check_configuration_variables() {
3701 if (!defined('SESSION_EXPIRE_TIME')) {
3702 return "config: SESSION_EXPIRE_TIME is undefined";
3705 if (SESSION_EXPIRE_TIME
< 60) {
3706 return "config: SESSION_EXPIRE_TIME is too low (less than 60)";
3709 if (SESSION_EXPIRE_TIME
< SESSION_COOKIE_LIFETIME_REMEMBER
) {
3710 return "config: SESSION_EXPIRE_TIME should be greater or equal to" .
3711 "SESSION_COOKIE_LIFETIME_REMEMBER";
3714 if (defined('DISABLE_SESSIONS')) {
3715 return "config: you have enabled DISABLE_SESSIONS. Please disable this option.";
3718 if (DATABASE_BACKED_SESSIONS
&& SINGLE_USER_MODE
) {
3719 return "config: DATABASE_BACKED_SESSIONS is incompatible with SINGLE_USER_MODE";
3725 if ($op == "labelFromSearch") {
3726 $search = db_escape_string($_GET["search"]);
3727 $search_mode = db_escape_string($_GET["smode"]);
3728 $match_on = db_escape_string($_GET["match"]);
3729 $is_cat = db_escape_string($_GET["is_cat"]);
3730 $title = db_escape_string($_GET["title"]);
3731 $feed = sprintf("%d", $_GET["feed"]);
3733 $label_qparts = array();
3735 $search_expr = getSearchSql($search, $match_on);
3739 $search_expr .= " AND ttrss_feeds.cat_id = $feed ";
3741 $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
3744 if ($search_mode == "all_feeds") {
3746 } else if ($search_mode == "this_cat") {
3748 $tmp_result = db_query($link, "SELECT cat_id
3749 FROM ttrss_feeds WHERE id = '$feed'");
3751 $cat_id = db_fetch_result($tmp_result, 0, "cat_id");
3754 $search_expr .= " AND ttrss_feeds.cat_id = $cat_id ";
3756 $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
3759 $search_expr .= " AND ttrss_feeds.id = $feed ";
3764 $search_expr = db_escape_string($search_expr);
3769 $result = db_query($link,
3770 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
3771 VALUES ('$search_expr', '$title', '".$_SESSION["uid"]."')");
3775 if ($op == "getUnread") {
3776 $login = db_escape_string($_GET["login"]);
3778 header("Content-Type: text/plain; charset=utf-8");
3780 $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$login'");
3782 if (db_num_rows($result) == 1) {
3783 $uid = db_fetch_result($result, 0, "id");
3784 print getGlobalUnread($link, $uid);
3786 print "-1;User not found";
3789 $print_exec_time = false;
3792 if ($op == "digestTest") {
3793 header("Content-Type: text/plain");
3794 print_r(prepare_headlines_digest($link, $_SESSION["uid"]));
3795 $print_exec_time = false;
3799 if ($op == "digestSend") {
3800 header("Content-Type: text/plain");
3801 send_headlines_digests($link);
3802 $print_exec_time = false;
3809 <?php
if ($print_exec_time) { ?
>
3810 <!-- <?php
echo sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?
> -->