6 if ((!$op ||
$op == "rpc" ||
$op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
7 header("Content-Type: application/xml");
10 if (!$_SESSION["uid"] && $op != "globalUpdateFeeds") {
13 print "<error error-code=\"6\"/>";
19 print "<error error-code=\"7\"/>";
23 define(SCHEMA_VERSION
, 2);
25 require_once "config.php";
26 require_once "db.php";
27 require_once "db-prefs.php";
28 require_once "functions.php";
29 require_once "magpierss/rss_fetch.inc";
31 $script_started = getmicrotime();
33 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
36 if (DB_TYPE
== "mysql") {
39 // PG seems to display its own errors just fine by default.
43 if (DB_TYPE
== "pgsql") {
44 pg_query("set client_encoding = 'utf-8'");
47 $fetch = $_GET["fetch"];
49 /* FIXME this needs reworking */
51 function getGlobalCounters($link) {
52 $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries,ttrss_user_entries
53 WHERE unread = true AND
54 ttrss_user_entries.ref_id = ttrss_entries.id AND
55 owner_uid = " . $_SESSION["uid"]);
56 $c_id = db_fetch_result($result, 0, "c_id");
57 print "<counter id='global-unread' counter='$c_id'/>";
60 function getTagCounters($link) {
62 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
63 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
64 ttrss_user_entries.ref_id = ttrss_entries.id AND
65 ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND
66 post_int_id = ttrss_user_entries.int_id AND unread = true GROUP BY tag_name
68 select tag_name,0 as count FROM ttrss_tags
69 WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]);
73 while ($line = db_fetch_assoc($result)) {
74 $tags[$line["tag_name"]] +
= $line["count"];
77 foreach (array_keys($tags) as $tag) {
78 $unread = $tags[$tag];
80 $tag = htmlspecialchars($tag);
81 print "<tag id=\"$tag\" counter=\"$unread\"/>";
85 function getLabelCounters($link) {
87 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries
88 WHERE marked = true AND ttrss_user_entries.ref_id = ttrss_entries.id AND
89 unread = true AND owner_uid = ".$_SESSION["uid"]);
91 $count = db_fetch_result($result, 0, "count");
93 print "<label id=\"-1\" counter=\"$count\"/>";
95 $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM
96 ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description");
98 while ($line = db_fetch_assoc($result)) {
100 $id = -$line["id"] - 11;
104 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_user_entries,ttrss_entries
105 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
106 ttrss_user_entries.ref_id = ttrss_entries.id AND
107 owner_uid = ".$_SESSION["uid"]);
109 $count = db_fetch_result($tmp_result, 0, "count");
111 print "<label id=\"$id\" counter=\"$count\"/>";
113 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
118 function getFeedCounter($link, $id) {
120 $result = db_query($link, "SELECT
121 count(id) as count FROM ttrss_entries,ttrss_user_entries
122 WHERE feed_id = '$id' AND unread = true
123 AND ttrss_user_entries.ref_id = ttrss_entries.id");
125 $count = db_fetch_result($result, 0, "count");
127 print "<feed id=\"$id\" counter=\"$count\"/>";
130 function getFeedCounters($link) {
132 $result = db_query($link, "SELECT id,
134 FROM ttrss_entries,ttrss_user_entries
135 WHERE feed_id = ttrss_feeds.id AND ttrss_user_entries.ref_id = ttrss_entries.id
136 AND unread = true AND owner_uid = ".$_SESSION["uid"].") as count
137 FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]);
139 while ($line = db_fetch_assoc($result)) {
142 $count = $line["count"];
144 print "<feed id=\"$id\" counter=\"$count\"/>";
148 function outputFeedList($link, $tags = false) {
151 <title>Tiny Tiny RSS : Feedlist</title>
152 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
154 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
155 print "<link rel=\"stylesheet\" type=\"text/css\"
156 href=\"tt-rss_compact.css\"/>";
158 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
159 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
162 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
163 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
164 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
165 </head><body onload=\"init()\">";
167 print "<ul class=\"feedList\" id=\"feedList\">";
169 $owner_uid = $_SESSION["uid"];
175 $result = db_query($link, "SELECT count(id) as num_starred
176 FROM ttrss_entries,ttrss_user_entries
177 WHERE marked = true AND
178 ttrss_user_entries.ref_id = ttrss_entries.id AND
179 unread = true AND owner_uid = '$owner_uid'");
180 $num_starred = db_fetch_result($result, 0, "num_starred");
184 if ($num_starred > 0) $class .= "Unread";
186 printFeedEntry(-1, $class, "Starred articles", $num_starred,
187 "images/mark_set.png", $link);
189 if (get_pref($link, 'ENABLE_LABELS')) {
191 $result = db_query($link, "SELECT id,sql_exp,description FROM
192 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
194 if (db_num_rows($result) > 0) {
195 print "<li><hr></li>";
198 while ($line = db_fetch_assoc($result)) {
202 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries
203 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
204 ttrss_user_entries.ref_id = ttrss_entries.id
205 AND owner_uid = '$owner_uid'");
207 $count = db_fetch_result($tmp_result, 0, "count");
215 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
217 printFeedEntry(-$line["id"]-11,
218 $class, $line["description"], $count, "images/label.png", $link);
223 print "<li><hr></li>";
225 $result = db_query($link, "SELECT *,
226 (SELECT count(id) FROM ttrss_entries,ttrss_user_entries
227 WHERE feed_id = ttrss_feeds.id AND
228 ttrss_user_entries.ref_id = ttrss_entries.id AND
229 owner_uid = '$owner_uid') AS total,
230 (SELECT count(id) FROM ttrss_entries,ttrss_user_entries
231 WHERE feed_id = ttrss_feeds.id AND unread = true
232 AND ttrss_user_entries.ref_id = ttrss_entries.id
233 AND owner_uid = '$owner_uid') as unread
234 FROM ttrss_feeds WHERE owner_uid = '$owner_uid' ORDER BY title");
236 $actid = $_GET["actid"];
244 while ($line = db_fetch_assoc($result)) {
246 $feed = $line["title"];
247 $feed_id = $line["id"];
249 $subop = $_GET["subop"];
251 $total = $line["total"];
252 $unread = $line["unread"];
254 // $class = ($lnum % 2) ? "even" : "odd";
258 if ($unread > 0) $class .= "Unread";
260 if ($actid == $feed_id) {
261 $class .= "Selected";
264 $total_unread +
= $unread;
266 printFeedEntry($feed_id, $class, $feed, $unread, "icons/$feed_id.ico", $link);
274 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
275 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
276 post_int_id = ttrss_user_entries.int_id AND
277 unread = true AND ref_id = ttrss_entries.id
278 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
280 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'
285 while ($line = db_fetch_assoc($result)) {
286 $tags[$line["tag_name"]] +
= $line["count"];
289 foreach (array_keys($tags) as $tag) {
291 $unread = $tags[$tag];
299 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
305 if (db_num_rows($result) == 0) {
306 print "<li>No tags/feeds to display.</li>";
311 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
318 $subop = $_GET["subop"];
320 if ($subop == "getLabelCounters") {
323 getLabelCounters($link);
325 getFeedCounter($link, $aid);
327 print "</rpc-reply>";
330 if ($subop == "getFeedCounters") {
332 getFeedCounters($link);
333 print "</rpc-reply>";
336 if ($subop == "getAllCounters") {
338 getLabelCounters($link);
339 getFeedCounters($link);
340 getTagCounters($link);
341 getGlobalCounters($link);
342 print "</rpc-reply>";
345 if ($subop == "mark") {
346 $mark = $_GET["mark"];
347 $id = db_escape_string($_GET["id"]);
355 // FIXME this needs collision testing
357 $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
358 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
361 if ($subop == "updateFeed") {
362 $feed_id = db_escape_string($_GET["feed"]);
364 $result = db_query($link,
365 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'
366 AND owner_uid = " . $_SESSION["uid"]);
368 if (db_num_rows($result) > 0) {
369 $feed_url = db_fetch_result($result, 0, "feed_url");
370 update_rss_feed($link, $feed_url, $feed_id);
374 getFeedCounter($link, $feed_id);
375 print "</rpc-reply>";
380 if ($subop == "forceUpdateAllFeeds" ||
$subop == "updateAllFeeds") {
382 update_all_feeds($link, $subop == "forceUpdateAllFeeds");
384 $omode = $_GET["omode"];
386 if (!$omode) $omode = "tfl";
389 if (strchr($omode, "l")) getLabelCounters($link);
390 if (strchr($omode, "f")) getFeedCounters($link);
391 if (strchr($omode, "t")) getTagCounters($link);
392 getGlobalCounters($link);
393 print "</rpc-reply>";
396 if ($subop == "catchupSelected") {
398 $ids = split(",", $_GET["ids"]);
400 foreach ($ids as $id) {
402 db_query($link, "UPDATE ttrss_user_entries SET unread=false,last_read = NOW()
403 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
407 print "Marked active page as read.";
410 if ($subop == "sanityCheck") {
414 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
416 $schema_version = db_fetch_result($result, 0, "schema_version");
418 if ($schema_version != SCHEMA_VERSION
) {
422 print "<error error-code='$error_code'/>";
425 if ($subop == "globalPurge") {
428 global_purge_old_posts($link, true);
429 print "</rpc-reply>";
435 if ($op == "feeds") {
437 $tags = $_GET["tags"];
439 $subop = $_GET["subop"];
441 if ($subop == "catchupAll") {
442 db_query($link, "UPDATE ttrss_user_entries SET
443 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
446 outputFeedList($link, $tags);
453 $feed_id = $_GET["feed"];
455 $result = db_query($link, "UPDATE ttrss_user_entries
456 SET unread = false,last_read = NOW()
457 WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
459 $addheader = $_GET["addheader"];
461 $result = db_query($link, "SELECT title,link,content,feed_id,comments,
462 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
463 FROM ttrss_entries,ttrss_user_entries
464 WHERE id = '$id' AND ref_id = id");
468 <title>Tiny Tiny RSS : Article $id</title>
469 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
470 <script type=\"text/javascript\" src=\"functions.js\"></script>
471 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
477 $line = db_fetch_assoc($result);
479 if ($line["icon_url"]) {
480 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
482 $feed_icon = " ";
485 if ($line["comments"] && $line["link"] != $line["comments"]) {
486 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
488 $entry_comments = "";
491 print "<div class=\"postReply\">";
493 print "<div class=\"postHeader\"><table>";
495 print "<tr><td><b>Title:</b></td>
496 <td width='100%'>" . $line["title"] . "</td></tr>";
498 print "<tr><td><b>Link:</b></td>
500 <a href=\"" . $line["link"] . "\">".$line["link"]."</a>
501 $entry_comments</td></tr>";
503 print "</table></div>";
505 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
506 print "<div class=\"postContent\">" . $line["content"] . "</div>";
510 print "<script type=\"text/javascript\">
511 update_label_counters('$feed_id');
516 print "</body></html>";
520 if ($op == "viewfeed") {
522 $feed = $_GET["feed"];
523 $skip = $_GET["skip"];
524 $subop = $_GET["subop"];
525 $view_mode = $_GET["view"];
526 $addheader = $_GET["addheader"];
527 $limit = $_GET["limit"];
530 print "Error: no feed to display.";
534 if (!$skip) $skip = 0;
536 if ($subop == "undefined") $subop = "";
540 <title>Tiny Tiny RSS : Feed $feed</title>
541 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
543 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
544 print "<link rel=\"stylesheet\"
545 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
548 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
549 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
551 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
552 <script type=\"text/javascript\" src=\"functions.js\"></script>
553 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
554 </head><body onload='init()'>";
557 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
559 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
560 WHERE id = '$feed'");
562 $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
564 update_rss_feed($link, $feed_url, $feed);
568 if ($subop == "MarkAllRead") {
570 if (sprintf("%d", $feed) != 0) {
573 db_query($link, "UPDATE ttrss_user_entries
574 SET unread = false,last_read = NOW()
575 WHERE feed_id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
577 } else if ($feed < 0 && $feed > -10) { // special, like starred
580 db_query($link, "UPDATE ttrss_user_entries
581 SET unread = false,last_read = NOW()
582 WHERE marked = true AND owner_uid = ".$_SESSION["uid"]);
585 } else if ($feed < -10) { // label
587 // TODO make this more efficient
589 $label_id = -$feed - 11;
591 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
592 WHERE id = '$label_id'");
595 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
597 db_query($link, "BEGIN");
599 $tmp2_result = db_query($link,
603 ttrss_user_entries,ttrss_entries
607 owner_uid = " . $_SESSION["uid"]);
609 while ($tmp_line = db_fetch_assoc($tmp2_result)) {
610 db_query($link, "UPDATE
613 unread = false, last_read = NOW()
615 int_id = " . $tmp_line["int_id"]);
618 db_query($link, "COMMIT");
620 /* db_query($link, "UPDATE ttrss_user_entries,ttrss_entries
621 SET unread = false,last_read = NOW()
624 AND owner_uid = ".$_SESSION["uid"]); */
628 // FIXME, implement catchup for tags
633 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
635 $search = $_GET["search"];
637 $search_mode = $_GET["smode"];
640 $search_query_part = "(upper(title) LIKE upper('%$search%')
641 OR content LIKE '%$search%') AND";
643 $search_query_part = "";
646 $view_query_part = "";
648 if ($view_mode == "Starred") {
649 $view_query_part = " marked = true AND ";
652 if ($view_mode == "Unread") {
653 $view_query_part = " unread = true AND ";
656 if ($view_mode == "Unread or Starred") {
657 $view_query_part = " (unread = true OR marked = true) AND ";
660 if ($view_mode == "Unread or Updated") {
661 $view_query_part = " (unread = true OR last_read is NULL) AND ";
664 /* $result = db_query($link, "SELECT count(id) AS total_entries
665 FROM ttrss_entries WHERE
669 $total_entries = db_fetch_result($result, 0, "total_entries"); */
671 /* $result = db_query("SELECT count(id) AS unread_entries
672 FROM ttrss_entries WHERE
677 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
679 if ($limit && $limit != "All") {
680 $limit_query_part = "LIMIT " . $limit;
683 $vfeed_query_part = "";
685 // override query strategy and enable feed display when searching globally
686 if ($search && $search_mode == "All feeds") {
687 $query_strategy_part = "id > 0";
688 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
689 id = feed_id) as feed_title,";
690 } else if (sprintf("%d", $feed) == 0) {
691 $query_strategy_part = "ttrss_entries.id > 0";
692 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
693 id = feed_id) as feed_title,";
694 } else if ($feed >= 0) {
695 $query_strategy_part = "feed_id = '$feed'";
696 } else if ($feed == -1) { // starred virtual feed
697 $query_strategy_part = "marked = true";
698 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
699 id = feed_id) as feed_title,";
700 } else if ($feed <= -10) { // labels
701 $label_id = -$feed - 11;
703 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
704 WHERE id = '$label_id'");
706 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
708 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
709 id = feed_id) as feed_title,";
711 $query_strategy_part = "id > 0"; // dumb
715 $order_by = "updated DESC";
717 // if ($feed < -10) {
718 // $order_by = "feed_id,updated DESC";
721 if ($feed < -10) error_reporting (0);
723 if (sprintf("%d", $feed) != 0) {
725 $result = db_query($link, "SELECT
726 id,title,updated,unread,feed_id,marked,link,last_read,
727 SUBSTRING(last_read,1,19) as last_read_noms,
729 SUBSTRING(updated,1,19) as updated_noms
731 ttrss_entries,ttrss_user_entries
733 ttrss_user_entries.ref_id = ttrss_entries.id AND
734 owner_uid = '".$_SESSION["uid"]."' AND
737 $query_strategy_part ORDER BY $order_by
743 $result = db_query($link, "SELECT
744 ttrss_entries.id as id,title,updated,unread,feed_id,
745 marked,link,last_read,
746 SUBSTRING(last_read,1,19) as last_read_noms,
748 SUBSTRING(updated,1,19) as updated_noms
750 ttrss_entries,ttrss_user_entries,ttrss_tags
752 ref_id = ttrss_entries.id AND
753 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
754 post_int_id = int_id AND tag_name = '$feed' AND
757 $query_strategy_part ORDER BY $order_by
762 print "<tr><td colspan='4' align='center'>
763 Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>";
769 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
773 while ($line = db_fetch_assoc($result)) {
775 $class = ($lnum %
2) ?
"even" : "odd";
778 $feed_id = $line["feed_id"];
780 // printf("L %d (%s) > U %d (%s) = %d<br>",
781 // strtotime($line["last_read_noms"]), $line["last_read_noms"],
782 // strtotime($line["updated"]), $line["updated"],
783 // strtotime($line["last_read"]) >= strtotime($line["updated"]));
785 /* if ($line["last_read"] != "" && $line["updated"] != "" &&
786 strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) {
788 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
793 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
798 if ($line["last_read"] == "" &&
799 ($line["unread"] != "t" && $line["unread"] != "1")) {
801 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
804 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
808 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
813 if ($line["marked"] == "t" ||
$line["marked"] == "1") {
814 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
815 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
817 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
818 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
821 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
822 $line["title"] . "</a>";
824 print "<tr class='$class' id='RROW-$id'>";
825 // onclick=\"javascript:view($id,$feed_id)\">
827 print "<td valign='center' align='center'>$update_pic</td>";
828 print "<td valign='center' align='center'>$marked_pic</td>";
830 print "<td width='25%'>
831 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
833 if ($line["feed_title"]) {
834 print "<td width='50%'>$content_link</td>";
835 print "<td width='20%'>
836 <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a></td>";
838 print "<td width='70%'>$content_link</td>";
847 print "<tr><td align='center'>No articles found.</td></tr>";
852 print "<script type=\"text/javascript\">
853 document.onkeydown = hotkey_handler;
854 update_label_counters('$feed');
858 print "</body></html>";
863 if ($op == "pref-rpc") {
865 $subop = $_GET["subop"];
867 if ($subop == "unread") {
868 $ids = split(",", $_GET["ids"]);
869 foreach ($ids as $id) {
870 db_query($link, "UPDATE ttrss_user_entries SET unread = true
871 WHERE feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
874 print "Marked selected feeds as unread.";
877 if ($subop == "read") {
878 $ids = split(",", $_GET["ids"]);
879 foreach ($ids as $id) {
880 db_query($link, "UPDATE ttrss_user_entries
881 SET unread = false,last_read = NOW() WHERE
882 feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
885 print "Marked selected feeds as read.";
891 if ($op == "pref-feeds") {
893 $subop = $_GET["subop"];
895 if ($subop == "editSave") {
896 $feed_title = db_escape_string($_GET["t"]);
897 $feed_link = db_escape_string($_GET["l"]);
898 $upd_intl = db_escape_string($_GET["ui"]);
899 $purge_intl = db_escape_string($_GET["pi"]);
900 $feed_id = $_GET["id"];
902 if (strtoupper($upd_intl) == "DEFAULT")
905 if (strtoupper($purge_intl) == "DEFAULT")
908 if (strtoupper($purge_intl) == "DISABLED")
911 $result = db_query($link, "UPDATE ttrss_feeds SET
912 title = '$feed_title', feed_url = '$feed_link',
913 update_interval = '$upd_intl',
914 purge_interval = '$purge_intl'
915 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
919 if ($subop == "remove") {
921 if (!WEB_DEMO_MODE
) {
923 $ids = split(",", $_GET["ids"]);
925 foreach ($ids as $id) {
926 db_query($link, "DELETE FROM ttrss_feeds
927 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
929 $icons_dir = ICONS_DIR
;
931 if (file_exists($icons_dir . "/$id.ico")) {
932 unlink($icons_dir . "/$id.ico");
938 if ($subop == "add") {
940 if (!WEB_DEMO_MODE
) {
942 $feed_link = db_escape_string(trim($_GET["link"]));
944 $result = db_query($link,
945 "SELECT id FROM ttrss_feeds
946 WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]);
948 if (db_num_rows($result) == 0) {
950 $result = db_query($link,
951 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title)
952 VALUES ('".$_SESSION["uid"]."', '$feed_link', '')");
954 $result = db_query($link,
955 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'
956 AND owner_uid = " . $_SESSION["uid"]);
958 $feed_id = db_fetch_result($result, 0, "id");
961 update_rss_feed($link, $feed_link, $feed_id);
965 print "<div class=\"warning\">
966 Feed <b>$feed_link</b> already exists in the database.
972 $result = db_query($link, "SELECT id,title,feed_url,last_error
973 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
975 if (db_num_rows($result) > 0) {
977 print "<div class=\"warning\">";
979 print "<b>Feeds with update errors:</b>";
981 print "<ul class=\"nomarks\">";
983 while ($line = db_fetch_assoc($result)) {
984 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
993 print "<div class=\"prefGenericAddBox\">
994 <input id=\"fadd_link\" size=\"40\"> <input
995 type=\"submit\" class=\"button\"
996 onclick=\"javascript:addFeed()\" value=\"Add feed\"></div>";
998 $result = db_query($link, "SELECT
999 id,title,feed_url,substring(last_updated,1,16) as last_updated,
1000 update_interval,purge_interval
1002 ttrss_feeds WHERE owner_uid = '".$_SESSION["uid"]."' ORDER by title");
1004 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1006 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
1007 print "<tr class=\"title\">
1008 <td> </td><td>Select</td><td width=\"30%\">Title</td>
1009 <td width=\"30%\">Link</td>
1010 <td width=\"10%\">Update Interval</td>
1011 <td width=\"10%\">Purge Days</td>
1012 <td>Last updated</td></tr>";
1016 while ($line = db_fetch_assoc($result)) {
1018 $class = ($lnum %
2) ?
"even" : "odd";
1020 $feed_id = $line["id"];
1022 $edit_feed_id = $_GET["id"];
1024 if ($subop == "edit" && $feed_id != $edit_feed_id) {
1028 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
1030 $icon_file = ICONS_DIR
. "/$feed_id.ico";
1032 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1033 $feed_icon = "<img width=\"16\" height=\"16\"
1034 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
1036 $feed_icon = " ";
1038 print "<td align='center'>$feed_icon</td>";
1040 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1041 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
1043 if (!$edit_feed_id ||
$subop != "edit") {
1045 print "<td><input onclick='toggleSelectRow(this);'
1046 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
1048 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1049 $edit_title . "</a></td>";
1050 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1051 $edit_link . "</a></td>";
1053 if ($line["update_interval"] == "0")
1054 $line["update_interval"] = "Default";
1056 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1057 $line["update_interval"] . "</a></td>";
1059 if ($line["purge_interval"] == "0")
1060 $line["purge_interval"] = "Default";
1062 if ($line["purge_interval"] < 0)
1063 $line["purge_interval"] = "Disabled";
1065 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1066 $line["purge_interval"] . "</a></td>";
1068 } else if ($feed_id != $edit_feed_id) {
1070 print "<td><input disabled=\"true\" type=\"checkbox\"
1071 id=\"FRCHK-".$line["id"]."\"></td>";
1073 print "<td>$edit_title</td>";
1074 print "<td>$edit_link</td>";
1076 if ($line["update_interval"] == "0")
1077 $line["update_interval"] = "Default";
1079 print "<td>" . $line["update_interval"] . "</td>";
1081 if ($line["purge_interval"] == "0")
1082 $line["purge_interval"] = "Default";
1084 if ($line["purge_interval"] < 0)
1085 $line["purge_interval"] = "Disabled";
1087 print "<td>" . $line["purge_interval"] . "</td>";
1091 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1093 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
1094 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
1095 print "<td><input id=\"iedit_updintl\" value=\"".$line["update_interval"]."\"></td>";
1096 print "<td><input id=\"iedit_purgintl\" value=\"".$line["purge_interval"]."\"></td>";
1100 if (!$line["last_updated"]) $line["last_updated"] = "Never";
1102 print "<td>" . $line["last_updated"] . "</td>";
1110 print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>";
1117 if ($subop == "edit") {
1118 print "Edit feed:
1119 <input type=\"submit\" class=\"button\"
1120 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
1121 <input type=\"submit\" class=\"button\"
1122 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1127 <input type=\"submit\" class=\"button\"
1128 onclick=\"javascript:selectedFeedDetails()\" value=\"Details\">
1129 <input type=\"submit\" class=\"button\"
1130 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
1131 <input type=\"submit\" class=\"button\"
1132 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
1134 if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
1136 <input type=\"submit\" class=\"button\"
1137 onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\">
1138 <input type=\"submit\" class=\"button\"
1139 onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\"> ";
1143 <input type=\"submit\"
1144 class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">";
1148 print "<h3>OPML Import</h3>
1149 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1150 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">
1151 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
1152 type=\"submit\" value=\"Import\">
1157 if ($op == "pref-filters") {
1159 $subop = $_GET["subop"];
1161 if ($subop == "editSave") {
1163 $regexp = db_escape_string($_GET["r"]);
1164 $descr = db_escape_string($_GET["d"]);
1165 $match = db_escape_string($_GET["m"]);
1166 $filter_id = db_escape_string($_GET["id"]);
1167 $feed_id = db_escape_string($_GET["fid"]);
1172 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
1175 $result = db_query($link, "UPDATE ttrss_filters SET
1176 reg_exp = '$regexp',
1177 description = '$descr',
1179 filter_type = (SELECT id FROM ttrss_filter_types WHERE
1180 description = '$match')
1181 WHERE id = '$filter_id'");
1184 if ($subop == "remove") {
1186 if (!WEB_DEMO_MODE
) {
1188 $ids = split(",", $_GET["ids"]);
1190 foreach ($ids as $id) {
1191 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
1197 if ($subop == "add") {
1199 if (!WEB_DEMO_MODE
) {
1201 $regexp = db_escape_string(trim($_GET["regexp"]));
1202 $match = db_escape_string(trim($_GET["match"]));
1203 $feed_id = db_escape_string($_GET["fid"]);
1208 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
1211 $result = db_query($link,
1212 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id) VALUES
1213 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
1214 description = '$match'),'".$_SESSION["uid"]."', $feed_id)");
1218 $result = db_query($link, "SELECT description
1219 FROM ttrss_filter_types ORDER BY description");
1221 $filter_types = array();
1223 while ($line = db_fetch_assoc($result)) {
1224 array_push($filter_types, $line["description"]);
1227 print "<div class=\"prefGenericAddBox\">
1228 <input id=\"fadd_regexp\" size=\"40\"> ";
1230 print_select("fadd_match", "Title", $filter_types);
1232 print " <select id=\"fadd_feed\">";
1234 print "<option selected id=\"0\">All feeds</option>";
1236 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
1237 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1239 if (db_num_rows($result) > 0) {
1240 print "<option disabled>--------</option>";
1243 while ($line = db_fetch_assoc($result)) {
1244 printf("<option id='%d'>%s</option>", $line["id"], $line["title"]);
1247 print "</select> ";
1249 print "<input type=\"submit\"
1250 class=\"button\" onclick=\"javascript:addFilter()\"
1251 value=\"Add filter\">";
1253 $result = db_query($link, "SELECT
1254 ttrss_filters.id AS id,reg_exp,
1255 ttrss_filters.description AS description,
1256 ttrss_filter_types.name AS filter_type_name,
1257 ttrss_filter_types.description AS filter_type_descr,
1259 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
1261 ttrss_filters,ttrss_filter_types
1263 filter_type = ttrss_filter_types.id AND
1264 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
1267 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
1269 print "<tr class=\"title\">
1270 <td width=\"5%\">Select</td><td width=\"30%\">Filter expression</td>
1271 <td width=\"30%\">Feed</td><td width=\"10%\">Match</td>
1272 <td width=\"30%\">Description</td></tr>";
1276 while ($line = db_fetch_assoc($result)) {
1278 $class = ($lnum %
2) ?
"even" : "odd";
1280 $filter_id = $line["id"];
1281 $edit_filter_id = $_GET["id"];
1283 if ($subop == "edit" && $filter_id != $edit_filter_id) {
1287 print "<tr class=\"$class\" id=\"FILRR-$filter_id\">";
1289 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
1290 $line["description"] = htmlspecialchars($line["description"]);
1292 if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
1294 if (!$edit_filter_id ||
$subop != "edit") {
1296 if (!$line["description"]) $line["description"] = "[No description]";
1298 print "<td><input onclick='toggleSelectRow(this);'
1299 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
1301 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1302 $line["reg_exp"] . "</td>";
1304 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1305 $line["feed_title"] . "</td>";
1307 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1308 $line["filter_type_descr"] . "</td>";
1310 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1311 $line["description"] . "</td>";
1313 } else if ($filter_id != $edit_filter_id) {
1315 if (!$line["description"]) $line["description"] = "[No description]";
1317 print "<td><input disabled=\"true\" type=\"checkbox\"
1318 id=\"FICHK-".$line["id"]."\"></td>";
1320 print "<td>".$line["reg_exp"]."</td>";
1321 print "<td>".$line["feed_title"]."</td>";
1322 print "<td>".$line["filter_type_descr"]."</td>";
1323 print "<td>".$line["description"]."</td>";
1327 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1329 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
1334 print "<select id=\"iedit_feed\">";
1336 print "<option id=\"0\">All feeds</option>";
1338 if (db_num_rows($result) > 0) {
1339 print "<option disabled>--------</option>";
1342 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
1343 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1345 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1346 if ($tmp_line["id"] == $line["feed_id"]) {
1347 $is_selected = "selected";
1351 printf("<option $is_selected id='%d'>%s</option>",
1352 $tmp_line["id"], $tmp_line["title"]);
1355 print "</select></td>";
1358 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
1361 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1373 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
1380 if ($subop == "edit") {
1382 <input type=\"submit\" class=\"button\"
1383 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
1384 <input type=\"submit\" class=\"button\"
1385 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
1391 <input type=\"submit\" class=\"button\"
1392 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
1393 <input type=\"submit\" class=\"button\"
1394 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
1398 if ($op == "pref-labels") {
1400 $subop = $_GET["subop"];
1402 if ($subop == "editSave") {
1404 $sql_exp = $_GET["s"];
1405 $descr = $_GET["d"];
1406 $label_id = db_escape_string($_GET["id"]);
1408 // print "$sql_exp : $descr : $label_id";
1410 $result = db_query($link, "UPDATE ttrss_labels SET
1411 sql_exp = '$sql_exp',
1412 description = '$descr'
1413 WHERE id = '$label_id'");
1416 if ($subop == "remove") {
1418 if (!WEB_DEMO_MODE
) {
1420 $ids = split(",", $_GET["ids"]);
1422 foreach ($ids as $id) {
1423 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
1429 if ($subop == "add") {
1431 if (!WEB_DEMO_MODE
) {
1433 // no escaping is done here on purpose
1434 $exp = trim($_GET["exp"]);
1436 $result = db_query($link,
1437 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
1438 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
1442 print "<div class=\"prefGenericAddBox\">
1443 <input size=\"40\" id=\"ladd_expr\"> ";
1445 print"<input type=\"submit\" class=\"button\"
1446 onclick=\"javascript:addLabel()\" value=\"Add label\"></div>";
1448 $result = db_query($link, "SELECT
1449 id,sql_exp,description
1453 owner_uid = ".$_SESSION["uid"]."
1454 ORDER by description");
1456 print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">";
1458 print "<tr class=\"title\">
1459 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
1460 <a class=\"helpLink\" href=\"javascript:popupHelp(1)\">(?)</a>
1462 <td width=\"40%\">Caption</td></tr>";
1466 while ($line = db_fetch_assoc($result)) {
1468 $class = ($lnum %
2) ?
"even" : "odd";
1470 $label_id = $line["id"];
1471 $edit_label_id = $_GET["id"];
1473 if ($subop == "edit" && $label_id != $edit_label_id) {
1477 print "<tr class=\"$class\" id=\"LILRR-$label_id\">";
1479 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
1480 $line["description"] = htmlspecialchars($line["description"]);
1482 if (!$edit_label_id ||
$subop != "edit") {
1484 if (!$line["description"]) $line["description"] = "[No caption]";
1486 print "<td><input onclick='toggleSelectRow(this);'
1487 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
1489 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1490 $line["sql_exp"] . "</td>";
1492 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1493 $line["description"] . "</td>";
1495 } else if ($label_id != $edit_label_id) {
1497 if (!$line["description"]) $line["description"] = "[No description]";
1499 print "<td><input disabled=\"true\" type=\"checkbox\"
1500 id=\"LICHK-".$line["id"]."\"></td>";
1502 print "<td>".$line["sql_exp"]."</td>";
1503 print "<td>".$line["description"]."</td>";
1507 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1509 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
1512 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1524 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
1531 if ($subop == "edit") {
1533 <input type=\"submit\" class=\"button\"
1534 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
1535 <input type=\"submit\" class=\"button\"
1536 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
1542 <input type=\"submit\" class=\"button\"
1543 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
1544 <input type=\"submit\" class=\"button\"
1545 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
1549 if ($op == "error") {
1550 print "<div width=\"100%\" align='center'>";
1551 $msg = $_GET["msg"];
1556 if ($op == "help") {
1558 <title>Tiny Tiny RSS : Help</title>
1559 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
1560 <script type=\"text/javascript\" src=\"functions.js\"></script>
1561 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1564 $tid = sprintf("%d", $_GET["tid"]);
1566 /* FIXME this badly needs real implementation */
1568 print "<div class='helpResponse'>";
1572 <h1
>Help
for SQL expressions
</h1
>
1574 <h2
>Description
</h2
>
1576 <p
>The
«
;SQL expression
»
; is added to WHERE clause of
1577 view feed query
. You can match on ttrss_entries table fields
1578 and even
use subselect to query additional information
. This
1579 functionality is considered to be advanced
and requires basic
1580 understanding of SQL
.</p
>
1584 <pre
>unread
= true</pre
>
1586 Matches all unread articles
1588 <pre
>title like
'%Linux%'</pre
>
1590 Matches all articles which mention Linux in the title
. You get the idea
.
1592 <p
>See the database schema included in the distribution package
for gruesome
1597 print "<div align='center'>
1598 <a class=\"helpLink\"
1599 href=\"javascript:window.close()\">(Close this window)</a></div>";
1603 print "</body></html>";
1609 $param = $_GET["param"];
1611 if ($id == "quickAddFeed") {
1612 print "Feed URL: <input
1613 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1615 <input class=\"button\"
1616 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
1617 <input class=\"button\"
1618 type=\"submit\" onclick=\"javascript:closeDlg()\"
1622 if ($id == "quickDelFeed") {
1624 $param = db_escape_string($param);
1626 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
1630 $f_title = db_fetch_result($result, 0, "title");
1632 print "Remove current feed ($f_title)?
1633 <input class=\"button\"
1634 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
1635 <input class=\"button\"
1636 type=\"submit\" onclick=\"javascript:closeDlg()\"
1639 print "Error: Feed $param not found.
1640 <input class=\"button\"
1641 type=\"submit\" onclick=\"javascript:closeDlg()\"
1646 if ($id == "search") {
1648 print "<input id=\"searchbox\" class=\"extSearch\"
1649 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1650 onchange=\"javascript:search()\">
1651 <select id=\"searchmodebox\">
1652 <option selected>All feeds</option>
1653 <option>This feed</option>
1655 <input type=\"submit\"
1656 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
1657 <input class=\"button\"
1658 type=\"submit\" onclick=\"javascript:closeDlg()\"
1665 // update feeds of all users, may be used anonymously
1666 if ($op == "globalUpdateFeeds") {
1668 $result = db_query($link, "SELECT id FROM ttrss_users");
1670 while ($line = db_fetch_assoc($result)) {
1671 $user_id = $line["id"];
1672 // print "<!-- updating feeds of uid $user_id -->";
1673 update_all_feeds($link, false, $user_id);
1677 <message msg=\"All feeds updated\"/>
1682 if ($op == "pref-prefs") {
1684 $subop = $_REQUEST["subop"];
1686 if ($subop == "Save configuration") {
1688 if (WEB_DEMO_MODE
) {
1689 header("Location: prefs.php");
1693 $_SESSION["prefs_op_result"] = "save-config";
1695 foreach (array_keys($_POST) as $pref_name) {
1697 $pref_name = db_escape_string($pref_name);
1698 $value = db_escape_string($_POST[$pref_name]);
1700 $result = db_query($link, "SELECT type_name
1701 FROM ttrss_prefs,ttrss_prefs_types
1702 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
1704 if (db_num_rows($result) > 0) {
1706 $type_name = db_fetch_result($result, 0, "type_name");
1708 // print "$pref_name : $type_name : $value<br>";
1710 if ($type_name == "bool") {
1711 if ($value == "1") {
1716 } else if ($type_name == "integer") {
1717 $value = sprintf("%d", $value);
1720 // print "$pref_name : $type_name : $value<br>";
1722 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
1723 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
1727 header("Location: prefs.php");
1731 } else if ($subop == "getHelp") {
1733 $pref_name = db_escape_string($_GET["pn"]);
1735 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
1736 WHERE pref_name = '$pref_name'");
1738 if (db_num_rows($result) > 0) {
1739 $help_text = db_fetch_result($result, 0, "help_text");
1742 print "Unknown option: $pref_name";
1745 } else if ($subop == "Change password") {
1747 if (WEB_DEMO_MODE
) {
1748 header("Location: prefs.php");
1752 $old_pw = $_POST["OLD_PASSWORD"];
1753 $new_pw = $_POST["OLD_PASSWORD"];
1755 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
1756 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
1758 $active_uid = $_SESSION["uid"];
1760 if ($old_pw && $new_pw) {
1762 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
1764 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
1765 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
1766 pwd_hash = '$old_pw_hash')");
1768 if (db_num_rows($result) == 1) {
1769 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
1770 WHERE id = '$active_uid'");
1772 $_SESSION["pwd_change_result"] = "ok";
1774 $_SESSION["pwd_change_result"] = "failed";
1778 header("Location: prefs.php");
1780 } else if ($subop == "Reset to defaults") {
1782 if (WEB_DEMO_MODE
) {
1783 header("Location: prefs.php");
1787 $_SESSION["prefs_op_result"] = "reset-to-defaults";
1789 if (DB_TYPE
== "pgsql") {
1790 db_query($link,"UPDATE ttrss_user_prefs
1791 SET value = ttrss_prefs.def_value
1792 WHERE owner_uid = '".$_SESSION["uid"]."' AND
1793 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
1795 db_query($link, "DELETE FROM ttrss_user_prefs
1796 WHERE owner_uid = ".$_SESSION["uid"]);
1797 initialize_user_prefs($link, $_SESSION["uid"]);
1800 header("Location: prefs.php");
1804 if (!SINGLE_USER_MODE
) {
1806 $result = db_query($link, "SELECT id FROM ttrss_users
1807 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
1808 pwd_hash = 'SHA1:".sha1("password")."')");
1810 if (db_num_rows($result) != 0) {
1811 print "<div class=\"warning\">
1812 Your password is at default value, please change it.
1816 if ($_SESSION["pwd_change_result"] == "failed") {
1817 print "<div class=\"warning\">
1818 There was an error while changing your password.
1822 if ($_SESSION["pwd_change_result"] == "ok") {
1823 print "<div class=\"notice\">
1824 Password changed successfully.
1828 $_SESSION["pwd_change_result"] = "";
1830 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
1831 print "<div class=\"notice\">
1832 Your configuration was reset to defaults.
1836 if ($_SESSION["prefs_op_result"] == "save-config") {
1837 print "<div class=\"notice\">
1838 Your configuration was saved successfully.
1842 $_SESSION["prefs_op_result"] = "";
1844 print "<form action=\"backend.php\" method=\"POST\">";
1846 print "<table width=\"100%\" class=\"prefPrefsList\">";
1847 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
1849 print "<tr><td width=\"40%\">Old password</td>";
1850 print "<td><input class=\"editbox\" type=\"password\"
1851 name=\"OLD_PASSWORD\"></td></tr>";
1853 print "<tr><td width=\"40%\">New password</td>";
1855 print "<td><input class=\"editbox\" type=\"password\"
1856 name=\"NEW_PASSWORD\"></td></tr>";
1860 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
1862 print "<p><input class=\"button\" type=\"submit\"
1863 value=\"Change password\" name=\"subop\">";
1869 $result = db_query($link, "SELECT
1870 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
1871 section_name,def_value
1872 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
1873 WHERE type_id = ttrss_prefs_types.id AND
1874 section_id = ttrss_prefs_sections.id AND
1875 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
1876 owner_uid = ".$_SESSION["uid"]."
1877 ORDER BY section_id,short_desc");
1879 print "<form action=\"backend.php\" method=\"POST\">";
1883 $active_section = "";
1885 while ($line = db_fetch_assoc($result)) {
1887 if ($active_section != $line["section_name"]) {
1889 if ($active_section != "") {
1893 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
1895 $active_section = $line["section_name"];
1897 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
1898 // print "<tr class=\"title\">
1899 // <td width=\"25%\">Option</td><td>Value</td></tr>";
1904 // $class = ($lnum % 2) ? "even" : "odd";
1908 $type_name = $line["type_name"];
1909 $pref_name = $line["pref_name"];
1910 $value = $line["value"];
1911 $def_value = $line["def_value"];
1912 $help_text = $line["help_text"];
1914 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
1916 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
1922 if ($type_name == "bool") {
1923 // print_select($pref_name, $value, array("true", "false"));
1925 if ($value == "true") {
1931 print_radio($pref_name, $value, array("Yes", "No"));
1934 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
1946 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
1948 print "<p><input class=\"button\" type=\"submit\"
1949 name=\"subop\" value=\"Save configuration\">";
1951 print " <input class=\"button\" type=\"submit\"
1952 name=\"subop\" value=\"Reset to defaults\"></p>";
1960 if ($op == "pref-users") {
1962 $subop = $_GET["subop"];
1964 if ($subop == "editSave") {
1966 if (!WEB_DEMO_MODE
) {
1968 $login = db_escape_string($_GET["l"]);
1969 $uid = db_escape_string($_GET["id"]);
1970 $access_level = sprintf("%d", $_GET["al"]);
1972 db_query($link, "UPDATE ttrss_users SET login = '$login', access_level = '$access_level' WHERE id = '$uid'");
1975 } else if ($subop == "remove") {
1977 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
1979 $ids = split(",", $_GET["ids"]);
1981 foreach ($ids as $id) {
1982 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
1986 } else if ($subop == "add") {
1988 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
1990 $login = db_escape_string(trim($_GET["login"]));
1991 $tmp_user_pwd = make_password(8);
1992 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
1994 db_query($link, "INSERT INTO ttrss_users (login,pwd_hash,access_level)
1995 VALUES ('$login', '$pwd_hash', 0)");
1998 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
1999 login = '$login' AND pwd_hash = '$pwd_hash'");
2001 if (db_num_rows($result) == 1) {
2003 $new_uid = db_fetch_result($result, 0, "id");
2005 print "<div class=\"notice\">Added user <b>".$_GET["login"].
2006 "</b> with password <b>$tmp_user_pwd</b>.</div>";
2008 initialize_user($link, $new_uid);
2012 print "<div class=\"warning\">Error while adding user <b>".
2013 $_GET["login"].".</b></div>";
2017 } else if ($subop == "resetPass") {
2019 if (!WEB_DEMO_MODE
&& $_SESSION["access_level"] >= 10) {
2021 $uid = db_escape_string($_GET["id"]);
2023 $result = db_query($link, "SELECT login FROM ttrss_users WHERE id = '$uid'");
2025 $login = db_fetch_result($result, 0, "login");
2026 $tmp_user_pwd = make_password(8);
2027 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
2029 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
2030 WHERE id = '$uid'");
2032 print "<div class=\"notice\">Changed password of
2033 user <b>$login</b> to <b>$tmp_user_pwd</b>.</div>";
2038 print "<div class=\"prefGenericAddBox\">
2039 <input id=\"uadd_box\" size=\"40\"> ";
2041 print"<input type=\"submit\" class=\"button\"
2042 onclick=\"javascript:addUser()\" value=\"Add user\"></div>";
2044 $result = db_query($link, "SELECT
2045 id,login,access_level,
2046 SUBSTRING(last_login,1,16) as last_login
2051 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2053 print "<p><table width=\"100%\" class=\"prefUserList\" id=\"prefUserList\">";
2055 print "<tr class=\"title\">
2056 <td width=\"5%\">Select</td>
2057 <td width='30%'>Username</td>
2058 <td width='30%'>Access Level</td>
2059 <td width='30%'>Last login</td></tr>";
2063 while ($line = db_fetch_assoc($result)) {
2065 $class = ($lnum %
2) ?
"even" : "odd";
2068 $edit_uid = $_GET["id"];
2070 if ($uid == $_SESSION["uid"] ||
($subop == "edit" && $uid != $edit_uid)) {
2074 print "<tr class=\"$class\" id=\"UMRR-$uid\">";
2076 $line["login"] = htmlspecialchars($line["login"]);
2078 if ($uid == $_SESSION["uid"]) {
2080 print "<td><input disabled=\"true\" type=\"checkbox\"
2081 id=\"UMCHK-".$line["id"]."\"></td>";
2083 print "<td>".$line["login"]."</td>";
2084 print "<td>".$line["access_level"]."</td>";
2086 } else if (!$edit_uid ||
$subop != "edit") {
2088 print "<td><input onclick='toggleSelectRow(this);'
2089 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
2091 print "<td><a href=\"javascript:editUser($uid);\">" .
2092 $line["login"] . "</td>";
2094 print "<td><a href=\"javascript:editUser($uid);\">" .
2095 $line["access_level"] . "</td>";
2097 } else if ($uid != $edit_uid) {
2099 print "<td><input disabled=\"true\" type=\"checkbox\"
2100 id=\"UMCHK-".$line["id"]."\"></td>";
2102 print "<td>".$line["login"]."</td>";
2103 print "<td>".$line["access_level"]."</td>";
2107 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2109 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
2112 print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
2117 print "<td>".$line["last_login"]."</td>";
2128 if ($subop == "edit") {
2130 <input type=\"submit\" class=\"button\"
2131 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">
2132 <input type=\"submit\" class=\"button\"
2133 onclick=\"javascript:userEditSave()\" value=\"Save\">";
2139 <input type=\"submit\" class=\"button\"
2140 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
2141 <input type=\"submit\" class=\"button\"
2142 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
2143 <input type=\"submit\" class=\"button\"
2144 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
2145 <input type=\"submit\" class=\"button\"
2146 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
2151 if ($op == "user-details") {
2153 if (WEB_DEMO_MODE ||
$_SESSION["access_level"] < 10) {
2157 /* print "<html><head>
2158 <title>Tiny Tiny RSS : User Details</title>
2159 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2160 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2163 $uid = sprintf("%d", $_GET["id"]);
2165 print "<div class='infoBoxContents'>";
2167 $result = db_query($link, "SELECT login,
2168 SUBSTRING(last_login,1,16) AS last_login,
2170 (SELECT COUNT(int_id) FROM ttrss_user_entries
2171 WHERE owner_uid = id) AS stored_articles
2173 WHERE id = '$uid'");
2175 if (db_num_rows($result) == 0) {
2176 print "<h1>User not found</h1>";
2180 print "<h1>User Details</h1>";
2182 print "<table width='100%'>";
2184 $login = db_fetch_result($result, 0, "login");
2185 $last_login = db_fetch_result($result, 0, "last_login");
2186 $access_level = db_fetch_result($result, 0, "access_level");
2187 $stored_articles = db_fetch_result($result, 0, "stored_articles");
2189 print "<tr><td>Username</td><td>$login</td></tr>";
2190 print "<tr><td>Access level</td><td>$access_level</td></tr>";
2191 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
2192 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
2194 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
2195 WHERE owner_uid = '$uid'");
2197 $num_feeds = db_fetch_result($result, 0, "num_feeds");
2199 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
2201 /* $result = db_query($link, "SELECT
2202 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
2203 FROM ttrss_user_entries,ttrss_entries
2204 WHERE owner_uid = '$uid' AND ref_id = id");
2206 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
2208 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
2212 print "<h1>Subscribed feeds</h1>";
2214 $result = db_query($link, "SELECT id,title,feed_url FROM ttrss_feeds
2215 WHERE owner_uid = '$uid' ORDER BY title");
2217 print "<ul class=\"nomarks\">";
2219 while ($line = db_fetch_assoc($result)) {
2221 $icon_file = ICONS_URL
."/".$line["id"].".ico";
2223 if (file_exists($icon_file) && filesize($icon_file) > 0) {
2224 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
2226 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
2229 print "<li>$feed_icon <a href=\"".$line["feed_url"]."\">".$line["title"]."</a></li>";
2236 print "<div align='center'>
2237 <input type='submit' class='button'
2238 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2240 // print "</body></html>";
2244 if ($op == "feed-details") {
2246 $feed_id = $_GET["id"];
2248 $result = db_query($link,
2250 title,feed_url,last_updated,icon_url,site_url,
2251 (SELECT COUNT(int_id) FROM ttrss_user_entries
2252 WHERE feed_id = id) AS total,
2253 (SELECT COUNT(int_id) FROM ttrss_user_entries
2254 WHERE feed_id = id AND unread = true) AS unread,
2255 (SELECT COUNT(int_id) FROM ttrss_user_entries
2256 WHERE feed_id = id AND marked = true) AS marked
2258 WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]);
2260 if (db_num_rows($result) == 0) return;
2262 $title = db_fetch_result($result, 0, "title");
2263 $last_updated = db_fetch_result($result, 0, "last_updated");
2264 $feed_url = db_fetch_result($result, 0, "feed_url");
2265 $icon_url = db_fetch_result($result, 0, "icon_url");
2266 $total = db_fetch_result($result, 0, "total");
2267 $unread = db_fetch_result($result, 0, "unread");
2268 $marked = db_fetch_result($result, 0, "marked");
2269 $site_url = db_fetch_result($result, 0, "site_url");
2271 $result = db_query($link, "SELECT COUNT(id) AS subscribed
2272 FROM ttrss_feeds WHERE feed_url = '$feed_url'");
2274 $subscribed = db_fetch_result($result, 0, "subscribed");
2276 print "<div class=\"infoBoxContents\">";
2278 $icon_file = ICONS_DIR
. "/$feed_id.ico";
2280 if (file_exists($icon_file) && filesize($icon_file) > 0) {
2281 $feed_icon = "<img width=\"16\" height=\"16\"
2282 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
2287 print "<h1>$feed_icon $title</h1>";
2289 print "<table width='100%'>";
2292 print "<tr><td width='30%'>Link</td>
2293 <td><a href=\"$site_url\">$site_url</a>
2294 <a href=\"$feed_url\">(feed)</a></td>
2297 print "<tr><td width='30%'>Feed URL</td>
2298 <td><a href=\"$feed_url\">$feed_url</a></td></tr>";
2300 print "<tr><td>Last updated</td><td>$last_updated</td></tr>";
2301 print "<tr><td>Total articles</td><td>$total</td></tr>";
2302 print "<tr><td>Unread articles</td><td>$unread</td></tr>";
2303 print "<tr><td>Starred articles</td><td>$marked</td></tr>";
2304 print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>";
2308 $result = db_query($link, "SELECT title,
2309 SUBSTRING(updated,1,16) AS updated,unread
2310 FROM ttrss_entries,ttrss_user_entries
2311 WHERE ref_id = id AND feed_id = '$feed_id'
2312 ORDER BY date_entered DESC LIMIT 5");
2314 if (db_num_rows($result) > 0) {
2316 print "<h1>Latest headlines</h1>";
2318 print "<ul class=\"nomarks\">";
2320 while ($line = db_fetch_assoc($result)) {
2321 if ($line["unread"] == "t" ||
$line["unread"] == "1") {
2322 $line["title"] = "<b>" . $line["title"] . "</b>";
2324 print "<li>" . $line["title"].
2325 " <span class=\"insensitive\">(" .$line["updated"].")</span></li>";
2332 print "<div align='center'>
2333 <input type='submit' class='button'
2334 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2341 <!-- <?
= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?
> -->