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 = $_REQUEST["subop"];
1429 $quiet = $_REQUEST["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>";
1516 // print "<tr><td colspan=\"2\"><b>Authentication</b></td></tr>";
1518 $row_class = toggleEvenOdd($row_class);
1519 $auth_login = db_fetch_result($result, 0, "auth_login");
1521 print "<tr class='$row_class'><td>Login:</td>";
1522 print "<td><input id=\"iedit_login\"
1523 value=\"$auth_login\"></td></tr>";
1525 $row_class = toggleEvenOdd($row_class);
1526 $auth_pass = db_fetch_result($result, 0, "auth_pass");
1528 print "<tr class='$row_class'><td>Password:</td>";
1529 print "<td><input type=\"password\" id=\"iedit_pass\"
1530 value=\"$auth_pass\"></td></tr>";
1535 print "<div align='center'>
1536 <input type='submit' class='button'
1537 onclick=\"feedEditCancel()\" value=\"Cancel\">
1538 <input type=\"submit\" class=\"button\"
1539 onclick=\"feedEditSave()\" value=\"Save\"></div>";
1543 if ($subop == "editSave") {
1544 $feed_title = db_escape_string($_POST["t"]);
1545 $feed_link = db_escape_string($_POST["l"]);
1546 $upd_intl = db_escape_string($_POST["ui"]);
1547 $purge_intl = db_escape_string($_POST["pi"]);
1548 $feed_id = db_escape_string($_POST["id"]);
1549 $cat_id = db_escape_string($_POST["catid"]);
1550 $auth_login = db_escape_string($_POST["login"]);
1551 $auth_pass = db_escape_string($_POST["pass"]);
1553 if (strtoupper($upd_intl) == "DEFAULT")
1556 if (strtoupper($upd_intl) == "DISABLED")
1559 if (strtoupper($purge_intl) == "DEFAULT")
1562 if (strtoupper($purge_intl) == "DISABLED")
1566 $category_qpart = "cat_id = '$cat_id'";
1568 $category_qpart = 'cat_id = NULL';
1571 $result = db_query($link, "UPDATE ttrss_feeds SET
1573 title = '$feed_title', feed_url = '$feed_link',
1574 update_interval = '$upd_intl',
1575 purge_interval = '$purge_intl',
1576 auth_login = '$auth_login',
1577 auth_pass = '$auth_pass'
1578 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
1581 if ($subop == "saveCat") {
1582 $cat_title = db_escape_string($_GET["title"]);
1583 $cat_id = db_escape_string($_GET["id"]);
1585 $result = db_query($link, "UPDATE ttrss_feed_categories SET
1586 title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
1590 if ($subop == "remove") {
1592 if (!WEB_DEMO_MODE
) {
1594 $ids = split(",", db_escape_string($_GET["ids"]));
1596 foreach ($ids as $id) {
1597 db_query($link, "DELETE FROM ttrss_feeds
1598 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1600 $icons_dir = ICONS_DIR
;
1602 if (file_exists($icons_dir . "/$id.ico")) {
1603 unlink($icons_dir . "/$id.ico");
1609 if ($subop == "add") {
1611 if (!WEB_DEMO_MODE
) {
1613 $feed_link = db_escape_string(trim($_GET["link"]));
1615 $result = db_query($link,
1616 "SELECT id FROM ttrss_feeds
1617 WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]);
1619 if (db_num_rows($result) == 0) {
1621 $result = db_query($link,
1622 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title)
1623 VALUES ('".$_SESSION["uid"]."', '$feed_link', '')");
1625 $result = db_query($link,
1626 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'
1627 AND owner_uid = " . $_SESSION["uid"]);
1629 $feed_id = db_fetch_result($result, 0, "id");
1632 update_rss_feed($link, $feed_link, $feed_id, true);
1636 print "<div class=\"warning\">
1637 Feed <b>$feed_link</b> already exists in the database.
1643 if ($subop == "addCat") {
1645 if (!WEB_DEMO_MODE
) {
1647 $feed_cat = db_escape_string(trim($_GET["cat"]));
1649 $result = db_query($link,
1650 "SELECT id FROM ttrss_feed_categories
1651 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
1653 if (db_num_rows($result) == 0) {
1655 $result = db_query($link,
1656 "INSERT INTO ttrss_feed_categories (owner_uid,title)
1657 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
1661 print "<div class=\"warning\">
1662 Category <b>$feed_cat</b> already exists in the database.
1670 if ($subop == "removeCats") {
1672 if (!WEB_DEMO_MODE
) {
1674 $ids = split(",", db_escape_string($_GET["ids"]));
1676 foreach ($ids as $id) {
1678 db_query($link, "BEGIN");
1680 $result = db_query($link,
1681 "SELECT count(id) as num_feeds FROM ttrss_feeds
1682 WHERE cat_id = '$id'");
1684 $num_feeds = db_fetch_result($result, 0, "num_feeds");
1686 if ($num_feeds == 0) {
1687 db_query($link, "DELETE FROM ttrss_feed_categories
1688 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1691 print "<div class=\"warning\">
1692 Unable to delete non empty feed categories.</div>";
1696 db_query($link, "COMMIT");
1701 if ($subop == "categorize") {
1703 if (!WEB_DEMO_MODE
) {
1705 $ids = split(",", db_escape_string($_GET["ids"]));
1707 $cat_id = db_escape_string($_GET["cat_id"]);
1710 $cat_id_qpart = 'NULL';
1712 $cat_id_qpart = "'$cat_id'";
1715 db_query($link, "BEGIN");
1717 foreach ($ids as $id) {
1719 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
1720 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1723 db_query($link, "COMMIT");
1730 // print "<h3>Edit Feeds</h3>";
1732 $result = db_query($link, "SELECT id,title,feed_url,last_error
1733 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1735 if (db_num_rows($result) > 0) {
1737 print "<div class=\"warning\">";
1739 print "<a href=\"javascript:showBlockElement('feedUpdateErrors')\">
1740 <b>Feeds with update errors</b> (click to expand)</a>";
1742 print "<ul id=\"feedUpdateErrors\" class=\"nomarks\">";
1744 while ($line = db_fetch_assoc($result)) {
1745 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
1746 $line["last_error"];
1754 $feed_search = db_escape_string($_GET["search"]);
1756 if (array_key_exists("search", $_GET)) {
1757 $_SESSION["prefs_feed_search"] = $feed_search;
1759 $feed_search = $_SESSION["prefs_feed_search"];
1762 print "<table width='100%' class=\"prefGenericAddBox\"
1763 cellspacing='0' cellpadding='0'><tr>
1765 <input id=\"fadd_link\"
1766 onchange=\"javascript:addFeed()\"
1768 <input type=\"submit\" class=\"button\"
1769 onclick=\"javascript:addFeed()\" value=\"Add feed\">
1770 </td><td align='right'>
1771 <input id=\"feed_search\" size=\"20\"
1772 onchange=\"javascript:updateFeedList()\"
1773 value=\"$feed_search\">
1774 <input type=\"submit\" class=\"button\"
1775 onclick=\"javascript:updateFeedList()\" value=\"Search\">
1779 $feeds_sort = db_escape_string($_GET["sort"]);
1781 if (!$feeds_sort ||
$feeds_sort == "undefined") {
1782 $feeds_sort = $_SESSION["pref_sort_feeds"];
1783 if (!$feeds_sort) $feeds_sort = "title";
1786 $_SESSION["pref_sort_feeds"] = $feeds_sort;
1789 $search_qpart = "(UPPER(title) LIKE UPPER('%$feed_search%') OR
1790 UPPER(feed_url) LIKE UPPER('%$feed_search%')) AND";
1795 $result = db_query($link, "SELECT
1796 id,title,feed_url,substring(last_updated,1,16) as last_updated,
1797 update_interval,purge_interval,cat_id,
1798 (SELECT title FROM ttrss_feed_categories
1799 WHERE id = cat_id) AS category
1803 $search_qpart owner_uid = '".$_SESSION["uid"]."'
1804 ORDER by category,$feeds_sort,title");
1806 if (db_num_rows($result) != 0) {
1808 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1810 print "<p><table width=\"100%\" cellspacing=\"0\"
1811 class=\"prefFeedList\" id=\"prefFeedList\">";
1812 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1814 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
1815 'FEEDR-', 'FRCHK-', true)\">All</a>,
1816 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
1817 'FEEDR-', 'FRCHK-', false)\">None</a>
1820 if (!get_pref($link, 'ENABLE_FEED_CATS')) {
1821 print "<tr class=\"title\">
1822 <td width='5%' align='center'> </td>
1823 <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
1824 <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
1825 <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td>
1826 <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Days</a></td></tr>";
1833 while ($line = db_fetch_assoc($result)) {
1835 $feed_id = $line["id"];
1836 $cat_id = $line["cat_id"];
1838 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1839 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
1840 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
1842 if ($line["update_interval"] == "0") $line["update_interval"] = "Default";
1843 if ($line["update_interval"] == "-1") $line["update_interval"] = "Disabled";
1844 if ($line["purge_interval"] == "0") $line["purge_interval"] = "Default";
1845 if ($line["purge_interval"] < 0) $line["purge_interval"] = "Disabled";
1847 if (!$edit_cat) $edit_cat = "Uncategorized";
1850 if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
1853 print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>";
1855 print "<tr class=\"title\">
1856 <td width='5%' align='center'> </td>
1857 <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
1858 <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
1859 <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td>
1860 <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Days</a></td></tr>";
1862 $cur_cat_id = $cat_id;
1865 $class = ($lnum %
2) ?
"even" : "odd";
1866 $this_row_id = "id=\"FEEDR-$feed_id\"";
1868 print "<tr class=\"$class\" $this_row_id>";
1870 $icon_file = ICONS_DIR
. "/$feed_id.ico";
1872 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1873 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL
. "/$feed_id.ico\">";
1875 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1877 // print "<td class='feedIcon'>$feed_icon</td>";
1879 print "<td class='feedSelect'><input onclick='toggleSelectRow(this);'
1880 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
1882 $edit_title = truncate_string($edit_title, 40);
1883 $edit_link = truncate_string($edit_link, 60);
1885 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1886 "$feed_icon $edit_title" . "</a></td>";
1888 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1889 $edit_link . "</a></td>";
1891 /* if (get_pref($link, 'ENABLE_FEED_CATS')) {
1892 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1893 $edit_cat . "</a></td>";
1896 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1897 $line["update_interval"] . "</a></td>";
1899 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1900 $line["purge_interval"] . "</a></td>";
1911 if ($subop == "edit") {
1912 print "Edit feed:
1913 <input type=\"submit\" class=\"button\"
1914 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
1915 <input type=\"submit\" class=\"button\"
1916 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1921 <input type=\"submit\" class=\"button\"
1922 onclick=\"javascript:selectedFeedDetails()\" value=\"Details\">
1923 <input type=\"submit\" class=\"button\"
1924 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
1925 <input type=\"submit\" class=\"button\"
1926 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
1928 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1930 print " ";
1932 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1933 WHERE owner_uid = ".$_SESSION["uid"]."
1936 print "<select id=\"sfeed_set_fcat\">";
1937 print "<option id=\"0\">Uncategorized</option>";
1939 if (db_num_rows($result) != 0) {
1941 print "<option disabled>--------</option>";
1943 while ($line = db_fetch_assoc($result)) {
1944 printf("<option id='%d'>%s</option>",
1945 $line["id"], $line["title"]);
1951 print " <input type=\"submit\" class=\"button\"
1952 onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Set category\">";
1956 if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
1958 <input type=\"submit\" class=\"button\"
1959 onclick=\"javascript:readSelectedFeeds(true)\" value=\"Mark as read\">
1960 <input type=\"submit\" class=\"button\"
1961 onclick=\"javascript:readSelectedFeeds(false)\"
1962 value=\"Mark as unread\"> ";
1966 All feeds: <input type=\"submit\"
1967 class=\"button\" onclick=\"gotoExportOpml()\"
1968 value=\"Export OPML\">";
1972 print "<p>No feeds defined.</p>";
1976 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1978 print "<h3>Edit Categories</h3>";
1980 // print "<h3>Categories</h3>";
1982 print "<div class=\"prefGenericAddBox\">
1983 <input id=\"fadd_cat\"
1984 onchange=\"javascript:addFeedCat()\"
1987 type=\"submit\" class=\"button\"
1988 onclick=\"javascript:addFeedCat()\" value=\"Add category\"></div>";
1990 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1991 WHERE owner_uid = ".$_SESSION["uid"]."
1994 if (db_num_rows($result) != 0) {
1996 print "<p><table width=\"100%\" class=\"prefFeedCatList\"
1997 cellspacing=\"0\" id=\"prefFeedCatList\">";
1999 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2001 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
2002 'FCATR-', 'FCCHK-', true)\">All</a>,
2003 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
2004 'FCATR-', 'FCCHK-', false)\">None</a>
2007 print "<tr class=\"title\">
2008 <td width=\"5%\"></td><td width=\"80%\">Title</td>
2013 while ($line = db_fetch_assoc($result)) {
2015 $class = ($lnum %
2) ?
"even" : "odd";
2017 $cat_id = $line["id"];
2019 $edit_cat_id = $_GET["id"];
2021 if ($subop == "editCat" && $cat_id != $edit_cat_id) {
2025 $this_row_id = "id=\"FCATR-$cat_id\"";
2028 print "<tr class=\"$class\" $this_row_id>";
2030 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
2032 if (!$edit_cat_id ||
$subop != "editCat") {
2034 print "<td align='center'><input onclick='toggleSelectRow(this);'
2035 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
2037 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
2038 $edit_title . "</a></td>";
2040 } else if ($cat_id != $edit_cat_id) {
2042 print "<td><input disabled=\"true\" type=\"checkbox\"
2043 id=\"FRCHK-".$line["id"]."\"></td>";
2045 print "<td>$edit_title</td>";
2049 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2051 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
2064 if ($subop == "editCat") {
2065 print "Edit category:
2066 <input type=\"submit\" class=\"button\"
2067 onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\">
2068 <input type=\"submit\" class=\"button\"
2069 onclick=\"javascript:feedCatEditSave()\" value=\"Save\">";
2074 <input type=\"submit\" class=\"button\"
2075 onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\">
2076 <input type=\"submit\" class=\"button\"
2077 onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">";
2082 print "<p>No feed categories defined.</p>";
2086 print "<h3>Import OPML</h3>
2087 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
2088 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">
2089 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
2090 type=\"submit\" value=\"Import\">
2095 if ($op == "pref-filters") {
2097 $subop = $_GET["subop"];
2098 $quiet = $_GET["quiet"];
2100 if ($subop == "editSave") {
2102 $regexp = db_escape_string($_GET["r"]);
2103 $descr = db_escape_string($_GET["d"]);
2104 $match = db_escape_string($_GET["m"]);
2105 $filter_id = db_escape_string($_GET["id"]);
2106 $feed_id = db_escape_string($_GET["fid"]);
2107 $action_id = db_escape_string($_GET["aid"]);
2112 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2115 $result = db_query($link, "UPDATE ttrss_filters SET
2116 reg_exp = '$regexp',
2117 description = '$descr',
2119 action_id = '$action_id',
2120 filter_type = (SELECT id FROM ttrss_filter_types WHERE
2121 description = '$match')
2122 WHERE id = '$filter_id'");
2125 if ($subop == "remove") {
2127 if (!WEB_DEMO_MODE
) {
2129 $ids = split(",", db_escape_string($_GET["ids"]));
2131 foreach ($ids as $id) {
2132 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
2138 if ($subop == "add") {
2140 if (!WEB_DEMO_MODE
) {
2142 $regexp = db_escape_string(trim($_GET["regexp"]));
2143 $match = db_escape_string(trim($_GET["match"]));
2144 $feed_id = db_escape_string($_GET["fid"]);
2145 $action_id = db_escape_string($_GET["aid"]);
2150 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2153 $result = db_query($link,
2154 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
2157 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
2158 description = '$match'),'".$_SESSION["uid"]."',
2159 $feed_id, '$action_id')");
2165 $result = db_query($link, "SELECT description
2166 FROM ttrss_filter_types ORDER BY description");
2168 $filter_types = array();
2170 while ($line = db_fetch_assoc($result)) {
2171 array_push($filter_types, $line["description"]);
2174 print "<div class=\"prefGenericAddBox\">
2175 <input id=\"fadd_regexp\" size=\"40\"> ";
2177 print_select("fadd_match", "Title", $filter_types);
2179 print " <select id=\"fadd_feed\">";
2181 print "<option selected id=\"0\">All feeds</option>";
2183 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
2184 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2186 if (db_num_rows($result) > 0) {
2187 print "<option disabled>--------</option>";
2190 while ($line = db_fetch_assoc($result)) {
2191 printf("<option id='%d'>%s</option>", $line["id"], $line["title"]);
2194 print "</select> ";
2196 print " Action: ";
2198 print "<select id=\"fadd_action\">";
2200 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2203 while ($line = db_fetch_assoc($result)) {
2204 printf("<option id='%d'>%s</option>", $line["id"], $line["description"]);
2207 print "</select> ";
2209 print "<input type=\"submit\"
2210 class=\"button\" onclick=\"javascript:addFilter()\"
2211 value=\"Add filter\">";
2215 $result = db_query($link, "SELECT
2216 ttrss_filters.id AS id,reg_exp,
2217 ttrss_filters.description AS description,
2218 ttrss_filter_types.name AS filter_type_name,
2219 ttrss_filter_types.description AS filter_type_descr,
2221 ttrss_filter_actions.description AS action_description,
2222 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
2224 ttrss_filters,ttrss_filter_types,ttrss_filter_actions
2226 filter_type = ttrss_filter_types.id AND
2227 ttrss_filter_actions.id = action_id AND
2228 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
2231 if (db_num_rows($result) != 0) {
2233 print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\"
2234 id=\"prefFilterList\">";
2236 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2238 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
2239 'FILRR-', 'FICHK-', true)\">All</a>,
2240 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
2241 'FILRR-', 'FICHK-', false)\">None</a>
2244 print "<tr class=\"title\">
2245 <td align='center' width=\"5%\"> </td>
2246 <td width=\"20%\">Filter expression</td>
2247 <td width=\"20%\">Feed</td>
2248 <td width=\"15%\">Match</td>
2249 <td width=\"15%\">Action</td>
2250 <td width=\"30%\">Description</td></tr>";
2254 while ($line = db_fetch_assoc($result)) {
2256 $class = ($lnum %
2) ?
"even" : "odd";
2258 $filter_id = $line["id"];
2259 $edit_filter_id = $_GET["id"];
2261 if ($subop == "edit" && $filter_id != $edit_filter_id) {
2265 $this_row_id = "id=\"FILRR-$filter_id\"";
2268 print "<tr class=\"$class\" $this_row_id>";
2270 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
2271 $line["description"] = htmlspecialchars($line["description"]);
2273 if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
2275 if (!$edit_filter_id ||
$subop != "edit") {
2277 if (!$line["description"]) $line["description"] = "[No description]";
2279 print "<td align='center'><input onclick='toggleSelectRow(this);'
2280 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
2282 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2283 $line["reg_exp"] . "</td>";
2285 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2286 $line["feed_title"] . "</td>";
2288 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2289 $line["filter_type_descr"] . "</td>";
2291 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2292 $line["action_description"] . "</td>";
2294 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2295 $line["description"] . "</td>";
2297 } else if ($filter_id != $edit_filter_id) {
2299 if (!$line["description"]) $line["description"] = "[No description]";
2301 print "<td><input disabled=\"true\" type=\"checkbox\"
2302 id=\"FICHK-".$line["id"]."\"></td>";
2304 print "<td>".$line["reg_exp"]."</td>";
2305 print "<td>".$line["feed_title"]."</td>";
2306 print "<td>".$line["filter_type_descr"]."</td>";
2307 print "<td>".$line["action_description"]."</td>";
2308 print "<td>".$line["description"]."</td>";
2312 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2314 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
2318 print "<select id=\"iedit_feed\">";
2319 print "<option id=\"0\">All feeds</option>";
2321 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
2322 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2324 if (db_num_rows($tmp_result) > 0) {
2325 print "<option disabled>--------</option>";
2328 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2329 if ($tmp_line["id"] == $line["feed_id"]) {
2330 $is_selected = "selected";
2334 printf("<option $is_selected id='%d'>%s</option>",
2335 $tmp_line["id"], $tmp_line["title"]);
2338 print "</select></td>";
2341 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
2345 print "<select id=\"iedit_filter_action\">";
2347 $tmp_result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2348 ORDER BY description");
2350 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2351 if ($tmp_line["description"] == $line["action_description"]) {
2352 $is_selected = "selected";
2356 printf("<option $is_selected id='%d'>%s</option>",
2357 $tmp_line["id"], $tmp_line["description"]);
2360 print "</select></td>";
2363 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2375 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
2382 if ($subop == "edit") {
2384 <input type=\"submit\" class=\"button\"
2385 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
2386 <input type=\"submit\" class=\"button\"
2387 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
2393 <input type=\"submit\" class=\"button\"
2394 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
2395 <input type=\"submit\" class=\"button\"
2396 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
2401 print "<p>No filters defined.</p>";
2406 // We need to accept raw SQL data in label queries, so not everything is escaped
2407 // here, this is by design. If you don't like the whole idea, disable labels
2408 // altogether with GLOBAL_ENABLE_LABELS = false
2410 if ($op == "pref-labels") {
2412 if (!GLOBAL_ENABLE_LABELS
) {
2416 $subop = $_GET["subop"];
2418 if ($subop == "test") {
2420 $expr = $_GET["expr"];
2421 $descr = $_GET["descr"];
2423 print "<div class='infoBoxContents'>";
2425 print "<h1>Label «$descr»</h1>";
2427 // print "<p><b>Expression</b>: $expr</p>";
2429 $result = db_query($link,
2430 "SELECT count(id) AS num_matches
2431 FROM ttrss_entries,ttrss_user_entries
2433 ttrss_user_entries.ref_id = ttrss_entries.id AND
2434 owner_uid = " . $_SESSION["uid"]);
2436 $num_matches = db_fetch_result($result, 0, "num_matches");;
2438 if ($num_matches > 0) {
2440 print "<p>Query returned <b>$num_matches</b> matches, first 5 follow:</p>";
2442 $result = db_query($link,
2444 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
2445 FROM ttrss_entries,ttrss_user_entries
2447 ttrss_user_entries.ref_id = ttrss_entries.id
2448 AND owner_uid = " . $_SESSION["uid"] . "
2449 ORDER BY date_entered DESC LIMIT 5");
2451 print "<ul class=\"nomarks\">";
2452 while ($line = db_fetch_assoc($result)) {
2453 print "<li>".$line["title"].
2454 " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
2459 print "<p>Query didn't return any matches.</p>";
2464 print "<div align='center'>
2465 <input type='submit' class='button'
2466 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2470 if ($subop == "editSave") {
2472 $sql_exp = $_GET["s"];
2473 $descr = $_GET["d"];
2474 $label_id = db_escape_string($_GET["id"]);
2476 // print "$sql_exp : $descr : $label_id";
2478 $result = db_query($link, "UPDATE ttrss_labels SET
2479 sql_exp = '$sql_exp',
2480 description = '$descr'
2481 WHERE id = '$label_id'");
2484 if ($subop == "remove") {
2486 if (!WEB_DEMO_MODE
) {
2488 $ids = split(",", db_escape_string($_GET["ids"]));
2490 foreach ($ids as $id) {
2491 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
2497 if ($subop == "add") {
2499 if (!WEB_DEMO_MODE
) {
2501 // no escaping is done here on purpose
2502 $exp = trim($_GET["exp"]);
2504 $result = db_query($link,
2505 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
2506 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
2510 print "<div class=\"prefGenericAddBox\">
2511 <input size=\"40\" id=\"ladd_expr\"> ";
2513 print"<input type=\"submit\" class=\"button\"
2514 onclick=\"javascript:addLabel()\" value=\"Add label\"></div>";
2516 $result = db_query($link, "SELECT
2517 id,sql_exp,description
2521 owner_uid = ".$_SESSION["uid"]."
2522 ORDER by description");
2524 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2526 if (db_num_rows($result) != 0) {
2528 print "<p><table width=\"100%\" cellspacing=\"0\"
2529 class=\"prefLabelList\" id=\"prefLabelList\">";
2531 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2533 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2534 'LILRR-', 'LICHK-', true)\">All</a>,
2535 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2536 'LILRR-', 'LICHK-', false)\">None</a>
2539 print "<tr class=\"title\">
2540 <td align='center' width=\"5%\"> </td>
2541 <td width=\"40%\">SQL expression
2542 <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a>
2544 <td width=\"40%\">Caption</td></tr>";
2548 while ($line = db_fetch_assoc($result)) {
2550 $class = ($lnum %
2) ?
"even" : "odd";
2552 $label_id = $line["id"];
2553 $edit_label_id = $_GET["id"];
2555 if ($subop == "edit" && $label_id != $edit_label_id) {
2559 $this_row_id = "id=\"LILRR-$label_id\"";
2562 print "<tr class=\"$class\" $this_row_id>";
2564 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
2565 $line["description"] = htmlspecialchars($line["description"]);
2567 if (!$edit_label_id ||
$subop != "edit") {
2569 if (!$line["description"]) $line["description"] = "[No caption]";
2571 print "<td align='center'><input onclick='toggleSelectRow(this);'
2572 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
2574 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2575 $line["sql_exp"] . "</td>";
2577 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2578 $line["description"] . "</td>";
2580 } else if ($label_id != $edit_label_id) {
2582 if (!$line["description"]) $line["description"] = "[No description]";
2584 print "<td><input disabled=\"true\" type=\"checkbox\"
2585 id=\"LICHK-".$line["id"]."\"></td>";
2587 print "<td>".$line["sql_exp"]."</td>";
2588 print "<td>".$line["description"]."</td>";
2592 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2594 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
2597 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2609 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
2616 if ($subop == "edit") {
2618 <input type=\"submit\" class=\"button\"
2619 onclick=\"javascript:labelTest()\" value=\"Test\">
2620 <input type=\"submit\" class=\"button\"
2621 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
2622 <input type=\"submit\" class=\"button\"
2623 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
2629 <input type=\"submit\" class=\"button\"
2630 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
2631 <input type=\"submit\" class=\"button\"
2632 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
2635 print "<p>No labels defined.</p>";
2639 if ($op == "error") {
2640 print "<div width=\"100%\" align='center'>";
2641 $msg = $_GET["msg"];
2646 if ($op == "help") {
2647 if (!$_GET["noheaders"]) {
2649 <title>Tiny Tiny RSS : Help</title>
2650 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2651 <script type=\"text/javascript\" src=\"functions.js\"></script>
2652 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2656 $tid = sprintf("%d", $_GET["tid"]);
2658 print "<div class='infoBoxContents'>";
2660 if (file_exists("help/$tid.php")) {
2661 include("help/$tid.php");
2663 print "<p>Help topic not found.</p>";
2668 print "<div align='center'>
2669 <input type='submit' class='button'
2670 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2672 if (!$_GET["noheaders"]) {
2673 print "</body></html>";
2680 $param = $_GET["param"];
2682 if ($id == "quickAddFeed") {
2685 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2687 <input class=\"button\"
2688 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
2689 <input class=\"button\"
2690 type=\"submit\" onclick=\"javascript:closeDlg()\"
2694 if ($id == "quickDelFeed") {
2696 $param = db_escape_string($param);
2698 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
2702 $f_title = db_fetch_result($result, 0, "title");
2704 print "Remove current feed (<b>$f_title</b>)?
2705 <input class=\"button\"
2706 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
2707 <input class=\"button\"
2708 type=\"submit\" onclick=\"javascript:closeDlg()\"
2711 print "Error: Feed $param not found.
2712 <input class=\"button\"
2713 type=\"submit\" onclick=\"javascript:closeDlg()\"
2718 if ($id == "search") {
2720 print "<input id=\"searchbox\" class=\"extSearch\"
2721 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2722 onchange=\"javascript:search()\">
2723 <select id=\"searchmodebox\">
2724 <option selected>All feeds</option>
2725 <option>This feed</option>
2727 <input type=\"submit\"
2728 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
2729 <input class=\"button\"
2730 type=\"submit\" onclick=\"javascript:closeDlg()\"
2735 if ($id == "quickAddFilter") {
2737 $result = db_query($link, "SELECT description
2738 FROM ttrss_filter_types ORDER BY description");
2740 $filter_types = array();
2742 while ($line = db_fetch_assoc($result)) {
2743 array_push($filter_types, $line["description"]);
2748 print "<tr><td>Match:</td><td><input id=\"fadd_regexp\" size=\"40\"> ";
2750 print_select("fadd_match", "Title", $filter_types);
2753 print "<tr><td>Feed:</td><td><select id=\"fadd_feed\">";
2755 print "<option selected id=\"0\">All feeds</option>";
2757 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
2758 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2760 if (db_num_rows($result) > 0) {
2761 print "<option disabled>--------</option>";
2764 while ($line = db_fetch_assoc($result)) {
2765 if ($param == $line["id"]) {
2766 $selected = "selected";
2770 printf("<option id='%d' %s>%s</option>", $line["id"], $selected, $line["title"]);
2773 print "</select></td></tr>";
2775 print "<tr><td>Action:</td>";
2777 print "<td><select id=\"fadd_action\">";
2779 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2782 while ($line = db_fetch_assoc($result)) {
2783 printf("<option id='%d'>%s</option>", $line["id"], $line["description"]);
2788 print "</td></tr><tr><td colspan=\"2\" align=\"right\">";
2790 print "<input type=\"submit\"
2791 class=\"button\" onclick=\"javascript:qaddFilter()\"
2792 value=\"Add filter\"> ";
2794 print "<input class=\"button\"
2795 type=\"submit\" onclick=\"javascript:closeDlg()\"
2798 print "</td></tr></table>";
2802 // update feeds of all users, may be used anonymously
2803 if ($op == "globalUpdateFeeds") {
2805 $result = db_query($link, "SELECT id FROM ttrss_users");
2807 while ($line = db_fetch_assoc($result)) {
2808 $user_id = $line["id"];
2809 // print "<!-- updating feeds of uid $user_id -->";
2810 update_all_feeds($link, false, $user_id);
2814 <message msg=\"All feeds updated\"/>
2819 if ($op == "pref-prefs") {
2821 $subop = $_REQUEST["subop"];
2823 if ($subop == "Save configuration") {
2825 if (WEB_DEMO_MODE
) {
2826 header("Location: prefs.php");
2830 $_SESSION["prefs_op_result"] = "save-config";
2832 foreach (array_keys($_POST) as $pref_name) {
2834 $pref_name = db_escape_string($pref_name);
2835 $value = db_escape_string($_POST[$pref_name]);
2837 $result = db_query($link, "SELECT type_name
2838 FROM ttrss_prefs,ttrss_prefs_types
2839 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
2841 if (db_num_rows($result) > 0) {
2843 $type_name = db_fetch_result($result, 0, "type_name");
2845 // print "$pref_name : $type_name : $value<br>";
2847 if ($type_name == "bool") {
2848 if ($value == "1") {
2853 } else if ($type_name == "integer") {
2854 $value = sprintf("%d", $value);
2857 // print "$pref_name : $type_name : $value<br>";
2859 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
2860 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
2864 header("Location: prefs.php");
2868 } else if ($subop == "getHelp") {
2870 $pref_name = db_escape_string($_GET["pn"]);
2872 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
2873 WHERE pref_name = '$pref_name'");
2875 if (db_num_rows($result) > 0) {
2876 $help_text = db_fetch_result($result, 0, "help_text");
2879 print "Unknown option: $pref_name";
2882 } else if ($subop == "Change password") {
2884 if (WEB_DEMO_MODE
) {
2885 header("Location: prefs.php");
2889 $old_pw = $_POST["OLD_PASSWORD"];
2890 $new_pw = $_POST["OLD_PASSWORD"];
2892 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
2893 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
2895 $active_uid = $_SESSION["uid"];
2897 if ($old_pw && $new_pw) {
2899 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
2901 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
2902 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
2903 pwd_hash = '$old_pw_hash')");
2905 if (db_num_rows($result) == 1) {
2906 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
2907 WHERE id = '$active_uid'");
2909 $_SESSION["pwd_change_result"] = "ok";
2911 $_SESSION["pwd_change_result"] = "failed";
2915 header("Location: prefs.php");
2917 } else if ($subop == "Reset to defaults") {
2919 if (WEB_DEMO_MODE
) {
2920 header("Location: prefs.php");
2924 $_SESSION["prefs_op_result"] = "reset-to-defaults";
2926 if (DB_TYPE
== "pgsql") {
2927 db_query($link,"UPDATE ttrss_user_prefs
2928 SET value = ttrss_prefs.def_value
2929 WHERE owner_uid = '".$_SESSION["uid"]."' AND
2930 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
2932 db_query($link, "DELETE FROM ttrss_user_prefs
2933 WHERE owner_uid = ".$_SESSION["uid"]);
2934 initialize_user_prefs($link, $_SESSION["uid"]);
2937 header("Location: prefs.php");
2939 } else if ($subop == "Change theme") {
2941 $theme = db_escape_string($_POST["theme"]);
2943 if ($theme == "Default") {
2944 $theme_qpart = 'NULL';
2946 $theme_qpart = "'$theme'";
2949 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
2950 WHERE theme_name = '$theme'");
2952 if (db_num_rows($result) == 1) {
2953 $theme_id = db_fetch_result($result, 0, "id");
2954 $theme_path = db_fetch_result($result, 0, "theme_path");
2960 db_query($link, "UPDATE ttrss_users SET
2961 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
2963 $_SESSION["theme"] = $theme_path;
2965 header("Location: prefs.php");
2969 if (!SINGLE_USER_MODE
) {
2971 $result = db_query($link, "SELECT id FROM ttrss_users
2972 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
2973 pwd_hash = 'SHA1:".sha1("password")."')");
2975 if (db_num_rows($result) != 0) {
2976 print "<div class=\"warning\">
2977 Your password is at default value, please change it.
2981 if ($_SESSION["pwd_change_result"] == "failed") {
2982 print "<div class=\"warning\">
2983 There was an error while changing your password.
2987 if ($_SESSION["pwd_change_result"] == "ok") {
2988 print "<div class=\"notice\">
2989 Password changed successfully.
2993 $_SESSION["pwd_change_result"] = "";
2995 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
2996 print "<div class=\"notice\">
2997 Your configuration was reset to defaults.
3001 if ($_SESSION["prefs_op_result"] == "save-config") {
3002 print "<div class=\"notice\">
3003 Your configuration was saved successfully.
3007 $_SESSION["prefs_op_result"] = "";
3009 print "<form action=\"backend.php\" method=\"POST\">";
3011 print "<table width=\"100%\" class=\"prefPrefsList\">";
3012 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
3014 print "<tr><td width=\"40%\">Old password</td>";
3015 print "<td><input class=\"editbox\" type=\"password\"
3016 name=\"OLD_PASSWORD\"></td></tr>";
3018 print "<tr><td width=\"40%\">New password</td>";
3020 print "<td><input class=\"editbox\" type=\"password\"
3021 name=\"NEW_PASSWORD\"></td></tr>";
3025 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3027 print "<p><input class=\"button\" type=\"submit\"
3028 value=\"Change password\" name=\"subop\">";
3034 $result = db_query($link, "SELECT
3035 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
3037 $user_theme_id = db_fetch_result($result, 0, "theme_id");
3039 $result = db_query($link, "SELECT
3040 id,theme_name FROM ttrss_themes ORDER BY theme_name");
3042 if (db_num_rows($result) > 0) {
3044 print "<form action=\"backend.php\" method=\"POST\">";
3045 print "<table width=\"100%\" class=\"prefPrefsList\">";
3046 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
3047 print "<tr><td width=\"40%\">Select theme</td>";
3048 print "<td><select name=\"theme\">";
3049 print "<option>Default</option>";
3050 print "<option disabled>--------</option>";
3052 while ($line = db_fetch_assoc($result)) {
3053 if ($line["id"] == $user_theme_id) {
3054 $selected = "selected";
3058 print "<option $selected>" . $line["theme_name"] . "</option>";
3060 print "</select></td></tr>";
3062 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3063 print "<p><input class=\"button\" type=\"submit\"
3064 value=\"Change theme\" name=\"subop\">";
3068 $result = db_query($link, "SELECT
3069 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
3070 section_name,def_value
3071 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
3072 WHERE type_id = ttrss_prefs_types.id AND
3073 section_id = ttrss_prefs_sections.id AND
3074 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
3075 owner_uid = ".$_SESSION["uid"]."
3076 ORDER BY section_id,short_desc");
3078 print "<form action=\"backend.php\" method=\"POST\">";
3082 $active_section = "";
3084 while ($line = db_fetch_assoc($result)) {
3086 if ($active_section != $line["section_name"]) {
3088 if ($active_section != "") {
3092 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
3094 $active_section = $line["section_name"];
3096 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
3097 // print "<tr class=\"title\">
3098 // <td width=\"25%\">Option</td><td>Value</td></tr>";
3103 // $class = ($lnum % 2) ? "even" : "odd";
3107 $type_name = $line["type_name"];
3108 $pref_name = $line["pref_name"];
3109 $value = $line["value"];
3110 $def_value = $line["def_value"];
3111 $help_text = $line["help_text"];
3113 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
3115 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
3121 if ($type_name == "bool") {
3122 // print_select($pref_name, $value, array("true", "false"));
3124 if ($value == "true") {
3130 print_radio($pref_name, $value, array("Yes", "No"));
3133 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
3145 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3147 print "<p><input class=\"button\" type=\"submit\"
3148 name=\"subop\" value=\"Save configuration\">";
3150 print " <input class=\"button\" type=\"submit\"
3151 name=\"subop\" onclick=\"return validatePrefsReset()\"
3152 value=\"Reset to defaults\"></p>";
3160 if ($op == "pref-users") {
3162 $subop = $_GET["subop"];
3164 if ($subop == "editSave") {
3166 if (!WEB_DEMO_MODE
) {
3168 $login = db_escape_string($_GET["l"]);
3169 $uid = db_escape_string($_GET["id"]);
3170 $access_level = sprintf("%d", $_GET["al"]);
3172 db_query($link, "UPDATE ttrss_users SET login = '$login', access_level = '$access_level' WHERE id = '$uid'");
3175 } else if ($subop == "remove") {
3177 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3179 $ids = split(",", db_escape_string($_GET["ids"]));
3181 foreach ($ids as $id) {
3182 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
3186 } else if ($subop == "add") {
3188 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3190 $login = db_escape_string(trim($_GET["login"]));
3191 $tmp_user_pwd = make_password(8);
3192 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3194 db_query($link, "INSERT INTO ttrss_users (login,pwd_hash,access_level)
3195 VALUES ('$login', '$pwd_hash', 0)");
3198 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3199 login = '$login' AND pwd_hash = '$pwd_hash'");
3201 if (db_num_rows($result) == 1) {
3203 $new_uid = db_fetch_result($result, 0, "id");
3205 print "<div class=\"notice\">Added user <b>".$_GET["login"].
3206 "</b> with password <b>$tmp_user_pwd</b>.</div>";
3208 initialize_user($link, $new_uid);
3212 print "<div class=\"warning\">Error while adding user <b>".
3213 $_GET["login"].".</b></div>";
3217 } else if ($subop == "resetPass") {
3219 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3221 $uid = db_escape_string($_GET["id"]);
3223 $result = db_query($link, "SELECT login FROM ttrss_users WHERE id = '$uid'");
3225 $login = db_fetch_result($result, 0, "login");
3226 $tmp_user_pwd = make_password(8);
3227 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3229 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
3230 WHERE id = '$uid'");
3232 print "<div class=\"notice\">Changed password of
3233 user <b>$login</b> to <b>$tmp_user_pwd</b>.</div>";
3238 print "<div class=\"prefGenericAddBox\">
3239 <input id=\"uadd_box\" onchange=\"javascript:addUser()\" size=\"40\"> ";
3241 print"<input type=\"submit\" class=\"button\"
3242 onclick=\"javascript:addUser()\" value=\"Add user\"></div>";
3244 $result = db_query($link, "SELECT
3245 id,login,access_level,
3246 SUBSTRING(last_login,1,16) as last_login
3251 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
3253 print "<p><table width=\"100%\" cellspacing=\"0\"
3254 class=\"prefUserList\" id=\"prefUserList\">";
3256 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
3258 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3259 'UMRR-', 'UMCHK-', true)\">All</a>,
3260 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3261 'UMRR-', 'UMCHK-', false)\">None</a>
3264 print "<tr class=\"title\">
3265 <td align='center' width=\"5%\"> </td>
3266 <td width='30%'>Username</td>
3267 <td width='30%'>Access Level</td>
3268 <td width='30%'>Last login</td></tr>";
3272 while ($line = db_fetch_assoc($result)) {
3274 $class = ($lnum %
2) ?
"even" : "odd";
3277 $edit_uid = $_GET["id"];
3279 if ($uid == $_SESSION["uid"] ||
($subop == "edit" && $uid != $edit_uid)) {
3283 $this_row_id = "id=\"UMRR-$uid\"";
3286 print "<tr class=\"$class\" $this_row_id>";
3288 $line["login"] = htmlspecialchars($line["login"]);
3290 $line["last_login"] = date(get_pref($link, 'SHORT_DATE_FORMAT'),
3291 strtotime($line["last_login"]));
3293 if ($uid == $_SESSION["uid"]) {
3295 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
3296 id=\"UMCHK-".$line["id"]."\"></td>";
3298 print "<td>".$line["login"]."</td>";
3299 print "<td>".$line["access_level"]."</td>";
3301 } else if (!$edit_uid ||
$subop != "edit") {
3303 print "<td align='center'><input onclick='toggleSelectRow(this);'
3304 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
3306 print "<td><a href=\"javascript:editUser($uid);\">" .
3307 $line["login"] . "</td>";
3309 print "<td><a href=\"javascript:editUser($uid);\">" .
3310 $line["access_level"] . "</td>";
3312 } else if ($uid != $edit_uid) {
3314 print "<td><input disabled=\"true\" type=\"checkbox\"
3315 id=\"UMCHK-".$line["id"]."\"></td>";
3317 print "<td>".$line["login"]."</td>";
3318 print "<td>".$line["access_level"]."</td>";
3322 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
3324 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
3327 print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
3332 print "<td>".$line["last_login"]."</td>";
3343 if ($subop == "edit") {
3345 <input type=\"submit\" class=\"button\"
3346 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">
3347 <input type=\"submit\" class=\"button\"
3348 onclick=\"javascript:userEditSave()\" value=\"Save\">";
3354 <input type=\"submit\" class=\"button\"
3355 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
3356 <input type=\"submit\" class=\"button\"
3357 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
3358 <input type=\"submit\" class=\"button\"
3359 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
3360 <input type=\"submit\" class=\"button\"
3361 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
3366 if ($op == "user-details") {
3368 if (WEB_DEMO_MODE ||
$_SESSION["access_level"] < 10) {
3372 /* print "<html><head>
3373 <title>Tiny Tiny RSS : User Details</title>
3374 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
3375 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
3378 $uid = sprintf("%d", $_GET["id"]);
3380 print "<div class='infoBoxContents'>";
3382 $result = db_query($link, "SELECT login,
3383 SUBSTRING(last_login,1,16) AS last_login,
3385 (SELECT COUNT(int_id) FROM ttrss_user_entries
3386 WHERE owner_uid = id) AS stored_articles
3388 WHERE id = '$uid'");
3390 if (db_num_rows($result) == 0) {
3391 print "<h1>User not found</h1>";
3395 print "<h1>User Details</h1>";
3397 print "<table width='100%'>";
3399 $login = db_fetch_result($result, 0, "login");
3400 $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'),
3401 strtotime(db_fetch_result($result, 0, "last_login")));
3402 $access_level = db_fetch_result($result, 0, "access_level");
3403 $stored_articles = db_fetch_result($result, 0, "stored_articles");
3405 print "<tr><td>Username</td><td>$login</td></tr>";
3406 print "<tr><td>Access level</td><td>$access_level</td></tr>";
3407 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
3408 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
3410 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
3411 WHERE owner_uid = '$uid'");
3413 $num_feeds = db_fetch_result($result, 0, "num_feeds");
3415 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
3417 /* $result = db_query($link, "SELECT
3418 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
3419 FROM ttrss_user_entries,ttrss_entries
3420 WHERE owner_uid = '$uid' AND ref_id = id");
3422 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
3424 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
3428 print "<h1>Subscribed feeds</h1>";
3430 $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
3431 WHERE owner_uid = '$uid' ORDER BY title LIMIT 20");
3433 print "<ul class=\"nomarks\">";
3435 while ($line = db_fetch_assoc($result)) {
3437 $icon_file = ICONS_URL
."/".$line["id"].".ico";
3439 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3440 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
3442 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3445 print "<li>$feed_icon <a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
3448 if (db_num_rows($result) < $num_feeds) {
3449 // FIXME - add link to show ALL subscribed feeds here somewhere
3451 class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\"> ...</li>";
3458 print "<div align='center'>
3459 <input type='submit' class='button'
3460 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3462 // print "</body></html>";
3466 if ($op == "feed-details") {
3468 // $feed_id = $_GET["id"];
3470 $feed_ids = split(",", db_escape_string($_GET["id"]));
3472 print "<div class=\"infoBoxContents\">";
3474 foreach ($feed_ids as $feed_id) {
3476 $result = db_query($link,
3479 SUBSTRING(last_updated,1,16) as last_updated,
3481 (SELECT COUNT(int_id) FROM ttrss_user_entries
3482 WHERE feed_id = id) AS total,
3483 (SELECT COUNT(int_id) FROM ttrss_user_entries
3484 WHERE feed_id = id AND unread = true) AS unread,
3485 (SELECT COUNT(int_id) FROM ttrss_user_entries
3486 WHERE feed_id = id AND marked = true) AS marked
3488 WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]);
3490 if (db_num_rows($result) == 0) return;
3492 $title = db_unescape_string(db_fetch_result($result, 0, "title"));
3493 $last_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
3494 strtotime(db_fetch_result($result, 0, "last_updated")));
3495 $feed_url = db_fetch_result($result, 0, "feed_url");
3496 $icon_url = db_fetch_result($result, 0, "icon_url");
3497 $total = db_fetch_result($result, 0, "total");
3498 $unread = db_fetch_result($result, 0, "unread");
3499 $marked = db_fetch_result($result, 0, "marked");
3500 $site_url = db_fetch_result($result, 0, "site_url");
3502 $result = db_query($link, "SELECT COUNT(id) AS subscribed
3503 FROM ttrss_feeds WHERE feed_url = '$feed_url'");
3505 $subscribed = db_fetch_result($result, 0, "subscribed");
3507 $icon_file = ICONS_DIR
. "/$feed_id.ico";
3509 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3510 $feed_icon = "<img width=\"16\" height=\"16\"
3511 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
3516 print "<h1>$feed_icon $title</h1>";
3518 print "<table width='100%'>";
3521 print "<tr><td width='30%'>Link</td>
3522 <td><a href=\"$site_url\">$site_url</a>
3523 <a href=\"$feed_url\">(feed)</a></td>
3526 print "<tr><td width='30%'>Feed URL</td>
3527 <td><a href=\"$feed_url\">$feed_url</a></td></tr>";
3529 print "<tr><td>Last updated</td><td>$last_updated</td></tr>";
3530 print "<tr><td>Total articles</td><td>$total</td></tr>";
3531 print "<tr><td>Unread articles</td><td>$unread</td></tr>";
3532 print "<tr><td>Starred articles</td><td>$marked</td></tr>";
3533 print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>";
3537 /* $result = db_query($link, "SELECT title,
3538 SUBSTRING(updated,1,16) AS updated,unread
3539 FROM ttrss_entries,ttrss_user_entries
3540 WHERE ref_id = id AND feed_id = '$feed_id'
3541 ORDER BY date_entered DESC LIMIT 5");
3543 if (db_num_rows($result) > 0) {
3545 print "<h1>Latest headlines</h1>";
3547 print "<ul class=\"nomarks\">";
3549 while ($line = db_fetch_assoc($result)) {
3550 if ($line["unread"] == "t" || $line["unread"] == "1") {
3551 $line["title"] = "<b>" . $line["title"] . "</b>";
3553 print "<li>" . $line["title"].
3554 " <span class=\"insensitive\">(" .
3555 date(get_pref($link, 'SHORT_DATE_FORMAT'),
3556 strtotime($line["updated"])).
3567 print "<div align='center'>
3568 <input type='submit' class='button'
3569 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3575 <!-- <?
= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?
> -->