5 define('DEFAULT_ERROR_LEVEL', E_ALL
);
7 define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE
);
10 error_reporting(DEFAULT_ERROR_LEVEL
);
12 $op = $_REQUEST["op"];
14 if ((!$op ||
$op == "rpc" ||
$op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
15 header("Content-Type: application/xml");
18 if (!$_SESSION["uid"] && $op != "globalUpdateFeeds") {
21 print "<error error-code=\"6\"/>";
27 print "<error error-code=\"7\"/>";
31 define('SCHEMA_VERSION', 3);
33 require_once "sanity_check.php";
34 require_once "config.php";
35 require_once "db.php";
36 require_once "db-prefs.php";
37 require_once "functions.php";
38 require_once "magpierss/rss_fetch.inc";
40 $script_started = getmicrotime();
42 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
45 if (DB_TYPE
== "mysql") {
48 // PG seems to display its own errors just fine by default.
52 if (DB_TYPE
== "pgsql") {
53 pg_query("set client_encoding = 'utf-8'");
56 $fetch = $_GET["fetch"];
58 setcookie("ttrss_icons_url", ICONS_URL
);
60 if (!sanity_check($link)) { return; }
62 function getAllCounters($link) {
63 getLabelCounters($link);
64 getFeedCounters($link);
65 getTagCounters($link);
66 getGlobalCounters($link);
67 if (get_pref($link, 'ENABLE_FEED_CATS')) {
68 getCategoryCounters($link);
72 function getCategoryCounters($link) {
73 $result = db_query($link, "SELECT cat_id,SUM((SELECT COUNT(int_id)
74 FROM ttrss_user_entries WHERE feed_id = ttrss_feeds.id
75 AND unread = true)) AS unread FROM ttrss_feeds
77 owner_uid = ".$_SESSION["uid"]." GROUP BY cat_id");
79 while ($line = db_fetch_assoc($result)) {
80 $line["cat_id"] = sprintf("%d", $line["cat_id"]);
81 print "<counter type=\"category\" id=\"".$line["cat_id"]."\" counter=\"".
82 $line["unread"]."\"/>";
86 function getFeedUnread($link, $feed) {
87 $n_feed = sprintf("%d", $feed);
90 $match_part = "marked = true";
91 } else if ($feed > 0) {
92 $match_part = "feed_id = '$n_feed'";
93 } else if ($feed < -10) {
94 $label_id = -$feed - 11;
96 $result = db_query($link, "SELECT sql_exp FROM ttrss_labels WHERE
97 id = '$label_id' AND owner_uid = " . $_SESSION["uid"]);
99 $match_part = db_fetch_result($result, 0, "sql_exp");
104 $result = db_query($link, "SELECT count(int_id) AS unread
105 FROM ttrss_user_entries
106 WHERE unread = true AND $match_part AND owner_uid = " . $_SESSION["uid"]);
110 $result = db_query($link, "SELECT COUNT(post_int_id) AS unread
111 FROM ttrss_tags,ttrss_user_entries
112 WHERE tag_name = '$feed' AND post_int_id = int_id AND unread = true AND
113 ttrss_tags.owner_uid = " . $_SESSION["uid"]);
116 $unread = db_fetch_result($result, 0, "unread");
120 /* FIXME this needs reworking */
122 function getGlobalCounters($link) {
123 $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries,ttrss_user_entries
124 WHERE unread = true AND
125 ttrss_user_entries.ref_id = ttrss_entries.id AND
126 owner_uid = " . $_SESSION["uid"]);
127 $c_id = db_fetch_result($result, 0, "c_id");
128 print "<counter type=\"global\" id='global-unread' counter='$c_id'/>";
131 function getTagCounters($link, $smart_mode = SMART_RPC_COUNTERS
) {
134 if (!$_SESSION["tctr_last_value"]) {
135 $_SESSION["tctr_last_value"] = array();
139 $old_counters = $_SESSION["tctr_last_value"];
141 $tctrs_modified = false;
143 /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
144 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
145 ttrss_user_entries.ref_id = ttrss_entries.id AND
146 ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND
147 post_int_id = ttrss_user_entries.int_id AND unread = true GROUP BY tag_name
149 select tag_name,0 as count FROM ttrss_tags
150 WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]); */
152 $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
153 FROM ttrss_user_entries WHERE int_id = post_int_id
154 AND unread = true)) AS count FROM ttrss_tags
155 WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name");
159 while ($line = db_fetch_assoc($result)) {
160 $tags[$line["tag_name"]] +
= $line["count"];
163 foreach (array_keys($tags) as $tag) {
164 $unread = $tags[$tag];
166 $tag = htmlspecialchars($tag);
168 if (!$smart_mode ||
$old_counters[$tag] != $unread) {
169 $old_counters[$tag] = $unread;
170 $tctrs_modified = true;
171 print "<counter type=\"tag\" id=\"$tag\" counter=\"$unread\"/>";
176 if ($smart_mode && $tctrs_modified) {
177 $_SESSION["tctr_last_value"] = $old_counters;
182 function getLabelCounters($link, $smart_mode = SMART_RPC_COUNTERS
) {
185 if (!$_SESSION["lctr_last_value"]) {
186 $_SESSION["lctr_last_value"] = array();
190 $old_counters = $_SESSION["lctr_last_value"];
191 $lctrs_modified = false;
193 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries
194 WHERE marked = true AND ttrss_user_entries.ref_id = ttrss_entries.id AND
195 unread = true AND owner_uid = ".$_SESSION["uid"]);
197 $count = db_fetch_result($result, 0, "count");
199 print "<counter type=\"label\" id=\"-1\" counter=\"$count\"/>";
201 $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM
202 ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description");
204 while ($line = db_fetch_assoc($result)) {
206 $id = -$line["id"] - 11;
210 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_user_entries,ttrss_entries
211 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
212 ttrss_user_entries.ref_id = ttrss_entries.id AND
213 owner_uid = ".$_SESSION["uid"]);
215 $count = db_fetch_result($tmp_result, 0, "count");
217 if (!$smart_mode ||
$old_counters[$id] != $count) {
218 $old_counters[$id] = $count;
219 $lctrs_modified = true;
220 print "<counter type=\"label\" id=\"$id\" counter=\"$count\"/>";
223 error_reporting (DEFAULT_ERROR_LEVEL
);
226 if ($smart_mode && $lctrs_modified) {
227 $_SESSION["lctr_last_value"] = $old_counters;
231 /* function getFeedCounter($link, $id) {
233 $result = db_query($link, "SELECT
234 count(id) as count,last_error
235 FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
236 WHERE feed_id = '$id' AND unread = true
237 AND ttrss_user_entries.feed_id = ttrss_feeds.id
238 AND ttrss_user_entries.ref_id = ttrss_entries.id");
240 $count = db_fetch_result($result, 0, "count");
241 $last_error = htmlspecialchars(db_fetch_result($result, 0, "last_error"));
243 print "<counter type=\"feed\" id=\"$id\" counter=\"$count\" error=\"$last_error\"/>";
246 function getFeedCounters($link, $smart_mode = SMART_RPC_COUNTERS
) {
249 if (!$_SESSION["fctr_last_value"]) {
250 $_SESSION["fctr_last_value"] = array();
254 $old_counters = $_SESSION["fctr_last_value"];
256 $result = db_query($link, "SELECT id,last_error,parent_feed,
258 FROM ttrss_entries,ttrss_user_entries
259 WHERE feed_id = ttrss_feeds.id AND
260 ttrss_user_entries.ref_id = ttrss_entries.id
261 AND unread = true AND owner_uid = ".$_SESSION["uid"].") as count
262 FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"] . "
263 AND parent_feed IS NULL");
265 $fctrs_modified = false;
267 while ($line = db_fetch_assoc($result)) {
270 $count = $line["count"];
271 $last_error = htmlspecialchars($line["last_error"]);
273 $has_img = is_file(ICONS_DIR
. "/$id.ico");
275 $tmp_result = db_query($link,
276 "SELECT id,COUNT(unread) AS unread
277 FROM ttrss_feeds LEFT JOIN ttrss_user_entries
278 ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
279 WHERE parent_feed = '$id' AND unread = true GROUP BY ttrss_feeds.id");
281 if (db_num_rows($tmp_result) > 0) {
282 while ($l = db_fetch_assoc($tmp_result)) {
283 $count +
= $l["unread"];
287 if (!$smart_mode ||
$old_counters[$id] != $count) {
288 $old_counters[$id] = $count;
289 $fctrs_modified = true;
292 $error_part = "error=\"$last_error\"";
298 $has_img_part = "hi=\"$has_img\"";
303 print "<counter type=\"feed\" id=\"$id\" counter=\"$count\" $has_img_part $error_part/>";
307 if ($smart_mode && $fctrs_modified) {
308 $_SESSION["fctr_last_value"] = $old_counters;
312 function outputFeedList($link, $tags = false) {
315 <title>Tiny Tiny RSS : Feedlist</title>
316 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
318 $user_theme = $_SESSION["theme"];
320 print "<link rel=\"stylesheet\" type=\"text/css\"
321 href=\"themes/$user_theme/theme.css\">";
324 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
325 print "<link rel=\"stylesheet\" type=\"text/css\"
326 href=\"tt-rss_compact.css\"/>";
328 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
329 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
332 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
333 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
334 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
335 <!--[if gte IE 5.5000]>
336 <script type=\"text/javascript\" src=\"pngfix.js\"></script>
337 <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
339 </head><body onload=\"init()\">";
341 print "<ul class=\"feedList\" id=\"feedList\">";
343 $owner_uid = $_SESSION["uid"];
349 if (get_pref($link, 'ENABLE_FEED_CATS')) {
350 print "<li class=\"feedCat\">Special</li>";
351 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
354 $result = db_query($link, "SELECT count(id) as num_starred
355 FROM ttrss_entries,ttrss_user_entries
356 WHERE marked = true AND
357 ttrss_user_entries.ref_id = ttrss_entries.id AND
358 unread = true AND owner_uid = '$owner_uid'");
359 $num_starred = db_fetch_result($result, 0, "num_starred");
363 if ($num_starred > 0) $class .= "Unread";
365 printFeedEntry(-1, $class, "Starred articles", $num_starred,
366 "images/mark_set.png", $link);
368 if (get_pref($link, 'ENABLE_FEED_CATS')) {
372 if (GLOBAL_ENABLE_LABELS
&& get_pref($link, 'ENABLE_LABELS')) {
374 $result = db_query($link, "SELECT id,sql_exp,description FROM
375 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
377 if (db_num_rows($result) > 0) {
378 if (get_pref($link, 'ENABLE_FEED_CATS')) {
379 print "<li class=\"feedCat\">Labels</li>";
380 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
382 print "<li><hr></li>";
386 while ($line = db_fetch_assoc($result)) {
390 $tmp_result = db_query($link, "SELECT count(id) as count
391 FROM ttrss_entries,ttrss_user_entries
392 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
393 ttrss_user_entries.ref_id = ttrss_entries.id
394 AND owner_uid = '$owner_uid'");
396 $count = db_fetch_result($tmp_result, 0, "count");
404 error_reporting (DEFAULT_ERROR_LEVEL
);
406 printFeedEntry(-$line["id"]-11,
407 $class, $line["description"], $count, "images/label.png", $link);
411 if (db_num_rows($result) > 0) {
412 if (get_pref($link, 'ENABLE_FEED_CATS')) {
419 // if (!get_pref($link, 'ENABLE_FEED_CATS')) {
420 print "<li><hr></li>";
423 if (get_pref($link, 'ENABLE_FEED_CATS')) {
424 $order_by_qpart = "category,title";
426 $order_by_qpart = "title";
429 $result = db_query($link, "SELECT ttrss_feeds.*,
430 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
431 WHERE feed_id = ttrss_feeds.id AND
432 ttrss_user_entries.ref_id = ttrss_entries.id AND
433 owner_uid = '$owner_uid') AS total,
434 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
435 WHERE feed_id = ttrss_feeds.id AND unread = true
436 AND ttrss_user_entries.ref_id = ttrss_entries.id
437 AND owner_uid = '$owner_uid') as unread,
439 ttrss_feed_categories.title AS category,
440 ttrss_feed_categories.collapsed
441 FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
442 ON (ttrss_feed_categories.id = cat_id)
444 ttrss_feeds.owner_uid = '$owner_uid' AND parent_feed IS NULL
445 ORDER BY $order_by_qpart");
447 $actid = $_GET["actid"];
457 while ($line = db_fetch_assoc($result)) {
459 $feed = db_unescape_string($line["title"]);
460 $feed_id = $line["id"];
462 $subop = $_GET["subop"];
464 $total = $line["total"];
465 $unread = $line["unread"];
467 $tmp_result = db_query($link,
468 "SELECT id,COUNT(unread) AS unread
469 FROM ttrss_feeds LEFT JOIN ttrss_user_entries
470 ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
471 WHERE parent_feed = '$feed_id' AND unread = true
472 GROUP BY ttrss_feeds.id");
474 if (db_num_rows($tmp_result) > 0) {
475 while ($l = db_fetch_assoc($tmp_result)) {
476 $unread +
= $l["unread"];
480 $cat_id = $line["cat_id"];
482 $tmp_category = $line["category"];
484 if (!$tmp_category) {
485 $tmp_category = "Uncategorized";
488 // $class = ($lnum % 2) ? "even" : "odd";
490 if ($line["last_error"]) {
496 if ($unread > 0) $class .= "Unread";
498 if ($actid == $feed_id) {
499 $class .= "Selected";
502 $total_unread +
= $unread;
504 if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
507 print "</li></ul></li>";
510 $category = $tmp_category;
512 $collapsed = $line["collapsed"];
514 // workaround for NULL category
515 if ($category == "Uncategorized") {
516 if ($_COOKIE["ttrss_vf_uclps"] == 1) {
521 if ($collapsed == "t" ||
$collapsed == "1") {
522 $holder_class = "invisible";
530 $cat_id_qpart = "cat_id = '$cat_id'";
532 $cat_id_qpart = "cat_id IS NULL";
535 $tmp_result = db_query($link, "SELECT count(int_id) AS unread
536 FROM ttrss_user_entries,ttrss_feeds WHERE
538 feed_id = ttrss_feeds.id AND $cat_id_qpart AND
539 ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
541 $cat_unread = db_fetch_result($tmp_result, 0, "unread");
543 $cat_id = sprintf("%d", $cat_id);
545 print "<li class=\"feedCat\" id=\"FCAT-$cat_id\">
546 <a href=\"javascript:toggleCollapseCat($cat_id)\">$tmp_category
547 <span id=\"FCATCTR-$cat_id\"
548 class=\"$catctr_class\">($cat_unread unread)$ellipsis</span></a></li>";
550 // !!! NO SPACE before <ul...feedCatList - breaks firstChild DOM function
551 // -> keyboard navigation, etc.
552 print "<li id=\"feedCatHolder\" class=\"$holder_class\"><ul class=\"feedCatList\" id=\"FCATLIST-$cat_id\">";
555 printFeedEntry($feed_id, $class, $feed, $unread,
556 "icons/$feed_id.ico", $link);
565 /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
566 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
567 post_int_id = ttrss_user_entries.int_id AND
568 unread = true AND ref_id = ttrss_entries.id
569 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
571 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'
572 ORDER BY tag_name"); */
574 $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
575 FROM ttrss_user_entries WHERE int_id = post_int_id
576 AND unread = true)) AS count FROM ttrss_tags
577 WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name");
581 while ($line = db_fetch_assoc($result)) {
582 $tags[$line["tag_name"]] +
= $line["count"];
585 foreach (array_keys($tags) as $tag) {
587 $unread = $tags[$tag];
595 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
601 if (db_num_rows($result) == 0) {
607 print "<li>No $what to display.</li>";
617 $subop = $_GET["subop"];
619 if ($subop == "getLabelCounters") {
622 getLabelCounters($link);
624 getFeedCounter($link, $aid);
626 print "</rpc-reply>";
629 if ($subop == "getFeedCounters") {
631 getFeedCounters($link);
632 print "</rpc-reply>";
635 if ($subop == "getAllCounters") {
637 getAllCounters($link);
638 print "</rpc-reply>";
641 if ($subop == "mark") {
642 $mark = $_GET["mark"];
643 $id = db_escape_string($_GET["id"]);
651 // FIXME this needs collision testing
653 $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
654 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
657 if ($subop == "updateFeed") {
658 $feed_id = db_escape_string($_GET["feed"]);
660 $result = db_query($link,
661 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'
662 AND owner_uid = " . $_SESSION["uid"]);
664 if (db_num_rows($result) > 0) {
665 $feed_url = db_fetch_result($result, 0, "feed_url");
666 update_rss_feed($link, $feed_url, $feed_id);
670 getFeedCounter($link, $feed_id);
671 print "</rpc-reply>";
676 if ($subop == "forceUpdateAllFeeds" ||
$subop == "updateAllFeeds") {
678 update_all_feeds($link, $subop == "forceUpdateAllFeeds");
680 $omode = $_GET["omode"];
682 if (!$omode) $omode = "tfl";
685 if (strchr($omode, "l")) getLabelCounters($link);
686 if (strchr($omode, "f")) getFeedCounters($link);
687 if (strchr($omode, "t")) getTagCounters($link);
688 if (get_pref($link, 'ENABLE_FEED_CATS')) {
689 getCategoryCounters($link);
691 getGlobalCounters($link);
692 print "</rpc-reply>";
695 /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
696 if ($subop == "catchupSelected") {
698 $ids = split(",", db_escape_string($_GET["ids"]));
700 $cmode = sprintf("%d", $_GET["cmode"]);
702 foreach ($ids as $id) {
705 db_query($link, "UPDATE ttrss_user_entries SET
706 unread = false,last_read = NOW()
707 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
708 } else if ($cmode == 1) {
709 db_query($link, "UPDATE ttrss_user_entries SET
711 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
713 db_query($link, "UPDATE ttrss_user_entries SET
714 unread = NOT unread,last_read = NOW()
715 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
719 getAllCounters($link);
720 print "</rpc-reply>";
723 if ($subop == "markSelected") {
725 $ids = split(",", db_escape_string($_GET["ids"]));
727 $cmode = sprintf("%d", $_GET["cmode"]);
729 foreach ($ids as $id) {
732 db_query($link, "UPDATE ttrss_user_entries SET
734 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
735 } else if ($cmode == 1) {
736 db_query($link, "UPDATE ttrss_user_entries SET
738 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
740 db_query($link, "UPDATE ttrss_user_entries SET
742 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
746 getAllCounters($link);
747 print "</rpc-reply>";
750 if ($subop == "sanityCheck") {
754 if ($subop == "globalPurge") {
757 global_purge_old_posts($link, true);
758 print "</rpc-reply>";
764 if ($op == "feeds") {
766 $tags = $_GET["tags"];
768 $subop = $_GET["subop"];
770 if ($subop == "catchupAll") {
771 db_query($link, "UPDATE ttrss_user_entries SET
772 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
775 if ($subop == "collapse") {
776 $cat_id = db_escape_string($_GET["cid"]);
778 db_query($link, "UPDATE ttrss_feed_categories SET
779 collapsed = NOT collapsed WHERE id = '$cat_id' AND owner_uid = " .
784 outputFeedList($link, $tags);
791 $feed_id = $_GET["feed"];
793 $result = db_query($link, "UPDATE ttrss_user_entries
794 SET unread = false,last_read = NOW()
795 WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
797 $addheader = $_GET["addheader"];
799 $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
800 SUBSTRING(updated,1,16) as updated,
801 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url,
803 FROM ttrss_entries,ttrss_user_entries
804 WHERE id = '$id' AND ref_id = id");
808 <title>Tiny Tiny RSS : Article $id</title>
809 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
811 $user_theme = $_SESSION["theme"];
813 print "<link rel=\"stylesheet\" type=\"text/css\"
814 href=\"themes/$user_theme/theme.css\">";
817 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
818 print "<link rel=\"stylesheet\" type=\"text/css\"
819 href=\"tt-rss_compact.css\"/>";
821 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
822 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
825 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
826 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
832 $line = db_fetch_assoc($result);
834 if ($line["icon_url"]) {
835 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
837 $feed_icon = " ";
840 /* if ($line["comments"] && $line["link"] != $line["comments"]) {
841 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
843 $entry_comments = "";
846 $num_comments = $line["num_comments"];
847 $entry_comments = "";
849 if ($num_comments > 0) {
850 if ($line["comments"]) {
851 $comments_url = $line["comments"];
853 $comments_url = $line["link"];
855 $entry_comments = "<a href=\"$comments_url\">$num_comments comments</a>";
857 if ($line["comments"] && $line["link"] != $line["comments"]) {
858 $entry_comments = "<a href=\"".$line["comments"]."\">comments</a>";
862 print "<div class=\"postReply\">";
864 print "<div class=\"postHeader\"><table width=\"100%\">";
866 print "<tr><td><a href=\"" . $line["link"] . "\">" . $line["title"] . "</a></td>";
868 $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
869 strtotime($line["updated"]));
871 print "<td class=\"postDate\">$parsed_updated</td>";
875 $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
876 ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
884 while ($tmp_line = db_fetch_assoc($tmp_result)) {
886 $tag = $tmp_line["tag_name"];
887 $tag_str = "<a href=\"javascript:parent.viewfeed('$tag')\">$tag</a>, ";
889 if ($num_tags == 5) {
890 $tags_str .= "<a href=\"javascript:showBlockElement('allEntryTags')\">...</a>";
891 } else if ($num_tags < 5) {
892 $tags_str .= $tag_str;
894 $f_tags_str .= $tag_str;
897 $tags_str = preg_replace("/, $/", "", $tags_str);
898 $f_tags_str = preg_replace("/, $/", "", $f_tags_str);
900 // $truncated_link = truncate_string($line["link"], 60);
902 if ($tags_str ||
$entry_comments) {
903 print "<tr><td width='50%'>
905 <td align=\"right\">$tags_str</td></tr>";
908 print "</table></div>";
910 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
911 print "<div class=\"postContent\">";
913 if (db_num_rows($tmp_result) > 5) {
914 print "<div id=\"allEntryTags\">Tags: $f_tags_str</div>";
917 print $line["content"] . "</div>";
921 print "<script type=\"text/javascript\">
922 update_all_counters('$feed_id');
927 print "</body></html>";
931 if ($op == "viewfeed") {
933 $feed = $_GET["feed"];
934 $skip = $_GET["skip"];
935 $subop = $_GET["subop"];
936 $view_mode = $_GET["view"];
937 $addheader = $_GET["addheader"];
938 $limit = $_GET["limit"];
944 if (!$skip) $skip = 0;
946 if ($subop == "undefined") $subop = "";
950 <title>Tiny Tiny RSS : Feed $feed</title>
951 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
953 $user_theme = $_SESSION["theme"];
955 print "<link rel=\"stylesheet\" type=\"text/css\"
956 href=\"themes/$user_theme/theme.css\">";
959 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
960 print "<link rel=\"stylesheet\"
961 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
964 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
965 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
968 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
969 <script type=\"text/javascript\" src=\"functions.js\"></script>
970 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
971 <!--[if gte IE 5.5000]>
972 <script type=\"text/javascript\" src=\"pngfix.js\"></script>
973 <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
975 </head><body onload='init()'>";
978 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
980 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
981 WHERE id = '$feed'");
983 $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
985 update_rss_feed($link, $feed_url, $feed);
989 if ($subop == "MarkAllRead") {
991 if (sprintf("%d", $feed) != 0) {
994 db_query($link, "UPDATE ttrss_user_entries
995 SET unread = false,last_read = NOW()
996 WHERE feed_id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
998 } else if ($feed < 0 && $feed > -10) { // special, like starred
1001 db_query($link, "UPDATE ttrss_user_entries
1002 SET unread = false,last_read = NOW()
1003 WHERE marked = true AND owner_uid = ".$_SESSION["uid"]);
1006 } else if ($feed < -10) { // label
1008 // TODO make this more efficient
1010 $label_id = -$feed - 11;
1012 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
1013 WHERE id = '$label_id'");
1016 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
1018 db_query($link, "BEGIN");
1020 $tmp2_result = db_query($link,
1024 ttrss_user_entries,ttrss_entries
1028 owner_uid = " . $_SESSION["uid"]);
1030 while ($tmp_line = db_fetch_assoc($tmp2_result)) {
1031 db_query($link, "UPDATE
1034 unread = false, last_read = NOW()
1036 int_id = " . $tmp_line["int_id"]);
1039 db_query($link, "COMMIT");
1041 /* db_query($link, "UPDATE ttrss_user_entries,ttrss_entries
1042 SET unread = false,last_read = NOW()
1045 AND owner_uid = ".$_SESSION["uid"]); */
1049 db_query($link, "BEGIN");
1051 $tag_name = db_escape_string($feed);
1053 $result = db_query($link, "SELECT post_int_id FROM ttrss_tags
1054 WHERE tag_name = '$tag_name' AND owner_uid = " . $_SESSION["uid"]);
1056 while ($line = db_fetch_assoc($result)) {
1057 db_query($link, "UPDATE ttrss_user_entries SET
1058 unread = false, last_read = NOW()
1059 WHERE int_id = " . $line["post_int_id"]);
1061 db_query($link, "COMMIT");
1066 $search = db_escape_string($_GET["search"]);
1067 $search_mode = db_escape_string($_GET["smode"]);
1070 $search_query_part = "(upper(title) LIKE upper('%$search%')
1071 OR content LIKE '%$search%') AND";
1073 $search_query_part = "";
1076 $view_query_part = "";
1078 if ($view_mode == "Adaptive") {
1080 $unread = getFeedUnread($link, $feed);
1082 $view_query_part = " unread = true AND ";
1087 if ($view_mode == "Starred") {
1088 $view_query_part = " marked = true AND ";
1091 if ($view_mode == "Unread") {
1092 $view_query_part = " unread = true AND ";
1095 if ($limit && $limit != "All") {
1096 $limit_query_part = "LIMIT " . $limit;
1099 $vfeed_query_part = "";
1101 // override query strategy and enable feed display when searching globally
1102 if ($search && $search_mode == "All feeds") {
1103 $query_strategy_part = "id > 0";
1104 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1105 } else if (sprintf("%d", $feed) == 0) {
1106 $query_strategy_part = "ttrss_entries.id > 0";
1107 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
1108 id = feed_id) as feed_title,";
1109 } else if ($feed >= 0) {
1111 $tmp_result = db_query($link, "SELECT id
1112 FROM ttrss_feeds WHERE parent_feed = '$feed'
1113 ORDER BY cat_id,title");
1115 $parent_ids = array();
1117 if (db_num_rows($tmp_result) > 0) {
1118 while ($p = db_fetch_assoc($tmp_result)) {
1119 array_push($parent_ids, "feed_id = " . $p["id"]);
1122 $query_strategy_part = sprintf("(feed_id = %d OR %s)",
1123 $feed, implode(" OR ", $parent_ids));
1125 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1127 $query_strategy_part = "feed_id = '$feed'";
1129 } else if ($feed == -1) { // starred virtual feed
1130 $query_strategy_part = "marked = true";
1131 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1132 } else if ($feed <= -10) { // labels
1133 $label_id = -$feed - 11;
1135 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
1136 WHERE id = '$label_id'");
1138 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
1140 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1142 $query_strategy_part = "id > 0"; // dumb
1145 $order_by = "updated DESC";
1147 // if ($feed < -10) {
1148 // $order_by = "feed_id,updated DESC";
1153 if ($search && $search_mode == "All feeds") {
1154 $feed_title = "Search results";
1155 } else if (sprintf("%d", $feed) == 0) {
1156 $feed_title = $feed;
1157 } else if ($feed > 0) {
1158 $result = db_query($link, "SELECT title,site_url,last_error FROM ttrss_feeds
1159 WHERE id = '$feed'");
1161 $feed_title = db_fetch_result($result, 0, "title");
1162 $feed_site_url = db_fetch_result($result, 0, "site_url");
1163 $last_error = db_fetch_result($result, 0, "last_error");
1165 } else if ($feed == -1) {
1166 $feed_title = "Starred articles";
1167 } else if ($feed < -10) {
1168 $label_id = -$feed - 11;
1169 $result = db_query($link, "SELECT description FROM ttrss_labels
1170 WHERE id = '$label_id'");
1171 $feed_title = db_fetch_result($result, 0, "description");
1176 if ($feed < -10) error_reporting (0);
1178 print "<div id=\"headlinesContainer\">";
1180 if (sprintf("%d", $feed) != 0) {
1183 $feed_kind = "Feeds";
1185 $feed_kind = "Labels";
1188 // if (!$vfeed_query_part) {
1189 $content_query_part = "content as content_preview,";
1191 // $content_query_part = "";
1194 $result = db_query($link, "SELECT
1195 ttrss_entries.id,ttrss_entries.title,
1196 SUBSTRING(updated,1,16) as updated,
1197 unread,feed_id,marked,link,last_read,
1198 SUBSTRING(last_read,1,19) as last_read_noms,
1201 SUBSTRING(updated,1,19) as updated_noms
1203 ttrss_entries,ttrss_user_entries,ttrss_feeds
1205 ttrss_user_entries.feed_id = ttrss_feeds.id AND
1206 ttrss_user_entries.ref_id = ttrss_entries.id AND
1207 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
1210 $query_strategy_part ORDER BY $order_by
1211 $limit_query_part");
1216 $feed_kind = "Tags";
1218 $result = db_query($link, "SELECT
1219 ttrss_entries.id as id,title,
1220 SUBSTRING(updated,1,16) as updated,
1222 marked,link,last_read,
1223 SUBSTRING(last_read,1,19) as last_read_noms,
1226 SUBSTRING(updated,1,19) as updated_noms
1228 ttrss_entries,ttrss_user_entries,ttrss_tags
1230 ref_id = ttrss_entries.id AND
1231 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
1232 post_int_id = int_id AND tag_name = '$feed' AND
1235 $query_strategy_part ORDER BY $order_by
1236 $limit_query_part");
1240 print "<div align='center'>
1241 Could not display feed (query failed). Please check label match syntax or local configuration.</div>";
1245 if (db_num_rows($result) > 0) {
1247 print "<table class=\"headlinesSubToolbar\"
1248 width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
1250 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1252 print "<td class=\"headlineActions\">
1254 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
1255 'RROW-', 'RCHK-', true)\">All</a>,
1256 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
1257 'RROW-', 'RCHK-', true, 'Unread')\">Unread</a>,
1258 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
1259 'RROW-', 'RCHK-', false)\">None</a>
1261 Toggle: <a href=\"javascript:selectionToggleUnread()\">Unread</a>,
1262 <a href=\"javascript:selectionToggleMarked()\">Starred</a>";
1267 print "<td class=\"headlineActions\">
1269 <a href=\"javascript:cdmSelectArticles('all')\">All</a>,
1270 <a href=\"javascript:cdmSelectArticles('unread')\">Unread</a>,
1271 <a href=\"javascript:cdmSelectArticles('none')\">None</a>
1273 Toggle: <a href=\"javascript:selectionToggleUnread(true)\">Unread</a>,
1274 <a href=\"javascript:selectionToggleMarked(true)\">Starred</a>";
1282 print "<td align='center' class='small'>
1283 <a class=\"warning\" href=\"javascript:alert('TT-RSS encountered an error while trying to update this feed.\\n\\n$last_error')\">Could not update this feed.</a></td>";
1286 print "<td class=\"headlineTitle\">";
1288 if ($feed_site_url) {
1289 print "<a target=\"_blank\" href=\"$feed_site_url\">$feed_title</a>";
1295 print "</tr></table>";
1297 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1298 print "<table class=\"headlinesList\" id=\"headlinesList\"
1299 cellspacing=\"0\" width=\"100%\">";
1304 error_reporting (DEFAULT_ERROR_LEVEL
);
1308 while ($line = db_fetch_assoc($result)) {
1310 $class = ($lnum %
2) ?
"even" : "odd";
1313 $feed_id = $line["feed_id"];
1315 if ($line["last_read"] == "" &&
1316 ($line["unread"] != "t" && $line["unread"] != "1")) {
1318 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
1321 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
1325 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
1333 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
1334 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
1335 alt=\"Reset mark\" onclick='javascript:toggleMark($id)'>";
1337 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
1338 alt=\"Set mark\" onclick='javascript:toggleMark($id)'>";
1341 $content_link = "<a href=\"javascript:view($id,$feed_id);\">" .
1342 $line["title"] . "</a>";
1344 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1345 $updated_fmt = smart_date_time(strtotime($line["updated"]));
1347 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1348 $updated_fmt = date($short_date, strtotime($line["updated"]));
1351 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
1352 $content_preview = truncate_string(strip_tags($line["content_preview"]),
1356 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1358 print "<tr class='$class' id='RROW-$id'>";
1360 print "<td class='hlUpdatePic'>$update_pic</td>";
1362 print "<td class='hlSelectRow'>
1363 <input type=\"checkbox\" onclick=\"toggleSelectRow(this)\"
1364 class=\"feedCheckBox\" id=\"RCHK-$id\">
1367 print "<td class='hlMarkedPic'>$marked_pic</td>";
1369 if ($line["feed_title"]) {
1370 print "<td class='hlContent'>$content_link</td>";
1371 print "<td class='hlFeed'>
1372 <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a> </td>";
1374 print "<td class='hlContent' valign='middle'>";
1376 print "<a href=\"javascript:view($id,$feed_id);\">" .
1379 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
1381 if ($content_preview) {
1382 print "<span class=\"contentPreview\"> - $content_preview</span>";
1390 print "<td class=\"hlUpdated\"><nobr>$updated_fmt </nobr></td>";
1397 $add_class = "Unread";
1402 print "<div class=\"cdmArticle$add_class\" id=\"RROW-$id\">";
1404 print "<div class=\"cdmHeader\">";
1406 print "<div style=\"float : right\">$updated_fmt</div>";
1408 print "<a href=\"".$line["link"]."\">".$line["title"]."</a>";
1410 if ($line["feed_title"]) {
1411 print " (<a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>)";
1416 print "<div class=\"cdmContent\">" . $line["content_preview"] . "</div>";
1418 print "<div style=\"float : right\">$marked_pic</div>
1419 <div class=\"cdmFooter\">
1420 <input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
1421 'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\"></div>";
1430 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1435 print "<div width='100%' align='center'>No articles found.</div>";
1440 print "<script type=\"text/javascript\">
1441 document.onkeydown = hotkey_handler;
1442 update_all_counters('$feed');
1446 print "</body></html>";
1450 if ($op == "pref-rpc") {
1452 $subop = $_GET["subop"];
1454 if ($subop == "unread") {
1455 $ids = split(",", db_escape_string($_GET["ids"]));
1456 foreach ($ids as $id) {
1457 db_query($link, "UPDATE ttrss_user_entries SET unread = true
1458 WHERE feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
1461 print "Marked selected feeds as unread.";
1464 if ($subop == "read") {
1465 $ids = split(",", db_escape_string($_GET["ids"]));
1466 foreach ($ids as $id) {
1467 db_query($link, "UPDATE ttrss_user_entries
1468 SET unread = false,last_read = NOW() WHERE
1469 feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
1472 print "Marked selected feeds as read.";
1478 if ($op == "pref-feeds") {
1480 $subop = $_REQUEST["subop"];
1481 $quiet = $_REQUEST["quiet"];
1483 if ($subop == "editfeed") {
1484 $feed_id = db_escape_string($_GET["id"]);
1486 $result = db_query($link,
1487 "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
1488 owner_uid = " . $_SESSION["uid"]);
1490 $title = htmlspecialchars(db_unescape_string(db_fetch_result($result,
1493 print "<div class=\"infoBoxContents\">";
1495 $icon_file = ICONS_DIR
. "/$feed_id.ico";
1497 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1498 $feed_icon = "<img width=\"16\" height=\"16\"
1499 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
1504 print "<h1>$feed_icon $title</h1>";
1506 print "<table width='100%'>";
1510 print "<tr class='$row_class'><td>Title:</td>";
1511 print "<td><input id=\"iedit_title\" value=\"$title\"></td></tr>";
1513 $feed_url = db_fetch_result($result, 0, "feed_url");
1514 $feed_url = htmlspecialchars(db_unescape_string(db_fetch_result($result,
1516 $row_class = toggleEvenOdd($row_class);
1518 print "<tr class='$row_class'><td>Feed URL:</td>";
1519 print "<td><input id=\"iedit_link\" value=\"$feed_url\"></td></tr>";
1521 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1523 $cat_id = db_fetch_result($result, 0, "cat_id");
1525 $row_class = toggleEvenOdd($row_class);
1527 print "<tr class='$row_class'><td>Category:</td>";
1529 print "<select id=\"iedit_fcat\">";
1530 print "<option id=\"0\">Uncategorized</option>";
1532 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feed_categories
1533 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1535 if (db_num_rows($tmp_result) > 0) {
1536 print "<option disabled>--------</option>";
1539 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1540 if ($tmp_line["id"] == $cat_id) {
1541 $is_selected = "selected";
1545 printf("<option $is_selected id='%d'>%s</option>",
1546 $tmp_line["id"], $tmp_line["title"]);
1549 print "</select></td>";
1554 $update_interval = db_fetch_result($result, 0, "update_interval");
1555 $row_class = toggleEvenOdd($row_class);
1557 print "<tr class='$row_class'><td>Update Interval:</td>";
1558 print "<td><input id=\"iedit_updintl\"
1559 value=\"$update_interval\"></td></tr>";
1561 $row_class = toggleEvenOdd($row_class);
1562 print "<tr class='$row_class'><td>Link to:</td>";
1564 $parent_feed = db_fetch_result($result, 0, "parent_feed");
1566 print "<select id=\"iedit_parent_feed\">";
1567 print "<option id=\"0\">None</option>";
1569 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1571 $cat_qpart = "AND cat_id = '$cat_id'";
1573 $cat_qpart = "AND cat_id IS NULL";
1577 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
1578 WHERE owner_uid = ".$_SESSION["uid"]." $cat_qpart ORDER BY title");
1580 if (db_num_rows($tmp_result) > 0) {
1581 print "<option disabled>--------</option>";
1584 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1585 if ($tmp_line["id"] == $parent_feed) {
1586 $is_selected = "selected";
1590 printf("<option $is_selected id='%d'>%s</option>",
1591 $tmp_line["id"], $tmp_line["title"]);
1594 print "</select></td>";
1597 $purge_interval = db_fetch_result($result, 0, "purge_interval");
1598 $row_class = toggleEvenOdd($row_class);
1600 print "<tr class='$row_class'><td>Purge Days:</td>";
1601 print "<td><input id=\"iedit_purgintl\"
1602 value=\"$purge_interval\"></td></tr>";
1604 // print "<tr><td colspan=\"2\"><b>Authentication</b></td></tr>";
1606 $row_class = toggleEvenOdd($row_class);
1607 $auth_login = db_fetch_result($result, 0, "auth_login");
1609 print "<tr class='$row_class'><td>Login:</td>";
1610 print "<td><input id=\"iedit_login\"
1611 value=\"$auth_login\"></td></tr>";
1613 $row_class = toggleEvenOdd($row_class);
1614 $auth_pass = db_fetch_result($result, 0, "auth_pass");
1616 print "<tr class='$row_class'><td>Password:</td>";
1617 print "<td><input type=\"password\" id=\"iedit_pass\"
1618 value=\"$auth_pass\"></td></tr>";
1623 print "<div align='center'>
1624 <input type='submit' class='button'
1625 onclick=\"feedEditCancel()\" value=\"Cancel\">
1626 <input type=\"submit\" class=\"button\"
1627 onclick=\"feedEditSave()\" value=\"Save\"></div>";
1631 if ($subop == "editSave") {
1632 $feed_title = db_escape_string($_POST["t"]);
1633 $feed_link = db_escape_string($_POST["l"]);
1634 $upd_intl = db_escape_string($_POST["ui"]);
1635 $purge_intl = db_escape_string($_POST["pi"]);
1636 $feed_id = db_escape_string($_POST["id"]);
1637 $cat_id = db_escape_string($_POST["catid"]);
1638 $auth_login = db_escape_string($_POST["login"]);
1639 $auth_pass = db_escape_string($_POST["pass"]);
1640 $parent_feed = db_escape_string($_POST["pfeed"]);
1642 if (strtoupper($upd_intl) == "DEFAULT")
1645 if (strtoupper($upd_intl) == "DISABLED")
1648 if (strtoupper($purge_intl) == "DEFAULT")
1651 if (strtoupper($purge_intl) == "DISABLED")
1655 $category_qpart = "cat_id = '$cat_id'";
1657 $category_qpart = 'cat_id = NULL';
1660 if ($parent_feed != 0) {
1661 $parent_qpart = "parent_feed = '$parent_feed'";
1663 $parent_qpart = 'parent_feed = NULL';
1666 $result = db_query($link, "UPDATE ttrss_feeds SET
1669 title = '$feed_title', feed_url = '$feed_link',
1670 update_interval = '$upd_intl',
1671 purge_interval = '$purge_intl',
1672 auth_login = '$auth_login',
1673 auth_pass = '$auth_pass'
1674 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
1677 if ($subop == "saveCat") {
1678 $cat_title = db_escape_string($_GET["title"]);
1679 $cat_id = db_escape_string($_GET["id"]);
1681 $result = db_query($link, "UPDATE ttrss_feed_categories SET
1682 title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
1686 if ($subop == "remove") {
1688 if (!WEB_DEMO_MODE
) {
1690 $ids = split(",", db_escape_string($_GET["ids"]));
1692 foreach ($ids as $id) {
1693 db_query($link, "DELETE FROM ttrss_feeds
1694 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1696 $icons_dir = ICONS_DIR
;
1698 if (file_exists($icons_dir . "/$id.ico")) {
1699 unlink($icons_dir . "/$id.ico");
1705 if ($subop == "add") {
1707 if (!WEB_DEMO_MODE
) {
1709 $feed_link = db_escape_string(trim($_GET["link"]));
1710 $cat_id = db_escape_string($_GET["cid"]);
1712 if ($cat_id == "0" ||
!$cat_id) {
1713 $cat_qpart = "NULL";
1715 $cat_qpart = "'$cat_id'";
1718 $result = db_query($link,
1719 "SELECT id FROM ttrss_feeds
1720 WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]);
1722 if (db_num_rows($result) == 0) {
1724 $result = db_query($link,
1725 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
1726 VALUES ('".$_SESSION["uid"]."', '$feed_link',
1727 '[Unknown]', $cat_qpart)");
1729 $result = db_query($link,
1730 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'
1731 AND owner_uid = " . $_SESSION["uid"]);
1733 $feed_id = db_fetch_result($result, 0, "id");
1736 update_rss_feed($link, $feed_link, $feed_id, true);
1740 print "<div class=\"warning\">
1741 Feed <b>$feed_link</b> already exists in the database.
1747 if ($subop == "addCat") {
1749 if (!WEB_DEMO_MODE
) {
1751 $feed_cat = db_escape_string(trim($_GET["cat"]));
1753 $result = db_query($link,
1754 "SELECT id FROM ttrss_feed_categories
1755 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
1757 if (db_num_rows($result) == 0) {
1759 $result = db_query($link,
1760 "INSERT INTO ttrss_feed_categories (owner_uid,title)
1761 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
1765 print "<div class=\"warning\">
1766 Category <b>$feed_cat</b> already exists in the database.
1774 if ($subop == "removeCats") {
1776 if (!WEB_DEMO_MODE
) {
1778 $ids = split(",", db_escape_string($_GET["ids"]));
1780 foreach ($ids as $id) {
1782 db_query($link, "BEGIN");
1784 $result = db_query($link,
1785 "SELECT count(id) as num_feeds FROM ttrss_feeds
1786 WHERE cat_id = '$id'");
1788 $num_feeds = db_fetch_result($result, 0, "num_feeds");
1790 if ($num_feeds == 0) {
1791 db_query($link, "DELETE FROM ttrss_feed_categories
1792 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1795 print "<div class=\"warning\">
1796 Unable to delete non empty feed categories.</div>";
1800 db_query($link, "COMMIT");
1805 if ($subop == "categorize") {
1807 if (!WEB_DEMO_MODE
) {
1809 $ids = split(",", db_escape_string($_GET["ids"]));
1811 $cat_id = db_escape_string($_GET["cat_id"]);
1814 $cat_id_qpart = 'NULL';
1816 $cat_id_qpart = "'$cat_id'";
1819 db_query($link, "BEGIN");
1821 foreach ($ids as $id) {
1823 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
1824 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1827 db_query($link, "COMMIT");
1834 // print "<h3>Edit Feeds</h3>";
1836 $result = db_query($link, "SELECT id,title,feed_url,last_error
1837 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1839 if (db_num_rows($result) > 0) {
1841 print "<div class=\"warning\">";
1843 // print"<img class=\"closeButton\"
1844 // onclick=\"javascript:hideParentElement(this);\" src=\"images/close.png\">";
1846 print "<a href=\"javascript:showBlockElement('feedUpdateErrors')\">
1847 <b>Feeds with update errors</b> (click to expand)</a>";
1849 print "<ul id=\"feedUpdateErrors\" class=\"nomarks\">";
1851 while ($line = db_fetch_assoc($result)) {
1852 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
1853 $line["last_error"];
1861 $feed_search = db_escape_string($_GET["search"]);
1863 if (array_key_exists("search", $_GET)) {
1864 $_SESSION["prefs_feed_search"] = $feed_search;
1866 $feed_search = $_SESSION["prefs_feed_search"];
1869 print "<table width='100%' class=\"prefGenericAddBox\"
1870 cellspacing='0' cellpadding='0'><tr>
1872 <input id=\"fadd_link\"
1873 onchange=\"javascript:addFeed()\"
1875 <input type=\"submit\" class=\"button\"
1876 onclick=\"javascript:addFeed()\" value=\"Add feed\">
1877 </td><td align='right'>
1878 <input id=\"feed_search\" size=\"20\"
1879 onchange=\"javascript:updateFeedList()\"
1880 value=\"$feed_search\">
1881 <input type=\"submit\" class=\"button\"
1882 onclick=\"javascript:updateFeedList()\" value=\"Search\">
1886 $feeds_sort = db_escape_string($_GET["sort"]);
1888 if (!$feeds_sort ||
$feeds_sort == "undefined") {
1889 $feeds_sort = $_SESSION["pref_sort_feeds"];
1890 if (!$feeds_sort) $feeds_sort = "title";
1893 $_SESSION["pref_sort_feeds"] = $feeds_sort;
1896 $search_qpart = "(UPPER(title) LIKE UPPER('%$feed_search%') OR
1897 UPPER(feed_url) LIKE UPPER('%$feed_search%')) AND";
1902 $result = db_query($link, "SELECT
1906 substring(F1.last_updated,1,16) AS last_updated,
1911 F2.title AS parent_title,
1912 C1.title AS category
1915 LEFT JOIN ttrss_feeds AS F2
1916 ON (F1.parent_feed = F2.id)
1917 LEFT JOIN ttrss_feed_categories AS C1
1918 ON (F1.cat_id = C1.id)
1920 $search_qpart F1.owner_uid = '".$_SESSION["uid"]."'
1921 ORDER by category,$feeds_sort,title");
1923 if (db_num_rows($result) != 0) {
1925 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1927 print "<p><table width=\"100%\" cellspacing=\"0\"
1928 class=\"prefFeedList\" id=\"prefFeedList\">";
1929 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1931 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
1932 'FEEDR-', 'FRCHK-', true)\">All</a>,
1933 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
1934 'FEEDR-', 'FRCHK-', false)\">None</a>
1937 if (!get_pref($link, 'ENABLE_FEED_CATS')) {
1938 print "<tr class=\"title\">
1939 <td width='5%' align='center'> </td>
1940 <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
1941 <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
1942 <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td>
1943 <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Days</a></td></tr>";
1950 while ($line = db_fetch_assoc($result)) {
1952 $feed_id = $line["id"];
1953 $cat_id = $line["cat_id"];
1955 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1956 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
1957 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
1959 if ($line["update_interval"] == "0") $line["update_interval"] = "Default";
1960 if ($line["update_interval"] == "-1") $line["update_interval"] = "Disabled";
1961 if ($line["purge_interval"] == "0") $line["purge_interval"] = "Default";
1962 if ($line["purge_interval"] < 0) $line["purge_interval"] = "Disabled";
1964 if (!$edit_cat) $edit_cat = "Uncategorized";
1967 if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
1970 print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>";
1972 print "<tr class=\"title\">
1973 <td width='5%' align='center'> </td>
1974 <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
1975 <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
1976 <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td>
1977 <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Days</a></td></tr>";
1979 $cur_cat_id = $cat_id;
1982 $class = ($lnum %
2) ?
"even" : "odd";
1983 $this_row_id = "id=\"FEEDR-$feed_id\"";
1985 print "<tr class=\"$class\" $this_row_id>";
1987 $icon_file = ICONS_DIR
. "/$feed_id.ico";
1989 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1990 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL
. "/$feed_id.ico\">";
1992 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1994 // print "<td class='feedIcon'>$feed_icon</td>";
1996 print "<td class='feedSelect'><input onclick='toggleSelectRow(this);'
1997 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
1999 $edit_title = truncate_string($edit_title, 40);
2000 $edit_link = truncate_string($edit_link, 60);
2002 $parent_title = $line["parent_title"];
2003 if ($parent_title) {
2004 $parent_title = "<span class='groupPrompt'>(linked to
2005 $parent_title)</span>";
2008 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
2009 "$feed_icon $edit_title $parent_title" . "</a></td>";
2011 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
2012 $edit_link . "</a></td>";
2014 /* if (get_pref($link, 'ENABLE_FEED_CATS')) {
2015 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
2016 $edit_cat . "</a></td>";
2019 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
2020 $line["update_interval"] . "</a></td>";
2022 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
2023 $line["purge_interval"] . "</a></td>";
2034 if ($subop == "edit") {
2035 print "Edit feed:
2036 <input type=\"submit\" class=\"button\"
2037 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
2038 <input type=\"submit\" class=\"button\"
2039 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
2044 <input type=\"submit\" class=\"button\"
2045 onclick=\"javascript:selectedFeedDetails()\" value=\"Details\">
2046 <input type=\"submit\" class=\"button\"
2047 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
2048 <input type=\"submit\" class=\"button\"
2049 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
2051 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2053 print " ";
2055 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2056 WHERE owner_uid = ".$_SESSION["uid"]."
2059 print "<select id=\"sfeed_set_fcat\">";
2060 print "<option id=\"0\">Uncategorized</option>";
2062 if (db_num_rows($result) != 0) {
2064 print "<option disabled>--------</option>";
2066 while ($line = db_fetch_assoc($result)) {
2067 printf("<option id='%d'>%s</option>",
2068 $line["id"], $line["title"]);
2074 print " <input type=\"submit\" class=\"button\"
2075 onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Set category\">";
2079 if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
2081 <input type=\"submit\" class=\"button\"
2082 onclick=\"javascript:readSelectedFeeds(true)\" value=\"Mark as read\">
2083 <input type=\"submit\" class=\"button\"
2084 onclick=\"javascript:readSelectedFeeds(false)\"
2085 value=\"Mark as unread\"> ";
2089 All feeds: <input type=\"submit\"
2090 class=\"button\" onclick=\"gotoExportOpml()\"
2091 value=\"Export OPML\">";
2095 print "<p>No feeds defined.</p>";
2099 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2101 print "<h3>Edit Categories</h3>";
2103 // print "<h3>Categories</h3>";
2105 print "<div class=\"prefGenericAddBox\">
2106 <input id=\"fadd_cat\"
2107 onchange=\"javascript:addFeedCat()\"
2110 type=\"submit\" class=\"button\"
2111 onclick=\"javascript:addFeedCat()\" value=\"Add category\"></div>";
2113 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2114 WHERE owner_uid = ".$_SESSION["uid"]."
2117 if (db_num_rows($result) != 0) {
2119 print "<p><table width=\"100%\" class=\"prefFeedCatList\"
2120 cellspacing=\"0\" id=\"prefFeedCatList\">";
2122 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2124 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
2125 'FCATR-', 'FCCHK-', true)\">All</a>,
2126 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
2127 'FCATR-', 'FCCHK-', false)\">None</a>
2130 print "<tr class=\"title\">
2131 <td width=\"5%\"></td><td width=\"80%\">Title</td>
2136 while ($line = db_fetch_assoc($result)) {
2138 $class = ($lnum %
2) ?
"even" : "odd";
2140 $cat_id = $line["id"];
2142 $edit_cat_id = $_GET["id"];
2144 if ($subop == "editCat" && $cat_id != $edit_cat_id) {
2148 $this_row_id = "id=\"FCATR-$cat_id\"";
2151 print "<tr class=\"$class\" $this_row_id>";
2153 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
2155 if (!$edit_cat_id ||
$subop != "editCat") {
2157 print "<td align='center'><input onclick='toggleSelectRow(this);'
2158 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
2160 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
2161 $edit_title . "</a></td>";
2163 } else if ($cat_id != $edit_cat_id) {
2165 print "<td><input disabled=\"true\" type=\"checkbox\"
2166 id=\"FRCHK-".$line["id"]."\"></td>";
2168 print "<td>$edit_title</td>";
2172 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2174 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
2187 if ($subop == "editCat") {
2188 print "Edit category:
2189 <input type=\"submit\" class=\"button\"
2190 onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\">
2191 <input type=\"submit\" class=\"button\"
2192 onclick=\"javascript:feedCatEditSave()\" value=\"Save\">";
2197 <input type=\"submit\" class=\"button\"
2198 onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\">
2199 <input type=\"submit\" class=\"button\"
2200 onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">";
2205 print "<p>No feed categories defined.</p>";
2209 print "<h3>Import OPML</h3>
2210 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
2211 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">
2212 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
2213 type=\"submit\" value=\"Import\">
2218 if ($op == "pref-filters") {
2220 $subop = $_GET["subop"];
2221 $quiet = $_GET["quiet"];
2223 if ($subop == "editSave") {
2225 $regexp = db_escape_string($_GET["r"]);
2226 $descr = db_escape_string($_GET["d"]);
2227 $match = db_escape_string($_GET["m"]);
2228 $filter_id = db_escape_string($_GET["id"]);
2229 $feed_id = db_escape_string($_GET["fid"]);
2230 $action_id = db_escape_string($_GET["aid"]);
2235 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2238 $result = db_query($link, "UPDATE ttrss_filters SET
2239 reg_exp = '$regexp',
2240 description = '$descr',
2242 action_id = '$action_id',
2243 filter_type = (SELECT id FROM ttrss_filter_types WHERE
2244 description = '$match')
2245 WHERE id = '$filter_id'");
2248 if ($subop == "remove") {
2250 if (!WEB_DEMO_MODE
) {
2252 $ids = split(",", db_escape_string($_GET["ids"]));
2254 foreach ($ids as $id) {
2255 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
2261 if ($subop == "add") {
2263 if (!WEB_DEMO_MODE
) {
2265 $regexp = db_escape_string(trim($_GET["regexp"]));
2266 $match = db_escape_string(trim($_GET["match"]));
2267 $feed_id = db_escape_string($_GET["fid"]);
2268 $action_id = db_escape_string($_GET["aid"]);
2273 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2276 $result = db_query($link,
2277 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
2280 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
2281 description = '$match'),'".$_SESSION["uid"]."',
2282 $feed_id, '$action_id')");
2288 $result = db_query($link, "SELECT description
2289 FROM ttrss_filter_types ORDER BY description");
2291 $filter_types = array();
2293 while ($line = db_fetch_assoc($result)) {
2294 array_push($filter_types, $line["description"]);
2297 print "<div class=\"prefGenericAddBox\">
2298 <input id=\"fadd_regexp\" size=\"40\"> ";
2300 print_select("fadd_match", "Title", $filter_types);
2302 print " <select id=\"fadd_feed\">";
2304 print "<option selected id=\"0\">All feeds</option>";
2306 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
2307 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2309 if (db_num_rows($result) > 0) {
2310 print "<option disabled>--------</option>";
2313 while ($line = db_fetch_assoc($result)) {
2314 printf("<option id='%d'>%s</option>", $line["id"], $line["title"]);
2317 print "</select> ";
2319 print " Action: ";
2321 print "<select id=\"fadd_action\">";
2323 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2326 while ($line = db_fetch_assoc($result)) {
2327 printf("<option id='%d'>%s</option>", $line["id"], $line["description"]);
2330 print "</select> ";
2332 print "<input type=\"submit\"
2333 class=\"button\" onclick=\"javascript:addFilter()\"
2334 value=\"Add filter\">";
2338 $result = db_query($link, "SELECT
2339 ttrss_filters.id AS id,reg_exp,
2340 ttrss_filters.description AS description,
2341 ttrss_filter_types.name AS filter_type_name,
2342 ttrss_filter_types.description AS filter_type_descr,
2344 ttrss_filter_actions.description AS action_description,
2345 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
2347 ttrss_filters,ttrss_filter_types,ttrss_filter_actions
2349 filter_type = ttrss_filter_types.id AND
2350 ttrss_filter_actions.id = action_id AND
2351 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
2354 if (db_num_rows($result) != 0) {
2356 print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\"
2357 id=\"prefFilterList\">";
2359 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2361 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
2362 'FILRR-', 'FICHK-', true)\">All</a>,
2363 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
2364 'FILRR-', 'FICHK-', false)\">None</a>
2367 print "<tr class=\"title\">
2368 <td align='center' width=\"5%\"> </td>
2369 <td width=\"20%\">Filter expression</td>
2370 <td width=\"20%\">Feed</td>
2371 <td width=\"15%\">Match</td>
2372 <td width=\"15%\">Action</td>
2373 <td width=\"30%\">Description</td></tr>";
2377 while ($line = db_fetch_assoc($result)) {
2379 $class = ($lnum %
2) ?
"even" : "odd";
2381 $filter_id = $line["id"];
2382 $edit_filter_id = $_GET["id"];
2384 if ($subop == "edit" && $filter_id != $edit_filter_id) {
2388 $this_row_id = "id=\"FILRR-$filter_id\"";
2391 print "<tr class=\"$class\" $this_row_id>";
2393 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
2394 $line["description"] = htmlspecialchars($line["description"]);
2396 if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
2398 if (!$edit_filter_id ||
$subop != "edit") {
2400 if (!$line["description"]) $line["description"] = "[No description]";
2402 print "<td align='center'><input onclick='toggleSelectRow(this);'
2403 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
2405 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2406 $line["reg_exp"] . "</td>";
2408 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2409 $line["feed_title"] . "</td>";
2411 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2412 $line["filter_type_descr"] . "</td>";
2414 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2415 $line["action_description"] . "</td>";
2417 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2418 $line["description"] . "</td>";
2420 } else if ($filter_id != $edit_filter_id) {
2422 if (!$line["description"]) $line["description"] = "[No description]";
2424 print "<td><input disabled=\"true\" type=\"checkbox\"
2425 id=\"FICHK-".$line["id"]."\"></td>";
2427 print "<td>".$line["reg_exp"]."</td>";
2428 print "<td>".$line["feed_title"]."</td>";
2429 print "<td>".$line["filter_type_descr"]."</td>";
2430 print "<td>".$line["action_description"]."</td>";
2431 print "<td>".$line["description"]."</td>";
2435 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2437 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
2441 print "<select id=\"iedit_feed\">";
2442 print "<option id=\"0\">All feeds</option>";
2444 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
2445 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2447 if (db_num_rows($tmp_result) > 0) {
2448 print "<option disabled>--------</option>";
2451 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2452 if ($tmp_line["id"] == $line["feed_id"]) {
2453 $is_selected = "selected";
2457 printf("<option $is_selected id='%d'>%s</option>",
2458 $tmp_line["id"], $tmp_line["title"]);
2461 print "</select></td>";
2464 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
2468 print "<select id=\"iedit_filter_action\">";
2470 $tmp_result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2471 ORDER BY description");
2473 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2474 if ($tmp_line["description"] == $line["action_description"]) {
2475 $is_selected = "selected";
2479 printf("<option $is_selected id='%d'>%s</option>",
2480 $tmp_line["id"], $tmp_line["description"]);
2483 print "</select></td>";
2486 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2498 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
2505 if ($subop == "edit") {
2507 <input type=\"submit\" class=\"button\"
2508 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
2509 <input type=\"submit\" class=\"button\"
2510 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
2516 <input type=\"submit\" class=\"button\"
2517 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
2518 <input type=\"submit\" class=\"button\"
2519 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
2524 print "<p>No filters defined.</p>";
2529 // We need to accept raw SQL data in label queries, so not everything is escaped
2530 // here, this is by design. If you don't like the whole idea, disable labels
2531 // altogether with GLOBAL_ENABLE_LABELS = false
2533 if ($op == "pref-labels") {
2535 if (!GLOBAL_ENABLE_LABELS
) {
2539 $subop = $_GET["subop"];
2541 if ($subop == "test") {
2543 $expr = $_GET["expr"];
2544 $descr = $_GET["descr"];
2546 print "<div class='infoBoxContents'>";
2548 print "<h1>Label «$descr»</h1>";
2550 // print "<p><b>Expression</b>: $expr</p>";
2552 $result = db_query($link,
2553 "SELECT count(id) AS num_matches
2554 FROM ttrss_entries,ttrss_user_entries
2556 ttrss_user_entries.ref_id = ttrss_entries.id AND
2557 owner_uid = " . $_SESSION["uid"]);
2559 $num_matches = db_fetch_result($result, 0, "num_matches");;
2561 if ($num_matches > 0) {
2563 print "<p>Query returned <b>$num_matches</b> matches, first 5 follow:</p>";
2565 $result = db_query($link,
2567 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
2568 FROM ttrss_entries,ttrss_user_entries
2570 ttrss_user_entries.ref_id = ttrss_entries.id
2571 AND owner_uid = " . $_SESSION["uid"] . "
2572 ORDER BY date_entered DESC LIMIT 5");
2574 print "<ul class=\"nomarks\">";
2575 while ($line = db_fetch_assoc($result)) {
2576 print "<li>".$line["title"].
2577 " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
2582 print "<p>Query didn't return any matches.</p>";
2587 print "<div align='center'>
2588 <input type='submit' class='button'
2589 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2593 if ($subop == "editSave") {
2595 $sql_exp = $_GET["s"];
2596 $descr = $_GET["d"];
2597 $label_id = db_escape_string($_GET["id"]);
2599 // print "$sql_exp : $descr : $label_id";
2601 $result = db_query($link, "UPDATE ttrss_labels SET
2602 sql_exp = '$sql_exp',
2603 description = '$descr'
2604 WHERE id = '$label_id'");
2607 if ($subop == "remove") {
2609 if (!WEB_DEMO_MODE
) {
2611 $ids = split(",", db_escape_string($_GET["ids"]));
2613 foreach ($ids as $id) {
2614 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
2620 if ($subop == "add") {
2622 if (!WEB_DEMO_MODE
) {
2624 // no escaping is done here on purpose
2625 $exp = trim($_GET["exp"]);
2627 $result = db_query($link,
2628 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
2629 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
2633 print "<div class=\"prefGenericAddBox\">
2634 <input size=\"40\" id=\"ladd_expr\"> ";
2636 print"<input type=\"submit\" class=\"button\"
2637 onclick=\"javascript:addLabel()\" value=\"Add label\"></div>";
2639 $result = db_query($link, "SELECT
2640 id,sql_exp,description
2644 owner_uid = ".$_SESSION["uid"]."
2645 ORDER by description");
2647 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2649 if (db_num_rows($result) != 0) {
2651 print "<p><table width=\"100%\" cellspacing=\"0\"
2652 class=\"prefLabelList\" id=\"prefLabelList\">";
2654 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2656 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2657 'LILRR-', 'LICHK-', true)\">All</a>,
2658 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2659 'LILRR-', 'LICHK-', false)\">None</a>
2662 print "<tr class=\"title\">
2663 <td align='center' width=\"5%\"> </td>
2664 <td width=\"40%\">SQL expression
2665 <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a>
2667 <td width=\"40%\">Caption</td></tr>";
2671 while ($line = db_fetch_assoc($result)) {
2673 $class = ($lnum %
2) ?
"even" : "odd";
2675 $label_id = $line["id"];
2676 $edit_label_id = $_GET["id"];
2678 if ($subop == "edit" && $label_id != $edit_label_id) {
2682 $this_row_id = "id=\"LILRR-$label_id\"";
2685 print "<tr class=\"$class\" $this_row_id>";
2687 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
2688 $line["description"] = htmlspecialchars($line["description"]);
2690 if (!$edit_label_id ||
$subop != "edit") {
2692 if (!$line["description"]) $line["description"] = "[No caption]";
2694 print "<td align='center'><input onclick='toggleSelectRow(this);'
2695 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
2697 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2698 $line["sql_exp"] . "</td>";
2700 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2701 $line["description"] . "</td>";
2703 } else if ($label_id != $edit_label_id) {
2705 if (!$line["description"]) $line["description"] = "[No description]";
2707 print "<td><input disabled=\"true\" type=\"checkbox\"
2708 id=\"LICHK-".$line["id"]."\"></td>";
2710 print "<td>".$line["sql_exp"]."</td>";
2711 print "<td>".$line["description"]."</td>";
2715 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2717 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
2720 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2732 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
2739 if ($subop == "edit") {
2741 <input type=\"submit\" class=\"button\"
2742 onclick=\"javascript:labelTest()\" value=\"Test\">
2743 <input type=\"submit\" class=\"button\"
2744 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
2745 <input type=\"submit\" class=\"button\"
2746 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
2752 <input type=\"submit\" class=\"button\"
2753 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
2754 <input type=\"submit\" class=\"button\"
2755 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
2758 print "<p>No labels defined.</p>";
2762 if ($op == "error") {
2763 print "<div width=\"100%\" align='center'>";
2764 $msg = $_GET["msg"];
2769 if ($op == "help") {
2770 if (!$_GET["noheaders"]) {
2772 <title>Tiny Tiny RSS : Help</title>
2773 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2774 <script type=\"text/javascript\" src=\"functions.js\"></script>
2775 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2779 $tid = sprintf("%d", $_GET["tid"]);
2781 print "<div class='infoBoxContents'>";
2783 if (file_exists("help/$tid.php")) {
2784 include("help/$tid.php");
2786 print "<p>Help topic not found.</p>";
2791 print "<div align='center'>
2792 <input type='submit' class='button'
2793 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2795 if (!$_GET["noheaders"]) {
2796 print "</body></html>";
2803 $param = $_GET["param"];
2805 if ($id == "quickAddFeed") {
2808 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2811 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2812 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2813 WHERE owner_uid = ".$_SESSION["uid"]."
2816 print " <select id=\"qafCat\">";
2817 print "<option id=\"0\">Uncategorized</option>";
2819 if (db_num_rows($result) != 0) {
2821 print "<option disabled>--------</option>";
2823 while ($line = db_fetch_assoc($result)) {
2824 printf("<option id='%d'>%s</option>",
2825 $line["id"], $line["title"]);
2832 print " <input class=\"button\"
2833 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
2834 <input class=\"button\"
2835 type=\"submit\" onclick=\"javascript:closeDlg()\"
2839 if ($id == "quickDelFeed") {
2841 $param = db_escape_string($param);
2843 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
2847 $f_title = db_fetch_result($result, 0, "title");
2849 print "Remove current feed (<b>$f_title</b>)?
2850 <input class=\"button\"
2851 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
2852 <input class=\"button\"
2853 type=\"submit\" onclick=\"javascript:closeDlg()\"
2856 print "Error: Feed $param not found.
2857 <input class=\"button\"
2858 type=\"submit\" onclick=\"javascript:closeDlg()\"
2863 if ($id == "search") {
2865 print "<input id=\"searchbox\" class=\"extSearch\"
2866 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2867 onchange=\"javascript:search()\">
2868 <select id=\"searchmodebox\">
2869 <option selected>All feeds</option>
2870 <option>This feed</option>
2872 <input type=\"submit\"
2873 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
2874 <input class=\"button\"
2875 type=\"submit\" onclick=\"javascript:closeDlg()\"
2880 if ($id == "quickAddFilter") {
2882 $result = db_query($link, "SELECT description
2883 FROM ttrss_filter_types ORDER BY description");
2885 $filter_types = array();
2887 while ($line = db_fetch_assoc($result)) {
2888 array_push($filter_types, $line["description"]);
2893 print "<tr><td>Match:</td><td><input id=\"fadd_regexp\" size=\"40\"> ";
2895 print_select("fadd_match", "Title", $filter_types);
2898 print "<tr><td>Feed:</td><td><select id=\"fadd_feed\">";
2900 print "<option selected id=\"0\">All feeds</option>";
2902 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
2903 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2905 if (db_num_rows($result) > 0) {
2906 print "<option disabled>--------</option>";
2909 while ($line = db_fetch_assoc($result)) {
2910 if ($param == $line["id"]) {
2911 $selected = "selected";
2915 printf("<option id='%d' %s>%s</option>", $line["id"], $selected, $line["title"]);
2918 print "</select></td></tr>";
2920 print "<tr><td>Action:</td>";
2922 print "<td><select id=\"fadd_action\">";
2924 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2927 while ($line = db_fetch_assoc($result)) {
2928 printf("<option id='%d'>%s</option>", $line["id"], $line["description"]);
2933 print "</td></tr><tr><td colspan=\"2\" align=\"right\">";
2935 print "<input type=\"submit\"
2936 class=\"button\" onclick=\"javascript:qaddFilter()\"
2937 value=\"Add filter\"> ";
2939 print "<input class=\"button\"
2940 type=\"submit\" onclick=\"javascript:closeDlg()\"
2943 print "</td></tr></table>";
2947 // update feeds of all users, may be used anonymously
2948 if ($op == "globalUpdateFeeds") {
2950 $result = db_query($link, "SELECT id FROM ttrss_users");
2952 while ($line = db_fetch_assoc($result)) {
2953 $user_id = $line["id"];
2954 // print "<!-- updating feeds of uid $user_id -->";
2955 update_all_feeds($link, false, $user_id);
2959 <message msg=\"All feeds updated\"/>
2964 if ($op == "pref-prefs") {
2966 $subop = $_REQUEST["subop"];
2968 if ($subop == "Save configuration") {
2970 if (WEB_DEMO_MODE
) {
2971 header("Location: prefs.php");
2975 $_SESSION["prefs_op_result"] = "save-config";
2977 foreach (array_keys($_POST) as $pref_name) {
2979 $pref_name = db_escape_string($pref_name);
2980 $value = db_escape_string($_POST[$pref_name]);
2982 $result = db_query($link, "SELECT type_name
2983 FROM ttrss_prefs,ttrss_prefs_types
2984 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
2986 if (db_num_rows($result) > 0) {
2988 $type_name = db_fetch_result($result, 0, "type_name");
2990 // print "$pref_name : $type_name : $value<br>";
2992 if ($type_name == "bool") {
2993 if ($value == "1") {
2998 } else if ($type_name == "integer") {
2999 $value = sprintf("%d", $value);
3002 // print "$pref_name : $type_name : $value<br>";
3004 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
3005 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
3009 header("Location: prefs.php");
3013 } else if ($subop == "getHelp") {
3015 $pref_name = db_escape_string($_GET["pn"]);
3017 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
3018 WHERE pref_name = '$pref_name'");
3020 if (db_num_rows($result) > 0) {
3021 $help_text = db_fetch_result($result, 0, "help_text");
3024 print "Unknown option: $pref_name";
3027 } else if ($subop == "Change e-mail") {
3029 if (WEB_DEMO_MODE
) {
3030 header("Location: prefs.php");
3034 $email = db_escape_string($_GET["email"]);
3035 $active_uid = $_SESSION["uid"];
3038 db_query($link, "UPDATE ttrss_users SET email = '$email'
3039 WHERE id = '$active_uid'");
3042 header("Location: prefs.php");
3044 } else if ($subop == "Change password") {
3046 if (WEB_DEMO_MODE
) {
3047 header("Location: prefs.php");
3051 $old_pw = $_POST["OLD_PASSWORD"];
3052 $new_pw = $_POST["OLD_PASSWORD"];
3054 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
3055 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
3057 $active_uid = $_SESSION["uid"];
3059 if ($old_pw && $new_pw) {
3061 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
3063 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3064 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
3065 pwd_hash = '$old_pw_hash')");
3067 if (db_num_rows($result) == 1) {
3068 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
3069 WHERE id = '$active_uid'");
3071 $_SESSION["pwd_change_result"] = "ok";
3073 $_SESSION["pwd_change_result"] = "failed";
3077 header("Location: prefs.php");
3079 } else if ($subop == "Reset to defaults") {
3081 if (WEB_DEMO_MODE
) {
3082 header("Location: prefs.php");
3086 $_SESSION["prefs_op_result"] = "reset-to-defaults";
3088 if (DB_TYPE
== "pgsql") {
3089 db_query($link,"UPDATE ttrss_user_prefs
3090 SET value = ttrss_prefs.def_value
3091 WHERE owner_uid = '".$_SESSION["uid"]."' AND
3092 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
3094 db_query($link, "DELETE FROM ttrss_user_prefs
3095 WHERE owner_uid = ".$_SESSION["uid"]);
3096 initialize_user_prefs($link, $_SESSION["uid"]);
3099 header("Location: prefs.php");
3101 } else if ($subop == "Change theme") {
3103 $theme = db_escape_string($_POST["theme"]);
3105 if ($theme == "Default") {
3106 $theme_qpart = 'NULL';
3108 $theme_qpart = "'$theme'";
3111 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
3112 WHERE theme_name = '$theme'");
3114 if (db_num_rows($result) == 1) {
3115 $theme_id = db_fetch_result($result, 0, "id");
3116 $theme_path = db_fetch_result($result, 0, "theme_path");
3122 db_query($link, "UPDATE ttrss_users SET
3123 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
3125 $_SESSION["theme"] = $theme_path;
3127 header("Location: prefs.php");
3131 if (!SINGLE_USER_MODE
) {
3133 $result = db_query($link, "SELECT id,email FROM ttrss_users
3134 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
3135 pwd_hash = 'SHA1:".sha1("password")."')");
3137 if (db_num_rows($result) != 0) {
3138 print "<div class=\"warning\">
3139 Your password is at default value, please change it.
3143 if ($_SESSION["pwd_change_result"] == "failed") {
3144 print "<div class=\"warning\">
3145 There was an error while changing your password.
3149 if ($_SESSION["pwd_change_result"] == "ok") {
3150 print "<div class=\"notice\">
3151 Password changed successfully.
3155 $_SESSION["pwd_change_result"] = "";
3157 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
3158 print "<div class=\"notice\">
3159 Your configuration was reset to defaults.
3163 if ($_SESSION["prefs_op_result"] == "save-config") {
3164 print "<div class=\"notice\">
3165 Your configuration was saved successfully.
3169 $_SESSION["prefs_op_result"] = "";
3171 print "<form action=\"backend.php\" method=\"GET\">";
3173 print "<table width=\"100%\" class=\"prefPrefsList\">";
3174 print "<tr><td colspan='3'><h3>Personal data</h3></tr></td>";
3176 $result = db_query($link, "SELECT email FROM ttrss_users
3177 WHERE id = ".$_SESSION["uid"]);
3179 $email = db_fetch_result($result, 0, "email");
3181 print "<tr><td width=\"40%\">E-mail</td>";
3182 print "<td><input class=\"editbox\" name=\"email\"
3183 value=\"$email\"></td></tr>";
3187 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3189 print "<p><input class=\"button\" type=\"submit\"
3190 value=\"Change e-mail\" name=\"subop\">";
3192 print "<form action=\"backend.php\" method=\"POST\">";
3194 print "<table width=\"100%\" class=\"prefPrefsList\">";
3195 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
3197 print "<tr><td width=\"40%\">Old password</td>";
3198 print "<td><input class=\"editbox\" type=\"password\"
3199 name=\"OLD_PASSWORD\"></td></tr>";
3201 print "<tr><td width=\"40%\">New password</td>";
3203 print "<td><input class=\"editbox\" type=\"password\"
3204 name=\"NEW_PASSWORD\"></td></tr>";
3208 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3210 print "<p><input class=\"button\" type=\"submit\"
3211 value=\"Change password\" name=\"subop\">";
3217 $result = db_query($link, "SELECT
3218 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
3220 $user_theme_id = db_fetch_result($result, 0, "theme_id");
3222 $result = db_query($link, "SELECT
3223 id,theme_name FROM ttrss_themes ORDER BY theme_name");
3225 if (db_num_rows($result) > 0) {
3227 print "<form action=\"backend.php\" method=\"POST\">";
3228 print "<table width=\"100%\" class=\"prefPrefsList\">";
3229 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
3230 print "<tr><td width=\"40%\">Select theme</td>";
3231 print "<td><select name=\"theme\">";
3232 print "<option>Default</option>";
3233 print "<option disabled>--------</option>";
3235 while ($line = db_fetch_assoc($result)) {
3236 if ($line["id"] == $user_theme_id) {
3237 $selected = "selected";
3241 print "<option $selected>" . $line["theme_name"] . "</option>";
3243 print "</select></td></tr>";
3245 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3246 print "<p><input class=\"button\" type=\"submit\"
3247 value=\"Change theme\" name=\"subop\">";
3251 $result = db_query($link, "SELECT
3252 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
3253 section_name,def_value
3254 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
3255 WHERE type_id = ttrss_prefs_types.id AND
3256 section_id = ttrss_prefs_sections.id AND
3257 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
3258 owner_uid = ".$_SESSION["uid"]."
3259 ORDER BY section_id,short_desc");
3261 print "<form action=\"backend.php\" method=\"POST\">";
3265 $active_section = "";
3267 while ($line = db_fetch_assoc($result)) {
3269 if ($active_section != $line["section_name"]) {
3271 if ($active_section != "") {
3275 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
3277 $active_section = $line["section_name"];
3279 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
3280 // print "<tr class=\"title\">
3281 // <td width=\"25%\">Option</td><td>Value</td></tr>";
3286 // $class = ($lnum % 2) ? "even" : "odd";
3290 $type_name = $line["type_name"];
3291 $pref_name = $line["pref_name"];
3292 $value = $line["value"];
3293 $def_value = $line["def_value"];
3294 $help_text = $line["help_text"];
3296 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
3298 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
3304 if ($type_name == "bool") {
3305 // print_select($pref_name, $value, array("true", "false"));
3307 if ($value == "true") {
3313 print_radio($pref_name, $value, array("Yes", "No"));
3316 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
3328 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3330 print "<p><input class=\"button\" type=\"submit\"
3331 name=\"subop\" value=\"Save configuration\">";
3333 print " <input class=\"button\" type=\"submit\"
3334 name=\"subop\" onclick=\"return validatePrefsReset()\"
3335 value=\"Reset to defaults\"></p>";
3343 if ($op == "pref-users") {
3345 $subop = $_GET["subop"];
3347 if ($subop == "editSave") {
3349 if (!WEB_DEMO_MODE
) {
3351 $login = db_escape_string($_GET["l"]);
3352 $uid = db_escape_string($_GET["id"]);
3353 $access_level = sprintf("%d", $_GET["al"]);
3354 $email = db_escape_string($_GET["e"]);
3356 db_query($link, "UPDATE ttrss_users SET login = '$login',
3357 access_level = '$access_level', email = '$email' WHERE id = '$uid'");
3360 } else if ($subop == "remove") {
3362 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3364 $ids = split(",", db_escape_string($_GET["ids"]));
3366 foreach ($ids as $id) {
3367 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
3371 } else if ($subop == "add") {
3373 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3375 $login = db_escape_string(trim($_GET["login"]));
3376 $tmp_user_pwd = make_password(8);
3377 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3379 db_query($link, "INSERT INTO ttrss_users (login,pwd_hash,access_level)
3380 VALUES ('$login', '$pwd_hash', 0)");
3383 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3384 login = '$login' AND pwd_hash = '$pwd_hash'");
3386 if (db_num_rows($result) == 1) {
3388 $new_uid = db_fetch_result($result, 0, "id");
3390 print "<div class=\"notice\">Added user <b>".$_GET["login"].
3391 "</b> with password <b>$tmp_user_pwd</b>.</div>";
3393 initialize_user($link, $new_uid);
3397 print "<div class=\"warning\">Error while adding user <b>".
3398 $_GET["login"].".</b></div>";
3402 } else if ($subop == "resetPass") {
3404 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3406 $uid = db_escape_string($_GET["id"]);
3408 $result = db_query($link, "SELECT login,email
3409 FROM ttrss_users WHERE id = '$uid'");
3411 $login = db_fetch_result($result, 0, "login");
3412 $email = db_fetch_result($result, 0, "email");
3413 $tmp_user_pwd = make_password(8);
3414 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3416 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
3417 WHERE id = '$uid'");
3419 print "<div class=\"notice\">Changed password of
3420 user <b>$login</b> to <b>$tmp_user_pwd</b>.";
3422 if (MAIL_RESET_PASS
&& $email) {
3423 print " Notifying <b>$email</b>.";
3425 mail("$login <$email>", "Password reset notification",
3428 "Your password for this TT-RSS installation was reset by".
3429 " an administrator.\n".
3431 "Your new password is $tmp_user_pwd, please remember".
3432 " it for later reference.\n".
3434 "Sincerely, TT-RSS Mail Daemon.", "From: " . MAIL_FROM
);
3442 print "<div class=\"prefGenericAddBox\">
3443 <input id=\"uadd_box\" onchange=\"javascript:addUser()\" size=\"40\"> ";
3445 print"<input type=\"submit\" class=\"button\"
3446 onclick=\"javascript:addUser()\" value=\"Add user\"></div>";
3448 $result = db_query($link, "SELECT
3449 id,login,access_level,email,
3450 SUBSTRING(last_login,1,16) as last_login
3455 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
3457 print "<p><table width=\"100%\" cellspacing=\"0\"
3458 class=\"prefUserList\" id=\"prefUserList\">";
3460 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
3462 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3463 'UMRR-', 'UMCHK-', true)\">All</a>,
3464 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3465 'UMRR-', 'UMCHK-', false)\">None</a>
3468 print "<tr class=\"title\">
3469 <td align='center' width=\"5%\"> </td>
3470 <td width='20%'>Username</td>
3471 <td width='20%'>E-mail</td>
3472 <td width='20%'>Access Level</td>
3473 <td width='20%'>Last login</td></tr>";
3477 while ($line = db_fetch_assoc($result)) {
3479 $class = ($lnum %
2) ?
"even" : "odd";
3482 $edit_uid = $_GET["id"];
3484 if ($uid == $_SESSION["uid"] ||
($subop == "edit" && $uid != $edit_uid)) {
3488 $this_row_id = "id=\"UMRR-$uid\"";
3491 print "<tr class=\"$class\" $this_row_id>";
3493 $line["login"] = htmlspecialchars($line["login"]);
3495 $line["last_login"] = date(get_pref($link, 'SHORT_DATE_FORMAT'),
3496 strtotime($line["last_login"]));
3498 /* if ($uid == $_SESSION["uid"]) {
3500 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
3501 id=\"UMCHK-".$line["id"]."\"></td>";
3503 print "<td>".$line["login"]."</td>";
3504 print "<td>".$line["email"]."</td>";
3505 print "<td>".$line["access_level"]."</td>";
3507 } else */ if (!$edit_uid ||
$subop != "edit") {
3509 print "<td align='center'><input onclick='toggleSelectRow(this);'
3510 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
3512 print "<td><a href=\"javascript:editUser($uid);\">" .
3513 $line["login"] . "</td>";
3515 print "<td><a href=\"javascript:editUser($uid);\">" .
3516 $line["email"] . "</td>";
3518 print "<td><a href=\"javascript:editUser($uid);\">" .
3519 $line["access_level"] . "</td>";
3521 } else if ($uid != $edit_uid) {
3523 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
3524 id=\"UMCHK-".$line["id"]."\"></td>";
3526 print "<td>".$line["login"]."</td>";
3527 print "<td>".$line["email"]."</td>";
3528 print "<td>".$line["access_level"]."</td>";
3532 print "<td align='center'>
3533 <input disabled=\"true\" type=\"checkbox\" checked></td>";
3535 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
3538 print "<td><input id=\"iedit_email\" value=\"".$line["email"].
3541 print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
3546 print "<td>".$line["last_login"]."</td>";
3557 if ($subop == "edit") {
3559 <input type=\"submit\" class=\"button\"
3560 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">
3561 <input type=\"submit\" class=\"button\"
3562 onclick=\"javascript:userEditSave()\" value=\"Save\">";
3568 <input type=\"submit\" class=\"button\"
3569 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
3570 <input type=\"submit\" class=\"button\"
3571 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
3572 <input type=\"submit\" class=\"button\"
3573 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
3574 <input type=\"submit\" class=\"button\"
3575 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
3580 if ($op == "user-details") {
3582 if (WEB_DEMO_MODE ||
$_SESSION["access_level"] < 10) {
3586 /* print "<html><head>
3587 <title>Tiny Tiny RSS : User Details</title>
3588 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
3589 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
3592 $uid = sprintf("%d", $_GET["id"]);
3594 print "<div class='infoBoxContents'>";
3596 $result = db_query($link, "SELECT login,
3597 SUBSTRING(last_login,1,16) AS last_login,
3599 (SELECT COUNT(int_id) FROM ttrss_user_entries
3600 WHERE owner_uid = id) AS stored_articles
3602 WHERE id = '$uid'");
3604 if (db_num_rows($result) == 0) {
3605 print "<h1>User not found</h1>";
3609 print "<h1>User Details</h1>";
3611 print "<table width='100%'>";
3613 $login = db_fetch_result($result, 0, "login");
3614 $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'),
3615 strtotime(db_fetch_result($result, 0, "last_login")));
3616 $access_level = db_fetch_result($result, 0, "access_level");
3617 $stored_articles = db_fetch_result($result, 0, "stored_articles");
3619 print "<tr><td>Username</td><td>$login</td></tr>";
3620 print "<tr><td>Access level</td><td>$access_level</td></tr>";
3621 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
3622 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
3624 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
3625 WHERE owner_uid = '$uid'");
3627 $num_feeds = db_fetch_result($result, 0, "num_feeds");
3629 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
3631 /* $result = db_query($link, "SELECT
3632 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
3633 FROM ttrss_user_entries,ttrss_entries
3634 WHERE owner_uid = '$uid' AND ref_id = id");
3636 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
3638 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
3642 print "<h1>Subscribed feeds</h1>";
3644 $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
3645 WHERE owner_uid = '$uid' ORDER BY title LIMIT 20");
3647 print "<ul class=\"nomarks\">";
3649 while ($line = db_fetch_assoc($result)) {
3651 $icon_file = ICONS_URL
."/".$line["id"].".ico";
3653 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3654 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
3656 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3659 print "<li>$feed_icon <a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
3662 if (db_num_rows($result) < $num_feeds) {
3663 // FIXME - add link to show ALL subscribed feeds here somewhere
3665 class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\"> ...</li>";
3672 print "<div align='center'>
3673 <input type='submit' class='button'
3674 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3676 // print "</body></html>";
3680 if ($op == "feed-details") {
3682 // $feed_id = $_GET["id"];
3684 $feed_ids = split(",", db_escape_string($_GET["id"]));
3686 print "<div class=\"infoBoxContents\">";
3688 foreach ($feed_ids as $feed_id) {
3690 $result = db_query($link,
3693 SUBSTRING(last_updated,1,16) as last_updated,
3695 (SELECT COUNT(int_id) FROM ttrss_user_entries
3696 WHERE feed_id = id) AS total,
3697 (SELECT COUNT(int_id) FROM ttrss_user_entries
3698 WHERE feed_id = id AND unread = true) AS unread,
3699 (SELECT COUNT(int_id) FROM ttrss_user_entries
3700 WHERE feed_id = id AND marked = true) AS marked
3702 WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]);
3704 if (db_num_rows($result) == 0) return;
3706 $title = db_unescape_string(db_fetch_result($result, 0, "title"));
3707 $last_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
3708 strtotime(db_fetch_result($result, 0, "last_updated")));
3709 $feed_url = db_fetch_result($result, 0, "feed_url");
3710 $icon_url = db_fetch_result($result, 0, "icon_url");
3711 $total = db_fetch_result($result, 0, "total");
3712 $unread = db_fetch_result($result, 0, "unread");
3713 $marked = db_fetch_result($result, 0, "marked");
3714 $site_url = db_fetch_result($result, 0, "site_url");
3716 $result = db_query($link, "SELECT COUNT(id) AS subscribed
3717 FROM ttrss_feeds WHERE feed_url = '$feed_url'");
3719 $subscribed = db_fetch_result($result, 0, "subscribed");
3721 $icon_file = ICONS_DIR
. "/$feed_id.ico";
3723 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3724 $feed_icon = "<img width=\"16\" height=\"16\"
3725 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
3730 print "<h1>$feed_icon $title</h1>";
3732 print "<table width='100%'>";
3735 print "<tr><td width='30%'>Link</td>
3736 <td><a href=\"$site_url\">$site_url</a>
3737 <a href=\"$feed_url\">(feed)</a></td>
3740 print "<tr><td width='30%'>Feed URL</td>
3741 <td><a href=\"$feed_url\">$feed_url</a></td></tr>";
3743 print "<tr><td>Last updated</td><td>$last_updated</td></tr>";
3744 print "<tr><td>Total articles</td><td>$total</td></tr>";
3745 print "<tr><td>Unread articles</td><td>$unread</td></tr>";
3746 print "<tr><td>Starred articles</td><td>$marked</td></tr>";
3747 print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>";
3751 /* $result = db_query($link, "SELECT title,
3752 SUBSTRING(updated,1,16) AS updated,unread
3753 FROM ttrss_entries,ttrss_user_entries
3754 WHERE ref_id = id AND feed_id = '$feed_id'
3755 ORDER BY date_entered DESC LIMIT 5");
3757 if (db_num_rows($result) > 0) {
3759 print "<h1>Latest headlines</h1>";
3761 print "<ul class=\"nomarks\">";
3763 while ($line = db_fetch_assoc($result)) {
3764 if ($line["unread"] == "t" || $line["unread"] == "1") {
3765 $line["title"] = "<b>" . $line["title"] . "</b>";
3767 print "<li>" . $line["title"].
3768 " <span class=\"insensitive\">(" .
3769 date(get_pref($link, 'SHORT_DATE_FORMAT'),
3770 strtotime($line["updated"])).
3781 print "<div align='center'>
3782 <input type='submit' class='button'
3783 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3789 <!-- <?
= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?
> -->