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', 2);
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 function getAllCounters($link) {
59 getLabelCounters($link);
60 getFeedCounters($link);
61 getTagCounters($link);
62 getGlobalCounters($link);
63 if (get_pref($link, 'ENABLE_FEED_CATS')) {
64 getCategoryCounters($link);
68 function getCategoryCounters($link) {
69 $result = db_query($link, "SELECT cat_id,SUM((SELECT COUNT(int_id)
70 FROM ttrss_user_entries WHERE feed_id = ttrss_feeds.id
71 AND unread = true)) AS unread FROM ttrss_feeds
72 WHERE owner_uid = ".$_SESSION["uid"]." GROUP BY cat_id");
74 while ($line = db_fetch_assoc($result)) {
75 $line["cat_id"] = sprintf("%d", $line["cat_id"]);
76 print "<counter type=\"category\" id=\"".$line["cat_id"]."\" counter=\"".
77 $line["unread"]."\"/>";
81 function getFeedUnread($link, $feed) {
82 $n_feed = sprintf("%d", $feed);
85 $match_part = "marked = true";
86 } else if ($feed > 0) {
87 $match_part = "feed_id = '$n_feed'";
88 } else if ($feed < -10) {
89 $label_id = -$feed - 11;
91 $result = db_query($link, "SELECT sql_exp FROM ttrss_labels WHERE
92 id = '$label_id' AND owner_uid = " . $_SESSION["uid"]);
94 $match_part = db_fetch_result($result, 0, "sql_exp");
99 $result = db_query($link, "SELECT count(int_id) AS unread
100 FROM ttrss_user_entries
101 WHERE unread = true AND $match_part AND owner_uid = " . $_SESSION["uid"]);
105 $result = db_query($link, "SELECT COUNT(post_int_id) AS unread
106 FROM ttrss_tags,ttrss_user_entries
107 WHERE tag_name = '$feed' AND post_int_id = int_id AND unread = true AND
108 ttrss_tags.owner_uid = " . $_SESSION["uid"]);
111 $unread = db_fetch_result($result, 0, "unread");
115 /* FIXME this needs reworking */
117 function getGlobalCounters($link) {
118 $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries,ttrss_user_entries
119 WHERE unread = true AND
120 ttrss_user_entries.ref_id = ttrss_entries.id AND
121 owner_uid = " . $_SESSION["uid"]);
122 $c_id = db_fetch_result($result, 0, "c_id");
123 print "<counter type=\"global\" id='global-unread' counter='$c_id'/>";
126 function getTagCounters($link, $smart_mode = SMART_RPC_COUNTERS
) {
129 if (!$_SESSION["tctr_last_value"]) {
130 $_SESSION["tctr_last_value"] = array();
134 $old_counters = $_SESSION["tctr_last_value"];
136 $tctrs_modified = false;
138 /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
139 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
140 ttrss_user_entries.ref_id = ttrss_entries.id AND
141 ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND
142 post_int_id = ttrss_user_entries.int_id AND unread = true GROUP BY tag_name
144 select tag_name,0 as count FROM ttrss_tags
145 WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]); */
147 $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
148 FROM ttrss_user_entries WHERE int_id = post_int_id
149 AND unread = true)) AS count FROM ttrss_tags
150 WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name");
154 while ($line = db_fetch_assoc($result)) {
155 $tags[$line["tag_name"]] +
= $line["count"];
158 foreach (array_keys($tags) as $tag) {
159 $unread = $tags[$tag];
161 $tag = htmlspecialchars($tag);
163 if (!$smart_mode ||
$old_counters[$tag] != $unread) {
164 $old_counters[$tag] = $unread;
165 $tctrs_modified = true;
166 print "<counter type=\"tag\" id=\"$tag\" counter=\"$unread\"/>";
171 if ($smart_mode && $tctrs_modified) {
172 $_SESSION["tctr_last_value"] = $old_counters;
177 function getLabelCounters($link, $smart_mode = SMART_RPC_COUNTERS
) {
180 if (!$_SESSION["lctr_last_value"]) {
181 $_SESSION["lctr_last_value"] = array();
185 $old_counters = $_SESSION["lctr_last_value"];
186 $lctrs_modified = false;
188 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries
189 WHERE marked = true AND ttrss_user_entries.ref_id = ttrss_entries.id AND
190 unread = true AND owner_uid = ".$_SESSION["uid"]);
192 $count = db_fetch_result($result, 0, "count");
194 print "<counter type=\"label\" id=\"-1\" counter=\"$count\"/>";
196 $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM
197 ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description");
199 while ($line = db_fetch_assoc($result)) {
201 $id = -$line["id"] - 11;
205 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_user_entries,ttrss_entries
206 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
207 ttrss_user_entries.ref_id = ttrss_entries.id AND
208 owner_uid = ".$_SESSION["uid"]);
210 $count = db_fetch_result($tmp_result, 0, "count");
212 if (!$smart_mode ||
$old_counters[$id] != $count) {
213 $old_counters[$id] = $count;
214 $lctrs_modified = true;
215 print "<counter type=\"label\" id=\"$id\" counter=\"$count\"/>";
218 error_reporting (DEFAULT_ERROR_LEVEL
);
221 if ($smart_mode && $lctrs_modified) {
222 $_SESSION["lctr_last_value"] = $old_counters;
226 function getFeedCounter($link, $id) {
228 $result = db_query($link, "SELECT
229 count(id) as count FROM ttrss_entries,ttrss_user_entries
230 WHERE feed_id = '$id' AND unread = true
231 AND ttrss_user_entries.ref_id = ttrss_entries.id");
233 $count = db_fetch_result($result, 0, "count");
235 print "<counter type=\"feed\" id=\"$id\" counter=\"$count\"/>";
238 function getFeedCounters($link, $smart_mode = SMART_RPC_COUNTERS
) {
241 if (!$_SESSION["fctr_last_value"]) {
242 $_SESSION["fctr_last_value"] = array();
246 $old_counters = $_SESSION["fctr_last_value"];
248 $result = db_query($link, "SELECT id,
250 FROM ttrss_entries,ttrss_user_entries
251 WHERE feed_id = ttrss_feeds.id AND ttrss_user_entries.ref_id = ttrss_entries.id
252 AND unread = true AND owner_uid = ".$_SESSION["uid"].") as count
253 FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]);
255 $fctrs_modified = false;
257 while ($line = db_fetch_assoc($result)) {
260 $count = $line["count"];
262 if (!$smart_mode ||
$old_counters[$id] != $count) {
263 $old_counters[$id] = $count;
264 $fctrs_modified = true;
265 print "<counter type=\"feed\" id=\"$id\" counter=\"$count\"/>";
269 if ($smart_mode && $fctrs_modified) {
270 $_SESSION["fctr_last_value"] = $old_counters;
274 function outputFeedList($link, $tags = false) {
277 <title>Tiny Tiny RSS : Feedlist</title>
278 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
280 $user_theme = $_SESSION["theme"];
282 print "<link rel=\"stylesheet\" type=\"text/css\"
283 href=\"themes/$user_theme/theme.css\">";
286 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
287 print "<link rel=\"stylesheet\" type=\"text/css\"
288 href=\"tt-rss_compact.css\"/>";
290 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
291 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
294 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
295 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
296 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
297 </head><body onload=\"init()\">";
299 print "<ul class=\"feedList\" id=\"feedList\">";
301 $owner_uid = $_SESSION["uid"];
307 if (get_pref($link, 'ENABLE_FEED_CATS')) {
308 print "<li class=\"feedCat\">Special</li>";
309 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
312 $result = db_query($link, "SELECT count(id) as num_starred
313 FROM ttrss_entries,ttrss_user_entries
314 WHERE marked = true AND
315 ttrss_user_entries.ref_id = ttrss_entries.id AND
316 unread = true AND owner_uid = '$owner_uid'");
317 $num_starred = db_fetch_result($result, 0, "num_starred");
321 if ($num_starred > 0) $class .= "Unread";
323 printFeedEntry(-1, $class, "Starred articles", $num_starred,
324 "images/mark_set.png", $link);
326 if (get_pref($link, 'ENABLE_FEED_CATS')) {
330 if (GLOBAL_ENABLE_LABELS
&& get_pref($link, 'ENABLE_LABELS')) {
332 $result = db_query($link, "SELECT id,sql_exp,description FROM
333 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
335 if (db_num_rows($result) > 0) {
336 if (get_pref($link, 'ENABLE_FEED_CATS')) {
337 print "<li class=\"feedCat\">Labels</li>";
338 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
340 print "<li><hr></li>";
344 while ($line = db_fetch_assoc($result)) {
348 $tmp_result = db_query($link, "SELECT count(id) as count
349 FROM ttrss_entries,ttrss_user_entries
350 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
351 ttrss_user_entries.ref_id = ttrss_entries.id
352 AND owner_uid = '$owner_uid'");
354 $count = db_fetch_result($tmp_result, 0, "count");
362 error_reporting (DEFAULT_ERROR_LEVEL
);
364 printFeedEntry(-$line["id"]-11,
365 $class, $line["description"], $count, "images/label.png", $link);
369 if (db_num_rows($result) > 0) {
370 if (get_pref($link, 'ENABLE_FEED_CATS')) {
377 // if (!get_pref($link, 'ENABLE_FEED_CATS')) {
378 print "<li><hr></li>";
381 if (get_pref($link, 'ENABLE_FEED_CATS')) {
382 $order_by_qpart = "category,title";
384 $order_by_qpart = "title";
387 $result = db_query($link, "SELECT *,
388 (SELECT count(id) FROM ttrss_entries,ttrss_user_entries
389 WHERE feed_id = ttrss_feeds.id AND
390 ttrss_user_entries.ref_id = ttrss_entries.id AND
391 owner_uid = '$owner_uid') AS total,
392 (SELECT count(id) FROM ttrss_entries,ttrss_user_entries
393 WHERE feed_id = ttrss_feeds.id AND unread = true
394 AND ttrss_user_entries.ref_id = ttrss_entries.id
395 AND owner_uid = '$owner_uid') as unread,
396 (SELECT title FROM ttrss_feed_categories
397 WHERE id = cat_id) AS category,
399 (SELECT collapsed FROM ttrss_feed_categories
400 WHERE id = cat_id) AS collapsed
401 FROM ttrss_feeds WHERE owner_uid = '$owner_uid' ORDER BY $order_by_qpart");
403 $actid = $_GET["actid"];
413 while ($line = db_fetch_assoc($result)) {
415 $feed = db_unescape_string($line["title"]);
416 $feed_id = $line["id"];
418 $subop = $_GET["subop"];
420 $total = $line["total"];
421 $unread = $line["unread"];
423 $cat_id = $line["cat_id"];
425 $tmp_category = $line["category"];
427 if (!$tmp_category) {
428 $tmp_category = "Uncategorized";
431 // $class = ($lnum % 2) ? "even" : "odd";
435 if ($unread > 0) $class .= "Unread";
437 if ($actid == $feed_id) {
438 $class .= "Selected";
441 $total_unread +
= $unread;
443 if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
446 print "</li></ul></li>";
449 $category = $tmp_category;
451 $collapsed = $line["collapsed"];
453 // workaround for NULL category
454 if ($category == "Uncategorized") {
455 if ($_COOKIE["ttrss_vf_uclps"] == 1) {
460 if ($collapsed == "t" ||
$collapsed == "1") {
461 $holder_class = "invisible";
469 $cat_id_qpart = "cat_id = '$cat_id'";
471 $cat_id_qpart = "cat_id IS NULL";
474 $tmp_result = db_query($link, "SELECT count(int_id) AS unread
475 FROM ttrss_user_entries,ttrss_feeds WHERE
477 feed_id = ttrss_feeds.id AND $cat_id_qpart AND
478 ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
480 $cat_unread = db_fetch_result($tmp_result, 0, "unread");
482 $cat_id = sprintf("%d", $cat_id);
484 print "<li class=\"feedCat\" id=\"FCAT-$cat_id\">
485 <a href=\"javascript:toggleCollapseCat($cat_id)\">$tmp_category
486 <span id=\"FCATCTR-$cat_id\"
487 class=\"$catctr_class\">($cat_unread unread)$ellipsis</span></a></li>";
489 // !!! NO SPACE before <ul...feedCatList - breaks firstChild DOM function
490 // -> keyboard navigation, etc.
491 print "<li id=\"feedCatHolder\" class=\"$holder_class\"><ul class=\"feedCatList\">";
494 printFeedEntry($feed_id, $class, $feed, $unread,
495 "icons/$feed_id.ico", $link);
504 /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
505 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
506 post_int_id = ttrss_user_entries.int_id AND
507 unread = true AND ref_id = ttrss_entries.id
508 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
510 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'
511 ORDER BY tag_name"); */
513 $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
514 FROM ttrss_user_entries WHERE int_id = post_int_id
515 AND unread = true)) AS count FROM ttrss_tags
516 WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name");
520 while ($line = db_fetch_assoc($result)) {
521 $tags[$line["tag_name"]] +
= $line["count"];
524 foreach (array_keys($tags) as $tag) {
526 $unread = $tags[$tag];
534 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
540 if (db_num_rows($result) == 0) {
546 print "<li>No $what to display.</li>";
556 $subop = $_GET["subop"];
558 if ($subop == "getLabelCounters") {
561 getLabelCounters($link);
563 getFeedCounter($link, $aid);
565 print "</rpc-reply>";
568 if ($subop == "getFeedCounters") {
570 getFeedCounters($link);
571 print "</rpc-reply>";
574 if ($subop == "getAllCounters") {
576 getAllCounters($link);
577 print "</rpc-reply>";
580 if ($subop == "mark") {
581 $mark = $_GET["mark"];
582 $id = db_escape_string($_GET["id"]);
590 // FIXME this needs collision testing
592 $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
593 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
596 if ($subop == "updateFeed") {
597 $feed_id = db_escape_string($_GET["feed"]);
599 $result = db_query($link,
600 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'
601 AND owner_uid = " . $_SESSION["uid"]);
603 if (db_num_rows($result) > 0) {
604 $feed_url = db_fetch_result($result, 0, "feed_url");
605 update_rss_feed($link, $feed_url, $feed_id);
609 getFeedCounter($link, $feed_id);
610 print "</rpc-reply>";
615 if ($subop == "forceUpdateAllFeeds" ||
$subop == "updateAllFeeds") {
617 update_all_feeds($link, $subop == "forceUpdateAllFeeds");
619 $omode = $_GET["omode"];
621 if (!$omode) $omode = "tfl";
624 if (strchr($omode, "l")) getLabelCounters($link);
625 if (strchr($omode, "f")) getFeedCounters($link);
626 if (strchr($omode, "t")) getTagCounters($link);
627 if (get_pref($link, 'ENABLE_FEED_CATS')) {
628 getCategoryCounters($link);
630 getGlobalCounters($link);
631 print "</rpc-reply>";
634 /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
635 if ($subop == "catchupSelected") {
637 $ids = split(",", db_escape_string($_GET["ids"]));
639 $cmode = sprintf("%d", $_GET["cmode"]);
641 foreach ($ids as $id) {
644 db_query($link, "UPDATE ttrss_user_entries SET
645 unread = false,last_read = NOW()
646 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
647 } else if ($cmode == 1) {
648 db_query($link, "UPDATE ttrss_user_entries SET
650 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
652 db_query($link, "UPDATE ttrss_user_entries SET
653 unread = NOT unread,last_read = NOW()
654 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
658 getAllCounters($link);
659 print "</rpc-reply>";
662 if ($subop == "markSelected") {
664 $ids = split(",", db_escape_string($_GET["ids"]));
666 $cmode = sprintf("%d", $_GET["cmode"]);
668 foreach ($ids as $id) {
671 db_query($link, "UPDATE ttrss_user_entries SET
673 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
674 } else if ($cmode == 1) {
675 db_query($link, "UPDATE ttrss_user_entries SET
677 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
679 db_query($link, "UPDATE ttrss_user_entries SET
681 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
685 getAllCounters($link);
686 print "</rpc-reply>";
689 if ($subop == "sanityCheck") {
693 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
695 $schema_version = db_fetch_result($result, 0, "schema_version");
697 if ($schema_version != SCHEMA_VERSION
) {
701 print "<error error-code='$error_code'/>";
704 if ($subop == "globalPurge") {
707 global_purge_old_posts($link, true);
708 print "</rpc-reply>";
714 if ($op == "feeds") {
716 $tags = $_GET["tags"];
718 $subop = $_GET["subop"];
720 if ($subop == "catchupAll") {
721 db_query($link, "UPDATE ttrss_user_entries SET
722 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
725 if ($subop == "collapse") {
726 $cat_id = db_escape_string($_GET["cid"]);
728 db_query($link, "UPDATE ttrss_feed_categories SET
729 collapsed = NOT collapsed WHERE id = '$cat_id' AND owner_uid = " .
734 outputFeedList($link, $tags);
741 $feed_id = $_GET["feed"];
743 $result = db_query($link, "UPDATE ttrss_user_entries
744 SET unread = false,last_read = NOW()
745 WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
747 $addheader = $_GET["addheader"];
749 $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
750 SUBSTRING(updated,1,16) as updated,
751 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url,
753 FROM ttrss_entries,ttrss_user_entries
754 WHERE id = '$id' AND ref_id = id");
758 <title>Tiny Tiny RSS : Article $id</title>
759 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
761 $user_theme = $_SESSION["theme"];
763 print "<link rel=\"stylesheet\" type=\"text/css\"
764 href=\"themes/$user_theme/theme.css\">";
767 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
768 print "<link rel=\"stylesheet\" type=\"text/css\"
769 href=\"tt-rss_compact.css\"/>";
771 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
772 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
775 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
776 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
782 $line = db_fetch_assoc($result);
784 if ($line["icon_url"]) {
785 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
787 $feed_icon = " ";
790 /* if ($line["comments"] && $line["link"] != $line["comments"]) {
791 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
793 $entry_comments = "";
796 $num_comments = $line["num_comments"];
797 $entry_comments = "";
799 if ($num_comments > 0) {
800 if ($line["comments"]) {
801 $comments_url = $line["comments"];
803 $comments_url = $line["link"];
805 $entry_comments = "<a href=\"$comments_url\">$num_comments comments</a>";
807 if ($line["comments"] && $line["link"] != $line["comments"]) {
808 $entry_comments = "<a href=\"".$line["comments"]."\">comments</a>";
812 print "<div class=\"postReply\">";
814 print "<div class=\"postHeader\"><table width=\"100%\">";
816 print "<tr><td><a href=\"" . $line["link"] . "\">" . $line["title"] . "</a></td>";
818 $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
819 strtotime($line["updated"]));
821 print "<td class=\"postDate\">$parsed_updated</td>";
825 $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
826 ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
834 while ($tmp_line = db_fetch_assoc($tmp_result)) {
836 $tag = $tmp_line["tag_name"];
837 $tag_str = "<a href=\"javascript:parent.viewfeed('$tag')\">$tag</a>, ";
839 if ($num_tags == 5) {
840 $tags_str .= "<a href=\"javascript:showBlockElement('allEntryTags')\">...</a>";
841 } else if ($num_tags < 5) {
842 $tags_str .= $tag_str;
844 $f_tags_str .= $tag_str;
847 $tags_str = preg_replace("/, $/", "", $tags_str);
848 $f_tags_str = preg_replace("/, $/", "", $f_tags_str);
850 // $truncated_link = truncate_string($line["link"], 60);
852 if ($tags_str ||
$entry_comments) {
853 print "<tr><td width='50%'>
855 <td align=\"right\">$tags_str</td></tr>";
858 print "</table></div>";
860 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
861 print "<div class=\"postContent\">";
863 if (db_num_rows($tmp_result) > 5) {
864 print "<div id=\"allEntryTags\">Tags: $f_tags_str</div>";
867 print $line["content"] . "</div>";
871 print "<script type=\"text/javascript\">
872 update_all_counters('$feed_id');
877 print "</body></html>";
881 if ($op == "viewfeed") {
883 $feed = $_GET["feed"];
884 $skip = $_GET["skip"];
885 $subop = $_GET["subop"];
886 $view_mode = $_GET["view"];
887 $addheader = $_GET["addheader"];
888 $limit = $_GET["limit"];
894 if (!$skip) $skip = 0;
896 if ($subop == "undefined") $subop = "";
900 <title>Tiny Tiny RSS : Feed $feed</title>
901 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
903 $user_theme = $_SESSION["theme"];
905 print "<link rel=\"stylesheet\" type=\"text/css\"
906 href=\"themes/$user_theme/theme.css\">";
909 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
910 print "<link rel=\"stylesheet\"
911 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
914 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
915 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
918 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
919 <script type=\"text/javascript\" src=\"functions.js\"></script>
920 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
921 </head><body onload='init()'>";
924 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
926 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
927 WHERE id = '$feed'");
929 $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
931 update_rss_feed($link, $feed_url, $feed);
935 if ($subop == "MarkAllRead") {
937 if (sprintf("%d", $feed) != 0) {
940 db_query($link, "UPDATE ttrss_user_entries
941 SET unread = false,last_read = NOW()
942 WHERE feed_id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
944 } else if ($feed < 0 && $feed > -10) { // special, like starred
947 db_query($link, "UPDATE ttrss_user_entries
948 SET unread = false,last_read = NOW()
949 WHERE marked = true AND owner_uid = ".$_SESSION["uid"]);
952 } else if ($feed < -10) { // label
954 // TODO make this more efficient
956 $label_id = -$feed - 11;
958 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
959 WHERE id = '$label_id'");
962 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
964 db_query($link, "BEGIN");
966 $tmp2_result = db_query($link,
970 ttrss_user_entries,ttrss_entries
974 owner_uid = " . $_SESSION["uid"]);
976 while ($tmp_line = db_fetch_assoc($tmp2_result)) {
977 db_query($link, "UPDATE
980 unread = false, last_read = NOW()
982 int_id = " . $tmp_line["int_id"]);
985 db_query($link, "COMMIT");
987 /* db_query($link, "UPDATE ttrss_user_entries,ttrss_entries
988 SET unread = false,last_read = NOW()
991 AND owner_uid = ".$_SESSION["uid"]); */
995 db_query($link, "BEGIN");
997 $tag_name = db_escape_string($feed);
999 $result = db_query($link, "SELECT post_int_id FROM ttrss_tags
1000 WHERE tag_name = '$tag_name' AND owner_uid = " . $_SESSION["uid"]);
1002 while ($line = db_fetch_assoc($result)) {
1003 db_query($link, "UPDATE ttrss_user_entries SET
1004 unread = false, last_read = NOW()
1005 WHERE int_id = " . $line["post_int_id"]);
1007 db_query($link, "COMMIT");
1012 $search = db_escape_string($_GET["search"]);
1013 $search_mode = db_escape_string($_GET["smode"]);
1016 $search_query_part = "(upper(title) LIKE upper('%$search%')
1017 OR content LIKE '%$search%') AND";
1019 $search_query_part = "";
1022 $view_query_part = "";
1024 if ($view_mode == "Adaptive") {
1026 $unread = getFeedUnread($link, $feed);
1028 $view_query_part = " unread = true AND ";
1033 if ($view_mode == "Starred") {
1034 $view_query_part = " marked = true AND ";
1037 if ($view_mode == "Unread") {
1038 $view_query_part = " unread = true AND ";
1041 /* if ($view_mode == "Unread or Starred") {
1042 $view_query_part = " (unread = true OR marked = true) AND ";
1045 if ($view_mode == "Unread or Updated") {
1046 $view_query_part = " (unread = true OR last_read is NULL) AND ";
1049 /* $result = db_query($link, "SELECT count(id) AS total_entries
1050 FROM ttrss_entries WHERE
1052 feed_id = '$feed'");
1054 $total_entries = db_fetch_result($result, 0, "total_entries"); */
1056 /* $result = db_query("SELECT count(id) AS unread_entries
1057 FROM ttrss_entries WHERE
1060 feed_id = '$feed'");
1062 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
1064 if ($limit && $limit != "All") {
1065 $limit_query_part = "LIMIT " . $limit;
1068 $vfeed_query_part = "";
1070 // override query strategy and enable feed display when searching globally
1071 if ($search && $search_mode == "All feeds") {
1072 $query_strategy_part = "id > 0";
1073 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
1074 id = feed_id) as feed_title,";
1075 } else if (sprintf("%d", $feed) == 0) {
1076 $query_strategy_part = "ttrss_entries.id > 0";
1077 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
1078 id = feed_id) as feed_title,";
1079 } else if ($feed >= 0) {
1080 $query_strategy_part = "feed_id = '$feed'";
1081 } else if ($feed == -1) { // starred virtual feed
1082 $query_strategy_part = "marked = true";
1083 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
1084 id = feed_id) as feed_title,";
1085 } else if ($feed <= -10) { // labels
1086 $label_id = -$feed - 11;
1088 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
1089 WHERE id = '$label_id'");
1091 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
1093 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
1094 id = feed_id) as feed_title,";
1096 $query_strategy_part = "id > 0"; // dumb
1099 $order_by = "updated DESC";
1101 // if ($feed < -10) {
1102 // $order_by = "feed_id,updated DESC";
1107 if ($search && $search_mode == "All feeds") {
1108 $feed_title = "Search results";
1109 } else if (sprintf("%d", $feed) == 0) {
1110 $feed_title = $feed;
1111 } else if ($feed > 0) {
1112 $result = db_query($link, "SELECT title,site_url FROM ttrss_feeds
1113 WHERE id = '$feed'");
1115 $feed_title = db_fetch_result($result, 0, "title");
1116 $feed_site_url = db_fetch_result($result, 0, "site_url");
1118 } else if ($feed == -1) {
1119 $feed_title = "Starred articles";
1120 } else if ($feed < -10) {
1121 $label_id = -$feed - 11;
1122 $result = db_query($link, "SELECT description FROM ttrss_labels
1123 WHERE id = '$label_id'");
1124 $feed_title = db_fetch_result($result, 0, "description");
1129 if ($feed < -10) error_reporting (0);
1131 print "<div id=\"headlinesContainer\">";
1133 if (sprintf("%d", $feed) != 0) {
1136 $feed_kind = "Feeds";
1138 $feed_kind = "Labels";
1141 // if (!$vfeed_query_part) {
1142 $content_query_part = "content as content_preview,";
1144 // $content_query_part = "";
1147 $result = db_query($link, "SELECT
1149 SUBSTRING(updated,1,16) as updated,
1150 unread,feed_id,marked,link,last_read,
1151 SUBSTRING(last_read,1,19) as last_read_noms,
1154 SUBSTRING(updated,1,19) as updated_noms
1156 ttrss_entries,ttrss_user_entries
1158 ttrss_user_entries.ref_id = ttrss_entries.id AND
1159 owner_uid = '".$_SESSION["uid"]."' AND
1162 $query_strategy_part ORDER BY $order_by
1163 $limit_query_part");
1168 $feed_kind = "Tags";
1170 $result = db_query($link, "SELECT
1171 ttrss_entries.id as id,title,
1172 SUBSTRING(updated,1,16) as updated,
1174 marked,link,last_read,
1175 SUBSTRING(last_read,1,19) as last_read_noms,
1178 SUBSTRING(updated,1,19) as updated_noms
1180 ttrss_entries,ttrss_user_entries,ttrss_tags
1182 ref_id = ttrss_entries.id AND
1183 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
1184 post_int_id = int_id AND tag_name = '$feed' AND
1187 $query_strategy_part ORDER BY $order_by
1188 $limit_query_part");
1192 print "<div align='center'>
1193 Could not display feed (query failed). Please check label match syntax or local configuration.</div>";
1197 if (db_num_rows($result) > 0) {
1199 print "<table class=\"headlinesSubToolbar\"
1200 width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
1202 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1204 print "<td class=\"headlineActions\">
1206 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
1207 'RROW-', 'RCHK-', true)\">All</a>,
1208 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
1209 'RROW-', 'RCHK-', true, 'Unread')\">Unread</a>,
1210 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
1211 'RROW-', 'RCHK-', false)\">None</a>
1213 Toggle: <a href=\"javascript:selectionToggleUnread()\">Unread</a>,
1214 <a href=\"javascript:selectionToggleMarked()\">Starred</a>";
1220 print "<td class=\"headlineActions\">
1222 <a href=\"javascript:cdmSelectArticles('all')\">All</a>,
1223 <a href=\"javascript:cdmSelectArticles('unread')\">Unread</a>,
1224 <a href=\"javascript:cdmSelectArticles('none')\">None</a>
1226 Toggle: <a href=\"javascript:selectionToggleUnread(true)\">Unread</a>,
1227 <a href=\"javascript:selectionToggleMarked(true)\">Starred</a>";
1234 print "<td class=\"headlineTitle\">";
1236 if ($feed_site_url) {
1237 print "<a target=\"_blank\" href=\"$feed_site_url\">$feed_title</a>";
1243 print "</tr></table>";
1245 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1246 print "<table class=\"headlinesList\" id=\"headlinesList\"
1247 cellspacing=\"0\" width=\"100%\">";
1252 error_reporting (DEFAULT_ERROR_LEVEL
);
1256 while ($line = db_fetch_assoc($result)) {
1258 $class = ($lnum %
2) ?
"even" : "odd";
1261 $feed_id = $line["feed_id"];
1263 if ($line["last_read"] == "" &&
1264 ($line["unread"] != "t" && $line["unread"] != "1")) {
1266 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
1269 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
1273 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
1281 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
1282 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
1283 alt=\"Reset mark\" onclick='javascript:toggleMark($id)'>";
1285 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
1286 alt=\"Set mark\" onclick='javascript:toggleMark($id)'>";
1289 $content_link = "<a href=\"javascript:view($id,$feed_id);\">" .
1290 $line["title"] . "</a>";
1292 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1293 $updated_fmt = smart_date_time(strtotime($line["updated"]));
1295 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1296 $updated_fmt = date($short_date, strtotime($line["updated"]));
1299 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
1300 $content_preview = truncate_string(strip_tags($line["content_preview"]),
1304 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1306 print "<tr class='$class' id='RROW-$id'>";
1308 print "<td class='hlUpdatePic'>$update_pic</td>";
1310 print "<td class='hlSelectRow'>
1311 <input type=\"checkbox\" onclick=\"toggleSelectRow(this)\"
1312 class=\"feedCheckBox\" id=\"RCHK-$id\">
1315 print "<td class='hlMarkedPic'>$marked_pic</td>";
1317 if ($line["feed_title"]) {
1318 print "<td class='hlContent'>$content_link</td>";
1319 print "<td class='hlFeed'>
1320 <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a> </td>";
1322 print "<td class='hlContent' valign='middle'>";
1324 print "<a href=\"javascript:view($id,$feed_id);\">" .
1327 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
1329 if ($content_preview) {
1330 print "<span class=\"contentPreview\"> - $content_preview</span>";
1338 print "<td class=\"hlUpdated\"><nobr>$updated_fmt </nobr></td>";
1345 $add_class = "Unread";
1350 print "<div class=\"cdmArticle$add_class\" id=\"RROW-$id\">";
1352 print "<div class=\"cdmHeader\">";
1354 print "<div style=\"float : right\">$updated_fmt</div>";
1356 print "<a href=\"".$line["link"]."\">".$line["title"]."</a>";
1358 if ($line["feed_title"]) {
1359 print " (<a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>)";
1364 print "<div class=\"cdmContent\">" . $line["content_preview"] . "</div>";
1366 print "<div style=\"float : right\">$marked_pic</div>
1367 <div class=\"cdmFooter\">
1368 <input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
1369 'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\"></div>";
1378 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1383 print "<div width='100%' align='center'>No articles found.</div>";
1388 print "<script type=\"text/javascript\">
1389 document.onkeydown = hotkey_handler;
1390 update_all_counters('$feed');
1394 print "</body></html>";
1398 if ($op == "pref-rpc") {
1400 $subop = $_GET["subop"];
1402 if ($subop == "unread") {
1403 $ids = split(",", db_escape_string($_GET["ids"]));
1404 foreach ($ids as $id) {
1405 db_query($link, "UPDATE ttrss_user_entries SET unread = true
1406 WHERE feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
1409 print "Marked selected feeds as unread.";
1412 if ($subop == "read") {
1413 $ids = split(",", db_escape_string($_GET["ids"]));
1414 foreach ($ids as $id) {
1415 db_query($link, "UPDATE ttrss_user_entries
1416 SET unread = false,last_read = NOW() WHERE
1417 feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
1420 print "Marked selected feeds as read.";
1426 if ($op == "pref-feeds") {
1428 $subop = $_GET["subop"];
1429 $quiet = $_GET["quiet"];
1431 if ($subop == "editfeed") {
1432 $feed_id = db_escape_string($_GET["id"]);
1434 $result = db_query($link,
1435 "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
1436 owner_uid = " . $_SESSION["uid"]);
1438 $title = htmlspecialchars(db_unescape_string(db_fetch_result($result,
1441 print "<div class=\"infoBoxContents\">";
1443 $icon_file = ICONS_DIR
. "/$feed_id.ico";
1445 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1446 $feed_icon = "<img width=\"16\" height=\"16\"
1447 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
1452 print "<h1>$feed_icon $title</h1>";
1454 print "<table width='100%'>";
1458 print "<tr class='$row_class'><td>Title:</td>";
1459 print "<td><input id=\"iedit_title\" value=\"$title\"></td></tr>";
1461 $feed_url = db_fetch_result($result, 0, "feed_url");
1462 $feed_url = htmlspecialchars(db_unescape_string(db_fetch_result($result,
1464 $row_class = toggleEvenOdd($row_class);
1466 print "<tr class='$row_class'><td>Feed URL:</td>";
1467 print "<td><input id=\"iedit_link\" value=\"$feed_url\"></td></tr>";
1469 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1471 $cat_id = db_fetch_result($result, 0, "cat_id");
1473 $row_class = toggleEvenOdd($row_class);
1475 print "<tr class='$row_class'><td>Category:</td>";
1477 print "<select id=\"iedit_fcat\">";
1478 print "<option id=\"0\">Uncategorized</option>";
1480 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feed_categories
1481 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1483 if (db_num_rows($tmp_result) > 0) {
1484 print "<option disabled>--------</option>";
1487 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1488 if ($tmp_line["id"] == $cat_id) {
1489 $is_selected = "selected";
1493 printf("<option $is_selected id='%d'>%s</option>",
1494 $tmp_line["id"], $tmp_line["title"]);
1497 print "</select></td>";
1502 $update_interval = db_fetch_result($result, 0, "update_interval");
1503 $row_class = toggleEvenOdd($row_class);
1505 print "<tr class='$row_class'><td>Update Interval:</td>";
1506 print "<td><input id=\"iedit_updintl\"
1507 value=\"$update_interval\"></td></tr>";
1509 $purge_interval = db_fetch_result($result, 0, "purge_interval");
1510 $row_class = toggleEvenOdd($row_class);
1512 print "<tr class='$row_class'><td>Purge Days:</td>";
1513 print "<td><input id=\"iedit_purgintl\"
1514 value=\"$purge_interval\"></td></tr>";
1519 print "<div align='center'>
1520 <input type='submit' class='button'
1521 onclick=\"feedEditCancel()\" value=\"Cancel\">
1522 <input type=\"submit\" class=\"button\"
1523 onclick=\"feedEditSave()\" value=\"Save\"></div>";
1527 if ($subop == "editSave") {
1528 $feed_title = db_escape_string($_GET["t"]);
1529 $feed_link = db_escape_string($_GET["l"]);
1530 $upd_intl = db_escape_string($_GET["ui"]);
1531 $purge_intl = db_escape_string($_GET["pi"]);
1532 $feed_id = db_escape_string($_GET["id"]);
1533 $cat_id = db_escape_string($_GET["catid"]);
1535 if (strtoupper($upd_intl) == "DEFAULT")
1538 if (strtoupper($upd_intl) == "DISABLED")
1541 if (strtoupper($purge_intl) == "DEFAULT")
1544 if (strtoupper($purge_intl) == "DISABLED")
1548 $category_qpart = "cat_id = '$cat_id'";
1550 $category_qpart = 'cat_id = NULL';
1553 $result = db_query($link, "UPDATE ttrss_feeds SET
1555 title = '$feed_title', feed_url = '$feed_link',
1556 update_interval = '$upd_intl',
1557 purge_interval = '$purge_intl'
1558 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
1561 if ($subop == "saveCat") {
1562 $cat_title = db_escape_string($_GET["title"]);
1563 $cat_id = db_escape_string($_GET["id"]);
1565 $result = db_query($link, "UPDATE ttrss_feed_categories SET
1566 title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
1570 if ($subop == "remove") {
1572 if (!WEB_DEMO_MODE
) {
1574 $ids = split(",", db_escape_string($_GET["ids"]));
1576 foreach ($ids as $id) {
1577 db_query($link, "DELETE FROM ttrss_feeds
1578 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1580 $icons_dir = ICONS_DIR
;
1582 if (file_exists($icons_dir . "/$id.ico")) {
1583 unlink($icons_dir . "/$id.ico");
1589 if ($subop == "add") {
1591 if (!WEB_DEMO_MODE
) {
1593 $feed_link = db_escape_string(trim($_GET["link"]));
1595 $result = db_query($link,
1596 "SELECT id FROM ttrss_feeds
1597 WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]);
1599 if (db_num_rows($result) == 0) {
1601 $result = db_query($link,
1602 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title)
1603 VALUES ('".$_SESSION["uid"]."', '$feed_link', '')");
1605 $result = db_query($link,
1606 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'
1607 AND owner_uid = " . $_SESSION["uid"]);
1609 $feed_id = db_fetch_result($result, 0, "id");
1612 update_rss_feed($link, $feed_link, $feed_id, true);
1616 print "<div class=\"warning\">
1617 Feed <b>$feed_link</b> already exists in the database.
1623 if ($subop == "addCat") {
1625 if (!WEB_DEMO_MODE
) {
1627 $feed_cat = db_escape_string(trim($_GET["cat"]));
1629 $result = db_query($link,
1630 "SELECT id FROM ttrss_feed_categories
1631 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
1633 if (db_num_rows($result) == 0) {
1635 $result = db_query($link,
1636 "INSERT INTO ttrss_feed_categories (owner_uid,title)
1637 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
1641 print "<div class=\"warning\">
1642 Category <b>$feed_cat</b> already exists in the database.
1650 if ($subop == "removeCats") {
1652 if (!WEB_DEMO_MODE
) {
1654 $ids = split(",", db_escape_string($_GET["ids"]));
1656 foreach ($ids as $id) {
1658 db_query($link, "BEGIN");
1660 $result = db_query($link,
1661 "SELECT count(id) as num_feeds FROM ttrss_feeds
1662 WHERE cat_id = '$id'");
1664 $num_feeds = db_fetch_result($result, 0, "num_feeds");
1666 if ($num_feeds == 0) {
1667 db_query($link, "DELETE FROM ttrss_feed_categories
1668 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1671 print "<div class=\"warning\">
1672 Unable to delete non empty feed categories.</div>";
1676 db_query($link, "COMMIT");
1681 if ($subop == "categorize") {
1683 if (!WEB_DEMO_MODE
) {
1685 $ids = split(",", db_escape_string($_GET["ids"]));
1687 $cat_id = db_escape_string($_GET["cat_id"]);
1690 $cat_id_qpart = 'NULL';
1692 $cat_id_qpart = "'$cat_id'";
1695 db_query($link, "BEGIN");
1697 foreach ($ids as $id) {
1699 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
1700 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1703 db_query($link, "COMMIT");
1710 // print "<h3>Edit Feeds</h3>";
1712 $result = db_query($link, "SELECT id,title,feed_url,last_error
1713 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1715 if (db_num_rows($result) > 0) {
1717 print "<div class=\"warning\">";
1719 print "<a href=\"javascript:showBlockElement('feedUpdateErrors')\">
1720 <b>Feeds with update errors</b> (click to expand)</a>";
1722 print "<ul id=\"feedUpdateErrors\" class=\"nomarks\">";
1724 while ($line = db_fetch_assoc($result)) {
1725 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
1726 $line["last_error"];
1734 $feed_search = db_escape_string($_GET["search"]);
1736 if (array_key_exists("search", $_GET)) {
1737 $_SESSION["prefs_feed_search"] = $feed_search;
1739 $feed_search = $_SESSION["prefs_feed_search"];
1742 print "<table width='100%' class=\"prefGenericAddBox\"
1743 cellspacing='0' cellpadding='0'><tr>
1745 <input id=\"fadd_link\"
1746 onchange=\"javascript:addFeed()\"
1748 <input type=\"submit\" class=\"button\"
1749 onclick=\"javascript:addFeed()\" value=\"Add feed\">
1750 </td><td align='right'>
1751 <input id=\"feed_search\" size=\"20\"
1752 onchange=\"javascript:updateFeedList()\"
1753 value=\"$feed_search\">
1754 <input type=\"submit\" class=\"button\"
1755 onclick=\"javascript:updateFeedList()\" value=\"Search\">
1759 $feeds_sort = db_escape_string($_GET["sort"]);
1761 if (!$feeds_sort ||
$feeds_sort == "undefined") {
1762 $feeds_sort = $_SESSION["pref_sort_feeds"];
1763 if (!$feeds_sort) $feeds_sort = "title";
1766 $_SESSION["pref_sort_feeds"] = $feeds_sort;
1769 $search_qpart = "(UPPER(title) LIKE UPPER('%$feed_search%') OR
1770 UPPER(feed_url) LIKE UPPER('%$feed_search%')) AND";
1775 $result = db_query($link, "SELECT
1776 id,title,feed_url,substring(last_updated,1,16) as last_updated,
1777 update_interval,purge_interval,cat_id,
1778 (SELECT title FROM ttrss_feed_categories
1779 WHERE id = cat_id) AS category
1783 $search_qpart owner_uid = '".$_SESSION["uid"]."'
1784 ORDER by category,$feeds_sort,title");
1786 if (db_num_rows($result) != 0) {
1788 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1790 print "<p><table width=\"100%\" cellspacing=\"0\"
1791 class=\"prefFeedList\" id=\"prefFeedList\">";
1792 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1794 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
1795 'FEEDR-', 'FRCHK-', true)\">All</a>,
1796 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
1797 'FEEDR-', 'FRCHK-', false)\">None</a>
1800 if (!get_pref($link, 'ENABLE_FEED_CATS')) {
1801 print "<tr class=\"title\">
1802 <td width='5%' align='center'> </td>
1803 <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
1804 <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
1805 <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td>
1806 <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Days</a></td></tr>";
1813 while ($line = db_fetch_assoc($result)) {
1815 $feed_id = $line["id"];
1816 $cat_id = $line["cat_id"];
1818 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1819 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
1820 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
1822 if ($line["update_interval"] == "0") $line["update_interval"] = "Default";
1823 if ($line["update_interval"] == "-1") $line["update_interval"] = "Disabled";
1824 if ($line["purge_interval"] == "0") $line["purge_interval"] = "Default";
1825 if ($line["purge_interval"] < 0) $line["purge_interval"] = "Disabled";
1827 if (!$edit_cat) $edit_cat = "Uncategorized";
1830 if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
1833 print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>";
1835 print "<tr class=\"title\">
1836 <td width='5%' align='center'> </td>
1837 <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
1838 <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
1839 <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td>
1840 <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Days</a></td></tr>";
1842 $cur_cat_id = $cat_id;
1845 $class = ($lnum %
2) ?
"even" : "odd";
1846 $this_row_id = "id=\"FEEDR-$feed_id\"";
1848 print "<tr class=\"$class\" $this_row_id>";
1850 $icon_file = ICONS_DIR
. "/$feed_id.ico";
1852 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1853 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL
. "/$feed_id.ico\">";
1855 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1857 // print "<td class='feedIcon'>$feed_icon</td>";
1859 print "<td class='feedSelect'><input onclick='toggleSelectRow(this);'
1860 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
1862 $edit_title = truncate_string($edit_title, 40);
1863 $edit_link = truncate_string($edit_link, 60);
1865 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1866 "$feed_icon $edit_title" . "</a></td>";
1868 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1869 $edit_link . "</a></td>";
1871 /* if (get_pref($link, 'ENABLE_FEED_CATS')) {
1872 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1873 $edit_cat . "</a></td>";
1876 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1877 $line["update_interval"] . "</a></td>";
1879 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1880 $line["purge_interval"] . "</a></td>";
1891 if ($subop == "edit") {
1892 print "Edit feed:
1893 <input type=\"submit\" class=\"button\"
1894 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
1895 <input type=\"submit\" class=\"button\"
1896 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1901 <input type=\"submit\" class=\"button\"
1902 onclick=\"javascript:selectedFeedDetails()\" value=\"Details\">
1903 <input type=\"submit\" class=\"button\"
1904 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
1905 <input type=\"submit\" class=\"button\"
1906 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
1908 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1910 print " ";
1912 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1913 WHERE owner_uid = ".$_SESSION["uid"]."
1916 print "<select id=\"sfeed_set_fcat\">";
1917 print "<option id=\"0\">Uncategorized</option>";
1919 if (db_num_rows($result) != 0) {
1921 print "<option disabled>--------</option>";
1923 while ($line = db_fetch_assoc($result)) {
1924 printf("<option id='%d'>%s</option>",
1925 $line["id"], $line["title"]);
1931 print " <input type=\"submit\" class=\"button\"
1932 onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Set category\">";
1936 if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
1938 <input type=\"submit\" class=\"button\"
1939 onclick=\"javascript:readSelectedFeeds(true)\" value=\"Mark as read\">
1940 <input type=\"submit\" class=\"button\"
1941 onclick=\"javascript:readSelectedFeeds(false)\"
1942 value=\"Mark as unread\"> ";
1946 All feeds: <input type=\"submit\"
1947 class=\"button\" onclick=\"gotoExportOpml()\"
1948 value=\"Export OPML\">";
1952 print "<p>No feeds defined.</p>";
1956 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1958 print "<h3>Edit Categories</h3>";
1960 // print "<h3>Categories</h3>";
1962 print "<div class=\"prefGenericAddBox\">
1963 <input id=\"fadd_cat\"
1964 onchange=\"javascript:addFeedCat()\"
1967 type=\"submit\" class=\"button\"
1968 onclick=\"javascript:addFeedCat()\" value=\"Add category\"></div>";
1970 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1971 WHERE owner_uid = ".$_SESSION["uid"]."
1974 if (db_num_rows($result) != 0) {
1976 print "<p><table width=\"100%\" class=\"prefFeedCatList\"
1977 cellspacing=\"0\" id=\"prefFeedCatList\">";
1979 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1981 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
1982 'FCATR-', 'FCCHK-', true)\">All</a>,
1983 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
1984 'FCATR-', 'FCCHK-', false)\">None</a>
1987 print "<tr class=\"title\">
1988 <td width=\"5%\"></td><td width=\"80%\">Title</td>
1993 while ($line = db_fetch_assoc($result)) {
1995 $class = ($lnum %
2) ?
"even" : "odd";
1997 $cat_id = $line["id"];
1999 $edit_cat_id = $_GET["id"];
2001 if ($subop == "editCat" && $cat_id != $edit_cat_id) {
2005 $this_row_id = "id=\"FCATR-$cat_id\"";
2008 print "<tr class=\"$class\" $this_row_id>";
2010 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
2012 if (!$edit_cat_id ||
$subop != "editCat") {
2014 print "<td align='center'><input onclick='toggleSelectRow(this);'
2015 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
2017 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
2018 $edit_title . "</a></td>";
2020 } else if ($cat_id != $edit_cat_id) {
2022 print "<td><input disabled=\"true\" type=\"checkbox\"
2023 id=\"FRCHK-".$line["id"]."\"></td>";
2025 print "<td>$edit_title</td>";
2029 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2031 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
2044 if ($subop == "editCat") {
2045 print "Edit category:
2046 <input type=\"submit\" class=\"button\"
2047 onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\">
2048 <input type=\"submit\" class=\"button\"
2049 onclick=\"javascript:feedCatEditSave()\" value=\"Save\">";
2054 <input type=\"submit\" class=\"button\"
2055 onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\">
2056 <input type=\"submit\" class=\"button\"
2057 onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">";
2062 print "<p>No feed categories defined.</p>";
2066 print "<h3>Import OPML</h3>
2067 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
2068 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">
2069 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
2070 type=\"submit\" value=\"Import\">
2075 if ($op == "pref-filters") {
2077 $subop = $_GET["subop"];
2078 $quiet = $_GET["quiet"];
2080 if ($subop == "editSave") {
2082 $regexp = db_escape_string($_GET["r"]);
2083 $descr = db_escape_string($_GET["d"]);
2084 $match = db_escape_string($_GET["m"]);
2085 $filter_id = db_escape_string($_GET["id"]);
2086 $feed_id = db_escape_string($_GET["fid"]);
2087 $action_id = db_escape_string($_GET["aid"]);
2092 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2095 $result = db_query($link, "UPDATE ttrss_filters SET
2096 reg_exp = '$regexp',
2097 description = '$descr',
2099 action_id = '$action_id',
2100 filter_type = (SELECT id FROM ttrss_filter_types WHERE
2101 description = '$match')
2102 WHERE id = '$filter_id'");
2105 if ($subop == "remove") {
2107 if (!WEB_DEMO_MODE
) {
2109 $ids = split(",", db_escape_string($_GET["ids"]));
2111 foreach ($ids as $id) {
2112 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
2118 if ($subop == "add") {
2120 if (!WEB_DEMO_MODE
) {
2122 $regexp = db_escape_string(trim($_GET["regexp"]));
2123 $match = db_escape_string(trim($_GET["match"]));
2124 $feed_id = db_escape_string($_GET["fid"]);
2125 $action_id = db_escape_string($_GET["aid"]);
2130 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2133 $result = db_query($link,
2134 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
2137 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
2138 description = '$match'),'".$_SESSION["uid"]."',
2139 $feed_id, '$action_id')");
2145 $result = db_query($link, "SELECT description
2146 FROM ttrss_filter_types ORDER BY description");
2148 $filter_types = array();
2150 while ($line = db_fetch_assoc($result)) {
2151 array_push($filter_types, $line["description"]);
2154 print "<div class=\"prefGenericAddBox\">
2155 <input id=\"fadd_regexp\" size=\"40\"> ";
2157 print_select("fadd_match", "Title", $filter_types);
2159 print " <select id=\"fadd_feed\">";
2161 print "<option selected id=\"0\">All feeds</option>";
2163 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
2164 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2166 if (db_num_rows($result) > 0) {
2167 print "<option disabled>--------</option>";
2170 while ($line = db_fetch_assoc($result)) {
2171 printf("<option id='%d'>%s</option>", $line["id"], $line["title"]);
2174 print "</select> ";
2176 print " Action: ";
2178 print "<select id=\"fadd_action\">";
2180 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2183 while ($line = db_fetch_assoc($result)) {
2184 printf("<option id='%d'>%s</option>", $line["id"], $line["description"]);
2187 print "</select> ";
2189 print "<input type=\"submit\"
2190 class=\"button\" onclick=\"javascript:addFilter()\"
2191 value=\"Add filter\">";
2195 $result = db_query($link, "SELECT
2196 ttrss_filters.id AS id,reg_exp,
2197 ttrss_filters.description AS description,
2198 ttrss_filter_types.name AS filter_type_name,
2199 ttrss_filter_types.description AS filter_type_descr,
2201 ttrss_filter_actions.description AS action_description,
2202 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
2204 ttrss_filters,ttrss_filter_types,ttrss_filter_actions
2206 filter_type = ttrss_filter_types.id AND
2207 ttrss_filter_actions.id = action_id AND
2208 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
2211 if (db_num_rows($result) != 0) {
2213 print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\"
2214 id=\"prefFilterList\">";
2216 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2218 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
2219 'FILRR-', 'FICHK-', true)\">All</a>,
2220 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
2221 'FILRR-', 'FICHK-', false)\">None</a>
2224 print "<tr class=\"title\">
2225 <td align='center' width=\"5%\"> </td>
2226 <td width=\"20%\">Filter expression</td>
2227 <td width=\"20%\">Feed</td>
2228 <td width=\"15%\">Match</td>
2229 <td width=\"15%\">Action</td>
2230 <td width=\"30%\">Description</td></tr>";
2234 while ($line = db_fetch_assoc($result)) {
2236 $class = ($lnum %
2) ?
"even" : "odd";
2238 $filter_id = $line["id"];
2239 $edit_filter_id = $_GET["id"];
2241 if ($subop == "edit" && $filter_id != $edit_filter_id) {
2245 $this_row_id = "id=\"FILRR-$filter_id\"";
2248 print "<tr class=\"$class\" $this_row_id>";
2250 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
2251 $line["description"] = htmlspecialchars($line["description"]);
2253 if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
2255 if (!$edit_filter_id ||
$subop != "edit") {
2257 if (!$line["description"]) $line["description"] = "[No description]";
2259 print "<td align='center'><input onclick='toggleSelectRow(this);'
2260 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
2262 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2263 $line["reg_exp"] . "</td>";
2265 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2266 $line["feed_title"] . "</td>";
2268 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2269 $line["filter_type_descr"] . "</td>";
2271 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2272 $line["action_description"] . "</td>";
2274 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2275 $line["description"] . "</td>";
2277 } else if ($filter_id != $edit_filter_id) {
2279 if (!$line["description"]) $line["description"] = "[No description]";
2281 print "<td><input disabled=\"true\" type=\"checkbox\"
2282 id=\"FICHK-".$line["id"]."\"></td>";
2284 print "<td>".$line["reg_exp"]."</td>";
2285 print "<td>".$line["feed_title"]."</td>";
2286 print "<td>".$line["filter_type_descr"]."</td>";
2287 print "<td>".$line["action_description"]."</td>";
2288 print "<td>".$line["description"]."</td>";
2292 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2294 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
2298 print "<select id=\"iedit_feed\">";
2299 print "<option id=\"0\">All feeds</option>";
2301 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
2302 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2304 if (db_num_rows($tmp_result) > 0) {
2305 print "<option disabled>--------</option>";
2308 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2309 if ($tmp_line["id"] == $line["feed_id"]) {
2310 $is_selected = "selected";
2314 printf("<option $is_selected id='%d'>%s</option>",
2315 $tmp_line["id"], $tmp_line["title"]);
2318 print "</select></td>";
2321 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
2325 print "<select id=\"iedit_filter_action\">";
2327 $tmp_result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2328 ORDER BY description");
2330 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2331 if ($tmp_line["description"] == $line["action_description"]) {
2332 $is_selected = "selected";
2336 printf("<option $is_selected id='%d'>%s</option>",
2337 $tmp_line["id"], $tmp_line["description"]);
2340 print "</select></td>";
2343 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2355 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
2362 if ($subop == "edit") {
2364 <input type=\"submit\" class=\"button\"
2365 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
2366 <input type=\"submit\" class=\"button\"
2367 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
2373 <input type=\"submit\" class=\"button\"
2374 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
2375 <input type=\"submit\" class=\"button\"
2376 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
2381 print "<p>No filters defined.</p>";
2386 // We need to accept raw SQL data in label queries, so not everything is escaped
2387 // here, this is by design. If you don't like the whole idea, disable labels
2388 // altogether with GLOBAL_ENABLE_LABELS = false
2390 if ($op == "pref-labels") {
2392 if (!GLOBAL_ENABLE_LABELS
) {
2396 $subop = $_GET["subop"];
2398 if ($subop == "test") {
2400 $expr = $_GET["expr"];
2401 $descr = $_GET["descr"];
2403 print "<div class='infoBoxContents'>";
2405 print "<h1>Label «$descr»</h1>";
2407 // print "<p><b>Expression</b>: $expr</p>";
2409 $result = db_query($link,
2410 "SELECT count(id) AS num_matches
2411 FROM ttrss_entries,ttrss_user_entries
2413 ttrss_user_entries.ref_id = ttrss_entries.id AND
2414 owner_uid = " . $_SESSION["uid"]);
2416 $num_matches = db_fetch_result($result, 0, "num_matches");;
2418 if ($num_matches > 0) {
2420 print "<p>Query returned <b>$num_matches</b> matches, first 5 follow:</p>";
2422 $result = db_query($link,
2424 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
2425 FROM ttrss_entries,ttrss_user_entries
2427 ttrss_user_entries.ref_id = ttrss_entries.id
2428 AND owner_uid = " . $_SESSION["uid"] . "
2429 ORDER BY date_entered DESC LIMIT 5");
2431 print "<ul class=\"nomarks\">";
2432 while ($line = db_fetch_assoc($result)) {
2433 print "<li>".$line["title"].
2434 " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
2439 print "<p>Query didn't return any matches.</p>";
2444 print "<div align='center'>
2445 <input type='submit' class='button'
2446 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2450 if ($subop == "editSave") {
2452 $sql_exp = $_GET["s"];
2453 $descr = $_GET["d"];
2454 $label_id = db_escape_string($_GET["id"]);
2456 // print "$sql_exp : $descr : $label_id";
2458 $result = db_query($link, "UPDATE ttrss_labels SET
2459 sql_exp = '$sql_exp',
2460 description = '$descr'
2461 WHERE id = '$label_id'");
2464 if ($subop == "remove") {
2466 if (!WEB_DEMO_MODE
) {
2468 $ids = split(",", db_escape_string($_GET["ids"]));
2470 foreach ($ids as $id) {
2471 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
2477 if ($subop == "add") {
2479 if (!WEB_DEMO_MODE
) {
2481 // no escaping is done here on purpose
2482 $exp = trim($_GET["exp"]);
2484 $result = db_query($link,
2485 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
2486 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
2490 print "<div class=\"prefGenericAddBox\">
2491 <input size=\"40\" id=\"ladd_expr\"> ";
2493 print"<input type=\"submit\" class=\"button\"
2494 onclick=\"javascript:addLabel()\" value=\"Add label\"></div>";
2496 $result = db_query($link, "SELECT
2497 id,sql_exp,description
2501 owner_uid = ".$_SESSION["uid"]."
2502 ORDER by description");
2504 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2506 if (db_num_rows($result) != 0) {
2508 print "<p><table width=\"100%\" cellspacing=\"0\"
2509 class=\"prefLabelList\" id=\"prefLabelList\">";
2511 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2513 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2514 'LILRR-', 'LICHK-', true)\">All</a>,
2515 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2516 'LILRR-', 'LICHK-', false)\">None</a>
2519 print "<tr class=\"title\">
2520 <td align='center' width=\"5%\"> </td>
2521 <td width=\"40%\">SQL expression
2522 <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a>
2524 <td width=\"40%\">Caption</td></tr>";
2528 while ($line = db_fetch_assoc($result)) {
2530 $class = ($lnum %
2) ?
"even" : "odd";
2532 $label_id = $line["id"];
2533 $edit_label_id = $_GET["id"];
2535 if ($subop == "edit" && $label_id != $edit_label_id) {
2539 $this_row_id = "id=\"LILRR-$label_id\"";
2542 print "<tr class=\"$class\" $this_row_id>";
2544 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
2545 $line["description"] = htmlspecialchars($line["description"]);
2547 if (!$edit_label_id ||
$subop != "edit") {
2549 if (!$line["description"]) $line["description"] = "[No caption]";
2551 print "<td align='center'><input onclick='toggleSelectRow(this);'
2552 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
2554 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2555 $line["sql_exp"] . "</td>";
2557 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2558 $line["description"] . "</td>";
2560 } else if ($label_id != $edit_label_id) {
2562 if (!$line["description"]) $line["description"] = "[No description]";
2564 print "<td><input disabled=\"true\" type=\"checkbox\"
2565 id=\"LICHK-".$line["id"]."\"></td>";
2567 print "<td>".$line["sql_exp"]."</td>";
2568 print "<td>".$line["description"]."</td>";
2572 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2574 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
2577 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2589 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
2596 if ($subop == "edit") {
2598 <input type=\"submit\" class=\"button\"
2599 onclick=\"javascript:labelTest()\" value=\"Test\">
2600 <input type=\"submit\" class=\"button\"
2601 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
2602 <input type=\"submit\" class=\"button\"
2603 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
2609 <input type=\"submit\" class=\"button\"
2610 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
2611 <input type=\"submit\" class=\"button\"
2612 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
2615 print "<p>No labels defined.</p>";
2619 if ($op == "error") {
2620 print "<div width=\"100%\" align='center'>";
2621 $msg = $_GET["msg"];
2626 if ($op == "help") {
2627 if (!$_GET["noheaders"]) {
2629 <title>Tiny Tiny RSS : Help</title>
2630 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2631 <script type=\"text/javascript\" src=\"functions.js\"></script>
2632 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2636 $tid = sprintf("%d", $_GET["tid"]);
2638 print "<div class='infoBoxContents'>";
2640 if (file_exists("help/$tid.php")) {
2641 include("help/$tid.php");
2643 print "<p>Help topic not found.</p>";
2648 print "<div align='center'>
2649 <input type='submit' class='button'
2650 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2652 if (!$_GET["noheaders"]) {
2653 print "</body></html>";
2660 $param = $_GET["param"];
2662 if ($id == "quickAddFeed") {
2665 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2667 <input class=\"button\"
2668 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
2669 <input class=\"button\"
2670 type=\"submit\" onclick=\"javascript:closeDlg()\"
2674 if ($id == "quickDelFeed") {
2676 $param = db_escape_string($param);
2678 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
2682 $f_title = db_fetch_result($result, 0, "title");
2684 print "Remove current feed (<b>$f_title</b>)?
2685 <input class=\"button\"
2686 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
2687 <input class=\"button\"
2688 type=\"submit\" onclick=\"javascript:closeDlg()\"
2691 print "Error: Feed $param not found.
2692 <input class=\"button\"
2693 type=\"submit\" onclick=\"javascript:closeDlg()\"
2698 if ($id == "search") {
2700 print "<input id=\"searchbox\" class=\"extSearch\"
2701 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2702 onchange=\"javascript:search()\">
2703 <select id=\"searchmodebox\">
2704 <option selected>All feeds</option>
2705 <option>This feed</option>
2707 <input type=\"submit\"
2708 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
2709 <input class=\"button\"
2710 type=\"submit\" onclick=\"javascript:closeDlg()\"
2715 if ($id == "quickAddFilter") {
2717 $result = db_query($link, "SELECT description
2718 FROM ttrss_filter_types ORDER BY description");
2720 $filter_types = array();
2722 while ($line = db_fetch_assoc($result)) {
2723 array_push($filter_types, $line["description"]);
2728 print "<tr><td>Match:</td><td><input id=\"fadd_regexp\" size=\"40\"> ";
2730 print_select("fadd_match", "Title", $filter_types);
2733 print "<tr><td>Feed:</td><td><select id=\"fadd_feed\">";
2735 print "<option selected id=\"0\">All feeds</option>";
2737 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
2738 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2740 if (db_num_rows($result) > 0) {
2741 print "<option disabled>--------</option>";
2744 while ($line = db_fetch_assoc($result)) {
2745 if ($param == $line["id"]) {
2746 $selected = "selected";
2750 printf("<option id='%d' %s>%s</option>", $line["id"], $selected, $line["title"]);
2753 print "</select></td></tr>";
2755 print "<tr><td>Action:</td>";
2757 print "<td><select id=\"fadd_action\">";
2759 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2762 while ($line = db_fetch_assoc($result)) {
2763 printf("<option id='%d'>%s</option>", $line["id"], $line["description"]);
2768 print "</td></tr><tr><td colspan=\"2\" align=\"right\">";
2770 print "<input type=\"submit\"
2771 class=\"button\" onclick=\"javascript:qaddFilter()\"
2772 value=\"Add filter\"> ";
2774 print "<input class=\"button\"
2775 type=\"submit\" onclick=\"javascript:closeDlg()\"
2778 print "</td></tr></table>";
2782 // update feeds of all users, may be used anonymously
2783 if ($op == "globalUpdateFeeds") {
2785 $result = db_query($link, "SELECT id FROM ttrss_users");
2787 while ($line = db_fetch_assoc($result)) {
2788 $user_id = $line["id"];
2789 // print "<!-- updating feeds of uid $user_id -->";
2790 update_all_feeds($link, false, $user_id);
2794 <message msg=\"All feeds updated\"/>
2799 if ($op == "pref-prefs") {
2801 $subop = $_REQUEST["subop"];
2803 if ($subop == "Save configuration") {
2805 if (WEB_DEMO_MODE
) {
2806 header("Location: prefs.php");
2810 $_SESSION["prefs_op_result"] = "save-config";
2812 foreach (array_keys($_POST) as $pref_name) {
2814 $pref_name = db_escape_string($pref_name);
2815 $value = db_escape_string($_POST[$pref_name]);
2817 $result = db_query($link, "SELECT type_name
2818 FROM ttrss_prefs,ttrss_prefs_types
2819 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
2821 if (db_num_rows($result) > 0) {
2823 $type_name = db_fetch_result($result, 0, "type_name");
2825 // print "$pref_name : $type_name : $value<br>";
2827 if ($type_name == "bool") {
2828 if ($value == "1") {
2833 } else if ($type_name == "integer") {
2834 $value = sprintf("%d", $value);
2837 // print "$pref_name : $type_name : $value<br>";
2839 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
2840 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
2844 header("Location: prefs.php");
2848 } else if ($subop == "getHelp") {
2850 $pref_name = db_escape_string($_GET["pn"]);
2852 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
2853 WHERE pref_name = '$pref_name'");
2855 if (db_num_rows($result) > 0) {
2856 $help_text = db_fetch_result($result, 0, "help_text");
2859 print "Unknown option: $pref_name";
2862 } else if ($subop == "Change password") {
2864 if (WEB_DEMO_MODE
) {
2865 header("Location: prefs.php");
2869 $old_pw = $_POST["OLD_PASSWORD"];
2870 $new_pw = $_POST["OLD_PASSWORD"];
2872 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
2873 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
2875 $active_uid = $_SESSION["uid"];
2877 if ($old_pw && $new_pw) {
2879 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
2881 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
2882 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
2883 pwd_hash = '$old_pw_hash')");
2885 if (db_num_rows($result) == 1) {
2886 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
2887 WHERE id = '$active_uid'");
2889 $_SESSION["pwd_change_result"] = "ok";
2891 $_SESSION["pwd_change_result"] = "failed";
2895 header("Location: prefs.php");
2897 } else if ($subop == "Reset to defaults") {
2899 if (WEB_DEMO_MODE
) {
2900 header("Location: prefs.php");
2904 $_SESSION["prefs_op_result"] = "reset-to-defaults";
2906 if (DB_TYPE
== "pgsql") {
2907 db_query($link,"UPDATE ttrss_user_prefs
2908 SET value = ttrss_prefs.def_value
2909 WHERE owner_uid = '".$_SESSION["uid"]."' AND
2910 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
2912 db_query($link, "DELETE FROM ttrss_user_prefs
2913 WHERE owner_uid = ".$_SESSION["uid"]);
2914 initialize_user_prefs($link, $_SESSION["uid"]);
2917 header("Location: prefs.php");
2919 } else if ($subop == "Change theme") {
2921 $theme = db_escape_string($_POST["theme"]);
2923 if ($theme == "Default") {
2924 $theme_qpart = 'NULL';
2926 $theme_qpart = "'$theme'";
2929 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
2930 WHERE theme_name = '$theme'");
2932 if (db_num_rows($result) == 1) {
2933 $theme_id = db_fetch_result($result, 0, "id");
2934 $theme_path = db_fetch_result($result, 0, "theme_path");
2940 db_query($link, "UPDATE ttrss_users SET
2941 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
2943 $_SESSION["theme"] = $theme_path;
2945 header("Location: prefs.php");
2949 if (!SINGLE_USER_MODE
) {
2951 $result = db_query($link, "SELECT id FROM ttrss_users
2952 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
2953 pwd_hash = 'SHA1:".sha1("password")."')");
2955 if (db_num_rows($result) != 0) {
2956 print "<div class=\"warning\">
2957 Your password is at default value, please change it.
2961 if ($_SESSION["pwd_change_result"] == "failed") {
2962 print "<div class=\"warning\">
2963 There was an error while changing your password.
2967 if ($_SESSION["pwd_change_result"] == "ok") {
2968 print "<div class=\"notice\">
2969 Password changed successfully.
2973 $_SESSION["pwd_change_result"] = "";
2975 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
2976 print "<div class=\"notice\">
2977 Your configuration was reset to defaults.
2981 if ($_SESSION["prefs_op_result"] == "save-config") {
2982 print "<div class=\"notice\">
2983 Your configuration was saved successfully.
2987 $_SESSION["prefs_op_result"] = "";
2989 print "<form action=\"backend.php\" method=\"POST\">";
2991 print "<table width=\"100%\" class=\"prefPrefsList\">";
2992 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
2994 print "<tr><td width=\"40%\">Old password</td>";
2995 print "<td><input class=\"editbox\" type=\"password\"
2996 name=\"OLD_PASSWORD\"></td></tr>";
2998 print "<tr><td width=\"40%\">New password</td>";
3000 print "<td><input class=\"editbox\" type=\"password\"
3001 name=\"NEW_PASSWORD\"></td></tr>";
3005 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3007 print "<p><input class=\"button\" type=\"submit\"
3008 value=\"Change password\" name=\"subop\">";
3014 $result = db_query($link, "SELECT
3015 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
3017 $user_theme_id = db_fetch_result($result, 0, "theme_id");
3019 $result = db_query($link, "SELECT
3020 id,theme_name FROM ttrss_themes ORDER BY theme_name");
3022 if (db_num_rows($result) > 0) {
3024 print "<form action=\"backend.php\" method=\"POST\">";
3025 print "<table width=\"100%\" class=\"prefPrefsList\">";
3026 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
3027 print "<tr><td width=\"40%\">Select theme</td>";
3028 print "<td><select name=\"theme\">";
3029 print "<option>Default</option>";
3030 print "<option disabled>--------</option>";
3032 while ($line = db_fetch_assoc($result)) {
3033 if ($line["id"] == $user_theme_id) {
3034 $selected = "selected";
3038 print "<option $selected>" . $line["theme_name"] . "</option>";
3040 print "</select></td></tr>";
3042 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3043 print "<p><input class=\"button\" type=\"submit\"
3044 value=\"Change theme\" name=\"subop\">";
3048 $result = db_query($link, "SELECT
3049 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
3050 section_name,def_value
3051 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
3052 WHERE type_id = ttrss_prefs_types.id AND
3053 section_id = ttrss_prefs_sections.id AND
3054 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
3055 owner_uid = ".$_SESSION["uid"]."
3056 ORDER BY section_id,short_desc");
3058 print "<form action=\"backend.php\" method=\"POST\">";
3062 $active_section = "";
3064 while ($line = db_fetch_assoc($result)) {
3066 if ($active_section != $line["section_name"]) {
3068 if ($active_section != "") {
3072 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
3074 $active_section = $line["section_name"];
3076 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
3077 // print "<tr class=\"title\">
3078 // <td width=\"25%\">Option</td><td>Value</td></tr>";
3083 // $class = ($lnum % 2) ? "even" : "odd";
3087 $type_name = $line["type_name"];
3088 $pref_name = $line["pref_name"];
3089 $value = $line["value"];
3090 $def_value = $line["def_value"];
3091 $help_text = $line["help_text"];
3093 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
3095 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
3101 if ($type_name == "bool") {
3102 // print_select($pref_name, $value, array("true", "false"));
3104 if ($value == "true") {
3110 print_radio($pref_name, $value, array("Yes", "No"));
3113 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
3125 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3127 print "<p><input class=\"button\" type=\"submit\"
3128 name=\"subop\" value=\"Save configuration\">";
3130 print " <input class=\"button\" type=\"submit\"
3131 name=\"subop\" onclick=\"return validatePrefsReset()\"
3132 value=\"Reset to defaults\"></p>";
3140 if ($op == "pref-users") {
3142 $subop = $_GET["subop"];
3144 if ($subop == "editSave") {
3146 if (!WEB_DEMO_MODE
) {
3148 $login = db_escape_string($_GET["l"]);
3149 $uid = db_escape_string($_GET["id"]);
3150 $access_level = sprintf("%d", $_GET["al"]);
3152 db_query($link, "UPDATE ttrss_users SET login = '$login', access_level = '$access_level' WHERE id = '$uid'");
3155 } else if ($subop == "remove") {
3157 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3159 $ids = split(",", db_escape_string($_GET["ids"]));
3161 foreach ($ids as $id) {
3162 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
3166 } else if ($subop == "add") {
3168 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3170 $login = db_escape_string(trim($_GET["login"]));
3171 $tmp_user_pwd = make_password(8);
3172 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3174 db_query($link, "INSERT INTO ttrss_users (login,pwd_hash,access_level)
3175 VALUES ('$login', '$pwd_hash', 0)");
3178 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3179 login = '$login' AND pwd_hash = '$pwd_hash'");
3181 if (db_num_rows($result) == 1) {
3183 $new_uid = db_fetch_result($result, 0, "id");
3185 print "<div class=\"notice\">Added user <b>".$_GET["login"].
3186 "</b> with password <b>$tmp_user_pwd</b>.</div>";
3188 initialize_user($link, $new_uid);
3192 print "<div class=\"warning\">Error while adding user <b>".
3193 $_GET["login"].".</b></div>";
3197 } else if ($subop == "resetPass") {
3199 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3201 $uid = db_escape_string($_GET["id"]);
3203 $result = db_query($link, "SELECT login FROM ttrss_users WHERE id = '$uid'");
3205 $login = db_fetch_result($result, 0, "login");
3206 $tmp_user_pwd = make_password(8);
3207 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3209 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
3210 WHERE id = '$uid'");
3212 print "<div class=\"notice\">Changed password of
3213 user <b>$login</b> to <b>$tmp_user_pwd</b>.</div>";
3218 print "<div class=\"prefGenericAddBox\">
3219 <input id=\"uadd_box\" onchange=\"javascript:addUser()\" size=\"40\"> ";
3221 print"<input type=\"submit\" class=\"button\"
3222 onclick=\"javascript:addUser()\" value=\"Add user\"></div>";
3224 $result = db_query($link, "SELECT
3225 id,login,access_level,
3226 SUBSTRING(last_login,1,16) as last_login
3231 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
3233 print "<p><table width=\"100%\" cellspacing=\"0\"
3234 class=\"prefUserList\" id=\"prefUserList\">";
3236 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
3238 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3239 'UMRR-', 'UMCHK-', true)\">All</a>,
3240 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3241 'UMRR-', 'UMCHK-', false)\">None</a>
3244 print "<tr class=\"title\">
3245 <td align='center' width=\"5%\"> </td>
3246 <td width='30%'>Username</td>
3247 <td width='30%'>Access Level</td>
3248 <td width='30%'>Last login</td></tr>";
3252 while ($line = db_fetch_assoc($result)) {
3254 $class = ($lnum %
2) ?
"even" : "odd";
3257 $edit_uid = $_GET["id"];
3259 if ($uid == $_SESSION["uid"] ||
($subop == "edit" && $uid != $edit_uid)) {
3263 $this_row_id = "id=\"UMRR-$uid\"";
3266 print "<tr class=\"$class\" $this_row_id>";
3268 $line["login"] = htmlspecialchars($line["login"]);
3270 $line["last_login"] = date(get_pref($link, 'SHORT_DATE_FORMAT'),
3271 strtotime($line["last_login"]));
3273 if ($uid == $_SESSION["uid"]) {
3275 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
3276 id=\"UMCHK-".$line["id"]."\"></td>";
3278 print "<td>".$line["login"]."</td>";
3279 print "<td>".$line["access_level"]."</td>";
3281 } else if (!$edit_uid ||
$subop != "edit") {
3283 print "<td align='center'><input onclick='toggleSelectRow(this);'
3284 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
3286 print "<td><a href=\"javascript:editUser($uid);\">" .
3287 $line["login"] . "</td>";
3289 print "<td><a href=\"javascript:editUser($uid);\">" .
3290 $line["access_level"] . "</td>";
3292 } else if ($uid != $edit_uid) {
3294 print "<td><input disabled=\"true\" type=\"checkbox\"
3295 id=\"UMCHK-".$line["id"]."\"></td>";
3297 print "<td>".$line["login"]."</td>";
3298 print "<td>".$line["access_level"]."</td>";
3302 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
3304 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
3307 print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
3312 print "<td>".$line["last_login"]."</td>";
3323 if ($subop == "edit") {
3325 <input type=\"submit\" class=\"button\"
3326 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">
3327 <input type=\"submit\" class=\"button\"
3328 onclick=\"javascript:userEditSave()\" value=\"Save\">";
3334 <input type=\"submit\" class=\"button\"
3335 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
3336 <input type=\"submit\" class=\"button\"
3337 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
3338 <input type=\"submit\" class=\"button\"
3339 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
3340 <input type=\"submit\" class=\"button\"
3341 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
3346 if ($op == "user-details") {
3348 if (WEB_DEMO_MODE ||
$_SESSION["access_level"] < 10) {
3352 /* print "<html><head>
3353 <title>Tiny Tiny RSS : User Details</title>
3354 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
3355 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
3358 $uid = sprintf("%d", $_GET["id"]);
3360 print "<div class='infoBoxContents'>";
3362 $result = db_query($link, "SELECT login,
3363 SUBSTRING(last_login,1,16) AS last_login,
3365 (SELECT COUNT(int_id) FROM ttrss_user_entries
3366 WHERE owner_uid = id) AS stored_articles
3368 WHERE id = '$uid'");
3370 if (db_num_rows($result) == 0) {
3371 print "<h1>User not found</h1>";
3375 print "<h1>User Details</h1>";
3377 print "<table width='100%'>";
3379 $login = db_fetch_result($result, 0, "login");
3380 $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'),
3381 strtotime(db_fetch_result($result, 0, "last_login")));
3382 $access_level = db_fetch_result($result, 0, "access_level");
3383 $stored_articles = db_fetch_result($result, 0, "stored_articles");
3385 print "<tr><td>Username</td><td>$login</td></tr>";
3386 print "<tr><td>Access level</td><td>$access_level</td></tr>";
3387 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
3388 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
3390 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
3391 WHERE owner_uid = '$uid'");
3393 $num_feeds = db_fetch_result($result, 0, "num_feeds");
3395 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
3397 /* $result = db_query($link, "SELECT
3398 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
3399 FROM ttrss_user_entries,ttrss_entries
3400 WHERE owner_uid = '$uid' AND ref_id = id");
3402 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
3404 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
3408 print "<h1>Subscribed feeds</h1>";
3410 $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
3411 WHERE owner_uid = '$uid' ORDER BY title LIMIT 20");
3413 print "<ul class=\"nomarks\">";
3415 while ($line = db_fetch_assoc($result)) {
3417 $icon_file = ICONS_URL
."/".$line["id"].".ico";
3419 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3420 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
3422 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3425 print "<li>$feed_icon <a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
3428 if (db_num_rows($result) < $num_feeds) {
3429 // FIXME - add link to show ALL subscribed feeds here somewhere
3431 class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\"> ...</li>";
3438 print "<div align='center'>
3439 <input type='submit' class='button'
3440 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3442 // print "</body></html>";
3446 if ($op == "feed-details") {
3448 // $feed_id = $_GET["id"];
3450 $feed_ids = split(",", db_escape_string($_GET["id"]));
3452 print "<div class=\"infoBoxContents\">";
3454 foreach ($feed_ids as $feed_id) {
3456 $result = db_query($link,
3459 SUBSTRING(last_updated,1,16) as last_updated,
3461 (SELECT COUNT(int_id) FROM ttrss_user_entries
3462 WHERE feed_id = id) AS total,
3463 (SELECT COUNT(int_id) FROM ttrss_user_entries
3464 WHERE feed_id = id AND unread = true) AS unread,
3465 (SELECT COUNT(int_id) FROM ttrss_user_entries
3466 WHERE feed_id = id AND marked = true) AS marked
3468 WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]);
3470 if (db_num_rows($result) == 0) return;
3472 $title = db_unescape_string(db_fetch_result($result, 0, "title"));
3473 $last_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
3474 strtotime(db_fetch_result($result, 0, "last_updated")));
3475 $feed_url = db_fetch_result($result, 0, "feed_url");
3476 $icon_url = db_fetch_result($result, 0, "icon_url");
3477 $total = db_fetch_result($result, 0, "total");
3478 $unread = db_fetch_result($result, 0, "unread");
3479 $marked = db_fetch_result($result, 0, "marked");
3480 $site_url = db_fetch_result($result, 0, "site_url");
3482 $result = db_query($link, "SELECT COUNT(id) AS subscribed
3483 FROM ttrss_feeds WHERE feed_url = '$feed_url'");
3485 $subscribed = db_fetch_result($result, 0, "subscribed");
3487 $icon_file = ICONS_DIR
. "/$feed_id.ico";
3489 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3490 $feed_icon = "<img width=\"16\" height=\"16\"
3491 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
3496 print "<h1>$feed_icon $title</h1>";
3498 print "<table width='100%'>";
3501 print "<tr><td width='30%'>Link</td>
3502 <td><a href=\"$site_url\">$site_url</a>
3503 <a href=\"$feed_url\">(feed)</a></td>
3506 print "<tr><td width='30%'>Feed URL</td>
3507 <td><a href=\"$feed_url\">$feed_url</a></td></tr>";
3509 print "<tr><td>Last updated</td><td>$last_updated</td></tr>";
3510 print "<tr><td>Total articles</td><td>$total</td></tr>";
3511 print "<tr><td>Unread articles</td><td>$unread</td></tr>";
3512 print "<tr><td>Starred articles</td><td>$marked</td></tr>";
3513 print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>";
3517 /* $result = db_query($link, "SELECT title,
3518 SUBSTRING(updated,1,16) AS updated,unread
3519 FROM ttrss_entries,ttrss_user_entries
3520 WHERE ref_id = id AND feed_id = '$feed_id'
3521 ORDER BY date_entered DESC LIMIT 5");
3523 if (db_num_rows($result) > 0) {
3525 print "<h1>Latest headlines</h1>";
3527 print "<ul class=\"nomarks\">";
3529 while ($line = db_fetch_assoc($result)) {
3530 if ($line["unread"] == "t" || $line["unread"] == "1") {
3531 $line["title"] = "<b>" . $line["title"] . "</b>";
3533 print "<li>" . $line["title"].
3534 " <span class=\"insensitive\">(" .
3535 date(get_pref($link, 'SHORT_DATE_FORMAT'),
3536 strtotime($line["updated"])).
3547 print "<div align='center'>
3548 <input type='submit' class='button'
3549 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3555 <!-- <?
= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?
> -->