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', 5);
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 if ($_SESSION["uid"]) {
57 if (get_pref($link, "HIDE_READ_FEEDS") == "true") {
58 setcookie("ttrss_vf_hreadf", 1);
60 setcookie("ttrss_vf_hreadf", 0);
63 setcookie('ttrss_vf_refresh', FEEDS_FRAME_REFRESH
);
64 setcookie('ttrss_vf_daemon', ENABLE_UPDATE_DAEMON
);
67 $fetch = $_GET["fetch"];
69 setcookie("ttrss_icons_url", ICONS_URL
);
71 if (!sanity_check($link)) { return; }
73 function getAllCounters($link) {
74 getLabelCounters($link);
75 getFeedCounters($link);
76 getTagCounters($link);
77 getGlobalCounters($link);
78 if (get_pref($link, 'ENABLE_FEED_CATS')) {
79 getCategoryCounters($link);
83 function getCategoryCounters($link) {
84 $result = db_query($link, "SELECT cat_id,SUM((SELECT COUNT(int_id)
85 FROM ttrss_user_entries WHERE feed_id = ttrss_feeds.id
86 AND unread = true)) AS unread FROM ttrss_feeds
88 owner_uid = ".$_SESSION["uid"]." GROUP BY cat_id");
90 while ($line = db_fetch_assoc($result)) {
91 $line["cat_id"] = sprintf("%d", $line["cat_id"]);
92 print "<counter type=\"category\" id=\"".$line["cat_id"]."\" counter=\"".
93 $line["unread"]."\"/>";
97 function getFeedUnread($link, $feed) {
98 $n_feed = sprintf("%d", $feed);
101 $match_part = "marked = true";
102 } else if ($feed > 0) {
103 $match_part = "feed_id = '$n_feed'";
104 } else if ($feed < -10) {
105 $label_id = -$feed - 11;
107 $result = db_query($link, "SELECT sql_exp FROM ttrss_labels WHERE
108 id = '$label_id' AND owner_uid = " . $_SESSION["uid"]);
110 $match_part = db_fetch_result($result, 0, "sql_exp");
115 $result = db_query($link, "SELECT count(int_id) AS unread
116 FROM ttrss_user_entries
117 WHERE unread = true AND $match_part AND owner_uid = " . $_SESSION["uid"]);
121 $result = db_query($link, "SELECT COUNT(post_int_id) AS unread
122 FROM ttrss_tags,ttrss_user_entries
123 WHERE tag_name = '$feed' AND post_int_id = int_id AND unread = true AND
124 ttrss_tags.owner_uid = " . $_SESSION["uid"]);
127 $unread = db_fetch_result($result, 0, "unread");
131 /* FIXME this needs reworking */
133 function getGlobalUnread($link) {
134 $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries,ttrss_user_entries
135 WHERE unread = true AND
136 ttrss_user_entries.ref_id = ttrss_entries.id AND
137 owner_uid = " . $_SESSION["uid"]);
138 $c_id = db_fetch_result($result, 0, "c_id");
142 function getGlobalCounters($link, $global_unread = -1) {
143 if ($global_unread == -1) {
144 $global_unread = getGlobalUnread($link);
146 print "<counter type=\"global\" id='global-unread' counter='$global_unread'/>";
149 function getTagCounters($link, $smart_mode = SMART_RPC_COUNTERS
) {
152 if (!$_SESSION["tctr_last_value"]) {
153 $_SESSION["tctr_last_value"] = array();
157 $old_counters = $_SESSION["tctr_last_value"];
159 $tctrs_modified = false;
161 /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
162 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
163 ttrss_user_entries.ref_id = ttrss_entries.id AND
164 ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND
165 post_int_id = ttrss_user_entries.int_id AND unread = true GROUP BY tag_name
167 select tag_name,0 as count FROM ttrss_tags
168 WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]); */
170 $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
171 FROM ttrss_user_entries WHERE int_id = post_int_id
172 AND unread = true)) AS count FROM ttrss_tags
173 WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name");
177 while ($line = db_fetch_assoc($result)) {
178 $tags[$line["tag_name"]] +
= $line["count"];
181 foreach (array_keys($tags) as $tag) {
182 $unread = $tags[$tag];
184 $tag = htmlspecialchars($tag);
186 if (!$smart_mode ||
$old_counters[$tag] != $unread) {
187 $old_counters[$tag] = $unread;
188 $tctrs_modified = true;
189 print "<counter type=\"tag\" id=\"$tag\" counter=\"$unread\"/>";
194 if ($smart_mode && $tctrs_modified) {
195 $_SESSION["tctr_last_value"] = $old_counters;
200 function getLabelCounters($link, $smart_mode = SMART_RPC_COUNTERS
) {
203 if (!$_SESSION["lctr_last_value"]) {
204 $_SESSION["lctr_last_value"] = array();
208 $old_counters = $_SESSION["lctr_last_value"];
209 $lctrs_modified = false;
211 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries
212 WHERE marked = true AND ttrss_user_entries.ref_id = ttrss_entries.id AND
213 unread = true AND owner_uid = ".$_SESSION["uid"]);
215 $count = db_fetch_result($result, 0, "count");
217 print "<counter type=\"label\" id=\"-1\" counter=\"$count\"/>";
219 $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM
220 ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description");
222 while ($line = db_fetch_assoc($result)) {
224 $id = -$line["id"] - 11;
228 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_user_entries,ttrss_entries
229 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
230 ttrss_user_entries.ref_id = ttrss_entries.id AND
231 owner_uid = ".$_SESSION["uid"]);
233 $count = db_fetch_result($tmp_result, 0, "count");
235 if (!$smart_mode ||
$old_counters[$id] != $count) {
236 $old_counters[$id] = $count;
237 $lctrs_modified = true;
238 print "<counter type=\"label\" id=\"$id\" counter=\"$count\"/>";
241 error_reporting (DEFAULT_ERROR_LEVEL
);
244 if ($smart_mode && $lctrs_modified) {
245 $_SESSION["lctr_last_value"] = $old_counters;
249 /* function getFeedCounter($link, $id) {
251 $result = db_query($link, "SELECT
252 count(id) as count,last_error
253 FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
254 WHERE feed_id = '$id' AND unread = true
255 AND ttrss_user_entries.feed_id = ttrss_feeds.id
256 AND ttrss_user_entries.ref_id = ttrss_entries.id");
258 $count = db_fetch_result($result, 0, "count");
259 $last_error = htmlspecialchars(db_fetch_result($result, 0, "last_error"));
261 print "<counter type=\"feed\" id=\"$id\" counter=\"$count\" error=\"$last_error\"/>";
264 function getFeedCounters($link, $smart_mode = SMART_RPC_COUNTERS
) {
267 if (!$_SESSION["fctr_last_value"]) {
268 $_SESSION["fctr_last_value"] = array();
272 $old_counters = $_SESSION["fctr_last_value"];
274 $result = db_query($link, "SELECT id,last_error,parent_feed,
276 FROM ttrss_entries,ttrss_user_entries
277 WHERE feed_id = ttrss_feeds.id AND
278 ttrss_user_entries.ref_id = ttrss_entries.id
279 AND unread = true AND owner_uid = ".$_SESSION["uid"].") as count
280 FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"] . "
281 AND parent_feed IS NULL");
283 $fctrs_modified = false;
285 while ($line = db_fetch_assoc($result)) {
288 $count = $line["count"];
289 $last_error = htmlspecialchars($line["last_error"]);
291 $has_img = is_file(ICONS_DIR
. "/$id.ico");
293 $tmp_result = db_query($link,
294 "SELECT id,COUNT(unread) AS unread
295 FROM ttrss_feeds LEFT JOIN ttrss_user_entries
296 ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
297 WHERE parent_feed = '$id' AND unread = true GROUP BY ttrss_feeds.id");
299 if (db_num_rows($tmp_result) > 0) {
300 while ($l = db_fetch_assoc($tmp_result)) {
301 $count +
= $l["unread"];
305 if (!$smart_mode ||
$old_counters[$id] != $count) {
306 $old_counters[$id] = $count;
307 $fctrs_modified = true;
310 $error_part = "error=\"$last_error\"";
316 $has_img_part = "hi=\"$has_img\"";
321 print "<counter type=\"feed\" id=\"$id\" counter=\"$count\" $has_img_part $error_part/>";
325 if ($smart_mode && $fctrs_modified) {
326 $_SESSION["fctr_last_value"] = $old_counters;
330 function outputFeedList($link, $tags = false) {
333 <title>Tiny Tiny RSS : Feedlist</title>
334 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
336 $user_theme = $_SESSION["theme"];
338 print "<link rel=\"stylesheet\" type=\"text/css\"
339 href=\"themes/$user_theme/theme.css\">";
342 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
343 print "<link rel=\"stylesheet\" type=\"text/css\"
344 href=\"tt-rss_compact.css\"/>";
346 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
347 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
350 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
351 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
352 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
353 <!--[if gte IE 5.5000]>
354 <script type=\"text/javascript\" src=\"pngfix.js\"></script>
355 <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
357 </head><body onload=\"init()\">";
359 print "<ul class=\"feedList\" id=\"feedList\">";
361 $owner_uid = $_SESSION["uid"];
367 if (get_pref($link, 'ENABLE_FEED_CATS')) {
368 print "<li class=\"feedCat\">Special</li>";
369 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
372 $result = db_query($link, "SELECT count(id) as num_starred
373 FROM ttrss_entries,ttrss_user_entries
374 WHERE marked = true AND
375 ttrss_user_entries.ref_id = ttrss_entries.id AND
376 unread = true AND owner_uid = '$owner_uid'");
377 $num_starred = db_fetch_result($result, 0, "num_starred");
381 if ($num_starred > 0) $class .= "Unread";
383 printFeedEntry(-1, $class, "Starred articles", $num_starred,
384 "images/mark_set.png", $link);
386 if (get_pref($link, 'ENABLE_FEED_CATS')) {
390 if (GLOBAL_ENABLE_LABELS
&& get_pref($link, 'ENABLE_LABELS')) {
392 $result = db_query($link, "SELECT id,sql_exp,description FROM
393 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
395 if (db_num_rows($result) > 0) {
396 if (get_pref($link, 'ENABLE_FEED_CATS')) {
397 print "<li class=\"feedCat\">Labels</li>";
398 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
400 print "<li><hr></li>";
404 while ($line = db_fetch_assoc($result)) {
408 $tmp_result = db_query($link, "SELECT count(id) as count
409 FROM ttrss_entries,ttrss_user_entries
410 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
411 ttrss_user_entries.ref_id = ttrss_entries.id
412 AND owner_uid = '$owner_uid'");
414 $count = db_fetch_result($tmp_result, 0, "count");
422 error_reporting (DEFAULT_ERROR_LEVEL
);
424 printFeedEntry(-$line["id"]-11,
425 $class, $line["description"], $count, "images/label.png", $link);
429 if (db_num_rows($result) > 0) {
430 if (get_pref($link, 'ENABLE_FEED_CATS')) {
437 // if (!get_pref($link, 'ENABLE_FEED_CATS')) {
438 print "<li><hr></li>";
441 if (get_pref($link, 'ENABLE_FEED_CATS')) {
442 $order_by_qpart = "category,title";
444 $order_by_qpart = "title";
447 $result = db_query($link, "SELECT ttrss_feeds.*,
448 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
449 WHERE feed_id = ttrss_feeds.id AND
450 ttrss_user_entries.ref_id = ttrss_entries.id AND
451 owner_uid = '$owner_uid') AS total,
452 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
453 WHERE feed_id = ttrss_feeds.id AND unread = true
454 AND ttrss_user_entries.ref_id = ttrss_entries.id
455 AND owner_uid = '$owner_uid') as unread,
457 ttrss_feed_categories.title AS category,
458 ttrss_feed_categories.collapsed
459 FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
460 ON (ttrss_feed_categories.id = cat_id)
462 ttrss_feeds.owner_uid = '$owner_uid' AND parent_feed IS NULL
463 ORDER BY $order_by_qpart");
465 $actid = $_GET["actid"];
475 while ($line = db_fetch_assoc($result)) {
477 $feed = db_unescape_string($line["title"]);
478 $feed_id = $line["id"];
480 $subop = $_GET["subop"];
482 $total = $line["total"];
483 $unread = $line["unread"];
485 $tmp_result = db_query($link,
486 "SELECT id,COUNT(unread) AS unread
487 FROM ttrss_feeds LEFT JOIN ttrss_user_entries
488 ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
489 WHERE parent_feed = '$feed_id' AND unread = true
490 GROUP BY ttrss_feeds.id");
492 if (db_num_rows($tmp_result) > 0) {
493 while ($l = db_fetch_assoc($tmp_result)) {
494 $unread +
= $l["unread"];
498 $cat_id = $line["cat_id"];
500 $tmp_category = $line["category"];
502 if (!$tmp_category) {
503 $tmp_category = "Uncategorized";
506 // $class = ($lnum % 2) ? "even" : "odd";
508 if ($line["last_error"]) {
514 if ($unread > 0) $class .= "Unread";
516 if ($actid == $feed_id) {
517 $class .= "Selected";
520 $total_unread +
= $unread;
522 if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
525 print "</li></ul></li>";
528 $category = $tmp_category;
530 $collapsed = $line["collapsed"];
532 // workaround for NULL category
533 if ($category == "Uncategorized") {
534 if ($_COOKIE["ttrss_vf_uclps"] == 1) {
539 if ($collapsed == "t" ||
$collapsed == "1") {
540 $holder_class = "invisible";
548 $cat_id_qpart = "cat_id = '$cat_id'";
550 $cat_id_qpart = "cat_id IS NULL";
553 $tmp_result = db_query($link, "SELECT count(int_id) AS unread
554 FROM ttrss_user_entries,ttrss_feeds WHERE
556 feed_id = ttrss_feeds.id AND $cat_id_qpart AND
557 ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
559 $cat_unread = db_fetch_result($tmp_result, 0, "unread");
561 $cat_id = sprintf("%d", $cat_id);
563 print "<li class=\"feedCat\" id=\"FCAT-$cat_id\">
564 <a href=\"javascript:toggleCollapseCat($cat_id)\">$tmp_category
565 <span id=\"FCATCTR-$cat_id\"
566 class=\"$catctr_class\">($cat_unread unread)$ellipsis</span></a></li>";
568 // !!! NO SPACE before <ul...feedCatList - breaks firstChild DOM function
569 // -> keyboard navigation, etc.
570 print "<li id=\"feedCatHolder\" class=\"$holder_class\"><ul class=\"feedCatList\" id=\"FCATLIST-$cat_id\">";
573 printFeedEntry($feed_id, $class, $feed, $unread,
574 "icons/$feed_id.ico", $link);
583 /* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
584 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
585 post_int_id = ttrss_user_entries.int_id AND
586 unread = true AND ref_id = ttrss_entries.id
587 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
589 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'
590 ORDER BY tag_name"); */
592 $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
593 FROM ttrss_user_entries WHERE int_id = post_int_id
594 AND unread = true)) AS count FROM ttrss_tags
595 WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name");
599 while ($line = db_fetch_assoc($result)) {
600 $tags[$line["tag_name"]] +
= $line["count"];
603 foreach (array_keys($tags) as $tag) {
605 $unread = $tags[$tag];
613 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
619 if (db_num_rows($result) == 0) {
625 print "<li>No $what to display.</li>";
635 $subop = $_GET["subop"];
637 if ($subop == "setpref") {
644 $key = db_escape_string($_GET["key"]);
645 $value = db_escape_string($_GET["value"]);
647 set_pref($link, $key, $value);
649 print "<param-set key=\"$key\" value=\"$value\"/>";
651 print "</rpc-reply>";
655 if ($subop == "getLabelCounters") {
658 getLabelCounters($link);
660 getFeedCounter($link, $aid);
662 print "</rpc-reply>";
665 if ($subop == "getFeedCounters") {
667 getFeedCounters($link);
668 print "</rpc-reply>";
671 if ($subop == "getAllCounters") {
673 getAllCounters($link);
674 print "</rpc-reply>";
677 if ($subop == "mark") {
678 $mark = $_GET["mark"];
679 $id = db_escape_string($_GET["id"]);
687 // FIXME this needs collision testing
689 $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
690 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
693 if ($subop == "updateFeed") {
694 $feed_id = db_escape_string($_GET["feed"]);
696 $result = db_query($link,
697 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'
698 AND owner_uid = " . $_SESSION["uid"]);
700 if (db_num_rows($result) > 0) {
701 $feed_url = db_fetch_result($result, 0, "feed_url");
702 update_rss_feed($link, $feed_url, $feed_id);
706 getFeedCounter($link, $feed_id);
707 print "</rpc-reply>";
712 if ($subop == "forceUpdateAllFeeds" ||
$subop == "updateAllFeeds") {
714 if (ENABLE_UPDATE_DAEMON
) {
716 if ($subop == "forceUpdateAllFeeds") {
718 $result = db_query($link, "SELECT count(id) AS cid FROM
719 ttrss_scheduled_updates WHERE feed_id IS NULL AND
720 owner_uid = " . $_SESSION["uid"]);
722 $cid = db_fetch_result($result, 0, "cid");
724 # print "<rpc-reply>";
728 db_query($link, "INSERT INTO ttrss_scheduled_updates
729 (owner_uid, feed_id, entered) VALUES
730 (".$_SESSION["uid"].", NULL, NOW())");
732 // print "<!-- ScheduledOK -->";
735 // print "<!-- RequestAlreadyInQueue -->";
738 # print "</rpc-reply>";
742 update_all_feeds($link, $subop == "forceUpdateAllFeeds");
745 $global_unread_caller = sprintf("%d", $_GET["uctr"]);
746 $global_unread = getGlobalUnread($link);
750 if ($global_unread_caller != $global_unread) {
752 $omode = $_GET["omode"];
754 if (!$omode) $omode = "tflc";
756 if (strchr($omode, "l")) getLabelCounters($link);
757 if (strchr($omode, "f")) getFeedCounters($link);
758 if (strchr($omode, "t")) getTagCounters($link);
759 if (strchr($omode, "c")) {
760 if (get_pref($link, 'ENABLE_FEED_CATS')) {
761 getCategoryCounters($link);
766 getGlobalCounters($link, $global_unread);
768 print "</rpc-reply>";
772 /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
773 if ($subop == "catchupSelected") {
775 $ids = split(",", db_escape_string($_GET["ids"]));
777 $cmode = sprintf("%d", $_GET["cmode"]);
779 foreach ($ids as $id) {
782 db_query($link, "UPDATE ttrss_user_entries SET
783 unread = false,last_read = NOW()
784 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
785 } else if ($cmode == 1) {
786 db_query($link, "UPDATE ttrss_user_entries SET
788 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
790 db_query($link, "UPDATE ttrss_user_entries SET
791 unread = NOT unread,last_read = NOW()
792 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
796 getAllCounters($link);
797 print "</rpc-reply>";
800 if ($subop == "markSelected") {
802 $ids = split(",", db_escape_string($_GET["ids"]));
804 $cmode = sprintf("%d", $_GET["cmode"]);
806 foreach ($ids as $id) {
809 db_query($link, "UPDATE ttrss_user_entries SET
811 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
812 } else if ($cmode == 1) {
813 db_query($link, "UPDATE ttrss_user_entries SET
815 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
817 db_query($link, "UPDATE ttrss_user_entries SET
819 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
823 getAllCounters($link);
824 print "</rpc-reply>";
827 if ($subop == "sanityCheck") {
828 if (sanity_check($link)) {
829 print "<error error-code=\"0\"/>";
833 if ($subop == "globalPurge") {
836 global_purge_old_posts($link, true);
837 print "</rpc-reply>";
843 if ($op == "feeds") {
845 $tags = $_GET["tags"];
847 $subop = $_GET["subop"];
849 if ($subop == "catchupAll") {
850 db_query($link, "UPDATE ttrss_user_entries SET
851 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
854 if ($subop == "collapse") {
855 $cat_id = db_escape_string($_GET["cid"]);
857 db_query($link, "UPDATE ttrss_feed_categories SET
858 collapsed = NOT collapsed WHERE id = '$cat_id' AND owner_uid = " .
863 outputFeedList($link, $tags);
870 $feed_id = $_GET["feed"];
872 $result = db_query($link, "UPDATE ttrss_user_entries
873 SET unread = false,last_read = NOW()
874 WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
876 $addheader = $_GET["addheader"];
878 $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
879 SUBSTRING(updated,1,16) as updated,
880 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url,
882 FROM ttrss_entries,ttrss_user_entries
883 WHERE id = '$id' AND ref_id = id");
887 <title>Tiny Tiny RSS : Article $id</title>
888 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
890 $user_theme = $_SESSION["theme"];
892 print "<link rel=\"stylesheet\" type=\"text/css\"
893 href=\"themes/$user_theme/theme.css\">";
896 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
897 print "<link rel=\"stylesheet\" type=\"text/css\"
898 href=\"tt-rss_compact.css\"/>";
900 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
901 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
904 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
905 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
911 $line = db_fetch_assoc($result);
913 if ($line["icon_url"]) {
914 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
916 $feed_icon = " ";
919 /* if ($line["comments"] && $line["link"] != $line["comments"]) {
920 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
922 $entry_comments = "";
925 $num_comments = $line["num_comments"];
926 $entry_comments = "";
928 if ($num_comments > 0) {
929 if ($line["comments"]) {
930 $comments_url = $line["comments"];
932 $comments_url = $line["link"];
934 $entry_comments = "<a href=\"$comments_url\">$num_comments comments</a>";
936 if ($line["comments"] && $line["link"] != $line["comments"]) {
937 $entry_comments = "<a href=\"".$line["comments"]."\">comments</a>";
941 print "<div class=\"postReply\">";
943 print "<div class=\"postHeader\"><table width=\"100%\">";
945 print "<tr><td><a href=\"" . $line["link"] . "\">" . $line["title"] . "</a></td>";
947 $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
948 strtotime($line["updated"]));
950 print "<td class=\"postDate\">$parsed_updated</td>";
954 $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
955 ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
963 while ($tmp_line = db_fetch_assoc($tmp_result)) {
965 $tag = $tmp_line["tag_name"];
966 $tag_str = "<a href=\"javascript:parent.viewfeed('$tag')\">$tag</a>, ";
968 if ($num_tags == 5) {
969 $tags_str .= "<a href=\"javascript:showBlockElement('allEntryTags')\">...</a>";
970 } else if ($num_tags < 5) {
971 $tags_str .= $tag_str;
973 $f_tags_str .= $tag_str;
976 $tags_str = preg_replace("/, $/", "", $tags_str);
977 $f_tags_str = preg_replace("/, $/", "", $f_tags_str);
979 // $truncated_link = truncate_string($line["link"], 60);
981 if ($tags_str ||
$entry_comments) {
982 print "<tr><td width='50%'>
984 <td align=\"right\">$tags_str</td></tr>";
987 print "</table></div>";
989 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
990 print "<div class=\"postContent\">";
992 if (db_num_rows($tmp_result) > 5) {
993 print "<div id=\"allEntryTags\">Tags: $f_tags_str</div>";
996 print $line["content"] . "</div>";
1000 print "<script type=\"text/javascript\">
1001 update_all_counters('$feed_id');
1006 print "</body></html>";
1010 if ($op == "viewfeed") {
1012 $feed = $_GET["feed"];
1013 $skip = $_GET["skip"];
1014 $subop = $_GET["subop"];
1015 $view_mode = $_GET["view"];
1016 $addheader = $_GET["addheader"];
1017 $limit = $_GET["limit"];
1023 if (!$skip) $skip = 0;
1025 if ($subop == "undefined") $subop = "";
1029 <title>Tiny Tiny RSS : Feed $feed</title>
1030 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
1032 $user_theme = $_SESSION["theme"];
1034 print "<link rel=\"stylesheet\" type=\"text/css\"
1035 href=\"themes/$user_theme/theme.css\">";
1038 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
1039 print "<link rel=\"stylesheet\"
1040 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
1043 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
1044 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
1047 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1048 <script type=\"text/javascript\" src=\"functions.js\"></script>
1049 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
1050 <!--[if gte IE 5.5000]>
1051 <script type=\"text/javascript\" src=\"pngfix.js\"></script>
1052 <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
1054 </head><body onload='init()'>";
1057 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
1059 /* if (ENABLE_UPDATE_DAEMON) {
1063 db_query($link, "INSERT INTO ttrss_scheduled_updates
1064 (owner_uid, feed_id, entered) VALUES
1065 (".$_SESSION["uid"].", '$feed', NOW())");
1069 // fixme update_rss_feed...
1072 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
1073 WHERE id = '$feed'");
1074 $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
1075 update_rss_feed($link, $feed_url, $feed, ENABLE_UPDATE_DAEMON
);
1078 if ($subop == "MarkAllRead") {
1080 if (sprintf("%d", $feed) != 0) {
1084 $tmp_result = db_query($link, "SELECT id
1085 FROM ttrss_feeds WHERE parent_feed = '$feed'
1086 ORDER BY cat_id,title");
1088 $parent_ids = array();
1090 if (db_num_rows($tmp_result) > 0) {
1091 while ($p = db_fetch_assoc($tmp_result)) {
1092 array_push($parent_ids, "feed_id = " . $p["id"]);
1095 $children_qpart = implode(" OR ", $parent_ids);
1097 db_query($link, "UPDATE ttrss_user_entries
1098 SET unread = false,last_read = NOW()
1099 WHERE (feed_id = '$feed' OR $children_qpart)
1100 AND owner_uid = " . $_SESSION["uid"]);
1103 db_query($link, "UPDATE ttrss_user_entries
1104 SET unread = false,last_read = NOW()
1105 WHERE feed_id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
1108 } else if ($feed < 0 && $feed > -10) { // special, like starred
1111 db_query($link, "UPDATE ttrss_user_entries
1112 SET unread = false,last_read = NOW()
1113 WHERE marked = true AND owner_uid = ".$_SESSION["uid"]);
1116 } else if ($feed < -10) { // label
1118 // TODO make this more efficient
1120 $label_id = -$feed - 11;
1122 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
1123 WHERE id = '$label_id'");
1126 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
1128 db_query($link, "BEGIN");
1130 $tmp2_result = db_query($link,
1134 ttrss_user_entries,ttrss_entries
1138 owner_uid = " . $_SESSION["uid"]);
1140 while ($tmp_line = db_fetch_assoc($tmp2_result)) {
1141 db_query($link, "UPDATE
1144 unread = false, last_read = NOW()
1146 int_id = " . $tmp_line["int_id"]);
1149 db_query($link, "COMMIT");
1151 /* db_query($link, "UPDATE ttrss_user_entries,ttrss_entries
1152 SET unread = false,last_read = NOW()
1155 AND owner_uid = ".$_SESSION["uid"]); */
1159 db_query($link, "BEGIN");
1161 $tag_name = db_escape_string($feed);
1163 $result = db_query($link, "SELECT post_int_id FROM ttrss_tags
1164 WHERE tag_name = '$tag_name' AND owner_uid = " . $_SESSION["uid"]);
1166 while ($line = db_fetch_assoc($result)) {
1167 db_query($link, "UPDATE ttrss_user_entries SET
1168 unread = false, last_read = NOW()
1169 WHERE int_id = " . $line["post_int_id"]);
1171 db_query($link, "COMMIT");
1176 $search = db_escape_string($_GET["search"]);
1177 $search_mode = db_escape_string($_GET["smode"]);
1180 $search_query_part = "(upper(ttrss_entries.title) LIKE upper('%$search%')
1181 OR ttrss_entries.content LIKE '%$search%') AND";
1183 $search_query_part = "";
1186 $view_query_part = "";
1188 if ($view_mode == "Adaptive") {
1190 $view_query_part = " ";
1191 } else if ($feed != -1) {
1192 $unread = getFeedUnread($link, $feed);
1194 $view_query_part = " unread = true AND ";
1199 if ($view_mode == "Starred") {
1200 $view_query_part = " marked = true AND ";
1203 if ($view_mode == "Unread") {
1204 $view_query_part = " unread = true AND ";
1207 if ($limit && $limit != "All") {
1208 $limit_query_part = "LIMIT " . $limit;
1211 $vfeed_query_part = "";
1213 // override query strategy and enable feed display when searching globally
1214 if ($search && $search_mode == "All feeds") {
1215 $query_strategy_part = "ttrss_entries.id > 0";
1216 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1217 } else if (sprintf("%d", $feed) == 0) {
1218 $query_strategy_part = "ttrss_entries.id > 0";
1219 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
1220 id = feed_id) as feed_title,";
1221 } else if ($feed >= 0) {
1223 $tmp_result = db_query($link, "SELECT id
1224 FROM ttrss_feeds WHERE parent_feed = '$feed'
1225 ORDER BY cat_id,title");
1227 $parent_ids = array();
1229 if (db_num_rows($tmp_result) > 0) {
1230 while ($p = db_fetch_assoc($tmp_result)) {
1231 array_push($parent_ids, "feed_id = " . $p["id"]);
1234 $query_strategy_part = sprintf("(feed_id = %d OR %s)",
1235 $feed, implode(" OR ", $parent_ids));
1237 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1239 $query_strategy_part = "feed_id = '$feed'";
1241 } else if ($feed == -1) { // starred virtual feed
1242 $query_strategy_part = "marked = true";
1243 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1244 } else if ($feed <= -10) { // labels
1245 $label_id = -$feed - 11;
1247 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
1248 WHERE id = '$label_id'");
1250 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
1252 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1254 $query_strategy_part = "id > 0"; // dumb
1257 $order_by = "updated DESC";
1259 // if ($feed < -10) {
1260 // $order_by = "feed_id,updated DESC";
1265 if ($search && $search_mode == "All feeds") {
1266 $feed_title = "Global search results ($search)";
1267 } else if ($search && sprintf("%d", $feed) == 0) {
1268 $feed_title = "Feed search results ($search, $feed)";
1269 } else if ($feed > 0) {
1270 $result = db_query($link, "SELECT title,site_url,last_error FROM ttrss_feeds
1271 WHERE id = '$feed'");
1273 $feed_title = db_fetch_result($result, 0, "title");
1274 $feed_site_url = db_fetch_result($result, 0, "site_url");
1275 $last_error = db_fetch_result($result, 0, "last_error");
1277 } else if ($feed == -1) {
1278 $feed_title = "Starred articles";
1279 } else if ($feed < -10) {
1280 $label_id = -$feed - 11;
1281 $result = db_query($link, "SELECT description FROM ttrss_labels
1282 WHERE id = '$label_id'");
1283 $feed_title = db_fetch_result($result, 0, "description");
1288 if ($feed < -10) error_reporting (0);
1290 print "<div id=\"headlinesContainer\">";
1292 if (sprintf("%d", $feed) != 0) {
1295 $feed_kind = "Feeds";
1297 $feed_kind = "Labels";
1300 // if (!$vfeed_query_part) {
1301 $content_query_part = "content as content_preview,";
1303 // $content_query_part = "";
1306 $result = db_query($link, "SELECT
1307 ttrss_entries.id,ttrss_entries.title,
1308 SUBSTRING(updated,1,16) as updated,
1309 unread,feed_id,marked,link,last_read,
1310 SUBSTRING(last_read,1,19) as last_read_noms,
1313 SUBSTRING(updated,1,19) as updated_noms
1315 ttrss_entries,ttrss_user_entries,ttrss_feeds
1317 ttrss_user_entries.feed_id = ttrss_feeds.id AND
1318 ttrss_user_entries.ref_id = ttrss_entries.id AND
1319 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
1322 $query_strategy_part ORDER BY $order_by
1323 $limit_query_part");
1328 $feed_kind = "Tags";
1330 $result = db_query($link, "SELECT
1331 ttrss_entries.id as id,title,
1332 SUBSTRING(updated,1,16) as updated,
1334 marked,link,last_read,
1335 SUBSTRING(last_read,1,19) as last_read_noms,
1338 SUBSTRING(updated,1,19) as updated_noms
1340 ttrss_entries,ttrss_user_entries,ttrss_tags
1342 ref_id = ttrss_entries.id AND
1343 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
1344 post_int_id = int_id AND tag_name = '$feed' AND
1347 $query_strategy_part ORDER BY $order_by
1348 $limit_query_part");
1352 print "<div align='center'>
1353 Could not display feed (query failed). Please check label match syntax or local configuration.</div>";
1357 function print_headline_subtoolbar($link, $feed_site_url, $feed_title) {
1359 print "<table class=\"headlinesSubToolbar\"
1360 width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
1362 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1364 print "<td class=\"headlineActions\">
1366 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
1367 'RROW-', 'RCHK-', true, '', true)\">All</a>,
1368 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
1369 'RROW-', 'RCHK-', true, 'Unread', true)\">Unread</a>,
1370 <a href=\"javascript:selectTableRowsByIdPrefix('headlinesList',
1371 'RROW-', 'RCHK-', false)\">None</a>
1373 Toggle: <a href=\"javascript:selectionToggleUnread()\">Unread</a>,
1374 <a href=\"javascript:selectionToggleMarked()\">Starred</a>";
1379 print "<td class=\"headlineActions\">
1381 <a href=\"javascript:cdmSelectArticles('all')\">All</a>,
1382 <a href=\"javascript:cdmSelectArticles('unread')\">Unread</a>,
1383 <a href=\"javascript:cdmSelectArticles('none')\">None</a>
1385 Toggle: <a href=\"javascript:selectionToggleUnread(true)\">Unread</a>,
1386 <a href=\"javascript:selectionToggleMarked(true)\">Starred</a>";
1393 print "<td align='center' class='small'>
1394 <a class=\"warning\" href=\"javascript:alert('TT-RSS encountered an error while trying to update this feed.\\n\\n$last_error')\">Could not update this feed.</a></td>";
1397 print "<td class=\"headlineTitle\">";
1399 if ($feed_site_url) {
1400 print "<a target=\"_blank\" href=\"$feed_site_url\">$feed_title</a>";
1406 print "</tr></table>";
1410 if (db_num_rows($result) > 0) {
1412 print_headline_subtoolbar($link, $feed_site_url, $feed_title);
1414 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1415 print "<table class=\"headlinesList\" id=\"headlinesList\"
1416 cellspacing=\"0\" width=\"100%\">";
1421 error_reporting (DEFAULT_ERROR_LEVEL
);
1425 while ($line = db_fetch_assoc($result)) {
1427 $class = ($lnum %
2) ?
"even" : "odd";
1430 $feed_id = $line["feed_id"];
1432 if ($line["last_read"] == "" &&
1433 ($line["unread"] != "t" && $line["unread"] != "1")) {
1435 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
1438 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
1442 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
1450 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
1451 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
1452 alt=\"Reset mark\" onclick='javascript:toggleMark($id)'>";
1454 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
1455 alt=\"Set mark\" onclick='javascript:toggleMark($id)'>";
1458 $content_link = "<a href=\"javascript:view($id,$feed_id);\">" .
1459 $line["title"] . "</a>";
1461 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1462 $updated_fmt = smart_date_time(strtotime($line["updated"]));
1464 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1465 $updated_fmt = date($short_date, strtotime($line["updated"]));
1468 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
1469 $content_preview = truncate_string(strip_tags($line["content_preview"]),
1473 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1475 print "<tr class='$class' id='RROW-$id'>";
1477 print "<td class='hlUpdatePic'>$update_pic</td>";
1479 print "<td class='hlSelectRow'>
1480 <input type=\"checkbox\" onclick=\"toggleSelectRow(this)\"
1481 class=\"feedCheckBox\" id=\"RCHK-$id\">
1484 print "<td class='hlMarkedPic'>$marked_pic</td>";
1486 if ($line["feed_title"]) {
1487 print "<td class='hlContent'>$content_link</td>";
1488 print "<td class='hlFeed'>
1489 <a href='javascript:viewfeed($feed_id)'>".
1490 $line["feed_title"]."</a> </td>";
1492 print "<td class='hlContent' valign='middle'>";
1494 print "<a href=\"javascript:view($id,$feed_id);\">" .
1497 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
1499 if ($content_preview) {
1500 print "<span class=\"contentPreview\"> - $content_preview</span>";
1508 print "<td class=\"hlUpdated\"><nobr>$updated_fmt </nobr></td>";
1515 $add_class = "Unread";
1520 print "<div class=\"cdmArticle$add_class\" id=\"RROW-$id\">";
1522 print "<div class=\"cdmHeader\">";
1524 print "<div style=\"float : right\">$updated_fmt</div>";
1526 print "<a target=\"new\" href=\"".$line["link"]."\">".$line["title"]."</a>";
1528 if ($line["feed_title"]) {
1529 print " (<a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>)";
1534 print "<div class=\"cdmContent\">" . $line["content_preview"] . "</div>";
1536 print "<div style=\"float : right\">$marked_pic</div>
1537 <div class=\"cdmFooter\">
1538 <input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
1539 'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\"></div>";
1548 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1552 print_headline_subtoolbar($link, "javascript:catchupPage()", "Mark page as read");
1556 print "<div width='100%' align='center'>No articles found.</div>";
1561 print "<script type=\"text/javascript\">
1562 document.onkeydown = hotkey_handler;
1563 // if (parent.daemon_enabled) parent.updateTitle('$feed_title');
1564 update_all_counters('$feed');
1568 print "</body></html>";
1572 if ($op == "pref-rpc") {
1574 $subop = $_GET["subop"];
1576 if ($subop == "unread") {
1577 $ids = split(",", db_escape_string($_GET["ids"]));
1578 foreach ($ids as $id) {
1579 db_query($link, "UPDATE ttrss_user_entries SET unread = true
1580 WHERE feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
1583 print "Marked selected feeds as unread.";
1586 if ($subop == "read") {
1587 $ids = split(",", db_escape_string($_GET["ids"]));
1588 foreach ($ids as $id) {
1589 db_query($link, "UPDATE ttrss_user_entries
1590 SET unread = false,last_read = NOW() WHERE
1591 feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
1594 print "Marked selected feeds as read.";
1600 if ($op == "pref-feeds") {
1602 $subop = $_REQUEST["subop"];
1603 $quiet = $_REQUEST["quiet"];
1605 if ($subop == "massSubscribe") {
1606 $ids = split(",", db_escape_string($_GET["ids"]));
1608 $subscribed = array();
1610 foreach ($ids as $id) {
1611 $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds
1614 $feed_url = db_fetch_result($result, 0, "feed_url");
1615 $title = db_fetch_result($result, 0, "title");
1617 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
1618 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
1620 if (db_num_rows($result) == 0) {
1621 $result = db_query($link,
1622 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
1623 VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)");
1625 array_push($subscribed, $title);
1629 if (count($subscribed) > 0) {
1630 print "<div class=\"notice\">";
1631 print "<b>Subscribed to feeds:</b>";
1632 print "<ul class=\"nomarks\">";
1633 foreach ($subscribed as $title) {
1634 print "<li>$title</li>";
1641 if ($subop == "browse") {
1643 if (!ENABLE_FEED_BROWSER
) {
1644 print "Feed browser is administratively disabled.";
1648 print "<div class=\"infoBoxContents\">";
1650 print "<h1>Feed browser</h1>";
1652 print "<p>Showing top 50 registered feeds, sorted by popularity:</p>";
1654 $result = db_query($link, "SELECT feed_url,count(id) AS subscribers
1656 WHERE auth_login = '' AND auth_pass = '' AND private = false
1657 GROUP BY feed_url ORDER BY subscribers DESC LIMIT 50");
1659 print "<ul class='browseFeedList' id='browseFeedList'>";
1663 while ($line = db_fetch_assoc($result)) {
1664 $feed_url = $line["feed_url"];
1665 $subscribers = $line["subscribers"];
1667 $sub_result = db_query($link, "SELECT id
1668 FROM ttrss_feeds WHERE feed_url = '$feed_url' AND owner_uid =" .
1671 if (db_num_rows($sub_result) > 0) {
1672 continue; // already subscribed
1675 $det_result = db_query($link, "SELECT site_url,title,id
1676 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
1678 $details = db_fetch_assoc($det_result);
1680 $icon_file = ICONS_DIR
. "/" . $details["id"] . ".ico";
1682 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1683 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL
.
1684 "/".$details["id"].".ico\">";
1686 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1689 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
1690 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
1692 $class = ($feedctr %
2) ?
"even" : "odd";
1694 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
1695 "$feed_icon " . db_unescape_string($details["title"]) .
1696 " <span class='subscribers'>($subscribers)</span></li>";
1701 if ($feedctr == 0) {
1702 print "<li>No feeds found to subscribe.</li>";
1707 print "<div align='center'>
1708 <input type=\"submit\" class=\"button\"
1709 onclick=\"feedBrowserSubscribe()\" value=\"Subscribe\">
1710 <input type='submit' class='button'
1711 onclick=\"closeInfoBox()\" value=\"Cancel\"></div>";
1717 if ($subop == "editfeed") {
1718 $feed_id = db_escape_string($_GET["id"]);
1720 $result = db_query($link,
1721 "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
1722 owner_uid = " . $_SESSION["uid"]);
1724 $title = htmlspecialchars(db_unescape_string(db_fetch_result($result,
1727 print "<div class=\"infoBoxContents\">";
1729 $icon_file = ICONS_DIR
. "/$feed_id.ico";
1731 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1732 $feed_icon = "<img width=\"16\" height=\"16\"
1733 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
1738 print "<h1>$feed_icon $title</h1>";
1740 print "<table width='100%'>";
1744 print "<tr class='$row_class'><td>Title:</td>";
1745 print "<td><input id=\"iedit_title\" value=\"$title\"></td></tr>";
1747 $feed_url = db_fetch_result($result, 0, "feed_url");
1748 $feed_url = htmlspecialchars(db_unescape_string(db_fetch_result($result,
1750 $row_class = toggleEvenOdd($row_class);
1752 print "<tr class='$row_class'><td>Feed URL:</td>";
1753 print "<td><input id=\"iedit_link\" value=\"$feed_url\"></td></tr>";
1755 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1757 $cat_id = db_fetch_result($result, 0, "cat_id");
1759 $row_class = toggleEvenOdd($row_class);
1761 print "<tr class='$row_class'><td>Category:</td>";
1763 print "<select id=\"iedit_fcat\">";
1764 print "<option id=\"0\">Uncategorized</option>";
1766 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feed_categories
1767 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1769 if (db_num_rows($tmp_result) > 0) {
1770 print "<option disabled>--------</option>";
1773 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1774 if ($tmp_line["id"] == $cat_id) {
1775 $is_selected = "selected";
1779 printf("<option $is_selected id='%d'>%s</option>",
1780 $tmp_line["id"], $tmp_line["title"]);
1783 print "</select></td>";
1788 $update_interval = db_fetch_result($result, 0, "update_interval");
1789 $row_class = toggleEvenOdd($row_class);
1791 print "<tr class='$row_class'><td>Update Interval:</td>";
1792 print "<td><input id=\"iedit_updintl\"
1793 value=\"$update_interval\"></td></tr>";
1795 $row_class = toggleEvenOdd($row_class);
1796 print "<tr class='$row_class'><td>Link to:</td>";
1798 $tmp_result = db_query($link, "SELECT COUNT(id) AS count
1799 FROM ttrss_feeds WHERE parent_feed = '$feed_id'");
1801 $linked_count = db_fetch_result($tmp_result, 0, "count");
1803 $parent_feed = db_fetch_result($result, 0, "parent_feed");
1805 if ($linked_count > 0) {
1806 $disabled = "disabled";
1809 print "<select $disabled id=\"iedit_parent_feed\">";
1811 print "<option id=\"0\">Not linked</option>";
1813 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1815 $cat_qpart = "AND cat_id = '$cat_id'";
1817 $cat_qpart = "AND cat_id IS NULL";
1821 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
1822 WHERE id != '$feed_id' AND owner_uid = ".$_SESSION["uid"]."
1823 $cat_qpart ORDER BY title");
1825 if (db_num_rows($tmp_result) > 0) {
1826 print "<option disabled>--------</option>";
1829 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1830 if ($tmp_line["id"] == $parent_feed) {
1831 $is_selected = "selected";
1835 printf("<option $is_selected id='%d'>%s</option>",
1836 $tmp_line["id"], $tmp_line["title"]);
1839 print "</select></td>";
1842 $purge_interval = db_fetch_result($result, 0, "purge_interval");
1843 $row_class = toggleEvenOdd($row_class);
1845 print "<tr class='$row_class'><td>Purge Days:</td>";
1846 print "<td><input id=\"iedit_purgintl\"
1847 value=\"$purge_interval\"></td></tr>";
1849 // print "<tr><td colspan=\"2\"><b>Authentication</b></td></tr>";
1851 $row_class = toggleEvenOdd($row_class);
1852 $auth_login = db_fetch_result($result, 0, "auth_login");
1854 print "<tr class='$row_class'><td>Login:</td>";
1855 print "<td><input id=\"iedit_login\"
1856 value=\"$auth_login\"></td></tr>";
1858 $row_class = toggleEvenOdd($row_class);
1859 $auth_pass = db_fetch_result($result, 0, "auth_pass");
1861 print "<tr class='$row_class'><td>Password:</td>";
1862 print "<td><input type=\"password\" id=\"iedit_pass\"
1863 value=\"$auth_pass\"></td></tr>";
1865 $row_class = toggleEvenOdd($row_class);
1866 $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
1869 $checked = "checked";
1874 print "<tr class='$row_class'><td>Options:</td>";
1875 print "<td><input type=\"checkbox\" id=\"iedit_private\"
1876 $checked><label for=\"iedit_private\">Hide from feed browser</label>
1882 print "<div align='center'>
1883 <input type=\"submit\" class=\"button\"
1884 onclick=\"feedEditSave()\" value=\"Save\">
1885 <input type='submit' class='button'
1886 onclick=\"feedEditCancel()\" value=\"Cancel\"></div>";
1890 if ($subop == "editSave") {
1891 $feed_title = db_escape_string($_POST["t"]);
1892 $feed_link = db_escape_string($_POST["l"]);
1893 $upd_intl = db_escape_string($_POST["ui"]);
1894 $purge_intl = db_escape_string($_POST["pi"]);
1895 $feed_id = db_escape_string($_POST["id"]);
1896 $cat_id = db_escape_string($_POST["catid"]);
1897 $auth_login = db_escape_string($_POST["login"]);
1898 $auth_pass = db_escape_string($_POST["pass"]);
1899 $parent_feed = db_escape_string($_POST["pfeed"]);
1900 $private = db_escape_string($_POST["is_pvt"]);
1902 if (strtoupper($upd_intl) == "DEFAULT")
1905 if (strtoupper($upd_intl) == "DISABLED")
1908 if (strtoupper($purge_intl) == "DEFAULT")
1911 if (strtoupper($purge_intl) == "DISABLED")
1915 $category_qpart = "cat_id = '$cat_id'";
1917 $category_qpart = 'cat_id = NULL';
1920 if ($parent_feed != 0) {
1921 $parent_qpart = "parent_feed = '$parent_feed'";
1923 $parent_qpart = 'parent_feed = NULL';
1926 $result = db_query($link, "UPDATE ttrss_feeds SET
1929 title = '$feed_title', feed_url = '$feed_link',
1930 update_interval = '$upd_intl',
1931 purge_interval = '$purge_intl',
1932 auth_login = '$auth_login',
1933 auth_pass = '$auth_pass',
1934 private = '$private'
1935 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
1938 if ($subop == "saveCat") {
1939 $cat_title = db_escape_string($_GET["title"]);
1940 $cat_id = db_escape_string($_GET["id"]);
1942 $result = db_query($link, "UPDATE ttrss_feed_categories SET
1943 title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
1947 if ($subop == "remove") {
1949 if (!WEB_DEMO_MODE
) {
1951 $ids = split(",", db_escape_string($_GET["ids"]));
1953 foreach ($ids as $id) {
1954 db_query($link, "DELETE FROM ttrss_feeds
1955 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1957 $icons_dir = ICONS_DIR
;
1959 if (file_exists($icons_dir . "/$id.ico")) {
1960 unlink($icons_dir . "/$id.ico");
1966 if ($subop == "add") {
1968 if (!WEB_DEMO_MODE
) {
1970 $feed_link = db_escape_string(trim($_GET["link"]));
1971 $cat_id = db_escape_string($_GET["cid"]);
1973 if ($cat_id == "0" ||
!$cat_id) {
1974 $cat_qpart = "NULL";
1976 $cat_qpart = "'$cat_id'";
1979 $result = db_query($link,
1980 "SELECT id FROM ttrss_feeds
1981 WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]);
1983 if (db_num_rows($result) == 0) {
1985 $result = db_query($link,
1986 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
1987 VALUES ('".$_SESSION["uid"]."', '$feed_link',
1988 '[Unknown]', $cat_qpart)");
1990 $result = db_query($link,
1991 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'
1992 AND owner_uid = " . $_SESSION["uid"]);
1994 $feed_id = db_fetch_result($result, 0, "id");
1997 update_rss_feed($link, $feed_link, $feed_id, true);
2001 print "<div class=\"warning\">
2002 Feed <b>$feed_link</b> already exists in the database.
2008 if ($subop == "addCat") {
2010 if (!WEB_DEMO_MODE
) {
2012 $feed_cat = db_escape_string(trim($_GET["cat"]));
2014 $result = db_query($link,
2015 "SELECT id FROM ttrss_feed_categories
2016 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
2018 if (db_num_rows($result) == 0) {
2020 $result = db_query($link,
2021 "INSERT INTO ttrss_feed_categories (owner_uid,title)
2022 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
2026 print "<div class=\"warning\">
2027 Category <b>$feed_cat</b> already exists in the database.
2035 if ($subop == "removeCats") {
2037 if (!WEB_DEMO_MODE
) {
2039 $ids = split(",", db_escape_string($_GET["ids"]));
2041 foreach ($ids as $id) {
2043 db_query($link, "BEGIN");
2045 $result = db_query($link,
2046 "SELECT count(id) as num_feeds FROM ttrss_feeds
2047 WHERE cat_id = '$id'");
2049 $num_feeds = db_fetch_result($result, 0, "num_feeds");
2051 if ($num_feeds == 0) {
2052 db_query($link, "DELETE FROM ttrss_feed_categories
2053 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
2056 print "<div class=\"warning\">
2057 Unable to delete non empty feed categories.</div>";
2061 db_query($link, "COMMIT");
2066 if ($subop == "categorize") {
2068 if (!WEB_DEMO_MODE
) {
2070 $ids = split(",", db_escape_string($_GET["ids"]));
2072 $cat_id = db_escape_string($_GET["cat_id"]);
2075 $cat_id_qpart = 'NULL';
2077 $cat_id_qpart = "'$cat_id'";
2080 db_query($link, "BEGIN");
2082 foreach ($ids as $id) {
2084 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
2085 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
2088 db_query($link, "COMMIT");
2095 // print "<h3>Edit Feeds</h3>";
2097 $result = db_query($link, "SELECT id,title,feed_url,last_error
2098 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
2100 if (db_num_rows($result) > 0) {
2102 print "<div class=\"warning\">";
2104 // print"<img class=\"closeButton\"
2105 // onclick=\"javascript:hideParentElement(this);\" src=\"images/close.png\">";
2107 print "<a href=\"javascript:showBlockElement('feedUpdateErrors')\">
2108 <b>Feeds with update errors</b> (click to expand)</a>";
2110 print "<ul id=\"feedUpdateErrors\" class=\"nomarks\">";
2112 while ($line = db_fetch_assoc($result)) {
2113 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
2114 $line["last_error"];
2122 $feed_search = db_escape_string($_GET["search"]);
2124 if (array_key_exists("search", $_GET)) {
2125 $_SESSION["prefs_feed_search"] = $feed_search;
2127 $feed_search = $_SESSION["prefs_feed_search"];
2130 print "<table width='100%' class=\"prefGenericAddBox\"
2131 cellspacing='0' cellpadding='0'><tr>
2133 <input id=\"fadd_link\"
2134 onchange=\"javascript:addFeed()\"
2136 <input type=\"submit\" class=\"button\"
2137 onclick=\"javascript:addFeed()\" value=\"Add feed\">";
2139 if (ENABLE_FEED_BROWSER
) {
2140 print " (<a href='javascript:browseFeeds()'>Top 50</a>)";
2143 print "</td><td align='right'>
2144 <input id=\"feed_search\" size=\"20\"
2145 onchange=\"javascript:updateFeedList()\"
2146 value=\"$feed_search\">
2147 <input type=\"submit\" class=\"button\"
2148 onclick=\"javascript:updateFeedList()\" value=\"Search\">
2152 $feeds_sort = db_escape_string($_GET["sort"]);
2154 if (!$feeds_sort ||
$feeds_sort == "undefined") {
2155 $feeds_sort = $_SESSION["pref_sort_feeds"];
2156 if (!$feeds_sort) $feeds_sort = "title";
2159 $_SESSION["pref_sort_feeds"] = $feeds_sort;
2162 $search_qpart = "(UPPER(F1.title) LIKE UPPER('%$feed_search%') OR
2163 UPPER(F1.feed_url) LIKE UPPER('%$feed_search%')) AND";
2168 $result = db_query($link, "SELECT
2172 substring(F1.last_updated,1,16) AS last_updated,
2177 F2.title AS parent_title,
2178 C1.title AS category
2181 LEFT JOIN ttrss_feeds AS F2
2182 ON (F1.parent_feed = F2.id)
2183 LEFT JOIN ttrss_feed_categories AS C1
2184 ON (F1.cat_id = C1.id)
2186 $search_qpart F1.owner_uid = '".$_SESSION["uid"]."'
2187 ORDER by category,$feeds_sort,title");
2189 if (db_num_rows($result) != 0) {
2191 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2193 print "<p><table width=\"100%\" cellspacing=\"0\"
2194 class=\"prefFeedList\" id=\"prefFeedList\">";
2195 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2197 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
2198 'FEEDR-', 'FRCHK-', true)\">All</a>,
2199 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
2200 'FEEDR-', 'FRCHK-', false)\">None</a>
2203 if (!get_pref($link, 'ENABLE_FEED_CATS')) {
2204 print "<tr class=\"title\">
2205 <td width='5%' align='center'> </td>
2206 <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
2207 <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
2208 <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td>
2209 <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Days</a></td></tr>";
2216 while ($line = db_fetch_assoc($result)) {
2218 $feed_id = $line["id"];
2219 $cat_id = $line["cat_id"];
2221 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
2222 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
2223 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
2225 if ($line["update_interval"] == "0") $line["update_interval"] = "Default";
2226 if ($line["update_interval"] == "-1") $line["update_interval"] = "Disabled";
2227 if ($line["purge_interval"] == "0") $line["purge_interval"] = "Default";
2228 if ($line["purge_interval"] < 0) $line["purge_interval"] = "Disabled";
2230 if (!$edit_cat) $edit_cat = "Uncategorized";
2233 if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
2236 print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>";
2238 print "<tr class=\"title\">
2239 <td width='5%' align='center'> </td>
2240 <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
2241 <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
2242 <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td>
2243 <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Days</a></td></tr>";
2245 $cur_cat_id = $cat_id;
2248 $class = ($lnum %
2) ?
"even" : "odd";
2249 $this_row_id = "id=\"FEEDR-$feed_id\"";
2251 print "<tr class=\"$class\" $this_row_id>";
2253 $icon_file = ICONS_DIR
. "/$feed_id.ico";
2255 if (file_exists($icon_file) && filesize($icon_file) > 0) {
2256 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL
. "/$feed_id.ico\">";
2258 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
2260 // print "<td class='feedIcon'>$feed_icon</td>";
2262 print "<td class='feedSelect'><input onclick='toggleSelectRow(this);'
2263 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
2265 $edit_title = truncate_string($edit_title, 40);
2266 $edit_link = truncate_string($edit_link, 60);
2268 $parent_title = $line["parent_title"];
2269 if ($parent_title) {
2270 $parent_title = "<span class='groupPrompt'>(linked to
2271 $parent_title)</span>";
2274 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
2275 "$feed_icon $edit_title $parent_title" . "</a></td>";
2277 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
2278 $edit_link . "</a></td>";
2280 /* if (get_pref($link, 'ENABLE_FEED_CATS')) {
2281 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
2282 $edit_cat . "</a></td>";
2285 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
2286 $line["update_interval"] . "</a></td>";
2288 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
2289 $line["purge_interval"] . "</a></td>";
2300 if ($subop == "edit") {
2301 print "Edit feed:
2302 <input type=\"submit\" class=\"button\"
2303 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
2304 <input type=\"submit\" class=\"button\"
2305 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
2310 <input type=\"submit\" class=\"button\"
2311 onclick=\"javascript:selectedFeedDetails()\" value=\"Details\">
2312 <input type=\"submit\" class=\"button\"
2313 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
2314 <input type=\"submit\" class=\"button\"
2315 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
2317 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2319 print " ";
2321 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2322 WHERE owner_uid = ".$_SESSION["uid"]."
2325 print "<select id=\"sfeed_set_fcat\">";
2326 print "<option id=\"0\">Uncategorized</option>";
2328 if (db_num_rows($result) != 0) {
2330 print "<option disabled>--------</option>";
2332 while ($line = db_fetch_assoc($result)) {
2333 printf("<option id='%d'>%s</option>",
2334 $line["id"], $line["title"]);
2340 print " <input type=\"submit\" class=\"button\"
2341 onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Set category\">";
2345 if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
2347 <input type=\"submit\" class=\"button\"
2348 onclick=\"javascript:readSelectedFeeds(true)\" value=\"Mark as read\">
2349 <input type=\"submit\" class=\"button\"
2350 onclick=\"javascript:readSelectedFeeds(false)\"
2351 value=\"Mark as unread\"> ";
2355 All feeds: <input type=\"submit\"
2356 class=\"button\" onclick=\"gotoExportOpml()\"
2357 value=\"Export OPML\">";
2361 print "<p>No feeds defined.</p>";
2365 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2367 print "<h3>Edit Categories</h3>";
2369 // print "<h3>Categories</h3>";
2371 print "<div class=\"prefGenericAddBox\">
2372 <input id=\"fadd_cat\"
2373 onchange=\"javascript:addFeedCat()\"
2376 type=\"submit\" class=\"button\"
2377 onclick=\"javascript:addFeedCat()\" value=\"Add category\"></div>";
2379 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2380 WHERE owner_uid = ".$_SESSION["uid"]."
2383 if (db_num_rows($result) != 0) {
2385 print "<p><table width=\"100%\" class=\"prefFeedCatList\"
2386 cellspacing=\"0\" id=\"prefFeedCatList\">";
2388 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2390 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
2391 'FCATR-', 'FCCHK-', true)\">All</a>,
2392 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
2393 'FCATR-', 'FCCHK-', false)\">None</a>
2396 print "<tr class=\"title\">
2397 <td width=\"5%\"></td><td width=\"80%\">Title</td>
2402 while ($line = db_fetch_assoc($result)) {
2404 $class = ($lnum %
2) ?
"even" : "odd";
2406 $cat_id = $line["id"];
2408 $edit_cat_id = $_GET["id"];
2410 if ($subop == "editCat" && $cat_id != $edit_cat_id) {
2414 $this_row_id = "id=\"FCATR-$cat_id\"";
2417 print "<tr class=\"$class\" $this_row_id>";
2419 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
2421 if (!$edit_cat_id ||
$subop != "editCat") {
2423 print "<td align='center'><input onclick='toggleSelectRow(this);'
2424 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
2426 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
2427 $edit_title . "</a></td>";
2429 } else if ($cat_id != $edit_cat_id) {
2431 print "<td><input disabled=\"true\" type=\"checkbox\"
2432 id=\"FRCHK-".$line["id"]."\"></td>";
2434 print "<td>$edit_title</td>";
2438 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2440 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
2453 if ($subop == "editCat") {
2454 print "Edit category:
2455 <input type=\"submit\" class=\"button\"
2456 onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\">
2457 <input type=\"submit\" class=\"button\"
2458 onclick=\"javascript:feedCatEditSave()\" value=\"Save\">";
2463 <input type=\"submit\" class=\"button\"
2464 onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\">
2465 <input type=\"submit\" class=\"button\"
2466 onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">";
2471 print "<p>No feed categories defined.</p>";
2475 print "<h3>Import OPML</h3>
2476 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
2477 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">
2478 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
2479 type=\"submit\" value=\"Import\">
2484 if ($op == "pref-filters") {
2486 $subop = $_GET["subop"];
2487 $quiet = $_GET["quiet"];
2489 if ($subop == "editSave") {
2491 $regexp = db_escape_string($_GET["r"]);
2492 $descr = db_escape_string($_GET["d"]);
2493 $match = db_escape_string($_GET["m"]);
2494 $filter_id = db_escape_string($_GET["id"]);
2495 $feed_id = db_escape_string($_GET["fid"]);
2496 $action_id = db_escape_string($_GET["aid"]);
2501 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2504 $result = db_query($link, "UPDATE ttrss_filters SET
2505 reg_exp = '$regexp',
2506 description = '$descr',
2508 action_id = '$action_id',
2509 filter_type = (SELECT id FROM ttrss_filter_types WHERE
2510 description = '$match')
2511 WHERE id = '$filter_id'");
2514 if ($subop == "remove") {
2516 if (!WEB_DEMO_MODE
) {
2518 $ids = split(",", db_escape_string($_GET["ids"]));
2520 foreach ($ids as $id) {
2521 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
2527 if ($subop == "add") {
2529 if (!WEB_DEMO_MODE
) {
2531 $regexp = db_escape_string(trim($_GET["regexp"]));
2532 $match = db_escape_string(trim($_GET["match"]));
2533 $feed_id = db_escape_string($_GET["fid"]);
2534 $action_id = db_escape_string($_GET["aid"]);
2539 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2542 $result = db_query($link,
2543 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
2546 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
2547 description = '$match'),'".$_SESSION["uid"]."',
2548 $feed_id, '$action_id')");
2554 $result = db_query($link, "SELECT description
2555 FROM ttrss_filter_types ORDER BY description");
2557 $filter_types = array();
2559 while ($line = db_fetch_assoc($result)) {
2560 array_push($filter_types, $line["description"]);
2563 print "<div class=\"prefGenericAddBox\">
2564 <input id=\"fadd_regexp\" size=\"40\"> ";
2566 print_select("fadd_match", "Title", $filter_types);
2568 print " <select id=\"fadd_feed\">";
2570 print "<option selected id=\"0\">All feeds</option>";
2572 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
2573 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2575 if (db_num_rows($result) > 0) {
2576 print "<option disabled>--------</option>";
2579 while ($line = db_fetch_assoc($result)) {
2580 printf("<option id='%d'>%s</option>", $line["id"], $line["title"]);
2583 print "</select> ";
2585 print " Action: ";
2587 print "<select id=\"fadd_action\">";
2589 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2592 while ($line = db_fetch_assoc($result)) {
2593 printf("<option id='%d'>%s</option>", $line["id"], $line["description"]);
2596 print "</select> ";
2598 print "<input type=\"submit\"
2599 class=\"button\" onclick=\"javascript:addFilter()\"
2600 value=\"Add filter\">";
2604 $result = db_query($link, "SELECT
2605 ttrss_filters.id AS id,reg_exp,
2606 ttrss_filters.description AS description,
2607 ttrss_filter_types.name AS filter_type_name,
2608 ttrss_filter_types.description AS filter_type_descr,
2610 ttrss_filter_actions.description AS action_description,
2611 ttrss_feeds.title AS feed_title
2613 ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN
2614 ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id)
2616 filter_type = ttrss_filter_types.id AND
2617 ttrss_filter_actions.id = action_id AND
2618 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
2621 if (db_num_rows($result) != 0) {
2623 print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\"
2624 id=\"prefFilterList\">";
2626 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2628 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
2629 'FILRR-', 'FICHK-', true)\">All</a>,
2630 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
2631 'FILRR-', 'FICHK-', false)\">None</a>
2634 print "<tr class=\"title\">
2635 <td align='center' width=\"5%\"> </td>
2636 <td width=\"20%\">Filter expression</td>
2637 <td width=\"20%\">Feed</td>
2638 <td width=\"15%\">Match</td>
2639 <td width=\"15%\">Action</td>
2640 <td width=\"30%\">Description</td></tr>";
2644 while ($line = db_fetch_assoc($result)) {
2646 $class = ($lnum %
2) ?
"even" : "odd";
2648 $filter_id = $line["id"];
2649 $edit_filter_id = $_GET["id"];
2651 if ($subop == "edit" && $filter_id != $edit_filter_id) {
2655 $this_row_id = "id=\"FILRR-$filter_id\"";
2658 print "<tr class=\"$class\" $this_row_id>";
2660 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
2661 $line["description"] = htmlspecialchars($line["description"]);
2663 if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
2665 if (!$edit_filter_id ||
$subop != "edit") {
2667 if (!$line["description"]) $line["description"] = "[No description]";
2669 print "<td align='center'><input onclick='toggleSelectRow(this);'
2670 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
2672 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2673 $line["reg_exp"] . "</td>";
2675 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2676 $line["feed_title"] . "</td>";
2678 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2679 $line["filter_type_descr"] . "</td>";
2681 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2682 $line["action_description"] . "</td>";
2684 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2685 $line["description"] . "</td>";
2687 } else if ($filter_id != $edit_filter_id) {
2689 if (!$line["description"]) $line["description"] = "[No description]";
2691 print "<td><input disabled=\"true\" type=\"checkbox\"
2692 id=\"FICHK-".$line["id"]."\"></td>";
2694 print "<td>".$line["reg_exp"]."</td>";
2695 print "<td>".$line["feed_title"]."</td>";
2696 print "<td>".$line["filter_type_descr"]."</td>";
2697 print "<td>".$line["action_description"]."</td>";
2698 print "<td>".$line["description"]."</td>";
2702 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2704 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
2708 print "<select id=\"iedit_feed\">";
2709 print "<option id=\"0\">All feeds</option>";
2711 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
2712 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2714 if (db_num_rows($tmp_result) > 0) {
2715 print "<option disabled>--------</option>";
2718 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2719 if ($tmp_line["id"] == $line["feed_id"]) {
2720 $is_selected = "selected";
2724 printf("<option $is_selected id='%d'>%s</option>",
2725 $tmp_line["id"], $tmp_line["title"]);
2728 print "</select></td>";
2731 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
2735 print "<select id=\"iedit_filter_action\">";
2737 $tmp_result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2738 ORDER BY description");
2740 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2741 if ($tmp_line["description"] == $line["action_description"]) {
2742 $is_selected = "selected";
2746 printf("<option $is_selected id='%d'>%s</option>",
2747 $tmp_line["id"], $tmp_line["description"]);
2750 print "</select></td>";
2753 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2765 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
2772 if ($subop == "edit") {
2774 <input type=\"submit\" class=\"button\"
2775 onclick=\"javascript:filterEditSave()\" value=\"Save\">
2776 <input type=\"submit\" class=\"button\"
2777 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">";
2783 <input type=\"submit\" class=\"button\"
2784 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
2785 <input type=\"submit\" class=\"button\"
2786 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
2791 print "<p>No filters defined.</p>";
2796 // We need to accept raw SQL data in label queries, so not everything is escaped
2797 // here, this is by design. If you don't like the whole idea, disable labels
2798 // altogether with GLOBAL_ENABLE_LABELS = false
2800 if ($op == "pref-labels") {
2802 if (!GLOBAL_ENABLE_LABELS
) {
2806 $subop = $_GET["subop"];
2808 if ($subop == "test") {
2810 $expr = $_GET["expr"];
2811 $descr = $_GET["descr"];
2813 print "<div class='infoBoxContents'>";
2815 print "<h1>Label «$descr»</h1>";
2817 // print "<p><b>Expression</b>: $expr</p>";
2819 $result = db_query($link,
2820 "SELECT count(id) AS num_matches
2821 FROM ttrss_entries,ttrss_user_entries
2823 ttrss_user_entries.ref_id = ttrss_entries.id AND
2824 owner_uid = " . $_SESSION["uid"]);
2826 $num_matches = db_fetch_result($result, 0, "num_matches");;
2828 if ($num_matches > 0) {
2830 print "<p>Query returned <b>$num_matches</b> matches, first 5 follow:</p>";
2832 $result = db_query($link,
2834 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
2835 FROM ttrss_entries,ttrss_user_entries
2837 ttrss_user_entries.ref_id = ttrss_entries.id
2838 AND owner_uid = " . $_SESSION["uid"] . "
2839 ORDER BY date_entered DESC LIMIT 5");
2841 print "<ul class=\"nomarks\">";
2842 while ($line = db_fetch_assoc($result)) {
2843 print "<li>".$line["title"].
2844 " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
2849 print "<p>Query didn't return any matches.</p>";
2854 print "<div align='center'>
2855 <input type='submit' class='button'
2856 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2860 if ($subop == "editSave") {
2862 $sql_exp = $_GET["s"];
2863 $descr = $_GET["d"];
2864 $label_id = db_escape_string($_GET["id"]);
2866 // print "$sql_exp : $descr : $label_id";
2868 $result = db_query($link, "UPDATE ttrss_labels SET
2869 sql_exp = '$sql_exp',
2870 description = '$descr'
2871 WHERE id = '$label_id'");
2874 if ($subop == "remove") {
2876 if (!WEB_DEMO_MODE
) {
2878 $ids = split(",", db_escape_string($_GET["ids"]));
2880 foreach ($ids as $id) {
2881 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
2887 if ($subop == "add") {
2889 if (!WEB_DEMO_MODE
) {
2891 // no escaping is done here on purpose
2892 $exp = trim($_GET["exp"]);
2894 $result = db_query($link,
2895 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
2896 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
2900 print "<div class=\"prefGenericAddBox\">
2901 <input size=\"40\" id=\"ladd_expr\"> ";
2903 print"<input type=\"submit\" class=\"button\"
2904 onclick=\"javascript:addLabel()\" value=\"Add label\"></div>";
2906 $result = db_query($link, "SELECT
2907 id,sql_exp,description
2911 owner_uid = ".$_SESSION["uid"]."
2912 ORDER by description");
2914 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2916 if (db_num_rows($result) != 0) {
2918 print "<p><table width=\"100%\" cellspacing=\"0\"
2919 class=\"prefLabelList\" id=\"prefLabelList\">";
2921 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2923 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2924 'LILRR-', 'LICHK-', true)\">All</a>,
2925 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2926 'LILRR-', 'LICHK-', false)\">None</a>
2929 print "<tr class=\"title\">
2930 <td align='center' width=\"5%\"> </td>
2931 <td width=\"40%\">SQL expression
2932 <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a>
2934 <td width=\"40%\">Caption</td></tr>";
2938 while ($line = db_fetch_assoc($result)) {
2940 $class = ($lnum %
2) ?
"even" : "odd";
2942 $label_id = $line["id"];
2943 $edit_label_id = $_GET["id"];
2945 if ($subop == "edit" && $label_id != $edit_label_id) {
2949 $this_row_id = "id=\"LILRR-$label_id\"";
2952 print "<tr class=\"$class\" $this_row_id>";
2954 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
2955 $line["description"] = htmlspecialchars($line["description"]);
2957 if (!$edit_label_id ||
$subop != "edit") {
2959 if (!$line["description"]) $line["description"] = "[No caption]";
2961 print "<td align='center'><input onclick='toggleSelectRow(this);'
2962 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
2964 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2965 $line["sql_exp"] . "</td>";
2967 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2968 $line["description"] . "</td>";
2970 } else if ($label_id != $edit_label_id) {
2972 if (!$line["description"]) $line["description"] = "[No description]";
2974 print "<td><input disabled=\"true\" type=\"checkbox\"
2975 id=\"LICHK-".$line["id"]."\"></td>";
2977 print "<td>".$line["sql_exp"]."</td>";
2978 print "<td>".$line["description"]."</td>";
2982 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2984 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
2987 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2999 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
3006 if ($subop == "edit") {
3008 <input type=\"submit\" class=\"button\"
3009 onclick=\"javascript:labelTest()\" value=\"Test\">
3010 <input type=\"submit\" class=\"button\"
3011 onclick=\"javascript:labelEditSave()\" value=\"Save\">
3012 <input type=\"submit\" class=\"button\"
3013 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">";
3019 <input type=\"submit\" class=\"button\"
3020 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
3021 <input type=\"submit\" class=\"button\"
3022 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
3025 print "<p>No labels defined.</p>";
3029 if ($op == "error") {
3030 print "<div width=\"100%\" align='center'>";
3031 $msg = $_GET["msg"];
3036 if ($op == "help") {
3037 if (!$_GET["noheaders"]) {
3039 <title>Tiny Tiny RSS : Help</title>
3040 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
3041 <script type=\"text/javascript\" src=\"functions.js\"></script>
3042 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
3046 $tid = sprintf("%d", $_GET["tid"]);
3048 print "<div class='infoBoxContents'>";
3050 if (file_exists("help/$tid.php")) {
3051 include("help/$tid.php");
3053 print "<p>Help topic not found.</p>";
3058 print "<div align='center'>
3059 <input type='submit' class='button'
3060 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3062 if (!$_GET["noheaders"]) {
3063 print "</body></html>";
3070 $param = $_GET["param"];
3072 if ($id == "quickAddFeed") {
3075 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
3078 if (get_pref($link, 'ENABLE_FEED_CATS')) {
3079 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
3080 WHERE owner_uid = ".$_SESSION["uid"]."
3083 print " <select id=\"qafCat\">";
3084 print "<option id=\"0\">Uncategorized</option>";
3086 if (db_num_rows($result) != 0) {
3088 print "<option disabled>--------</option>";
3090 while ($line = db_fetch_assoc($result)) {
3091 printf("<option id='%d'>%s</option>",
3092 $line["id"], $line["title"]);
3099 print " <input class=\"button\"
3100 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
3101 <input class=\"button\"
3102 type=\"submit\" onclick=\"javascript:closeDlg()\"
3106 if ($id == "quickDelFeed") {
3108 $param = db_escape_string($param);
3110 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
3114 $f_title = db_fetch_result($result, 0, "title");
3116 print "Remove current feed (<b>$f_title</b>)?
3117 <input class=\"button\"
3118 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
3119 <input class=\"button\"
3120 type=\"submit\" onclick=\"javascript:closeDlg()\"
3123 print "Error: Feed $param not found.
3124 <input class=\"button\"
3125 type=\"submit\" onclick=\"javascript:closeDlg()\"
3130 if ($id == "search") {
3132 $active_feed_id = db_escape_string($_GET["param"]);
3134 print "<input id=\"searchbox\" class=\"extSearch\"
3135 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
3136 onchange=\"javascript:search()\">
3137 <select id=\"searchmodebox\">
3138 <option selected>All feeds</option>";
3140 if ($active_feed_id) {
3141 print "<option>This feed</option>";
3143 print "<option disabled>This feed</option>";
3147 <input type=\"submit\"
3148 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
3149 <input class=\"button\"
3150 type=\"submit\" onclick=\"javascript:closeDlg()\"
3155 if ($id == "quickAddFilter") {
3157 $result = db_query($link, "SELECT description
3158 FROM ttrss_filter_types ORDER BY description");
3160 $filter_types = array();
3162 while ($line = db_fetch_assoc($result)) {
3163 array_push($filter_types, $line["description"]);
3168 print "<tr><td>Match:</td><td><input id=\"fadd_regexp\" size=\"40\"> ";
3170 print_select("fadd_match", "Title", $filter_types);
3173 print "<tr><td>Feed:</td><td><select id=\"fadd_feed\">";
3175 print "<option selected id=\"0\">All feeds</option>";
3177 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
3178 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
3180 if (db_num_rows($result) > 0) {
3181 print "<option disabled>--------</option>";
3184 while ($line = db_fetch_assoc($result)) {
3185 if ($param == $line["id"]) {
3186 $selected = "selected";
3190 printf("<option id='%d' %s>%s</option>", $line["id"], $selected, $line["title"]);
3193 print "</select></td></tr>";
3195 print "<tr><td>Action:</td>";
3197 print "<td><select id=\"fadd_action\">";
3199 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
3202 while ($line = db_fetch_assoc($result)) {
3203 printf("<option id='%d'>%s</option>", $line["id"], $line["description"]);
3208 print "</td></tr><tr><td colspan=\"2\" align=\"right\">";
3210 print "<input type=\"submit\"
3211 class=\"button\" onclick=\"javascript:qaddFilter()\"
3212 value=\"Add filter\"> ";
3214 print "<input class=\"button\"
3215 type=\"submit\" onclick=\"javascript:closeDlg()\"
3218 print "</td></tr></table>";
3222 // update feeds of all users, may be used anonymously
3223 if ($op == "globalUpdateFeeds") {
3225 $result = db_query($link, "SELECT id FROM ttrss_users");
3227 while ($line = db_fetch_assoc($result)) {
3228 $user_id = $line["id"];
3229 // print "<!-- updating feeds of uid $user_id -->";
3230 update_all_feeds($link, false, $user_id);
3234 <message msg=\"All feeds updated\"/>
3239 if ($op == "pref-prefs") {
3241 $subop = $_REQUEST["subop"];
3243 if ($subop == "Save configuration") {
3245 if (WEB_DEMO_MODE
) {
3246 header("Location: prefs.php");
3250 $_SESSION["prefs_op_result"] = "save-config";
3252 $_SESSION["prefs_cache"] = false;
3254 foreach (array_keys($_POST) as $pref_name) {
3256 $pref_name = db_escape_string($pref_name);
3257 $value = db_escape_string($_POST[$pref_name]);
3259 $result = db_query($link, "SELECT type_name
3260 FROM ttrss_prefs,ttrss_prefs_types
3261 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
3263 if (db_num_rows($result) > 0) {
3265 $type_name = db_fetch_result($result, 0, "type_name");
3267 // print "$pref_name : $type_name : $value<br>";
3269 if ($type_name == "bool") {
3270 if ($value == "1") {
3275 } else if ($type_name == "integer") {
3276 $value = sprintf("%d", $value);
3279 // print "$pref_name : $type_name : $value<br>";
3281 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
3282 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
3286 header("Location: prefs.php");
3290 } else if ($subop == "getHelp") {
3292 $pref_name = db_escape_string($_GET["pn"]);
3294 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
3295 WHERE pref_name = '$pref_name'");
3297 if (db_num_rows($result) > 0) {
3298 $help_text = db_fetch_result($result, 0, "help_text");
3301 print "Unknown option: $pref_name";
3304 } else if ($subop == "Change e-mail") {
3306 if (WEB_DEMO_MODE
) {
3307 header("Location: prefs.php");
3311 $email = db_escape_string($_GET["email"]);
3312 $active_uid = $_SESSION["uid"];
3315 db_query($link, "UPDATE ttrss_users SET email = '$email'
3316 WHERE id = '$active_uid'");
3319 header("Location: prefs.php");
3321 } else if ($subop == "Change password") {
3323 if (WEB_DEMO_MODE
) {
3324 header("Location: prefs.php");
3328 $old_pw = $_POST["OLD_PASSWORD"];
3329 $new_pw = $_POST["OLD_PASSWORD"];
3331 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
3332 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
3334 $active_uid = $_SESSION["uid"];
3336 if ($old_pw && $new_pw) {
3338 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
3340 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3341 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
3342 pwd_hash = '$old_pw_hash')");
3344 if (db_num_rows($result) == 1) {
3345 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
3346 WHERE id = '$active_uid'");
3348 $_SESSION["pwd_change_result"] = "ok";
3350 $_SESSION["pwd_change_result"] = "failed";
3354 header("Location: prefs.php");
3356 } else if ($subop == "Reset to defaults") {
3358 if (WEB_DEMO_MODE
) {
3359 header("Location: prefs.php");
3363 $_SESSION["prefs_op_result"] = "reset-to-defaults";
3365 if (DB_TYPE
== "pgsql") {
3366 db_query($link,"UPDATE ttrss_user_prefs
3367 SET value = ttrss_prefs.def_value
3368 WHERE owner_uid = '".$_SESSION["uid"]."' AND
3369 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
3371 db_query($link, "DELETE FROM ttrss_user_prefs
3372 WHERE owner_uid = ".$_SESSION["uid"]);
3373 initialize_user_prefs($link, $_SESSION["uid"]);
3376 header("Location: prefs.php");
3378 } else if ($subop == "Change theme") {
3380 $theme = db_escape_string($_POST["theme"]);
3382 if ($theme == "Default") {
3383 $theme_qpart = 'NULL';
3385 $theme_qpart = "'$theme'";
3388 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
3389 WHERE theme_name = '$theme'");
3391 if (db_num_rows($result) == 1) {
3392 $theme_id = db_fetch_result($result, 0, "id");
3393 $theme_path = db_fetch_result($result, 0, "theme_path");
3399 db_query($link, "UPDATE ttrss_users SET
3400 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
3402 $_SESSION["theme"] = $theme_path;
3404 header("Location: prefs.php");
3408 if (!SINGLE_USER_MODE
) {
3410 $result = db_query($link, "SELECT id,email FROM ttrss_users
3411 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
3412 pwd_hash = 'SHA1:".sha1("password")."')");
3414 if (db_num_rows($result) != 0) {
3415 print "<div class=\"warning\">
3416 Your password is at default value, please change it.
3420 if ($_SESSION["pwd_change_result"] == "failed") {
3421 print "<div class=\"warning\">
3422 There was an error while changing your password.
3426 if ($_SESSION["pwd_change_result"] == "ok") {
3427 print "<div class=\"notice\">
3428 Password changed successfully.
3432 $_SESSION["pwd_change_result"] = "";
3434 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
3435 print "<div class=\"notice\">
3436 Your configuration was reset to defaults.
3440 if ($_SESSION["prefs_op_result"] == "save-config") {
3441 print "<div class=\"notice\">
3442 Your configuration was saved successfully.
3446 $_SESSION["prefs_op_result"] = "";
3448 print "<form action=\"backend.php\" method=\"GET\">";
3450 print "<table width=\"100%\" class=\"prefPrefsList\">";
3451 print "<tr><td colspan='3'><h3>Personal data</h3></tr></td>";
3453 $result = db_query($link, "SELECT email FROM ttrss_users
3454 WHERE id = ".$_SESSION["uid"]);
3456 $email = db_fetch_result($result, 0, "email");
3458 print "<tr><td width=\"40%\">E-mail</td>";
3459 print "<td><input class=\"editbox\" name=\"email\"
3460 value=\"$email\"></td></tr>";
3464 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3466 print "<p><input class=\"button\" type=\"submit\"
3467 value=\"Change e-mail\" name=\"subop\">";
3471 print "<form action=\"backend.php\" method=\"POST\">";
3473 print "<table width=\"100%\" class=\"prefPrefsList\">";
3474 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
3476 print "<tr><td width=\"40%\">Old password</td>";
3477 print "<td><input class=\"editbox\" type=\"password\"
3478 name=\"OLD_PASSWORD\"></td></tr>";
3480 print "<tr><td width=\"40%\">New password</td>";
3482 print "<td><input class=\"editbox\" type=\"password\"
3483 name=\"NEW_PASSWORD\"></td></tr>";
3487 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3489 print "<p><input class=\"button\" type=\"submit\"
3490 value=\"Change password\" name=\"subop\">";
3496 $result = db_query($link, "SELECT
3497 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
3499 $user_theme_id = db_fetch_result($result, 0, "theme_id");
3501 $result = db_query($link, "SELECT
3502 id,theme_name FROM ttrss_themes ORDER BY theme_name");
3504 if (db_num_rows($result) > 0) {
3506 print "<form action=\"backend.php\" method=\"POST\">";
3507 print "<table width=\"100%\" class=\"prefPrefsList\">";
3508 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
3509 print "<tr><td width=\"40%\">Select theme</td>";
3510 print "<td><select name=\"theme\">";
3511 print "<option>Default</option>";
3512 print "<option disabled>--------</option>";
3514 while ($line = db_fetch_assoc($result)) {
3515 if ($line["id"] == $user_theme_id) {
3516 $selected = "selected";
3520 print "<option $selected>" . $line["theme_name"] . "</option>";
3522 print "</select></td></tr>";
3524 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3525 print "<p><input class=\"button\" type=\"submit\"
3526 value=\"Change theme\" name=\"subop\">";
3530 $result = db_query($link, "SELECT
3531 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
3532 section_name,def_value
3533 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
3534 WHERE type_id = ttrss_prefs_types.id AND
3535 section_id = ttrss_prefs_sections.id AND
3536 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
3537 owner_uid = ".$_SESSION["uid"]."
3538 ORDER BY section_id,short_desc");
3540 print "<form action=\"backend.php\" method=\"POST\">";
3544 $active_section = "";
3546 while ($line = db_fetch_assoc($result)) {
3548 if ($active_section != $line["section_name"]) {
3550 if ($active_section != "") {
3554 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
3556 $active_section = $line["section_name"];
3558 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
3559 // print "<tr class=\"title\">
3560 // <td width=\"25%\">Option</td><td>Value</td></tr>";
3565 // $class = ($lnum % 2) ? "even" : "odd";
3569 $type_name = $line["type_name"];
3570 $pref_name = $line["pref_name"];
3571 $value = $line["value"];
3572 $def_value = $line["def_value"];
3573 $help_text = $line["help_text"];
3575 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
3577 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
3583 if ($type_name == "bool") {
3584 // print_select($pref_name, $value, array("true", "false"));
3586 if ($value == "true") {
3592 print_radio($pref_name, $value, array("Yes", "No"));
3595 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
3607 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3609 print "<p><input class=\"button\" type=\"submit\"
3610 name=\"subop\" value=\"Save configuration\">";
3612 print " <input class=\"button\" type=\"submit\"
3613 name=\"subop\" onclick=\"return validatePrefsReset()\"
3614 value=\"Reset to defaults\"></p>";
3622 if ($op == "pref-users") {
3624 $subop = $_GET["subop"];
3626 if ($subop == "editSave") {
3628 if (!WEB_DEMO_MODE
) {
3630 $login = db_escape_string($_GET["l"]);
3631 $uid = db_escape_string($_GET["id"]);
3632 $access_level = sprintf("%d", $_GET["al"]);
3633 $email = db_escape_string($_GET["e"]);
3635 db_query($link, "UPDATE ttrss_users SET login = '$login',
3636 access_level = '$access_level', email = '$email' WHERE id = '$uid'");
3639 } else if ($subop == "remove") {
3641 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3643 $ids = split(",", db_escape_string($_GET["ids"]));
3645 foreach ($ids as $id) {
3646 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
3650 } else if ($subop == "add") {
3652 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3654 $login = db_escape_string(trim($_GET["login"]));
3655 $tmp_user_pwd = make_password(8);
3656 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3658 db_query($link, "INSERT INTO ttrss_users
3659 (login,pwd_hash,access_level,last_login)
3660 VALUES ('$login', '$pwd_hash', 0, NOW())");
3663 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3664 login = '$login' AND pwd_hash = '$pwd_hash'");
3666 if (db_num_rows($result) == 1) {
3668 $new_uid = db_fetch_result($result, 0, "id");
3670 print "<div class=\"notice\">Added user <b>".$_GET["login"].
3671 "</b> with password <b>$tmp_user_pwd</b>.</div>";
3673 initialize_user($link, $new_uid);
3677 print "<div class=\"warning\">Error while adding user <b>".
3678 $_GET["login"].".</b></div>";
3682 } else if ($subop == "resetPass") {
3684 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
3686 $uid = db_escape_string($_GET["id"]);
3688 $result = db_query($link, "SELECT login,email
3689 FROM ttrss_users WHERE id = '$uid'");
3691 $login = db_fetch_result($result, 0, "login");
3692 $email = db_fetch_result($result, 0, "email");
3693 $tmp_user_pwd = make_password(8);
3694 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3696 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
3697 WHERE id = '$uid'");
3699 print "<div class=\"notice\">Changed password of
3700 user <b>$login</b> to <b>$tmp_user_pwd</b>.";
3702 if (MAIL_RESET_PASS
&& $email) {
3703 print " Notifying <b>$email</b>.";
3705 mail("$login <$email>", "Password reset notification",
3708 "Your password for this TT-RSS installation was reset by".
3709 " an administrator.\n".
3711 "Your new password is $tmp_user_pwd, please remember".
3712 " it for later reference.\n".
3714 "Sincerely, TT-RSS Mail Daemon.", "From: " . MAIL_FROM
);
3722 print "<div class=\"prefGenericAddBox\">
3723 <input id=\"uadd_box\" onchange=\"javascript:addUser()\" size=\"40\"> ";
3725 print"<input type=\"submit\" class=\"button\"
3726 onclick=\"javascript:addUser()\" value=\"Add user\"></div>";
3728 $result = db_query($link, "SELECT
3729 id,login,access_level,email,
3730 SUBSTRING(last_login,1,16) as last_login
3735 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
3737 print "<p><table width=\"100%\" cellspacing=\"0\"
3738 class=\"prefUserList\" id=\"prefUserList\">";
3740 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
3742 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3743 'UMRR-', 'UMCHK-', true)\">All</a>,
3744 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3745 'UMRR-', 'UMCHK-', false)\">None</a>
3748 print "<tr class=\"title\">
3749 <td align='center' width=\"5%\"> </td>
3750 <td width='20%'>Username</td>
3751 <td width='20%'>E-mail</td>
3752 <td width='20%'>Access Level</td>
3753 <td width='20%'>Last login</td></tr>";
3757 while ($line = db_fetch_assoc($result)) {
3759 $class = ($lnum %
2) ?
"even" : "odd";
3762 $edit_uid = $_GET["id"];
3764 if ($subop == "edit" && $uid != $edit_uid) {
3768 $this_row_id = "id=\"UMRR-$uid\"";
3771 print "<tr class=\"$class\" $this_row_id>";
3773 $line["login"] = htmlspecialchars($line["login"]);
3775 $line["last_login"] = date(get_pref($link, 'SHORT_DATE_FORMAT'),
3776 strtotime($line["last_login"]));
3778 /* if ($uid == $_SESSION["uid"]) {
3780 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
3781 id=\"UMCHK-".$line["id"]."\"></td>";
3783 print "<td>".$line["login"]."</td>";
3784 print "<td>".$line["email"]."</td>";
3785 print "<td>".$line["access_level"]."</td>";
3787 } else */ if (!$edit_uid ||
$subop != "edit") {
3789 print "<td align='center'><input onclick='toggleSelectRow(this);'
3790 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
3792 print "<td><a href=\"javascript:editUser($uid);\">" .
3793 $line["login"] . "</td>";
3795 print "<td><a href=\"javascript:editUser($uid);\">" .
3796 $line["email"] . "</td>";
3798 print "<td><a href=\"javascript:editUser($uid);\">" .
3799 $line["access_level"] . "</td>";
3801 } else if ($uid != $edit_uid) {
3803 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
3804 id=\"UMCHK-".$line["id"]."\"></td>";
3806 print "<td>".$line["login"]."</td>";
3807 print "<td>".$line["email"]."</td>";
3808 print "<td>".$line["access_level"]."</td>";
3812 print "<td align='center'>
3813 <input disabled=\"true\" type=\"checkbox\" checked></td>";
3815 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
3818 print "<td><input id=\"iedit_email\" value=\"".$line["email"].
3821 print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
3826 print "<td>".$line["last_login"]."</td>";
3837 if ($subop == "edit") {
3839 <input type=\"submit\" class=\"button\"
3840 onclick=\"javascript:userEditSave()\" value=\"Save\">
3841 <input type=\"submit\" class=\"button\"
3842 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">";
3848 <input type=\"submit\" class=\"button\"
3849 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
3850 <input type=\"submit\" class=\"button\"
3851 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
3852 <input type=\"submit\" class=\"button\"
3853 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
3854 <input type=\"submit\" class=\"button\"
3855 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
3860 if ($op == "user-details") {
3862 if (WEB_DEMO_MODE ||
$_SESSION["access_level"] < 10) {
3866 /* print "<html><head>
3867 <title>Tiny Tiny RSS : User Details</title>
3868 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
3869 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
3872 $uid = sprintf("%d", $_GET["id"]);
3874 print "<div class='infoBoxContents'>";
3876 $result = db_query($link, "SELECT login,
3877 SUBSTRING(last_login,1,16) AS last_login,
3879 (SELECT COUNT(int_id) FROM ttrss_user_entries
3880 WHERE owner_uid = id) AS stored_articles
3882 WHERE id = '$uid'");
3884 if (db_num_rows($result) == 0) {
3885 print "<h1>User not found</h1>";
3889 print "<h1>User Details</h1>";
3891 print "<table width='100%'>";
3893 $login = db_fetch_result($result, 0, "login");
3894 $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'),
3895 strtotime(db_fetch_result($result, 0, "last_login")));
3896 $access_level = db_fetch_result($result, 0, "access_level");
3897 $stored_articles = db_fetch_result($result, 0, "stored_articles");
3899 print "<tr><td>Username</td><td>$login</td></tr>";
3900 print "<tr><td>Access level</td><td>$access_level</td></tr>";
3901 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
3902 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
3904 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
3905 WHERE owner_uid = '$uid'");
3907 $num_feeds = db_fetch_result($result, 0, "num_feeds");
3909 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
3911 /* $result = db_query($link, "SELECT
3912 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
3913 FROM ttrss_user_entries,ttrss_entries
3914 WHERE owner_uid = '$uid' AND ref_id = id");
3916 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
3918 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
3922 print "<h1>Subscribed feeds</h1>";
3924 $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
3925 WHERE owner_uid = '$uid' ORDER BY title");
3927 print "<ul class=\"userFeedList\">";
3929 while ($line = db_fetch_assoc($result)) {
3931 $icon_file = ICONS_URL
."/".$line["id"].".ico";
3933 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3934 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
3936 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3939 print "<li>$feed_icon <a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
3942 if (db_num_rows($result) < $num_feeds) {
3943 // FIXME - add link to show ALL subscribed feeds here somewhere
3945 class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\"> ...</li>";
3952 print "<div align='center'>
3953 <input type='submit' class='button'
3954 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3956 // print "</body></html>";
3960 if ($op == "feed-details") {
3962 // $feed_id = $_GET["id"];
3964 $feed_ids = split(",", db_escape_string($_GET["id"]));
3966 print "<div class=\"infoBoxContents\">";
3968 foreach ($feed_ids as $feed_id) {
3970 $result = db_query($link,
3973 SUBSTRING(last_updated,1,16) as last_updated,
3975 (SELECT COUNT(int_id) FROM ttrss_user_entries
3976 WHERE feed_id = id) AS total,
3977 (SELECT COUNT(int_id) FROM ttrss_user_entries
3978 WHERE feed_id = id AND unread = true) AS unread,
3979 (SELECT COUNT(int_id) FROM ttrss_user_entries
3980 WHERE feed_id = id AND marked = true) AS marked
3982 WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]);
3984 if (db_num_rows($result) == 0) return;
3986 $title = db_unescape_string(db_fetch_result($result, 0, "title"));
3987 $last_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
3988 strtotime(db_fetch_result($result, 0, "last_updated")));
3989 $feed_url = db_fetch_result($result, 0, "feed_url");
3990 $icon_url = db_fetch_result($result, 0, "icon_url");
3991 $total = db_fetch_result($result, 0, "total");
3992 $unread = db_fetch_result($result, 0, "unread");
3993 $marked = db_fetch_result($result, 0, "marked");
3994 $site_url = db_fetch_result($result, 0, "site_url");
3996 $result = db_query($link, "SELECT COUNT(id) AS subscribed
3997 FROM ttrss_feeds WHERE feed_url = '$feed_url' AND private = false");
3999 $subscribed = db_fetch_result($result, 0, "subscribed");
4001 $icon_file = ICONS_DIR
. "/$feed_id.ico";
4003 if (file_exists($icon_file) && filesize($icon_file) > 0) {
4004 $feed_icon = "<img width=\"16\" height=\"16\"
4005 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
4010 print "<h1>$feed_icon $title</h1>";
4012 print "<table width='100%'>";
4015 print "<tr><td width='30%'>Link</td>
4016 <td><a href=\"$site_url\">$site_url</a>
4017 <a href=\"$feed_url\">(feed)</a></td>
4020 print "<tr><td width='30%'>Feed URL</td>
4021 <td><a href=\"$feed_url\">$feed_url</a></td></tr>";
4023 print "<tr><td>Last updated</td><td>$last_updated</td></tr>";
4024 print "<tr><td>Total articles</td><td>$total</td></tr>";
4025 print "<tr><td>Unread articles</td><td>$unread</td></tr>";
4026 print "<tr><td>Starred articles</td><td>$marked</td></tr>";
4027 print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>";
4031 /* $result = db_query($link, "SELECT title,
4032 SUBSTRING(updated,1,16) AS updated,unread
4033 FROM ttrss_entries,ttrss_user_entries
4034 WHERE ref_id = id AND feed_id = '$feed_id'
4035 ORDER BY date_entered DESC LIMIT 5");
4037 if (db_num_rows($result) > 0) {
4039 print "<h1>Latest headlines</h1>";
4041 print "<ul class=\"nomarks\">";
4043 while ($line = db_fetch_assoc($result)) {
4044 if ($line["unread"] == "t" || $line["unread"] == "1") {
4045 $line["title"] = "<b>" . $line["title"] . "</b>";
4047 print "<li>" . $line["title"].
4048 " <span class=\"insensitive\">(" .
4049 date(get_pref($link, 'SHORT_DATE_FORMAT'),
4050 strtotime($line["updated"])).
4061 print "<div align='center'>
4062 <input type='submit' class='button'
4063 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
4066 if ($op == "pref-feed-browser") {
4068 if (!ENABLE_FEED_BROWSER
) {
4069 print "Feed browser is administratively disabled.";
4073 $subop = $_REQUEST["subop"];
4075 if ($subop == "details") {
4076 $id = db_escape_string($_GET["id"]);
4078 print "<div class=\"browserFeedInfo\">";
4079 print "<b>Feed information:</b>";
4080 print "<div class=\"detailsPart\">";
4082 $result = db_query($link, "SELECT
4084 SUBSTRING(last_updated,1,19) AS last_updated
4085 FROM ttrss_feeds WHERE id = '$id'");
4087 $feed_url = db_fetch_result($result, 0, "feed_url");
4088 $site_url = db_fetch_result($result, 0, "site_url");
4089 $last_updated = db_fetch_result($result, 0, "last_updated");
4091 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
4092 $last_updated = smart_date_time(strtotime($last_updated));
4094 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
4095 $last_updated = date($short_date, strtotime($last_updated));
4098 print "Site: <a href='$site_url'>$site_url</a> ".
4099 "(<a href='$feed_url'>feed</a>), ".
4100 "Last updated: $last_updated";
4104 $result = db_query($link, "SELECT
4105 ttrss_entries.title,
4107 substring(date_entered,1,19) as date_entered,
4108 substring(updated,1,19) as updated
4109 FROM ttrss_entries,ttrss_user_entries
4110 WHERE ttrss_entries.id = ref_id AND feed_id = '$id'
4111 ORDER BY updated DESC LIMIT 5");
4113 if (db_num_rows($result) > 0) {
4115 print "<b>Last headlines:</b><br>";
4117 print "<div class=\"detailsPart\">";
4118 print "<ul class=\"compact\">";
4119 while ($line = db_fetch_assoc($result)) {
4121 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
4122 $entry_dt = smart_date_time(strtotime($line["updated"]));
4124 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
4125 $entry_dt = date($short_date, strtotime($line["updated"]));
4128 print "<li>" . $line["title"] .
4129 " <span class=\"insensitive\">($entry_dt)</span></li>";
4131 print "</ul></div>";
4139 $result = db_query($link, "SELECT feed_url,count(id) AS subscribers
4141 WHERE auth_login = '' AND auth_pass = '' AND private = false
4142 GROUP BY feed_url ORDER BY subscribers DESC LIMIT 100");
4144 print "<ul class='nomarks' id='browseBigFeedList'>";
4148 while ($line = db_fetch_assoc($result)) {
4149 $feed_url = $line["feed_url"];
4150 $subscribers = $line["subscribers"];
4152 $sub_result = db_query($link, "SELECT id
4153 FROM ttrss_feeds WHERE feed_url = '$feed_url' AND owner_uid =" .
4156 if (db_num_rows($sub_result) > 0) {
4157 continue; // already subscribed
4160 $det_result = db_query($link, "SELECT site_url,title,id
4161 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
4163 $details = db_fetch_assoc($det_result);
4165 $icon_file = ICONS_DIR
. "/" . $details["id"] . ".ico";
4167 if (file_exists($icon_file) && filesize($icon_file) > 0) {
4168 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL
.
4169 "/".$details["id"].".ico\">";
4171 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
4174 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
4175 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
4177 $class = ($feedctr %
2) ?
"even" : "odd";
4179 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
4182 print "<a href=\"javascript:browserToggleExpand('".$details["id"]."')\">" .
4183 $details["title"] ."</a> " .
4184 "<span class='subscribers'>($subscribers)</span>";
4186 print "<div class=\"browserDetails\" id=\"BRDET-" . $details["id"] . "\">";
4194 if ($feedctr == 0) {
4195 print "<li>No feeds found to subscribe.</li>";
4200 print "<p>Selection:
4201 <input type='submit' class='button' onclick=\"feedBrowserSubscribe()\"
4202 value=\"Subscribe\"></p>";
4211 <!-- <?
= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?
> -->