]> git.wh0rd.org - tt-rss.git/blame_incremental - backend.php
mobile: interface tweaks
[tt-rss.git] / backend.php
... / ...
CommitLineData
1<?
2 require_once "sessions.php";
3
4 header("Cache-Control: no-cache, must-revalidate");
5 header("Pragma: no-cache");
6 header("Expires: -1");
7
8/* if ($_GET["debug"]) {
9 define('DEFAULT_ERROR_LEVEL', E_ALL);
10 } else {
11 define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE);
12 }
13
14 error_reporting(DEFAULT_ERROR_LEVEL); */
15
16 $op = $_REQUEST["op"];
17
18 if ((!$op || $op == "rpc" || $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
19 header("Content-Type: application/xml");
20 }
21
22 if (!$_SESSION["uid"] && $op != "globalUpdateFeeds") {
23
24 if ($op == "rpc") {
25 print "<error error-code=\"6\"/>";
26 } else {
27 print "
28 <html><body>
29 <p>Error: Not logged in.</p>
30 <script type=\"text/javascript\">
31 if (parent.window != 'undefined') {
32 parent.window.location = \"login.php\";
33 } else {
34 window.location = \"login.php\";
35 }
36 </script>
37 </body></html>
38 ";
39 }
40 exit;
41 }
42
43 if (!$op) {
44 print "<error error-code=\"7\"/>";
45 exit;
46 }
47
48 define('SCHEMA_VERSION', 7);
49
50 require_once "sanity_check.php";
51 require_once "config.php";
52 require_once "db.php";
53 require_once "db-prefs.php";
54 require_once "functions.php";
55 require_once "magpierss/rss_fetch.inc";
56
57 $purge_intervals = array(
58 0 => "Default",
59 -1 => "Never purge",
60 5 => "1 week",
61 14 => "2 weeks",
62 31 => "1 month",
63 60 => "2 months",
64 90 => "3 months");
65
66 $update_intervals = array(
67 0 => "Default",
68 -1 => "Disable updates",
69 30 => "30 minutes",
70 60 => "1 hour",
71 240 => "4 hours",
72 720 => "12 hours",
73 1440 => "Daily",
74 10080 => "Weekly");
75
76 $script_started = getmicrotime();
77
78 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
79
80 if (!$link) {
81 if (DB_TYPE == "mysql") {
82 print mysql_error();
83 }
84 // PG seems to display its own errors just fine by default.
85 return;
86 }
87
88 if (DB_TYPE == "pgsql") {
89 pg_query("set client_encoding = 'utf-8'");
90 }
91
92 if ($_SESSION["uid"]) {
93 if (get_pref($link, "HIDE_READ_FEEDS") == "true") {
94 setcookie("ttrss_vf_hreadf", 1);
95 } else {
96 setcookie("ttrss_vf_hreadf", 0);
97 }
98
99 setcookie('ttrss_vf_refresh', FEEDS_FRAME_REFRESH);
100 setcookie('ttrss_vf_daemon', ENABLE_UPDATE_DAEMON);
101 }
102
103 $fetch = $_GET["fetch"];
104
105// setcookie("ttrss_icons_url", ICONS_URL);
106
107 if (!sanity_check($link)) { return; }
108
109 function outputFeedList($link, $tags = false) {
110
111 print "<html><head>
112 <title>Tiny Tiny RSS : Feedlist</title>
113 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
114
115 $user_theme = $_SESSION["theme"];
116 if ($user_theme) {
117 print "<link rel=\"stylesheet\" type=\"text/css\"
118 href=\"themes/$user_theme/theme.css\">";
119 }
120
121 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
122 print "<link rel=\"stylesheet\" type=\"text/css\"
123 href=\"tt-rss_compact.css\"/>";
124 } else {
125 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
126 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
127 }
128
129 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
130 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
131 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
132 <!--[if gte IE 5.5000]>
133 <script type=\"text/javascript\" src=\"pngfix.js\"></script>
134 <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
135 <![endif]-->
136 </head><body>
137 <script type=\"text/javascript\">
138 if (document.addEventListener) {
139 document.addEventListener(\"DOMContentLoaded\", init, null);
140 }
141 window.onload = init;
142 </script>";
143
144 print "<ul class=\"feedList\" id=\"feedList\">\n";
145
146 $owner_uid = $_SESSION["uid"];
147
148 if (!$tags) {
149
150 /* virtual feeds */
151
152 if (get_pref($link, 'ENABLE_FEED_CATS')) {
153 print "<li class=\"feedCat\">Special</li>";
154 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
155 }
156
157 $result = db_query($link, "SELECT count(id) as num_starred
158 FROM ttrss_entries,ttrss_user_entries
159 WHERE marked = true AND
160 ttrss_user_entries.ref_id = ttrss_entries.id AND
161 unread = true AND owner_uid = '$owner_uid'");
162 $num_starred = db_fetch_result($result, 0, "num_starred");
163
164 $class = "virt";
165
166 if ($num_starred > 0) $class .= "Unread";
167
168 printFeedEntry(-1, $class, "Starred articles", $num_starred,
169 "images/mark_set.png", $link);
170
171 if (get_pref($link, 'ENABLE_FEED_CATS')) {
172 print "</ul>\n";
173 }
174
175 if (GLOBAL_ENABLE_LABELS && get_pref($link, 'ENABLE_LABELS')) {
176
177 $result = db_query($link, "SELECT id,sql_exp,description FROM
178 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
179
180 if (db_num_rows($result) > 0) {
181 if (get_pref($link, 'ENABLE_FEED_CATS')) {
182 print "<li class=\"feedCat\">Labels</li>";
183 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
184 } else {
185 print "<li><hr></li>";
186 }
187 }
188
189 while ($line = db_fetch_assoc($result)) {
190
191 error_reporting (0);
192
193 $tmp_result = db_query($link, "SELECT count(id) as count
194 FROM ttrss_entries,ttrss_user_entries
195 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
196 ttrss_user_entries.ref_id = ttrss_entries.id
197 AND owner_uid = '$owner_uid'");
198
199 $count = db_fetch_result($tmp_result, 0, "count");
200
201 $class = "label";
202
203 if ($count > 0) {
204 $class .= "Unread";
205 }
206
207 error_reporting (DEFAULT_ERROR_LEVEL);
208
209 printFeedEntry(-$line["id"]-11,
210 $class, $line["description"], $count, "images/label.png", $link);
211
212 }
213
214 if (db_num_rows($result) > 0) {
215 if (get_pref($link, 'ENABLE_FEED_CATS')) {
216 print "</ul>";
217 }
218 }
219
220 }
221
222// if (!get_pref($link, 'ENABLE_FEED_CATS')) {
223 print "<li><hr></li>";
224// }
225
226 if (get_pref($link, 'ENABLE_FEED_CATS')) {
227 $order_by_qpart = "category,title";
228 } else {
229 $order_by_qpart = "title";
230 }
231
232 $result = db_query($link, "SELECT ttrss_feeds.*,
233 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
234 WHERE feed_id = ttrss_feeds.id AND
235 ttrss_user_entries.ref_id = ttrss_entries.id AND
236 owner_uid = '$owner_uid') AS total,
237 (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
238 WHERE feed_id = ttrss_feeds.id AND unread = true
239 AND ttrss_user_entries.ref_id = ttrss_entries.id
240 AND owner_uid = '$owner_uid') as unread,
241 cat_id,last_error,
242 ttrss_feed_categories.title AS category,
243 ttrss_feed_categories.collapsed
244 FROM ttrss_feeds LEFT JOIN ttrss_feed_categories
245 ON (ttrss_feed_categories.id = cat_id)
246 WHERE
247 ttrss_feeds.owner_uid = '$owner_uid' AND parent_feed IS NULL
248 ORDER BY $order_by_qpart");
249
250 $actid = $_GET["actid"];
251
252 /* real feeds */
253
254 $lnum = 0;
255
256 $total_unread = 0;
257
258 $category = "";
259
260 while ($line = db_fetch_assoc($result)) {
261
262 $feed = db_unescape_string($line["title"]);
263 $feed_id = $line["id"];
264
265 $subop = $_GET["subop"];
266
267 $total = $line["total"];
268 $unread = $line["unread"];
269
270 $rtl_content = sql_bool_to_bool($line["rtl_content"]);
271
272 if ($rtl_content) {
273 $rtl_tag = "dir=\"RTL\"";
274 } else {
275 $rtl_tag = "";
276 }
277
278 $tmp_result = db_query($link,
279 "SELECT id,COUNT(unread) AS unread
280 FROM ttrss_feeds LEFT JOIN ttrss_user_entries
281 ON (ttrss_feeds.id = ttrss_user_entries.feed_id)
282 WHERE parent_feed = '$feed_id' AND unread = true
283 GROUP BY ttrss_feeds.id");
284
285 if (db_num_rows($tmp_result) > 0) {
286 while ($l = db_fetch_assoc($tmp_result)) {
287 $unread += $l["unread"];
288 }
289 }
290
291 $cat_id = $line["cat_id"];
292
293 $tmp_category = $line["category"];
294
295 if (!$tmp_category) {
296 $tmp_category = "Uncategorized";
297 }
298
299 // $class = ($lnum % 2) ? "even" : "odd";
300
301 if ($line["last_error"]) {
302 $class = "error";
303 } else {
304 $class = "feed";
305 }
306
307 if ($unread > 0) $class .= "Unread";
308
309 if ($actid == $feed_id) {
310 $class .= "Selected";
311 }
312
313 $total_unread += $unread;
314
315 if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
316
317 if ($category) {
318 print "</ul></li>";
319 }
320
321 $category = $tmp_category;
322
323 $collapsed = $line["collapsed"];
324
325 // workaround for NULL category
326 if ($category == "Uncategorized") {
327 if ($_COOKIE["ttrss_vf_uclps"] == 1) {
328 $collapsed = "t";
329 }
330 }
331
332 if ($collapsed == "t" || $collapsed == "1") {
333 $holder_class = "invisible";
334 $ellipsis = "...";
335 } else {
336 $holder_class = "";
337 $ellipsis = "";
338 }
339
340 if ($cat_id) {
341 $cat_id_qpart = "cat_id = '$cat_id'";
342 } else {
343 $cat_id_qpart = "cat_id IS NULL";
344 }
345
346 $tmp_result = db_query($link, "SELECT count(int_id) AS unread
347 FROM ttrss_user_entries,ttrss_feeds WHERE
348 unread = true AND
349 feed_id = ttrss_feeds.id AND $cat_id_qpart AND
350 ttrss_user_entries.owner_uid = " . $_SESSION["uid"]);
351
352 $cat_unread = db_fetch_result($tmp_result, 0, "unread");
353
354 $cat_id = sprintf("%d", $cat_id);
355
356 print "<li class=\"feedCat\" id=\"FCAT-$cat_id\">
357 <a href=\"javascript:toggleCollapseCat($cat_id)\">$tmp_category</a>
358 <a href=\"javascript:viewCategory($cat_id)\" id=\"FCAP-$cat_id\">
359 <span id=\"FCATCTR-$cat_id\"
360 class=\"$catctr_class\">($cat_unread unread)$ellipsis</span></a></li>";
361
362 // !!! NO SPACE before <ul...feedCatList - breaks firstChild DOM function
363 // -> keyboard navigation, etc.
364 print "<li id=\"feedCatHolder\" class=\"$holder_class\"><ul class=\"feedCatList\" id=\"FCATLIST-$cat_id\">";
365 }
366
367 printFeedEntry($feed_id, $class, $feed, $unread,
368 "icons/$feed_id.ico", $link, $rtl_content);
369
370 ++$lnum;
371 }
372
373 } else {
374
375 // tags
376
377/* $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
378 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
379 post_int_id = ttrss_user_entries.int_id AND
380 unread = true AND ref_id = ttrss_entries.id
381 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
382 UNION
383 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'
384 ORDER BY tag_name"); */
385
386 $result = db_query($link, "SELECT tag_name,SUM((SELECT COUNT(int_id)
387 FROM ttrss_user_entries WHERE int_id = post_int_id
388 AND unread = true)) AS count FROM ttrss_tags
389 WHERE owner_uid = 2 GROUP BY tag_name ORDER BY tag_name");
390
391 $tags = array();
392
393 while ($line = db_fetch_assoc($result)) {
394 $tags[$line["tag_name"]] += $line["count"];
395 }
396
397 foreach (array_keys($tags) as $tag) {
398
399 $unread = $tags[$tag];
400
401 $class = "tag";
402
403 if ($unread > 0) {
404 $class .= "Unread";
405 }
406
407 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
408
409 }
410
411 }
412
413 if (db_num_rows($result) == 0) {
414 if ($tags) {
415 $what = "tags";
416 } else {
417 $what = "feeds";
418 }
419 print "<li>No $what to display.</li>";
420 }
421
422 print "</ul>";
423
424 print '
425 <script type="text/javascript">
426 /* for IE */
427 function statechange() {
428 if (document.readyState == "interactive") init();
429 }
430
431 if (document.readyState) {
432 if (document.readyState == "interactive" || document.readyState == "complete") {
433 init();
434 } else {
435 document.onreadystatechange = statechange;
436 }
437 }
438 </script></body></html>';
439 }
440
441
442 if ($op == "rpc") {
443
444 $subop = $_GET["subop"];
445
446 if ($subop == "setpref") {
447 if (WEB_DEMO_MODE) {
448 return;
449 }
450
451 print "<rpc-reply>";
452
453 $key = db_escape_string($_GET["key"]);
454 $value = db_escape_string($_GET["value"]);
455
456 set_pref($link, $key, $value);
457
458 print "<param-set key=\"$key\" value=\"$value\"/>";
459
460 print "</rpc-reply>";
461
462 }
463
464 if ($subop == "getLabelCounters") {
465 $aid = $_GET["aid"];
466 print "<rpc-reply>";
467 getLabelCounters($link);
468 if ($aid) {
469 getFeedCounter($link, $aid);
470 }
471 print "</rpc-reply>";
472 }
473
474 if ($subop == "getFeedCounters") {
475 print "<rpc-reply>";
476 getFeedCounters($link);
477 print "</rpc-reply>";
478 }
479
480 if ($subop == "getAllCounters") {
481 print "<rpc-reply>";
482 getAllCounters($link);
483 print "</rpc-reply>";
484 }
485
486 if ($subop == "mark") {
487 $mark = $_GET["mark"];
488 $id = db_escape_string($_GET["id"]);
489
490 if ($mark == "1") {
491 $mark = "true";
492 } else {
493 $mark = "false";
494 }
495
496 // FIXME this needs collision testing
497
498 $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
499 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
500 }
501
502 if ($subop == "updateFeed") {
503 $feed_id = db_escape_string($_GET["feed"]);
504
505 $result = db_query($link,
506 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'
507 AND owner_uid = " . $_SESSION["uid"]);
508
509 if (db_num_rows($result) > 0) {
510 $feed_url = db_fetch_result($result, 0, "feed_url");
511 update_rss_feed($link, $feed_url, $feed_id);
512 }
513
514 print "<rpc-reply>";
515 getFeedCounter($link, $feed_id);
516 print "</rpc-reply>";
517
518 return;
519 }
520
521 if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") {
522
523 if (ENABLE_UPDATE_DAEMON) {
524
525 if ($subop == "forceUpdateAllFeeds") {
526
527 $result = db_query($link, "SELECT count(id) AS cid FROM
528 ttrss_scheduled_updates WHERE feed_id IS NULL AND
529 owner_uid = " . $_SESSION["uid"]);
530
531 $cid = db_fetch_result($result, 0, "cid");
532
533# print "<rpc-reply>";
534
535 if ($cid == 0) {
536
537 db_query($link, "INSERT INTO ttrss_scheduled_updates
538 (owner_uid, feed_id, entered) VALUES
539 (".$_SESSION["uid"].", NULL, NOW())");
540
541// print "<!-- ScheduledOK -->";
542
543 } else {
544// print "<!-- RequestAlreadyInQueue -->";
545 }
546
547# print "</rpc-reply>";
548 }
549
550 } else {
551 update_all_feeds($link, $subop == "forceUpdateAllFeeds");
552 }
553
554 $global_unread_caller = sprintf("%d", $_GET["uctr"]);
555 $global_unread = getGlobalUnread($link);
556
557 print "<rpc-reply>";
558
559 if ($global_unread_caller != $global_unread) {
560
561 $omode = $_GET["omode"];
562
563 if (!$omode) $omode = "tflc";
564
565 if (strchr($omode, "l")) getLabelCounters($link);
566 if (strchr($omode, "f")) getFeedCounters($link);
567 if (strchr($omode, "t")) getTagCounters($link);
568 if (strchr($omode, "c")) {
569 if (get_pref($link, 'ENABLE_FEED_CATS')) {
570 getCategoryCounters($link);
571 }
572 }
573 }
574
575 getGlobalCounters($link, $global_unread);
576
577 print "</rpc-reply>";
578
579 }
580
581 /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
582 if ($subop == "catchupSelected") {
583
584 $ids = split(",", db_escape_string($_GET["ids"]));
585
586 $cmode = sprintf("%d", $_GET["cmode"]);
587
588 foreach ($ids as $id) {
589
590 if ($cmode == 0) {
591 db_query($link, "UPDATE ttrss_user_entries SET
592 unread = false,last_read = NOW()
593 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
594 } else if ($cmode == 1) {
595 db_query($link, "UPDATE ttrss_user_entries SET
596 unread = true
597 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
598 } else {
599 db_query($link, "UPDATE ttrss_user_entries SET
600 unread = NOT unread,last_read = NOW()
601 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
602 }
603 }
604 print "<rpc-reply>";
605 getAllCounters($link);
606 print "</rpc-reply>";
607 }
608
609 if ($subop == "markSelected") {
610
611 $ids = split(",", db_escape_string($_GET["ids"]));
612
613 $cmode = sprintf("%d", $_GET["cmode"]);
614
615 foreach ($ids as $id) {
616
617 if ($cmode == 0) {
618 db_query($link, "UPDATE ttrss_user_entries SET
619 marked = false
620 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
621 } else if ($cmode == 1) {
622 db_query($link, "UPDATE ttrss_user_entries SET
623 marked = true
624 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
625 } else {
626 db_query($link, "UPDATE ttrss_user_entries SET
627 marked = NOT marked
628 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
629 }
630 }
631 print "<rpc-reply>";
632 getAllCounters($link);
633 print "</rpc-reply>";
634 }
635
636 if ($subop == "sanityCheck") {
637 if (sanity_check($link)) {
638 print "<error error-code=\"0\"/>";
639 }
640 }
641
642 if ($subop == "globalPurge") {
643
644 print "<rpc-reply>";
645 global_purge_old_posts($link, true);
646 print "</rpc-reply>";
647
648 }
649
650 }
651
652 if ($op == "feeds") {
653
654 $tags = $_GET["tags"];
655
656 $subop = $_GET["subop"];
657
658 if ($subop == "catchupAll") {
659 db_query($link, "UPDATE ttrss_user_entries SET
660 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
661 }
662
663 if ($subop == "collapse") {
664 $cat_id = db_escape_string($_GET["cid"]);
665
666 db_query($link, "UPDATE ttrss_feed_categories SET
667 collapsed = NOT collapsed WHERE id = '$cat_id' AND owner_uid = " .
668 $_SESSION["uid"]);
669 return;
670 }
671
672 outputFeedList($link, $tags);
673
674 }
675
676 if ($op == "view") {
677
678 $id = db_escape_string($_GET["id"]);
679 $feed_id = db_escape_string($_GET["feed"]);
680
681 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
682 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
683
684 if (db_num_rows($result) == 1) {
685 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
686 } else {
687 $rtl_content = false;
688 }
689
690 if ($rtl_content) {
691 $rtl_tag = "dir=\"RTL\"";
692 $rtl_class = "RTL";
693 } else {
694 $rtl_tag = "";
695 $rtl_class = "";
696 }
697
698 $result = db_query($link, "UPDATE ttrss_user_entries
699 SET unread = false,last_read = NOW()
700 WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
701
702 $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
703 SUBSTRING(updated,1,16) as updated,
704 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url,
705 num_comments,
706 author
707 FROM ttrss_entries,ttrss_user_entries
708 WHERE id = '$id' AND ref_id = id");
709
710 print "<html><head>
711 <title>Tiny Tiny RSS : Article $id</title>
712 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
713
714 $user_theme = $_SESSION["theme"];
715 if ($user_theme) {
716 print "<link rel=\"stylesheet\" type=\"text/css\"
717 href=\"themes/$user_theme/theme.css\">";
718 }
719
720 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
721 print "<link rel=\"stylesheet\" type=\"text/css\"
722 href=\"tt-rss_compact.css\"/>";
723 } else {
724 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
725 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
726 }
727
728 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
729 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
730 </head><body $rtl_tag>";
731
732 if ($result) {
733
734 $line = db_fetch_assoc($result);
735
736 if ($line["icon_url"]) {
737 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
738 } else {
739 $feed_icon = "&nbsp;";
740 }
741
742/* if ($line["comments"] && $line["link"] != $line["comments"]) {
743 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
744 } else {
745 $entry_comments = "";
746 } */
747
748 $num_comments = $line["num_comments"];
749 $entry_comments = "";
750
751 if ($num_comments > 0) {
752 if ($line["comments"]) {
753 $comments_url = $line["comments"];
754 } else {
755 $comments_url = $line["link"];
756 }
757 $entry_comments = "<a href=\"$comments_url\">$num_comments comments</a>";
758 } else {
759 if ($line["comments"] && $line["link"] != $line["comments"]) {
760 $entry_comments = "<a href=\"".$line["comments"]."\">comments</a>";
761 }
762 }
763
764 print "<div class=\"postReply\">";
765
766 print "<div class=\"postHeader\"><table width=\"100%\">";
767
768 $entry_author = $line["author"];
769
770 if ($entry_author) {
771 $entry_author = " - by $entry_author";
772 }
773
774 print "<tr><td><a href=\"" . $line["link"] . "\">" . $line["title"] .
775 "</a>$entry_author</td>";
776
777 $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
778 strtotime($line["updated"]));
779
780 print "<td class=\"postDate$rtl_class\">$parsed_updated</td>";
781
782 print "</tr>";
783
784 $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
785 ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
786 ORDER BY tag_name");
787
788 $tags_str = "";
789 $f_tags_str = "";
790
791 $num_tags = 0;
792
793 while ($tmp_line = db_fetch_assoc($tmp_result)) {
794 $num_tags++;
795 $tag = $tmp_line["tag_name"];
796 $tag_str = "<a href=\"javascript:parent.viewfeed('$tag')\">$tag</a>, ";
797
798 if ($num_tags == 5) {
799 $tags_str .= "<a href=\"javascript:showBlockElement('allEntryTags')\">...</a>";
800 } else if ($num_tags < 5) {
801 $tags_str .= $tag_str;
802 }
803 $f_tags_str .= $tag_str;
804 }
805
806 $tags_str = preg_replace("/, $/", "", $tags_str);
807 $f_tags_str = preg_replace("/, $/", "", $f_tags_str);
808
809// $truncated_link = truncate_string($line["link"], 60);
810
811 if ($tags_str || $entry_comments) {
812 print "<tr><td width='50%'>
813 $entry_comments</td>
814 <td align=\"right\">$tags_str</td></tr>";
815 }
816
817 print "</table></div>";
818
819 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
820 print "<div class=\"postContent\">";
821
822 if (db_num_rows($tmp_result) > 5) {
823 print "<div id=\"allEntryTags\">Tags: $f_tags_str</div>";
824 }
825
826 if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
827 $line["content"] = preg_replace("/href=/i", "target=\"_new\" href=", $line["content"]);
828 }
829
830 print $line["content"] . "</div>";
831
832 print "</div>";
833
834 print "<script type=\"text/javascript\">
835 update_all_counters('$feed_id');
836 </script>";
837 }
838
839 print "</body></html>";
840 }
841
842 if ($op == "viewfeed") {
843
844 $feed = db_escape_string($_GET["feed"]);
845 $skip = db_escape_string($_GET["skip"]);
846 $subop = db_escape_string($_GET["subop"]);
847 $view_mode = db_escape_string($_GET["view"]);
848 $limit = db_escape_string($_GET["limit"]);
849 $cat_view = db_escape_string($_GET["cat"]);
850
851 if (!$skip) $skip = 0;
852
853 if ($subop == "undefined") $subop = "";
854
855 print "<html><head>
856 <title>Tiny Tiny RSS : Feed $feed</title>
857 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
858
859 $user_theme = $_SESSION["theme"];
860 if ($user_theme) {
861 print "<link rel=\"stylesheet\" type=\"text/css\"
862 href=\"themes/$user_theme/theme.css\">";
863 }
864
865 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
866 print "<link rel=\"stylesheet\"
867 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
868
869 } else {
870 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
871 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
872 }
873
874 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
875
876 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
877 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
878
879 if (db_num_rows($result) == 1) {
880 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
881 } else {
882 $rtl_content = false;
883 }
884
885 if ($rtl_content) {
886 $rtl_tag = "dir=\"RTL\"";
887 } else {
888 $rtl_tag = "";
889 }
890 } else {
891 $rtl_tag = "";
892 $rtl_content = false;
893 }
894
895 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
896 <script type=\"text/javascript\" src=\"functions.js\"></script>
897 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
898 <!--[if gte IE 5.5000]>
899 <script type=\"text/javascript\" src=\"pngfix.js\"></script>
900 <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
901 <![endif]-->
902 </head><body $rtl_tag>
903 <script type=\"text/javascript\">
904 if (document.addEventListener) {
905 document.addEventListener(\"DOMContentLoaded\", init, null);
906 }
907 window.onload = init;
908 </script>";
909
910 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
911 update_generic_feed($link, $feed, $cat_view);
912 }
913
914 if ($subop == "MarkAllRead") {
915 catchup_feed($link, $feed, $cat_view);
916 }
917
918 $search = db_escape_string($_GET["search"]);
919 $search_mode = db_escape_string($_GET["smode"]);
920
921 if ($search) {
922 $search_query_part = "(upper(ttrss_entries.title) LIKE upper('%$search%')
923 OR ttrss_entries.content LIKE '%$search%') AND";
924 } else {
925 $search_query_part = "";
926 }
927
928 $view_query_part = "";
929
930 if ($view_mode == "Adaptive") {
931 if ($search) {
932 $view_query_part = " ";
933 } else if ($feed != -1) {
934 $unread = getFeedUnread($link, $feed);
935 if ($unread > 0) {
936 $view_query_part = " unread = true AND ";
937 }
938 }
939 }
940
941 if ($view_mode == "Starred") {
942 $view_query_part = " marked = true AND ";
943 }
944
945 if ($view_mode == "Unread") {
946 $view_query_part = " unread = true AND ";
947 }
948
949 if ($limit && $limit != "All") {
950 $limit_query_part = "LIMIT " . $limit;
951 }
952
953 $vfeed_query_part = "";
954
955 // override query strategy and enable feed display when searching globally
956 if ($search && $search_mode == "All feeds") {
957 $query_strategy_part = "ttrss_entries.id > 0";
958 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
959 } else if (preg_match("/^-?[0-9][0-9]*$/", $feed) == false) {
960 $query_strategy_part = "ttrss_entries.id > 0";
961 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
962 id = feed_id) as feed_title,";
963 } else if ($feed >= 0 && $search && $search_mode == "This category") {
964
965 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
966
967 $tmp_result = db_query($link, "SELECT id
968 FROM ttrss_feeds WHERE cat_id =
969 (SELECT cat_id FROM ttrss_feeds WHERE id = '$feed') AND id != '$feed'");
970
971 $cat_siblings = array();
972
973 if (db_num_rows($tmp_result) > 0) {
974 while ($p = db_fetch_assoc($tmp_result)) {
975 array_push($cat_siblings, "feed_id = " . $p["id"]);
976 }
977
978 $query_strategy_part = sprintf("(feed_id = %d OR %s)",
979 $feed, implode(" OR ", $cat_siblings));
980
981 } else {
982 $query_strategy_part = "ttrss_entries.id > 0";
983 }
984
985 } else if ($feed >= 0) {
986
987 if ($cat_view) {
988
989 if ($feed > 0) {
990 $query_strategy_part = "cat_id = '$feed'";
991 } else {
992 $query_strategy_part = "cat_id IS NULL";
993 }
994
995 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
996
997 } else {
998 $tmp_result = db_query($link, "SELECT id
999 FROM ttrss_feeds WHERE parent_feed = '$feed'
1000 ORDER BY cat_id,title");
1001
1002 $parent_ids = array();
1003
1004 if (db_num_rows($tmp_result) > 0) {
1005 while ($p = db_fetch_assoc($tmp_result)) {
1006 array_push($parent_ids, "feed_id = " . $p["id"]);
1007 }
1008
1009 $query_strategy_part = sprintf("(feed_id = %d OR %s)",
1010 $feed, implode(" OR ", $parent_ids));
1011
1012 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1013 } else {
1014 $query_strategy_part = "feed_id = '$feed'";
1015 }
1016 }
1017 } else if ($feed == -1) { // starred virtual feed
1018 $query_strategy_part = "marked = true";
1019 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1020 } else if ($feed <= -10) { // labels
1021 $label_id = -$feed - 11;
1022
1023 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
1024 WHERE id = '$label_id'");
1025
1026 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
1027
1028 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1029 } else {
1030 $query_strategy_part = "id > 0"; // dumb
1031 }
1032
1033 $order_by = "updated DESC";
1034
1035// if ($feed < -10) {
1036// $order_by = "feed_id,updated DESC";
1037// }
1038
1039 $feed_title = "";
1040
1041 if ($search && $search_mode == "All feeds") {
1042 $feed_title = "Global search results ($search)";
1043 } else if ($search && preg_match('/^-?[0-9][0-9]*$/', $feed) == false) {
1044 $feed_title = "Feed search results ($search, $feed)";
1045 } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) == false) {
1046 $feed_title = $feed;
1047 } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) != false && $feed >= 0) {
1048
1049 if ($cat_view) {
1050
1051 if ($feed != 0) {
1052 $result = db_query($link, "SELECT title FROM ttrss_feed_categories
1053 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
1054 $feed_title = db_fetch_result($result, 0, "title");
1055 } else {
1056 $feed_title = "Uncategorized";
1057 }
1058 } else {
1059
1060 $result = db_query($link, "SELECT title,site_url,last_error FROM ttrss_feeds
1061 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
1062
1063 $feed_title = db_fetch_result($result, 0, "title");
1064 $feed_site_url = db_fetch_result($result, 0, "site_url");
1065 $last_error = db_fetch_result($result, 0, "last_error");
1066
1067 }
1068
1069 } else if ($feed == -1) {
1070 $feed_title = "Starred articles";
1071 } else if ($feed < -10) {
1072 $label_id = -$feed - 11;
1073 $result = db_query($link, "SELECT description FROM ttrss_labels
1074 WHERE id = '$label_id'");
1075 $feed_title = db_fetch_result($result, 0, "description");
1076 } else {
1077 $feed_title = "?";
1078 }
1079
1080 if ($feed < -10) error_reporting (0);
1081
1082 print "<div id=\"headlinesContainer\">";
1083
1084 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
1085
1086 if ($feed >= 0) {
1087 $feed_kind = "Feeds";
1088 } else {
1089 $feed_kind = "Labels";
1090 }
1091
1092// if (!$vfeed_query_part) {
1093 $content_query_part = "content as content_preview,";
1094// } else {
1095// $content_query_part = "";
1096// }
1097
1098 $query = "SELECT
1099 ttrss_entries.id,ttrss_entries.title,
1100 SUBSTRING(updated,1,16) as updated,
1101 unread,feed_id,marked,link,last_read,
1102 SUBSTRING(last_read,1,19) as last_read_noms,
1103 $vfeed_query_part
1104 $content_query_part
1105 SUBSTRING(updated,1,19) as updated_noms
1106 FROM
1107 ttrss_entries,ttrss_user_entries,ttrss_feeds
1108 WHERE
1109 ttrss_user_entries.feed_id = ttrss_feeds.id AND
1110 ttrss_user_entries.ref_id = ttrss_entries.id AND
1111 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
1112 $search_query_part
1113 $view_query_part
1114 $query_strategy_part ORDER BY $order_by
1115 $limit_query_part";
1116
1117 $result = db_query($link, $query);
1118
1119 if ($_GET["debug"]) print $query;
1120
1121 } else {
1122 // browsing by tag
1123
1124 $feed_kind = "Tags";
1125
1126 $result = db_query($link, "SELECT
1127 ttrss_entries.id as id,title,
1128 SUBSTRING(updated,1,16) as updated,
1129 unread,feed_id,
1130 marked,link,last_read,
1131 SUBSTRING(last_read,1,19) as last_read_noms,
1132 $vfeed_query_part
1133 $content_query_part
1134 SUBSTRING(updated,1,19) as updated_noms
1135 FROM
1136 ttrss_entries,ttrss_user_entries,ttrss_tags
1137 WHERE
1138 ref_id = ttrss_entries.id AND
1139 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
1140 post_int_id = int_id AND tag_name = '$feed' AND
1141 $view_query_part
1142 $search_query_part
1143 $query_strategy_part ORDER BY $order_by
1144 $limit_query_part");
1145 }
1146
1147 if (!$result) {
1148 print "<div align='center'>
1149 Could not display feed (query failed). Please check label match syntax or local configuration.</div>";
1150 return;
1151 }
1152
1153 function print_headline_subtoolbar($link, $feed_site_url, $feed_title,
1154 $bottom = false, $rtl_content = false) {
1155
1156 if (!$bottom) {
1157 $class = "headlinesSubToolbar";
1158 $tid = "headlineActionsTop";
1159 } else {
1160 $class = "invisible";
1161 $tid = "headlineActionsBottom";
1162 }
1163
1164 print "<table class=\"$class\" id=\"$tid\"
1165 width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
1166
1167 if ($rtl_content) {
1168 $rtl_cpart = "RTL";
1169 } else {
1170 $rtl_cpart = "";
1171 }
1172
1173 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1174
1175 print "<td class=\"headlineActions$rtl_cpart\">
1176 Select:
1177 <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, '', true)\">All</a>,
1178 <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true)\">Unread</a>,
1179 <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false)\">None</a>
1180 &nbsp;&nbsp;
1181 Toggle: <a href='#' onclick=\"javascript:selectionToggleUnread()\">Unread</a>,
1182 <a href='#' onclick=\"javascript:selectionToggleMarked()\">Starred</a>";
1183 print "</td>";
1184
1185 } else {
1186
1187 print "<td class=\"headlineActions$rtl_cpart\">
1188 Select:
1189 <a href=\"#\" onclick=\"javascript:cdmSelectArticles('all')\">All</a>,
1190 <a href=\"#\" onclick=\"javascript:cdmSelectArticles('unread')\">Unread</a>,
1191 <a href=\"#\" onclick=\"javascript:cdmSelectArticles('none')\">None</a>
1192 &nbsp;&nbsp;
1193 Toggle: <a href=\"#\" onclick=\"javascript:selectionToggleUnread(true)\">Unread</a>,
1194 <a href=\"#\" onclick=\"javascript:selectionToggleMarked(true)\">Starred</a>";
1195
1196 print "</td>";
1197
1198 }
1199
1200 print "<td class=\"headlineTitle$rtl_cpart\">";
1201
1202 if ($feed_site_url) {
1203 if (!$bottom) {
1204 $target = "target=\"_blank\"";
1205 }
1206 print "<a $target href=\"$feed_site_url\">$feed_title</a>";
1207 } else {
1208 print $feed_title;
1209 }
1210
1211 print "</td>";
1212 print "</tr></table>";
1213
1214 }
1215
1216 if (db_num_rows($result) > 0) {
1217
1218 print_headline_subtoolbar($link, $feed_site_url, $feed_title, false,
1219 $rtl_content);
1220
1221 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1222 print "<table class=\"headlinesList\" id=\"headlinesList\"
1223 cellspacing=\"0\" width=\"100%\">";
1224 }
1225
1226 $lnum = 0;
1227
1228 error_reporting (DEFAULT_ERROR_LEVEL);
1229
1230 $num_unread = 0;
1231
1232 while ($line = db_fetch_assoc($result)) {
1233
1234 $class = ($lnum % 2) ? "even" : "odd";
1235
1236 $id = $line["id"];
1237 $feed_id = $line["feed_id"];
1238
1239 if ($line["last_read"] == "" &&
1240 ($line["unread"] != "t" && $line["unread"] != "1")) {
1241
1242 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
1243 alt=\"Updated\">";
1244 } else {
1245 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
1246 alt=\"Updated\">";
1247 }
1248
1249 if ($line["unread"] == "t" || $line["unread"] == "1") {
1250 $class .= "Unread";
1251 ++$num_unread;
1252 $is_unread = true;
1253 } else {
1254 $is_unread = false;
1255 }
1256
1257 if ($line["marked"] == "t" || $line["marked"] == "1") {
1258 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
1259 alt=\"Reset mark\" onclick='javascript:toggleMark($id)'>";
1260 } else {
1261 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
1262 alt=\"Set mark\" onclick='javascript:toggleMark($id)'>";
1263 }
1264
1265 $content_link = "<a href=\"javascript:view($id,$feed_id);\">" .
1266 $line["title"] . "</a>";
1267
1268 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1269 $updated_fmt = smart_date_time(strtotime($line["updated"]));
1270 } else {
1271 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1272 $updated_fmt = date($short_date, strtotime($line["updated"]));
1273 }
1274
1275 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
1276 $content_preview = truncate_string(strip_tags($line["content_preview"]),
1277 100);
1278 }
1279
1280 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1281
1282 print "<tr class='$class' id='RROW-$id'>";
1283
1284 print "<td class='hlUpdatePic'>$update_pic</td>";
1285
1286 print "<td class='hlSelectRow'>
1287 <input type=\"checkbox\" onclick=\"toggleSelectRow(this)\"
1288 class=\"feedCheckBox\" id=\"RCHK-$id\">
1289 </td>";
1290
1291 print "<td class='hlMarkedPic'>$marked_pic</td>";
1292
1293 if ($line["feed_title"]) {
1294 print "<td class='hlContent'>$content_link</td>";
1295 print "<td class='hlFeed'>
1296 <a href='javascript:viewfeed($feed_id)'>".
1297 $line["feed_title"]."</a>&nbsp;</td>";
1298 } else {
1299 print "<td class='hlContent' valign='middle'>";
1300
1301 print "<a href=\"javascript:view($id,$feed_id);\">" .
1302 $line["title"];
1303
1304 if (get_pref($link, 'SHOW_CONTENT_PREVIEW') && !$rtl_tag) {
1305 if ($content_preview) {
1306 print "<span class=\"contentPreview\"> - $content_preview</span>";
1307 }
1308 }
1309
1310 print "</a>";
1311 print "</td>";
1312 }
1313
1314 print "<td class=\"hlUpdated\"><nobr>$updated_fmt&nbsp;</nobr></td>";
1315
1316 print "</tr>";
1317
1318 } else {
1319
1320 if ($is_unread) {
1321 $add_class = "Unread";
1322 } else {
1323 $add_class = "";
1324 }
1325
1326 print "<div class=\"cdmArticle$add_class\" id=\"RROW-$id\">";
1327
1328 print "<div class=\"cdmHeader\">";
1329
1330 print "<div style=\"float : right\">$updated_fmt</div>";
1331
1332 print "<a target=\"new\" href=\"".$line["link"]."\">".$line["title"]."</a>";
1333
1334 if ($line["feed_title"]) {
1335 print "&nbsp;(<a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>)";
1336 }
1337
1338 print "</div>";
1339
1340 print "<div class=\"cdmContent\">" . $line["content_preview"] . "</div>";
1341
1342 print "<div style=\"float : right\">$marked_pic</div>
1343 <div class=\"cdmFooter\">
1344 <input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
1345 'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\"></div>";
1346
1347 print "</div>";
1348
1349 }
1350
1351 ++$lnum;
1352 }
1353
1354 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1355 print "</table>";
1356 }
1357
1358 print_headline_subtoolbar($link,
1359 "javascript:catchupPage()", "Mark page as read", true, $rtl_content);
1360
1361
1362 } else {
1363 print "<div width='100%' align='center'>No articles found.</div>";
1364 }
1365
1366 print "</div>";
1367
1368 print "<script type=\"text/javascript\">
1369 document.onkeydown = hotkey_handler;
1370 // if (parent.daemon_enabled) parent.updateTitle('$feed_title');
1371 update_all_counters('$feed');
1372 </script>";
1373
1374 print '
1375 <script type="text/javascript">
1376 /* for IE */
1377 function statechange() {
1378 if (document.readyState == "interactive") init();
1379 }
1380
1381 if (document.readyState) {
1382 if (document.readyState == "interactive" || document.readyState == "complete") {
1383 init();
1384 } else {
1385 document.onreadystatechange = statechange;
1386 }
1387 }
1388 </script>';
1389
1390 print "</body></html>";
1391 }
1392
1393 if ($op == "pref-rpc") {
1394
1395 $subop = $_GET["subop"];
1396
1397 if ($subop == "unread") {
1398 $ids = split(",", db_escape_string($_GET["ids"]));
1399 foreach ($ids as $id) {
1400 db_query($link, "UPDATE ttrss_user_entries SET unread = true
1401 WHERE feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
1402 }
1403
1404 print "Marked selected feeds as unread.";
1405 }
1406
1407 if ($subop == "read") {
1408 $ids = split(",", db_escape_string($_GET["ids"]));
1409 foreach ($ids as $id) {
1410 db_query($link, "UPDATE ttrss_user_entries
1411 SET unread = false,last_read = NOW() WHERE
1412 feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
1413 }
1414
1415 print "Marked selected feeds as read.";
1416
1417 }
1418
1419 }
1420
1421 if ($op == "pref-feeds") {
1422
1423 $subop = $_REQUEST["subop"];
1424 $quiet = $_REQUEST["quiet"];
1425
1426 if ($subop == "massSubscribe") {
1427 $ids = split(",", db_escape_string($_GET["ids"]));
1428
1429 $subscribed = array();
1430
1431 foreach ($ids as $id) {
1432 $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds
1433 WHERE id = '$id'");
1434
1435 $feed_url = db_fetch_result($result, 0, "feed_url");
1436 $title = db_fetch_result($result, 0, "title");
1437
1438 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
1439 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
1440
1441 if (db_num_rows($result) == 0) {
1442 $result = db_query($link,
1443 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
1444 VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)");
1445
1446 array_push($subscribed, $title);
1447 }
1448 }
1449
1450 if (count($subscribed) > 0) {
1451 print "<div class=\"notice\">";
1452 print "<b>Subscribed to feeds:</b>";
1453 print "<ul class=\"nomarks\">";
1454 foreach ($subscribed as $title) {
1455 print "<li>$title</li>";
1456 }
1457 print "</ul>";
1458 print "</div>";
1459 }
1460 }
1461
1462 if ($subop == "browse") {
1463
1464 if (!ENABLE_FEED_BROWSER) {
1465 print "Feed browser is administratively disabled.";
1466 return;
1467 }
1468
1469 print "<div class=\"infoBoxContents\">";
1470
1471 print "<h1>Feed browser</h1>";
1472
1473 print "<p>Showing top 50 registered feeds, sorted by popularity:</p>";
1474
1475 $result = db_query($link, "SELECT feed_url,count(id) AS subscribers
1476 FROM ttrss_feeds
1477 WHERE auth_login = '' AND auth_pass = '' AND private = false
1478 GROUP BY feed_url ORDER BY subscribers DESC LIMIT 50");
1479
1480 print "<ul class='browseFeedList' id='browseFeedList'>";
1481
1482 $feedctr = 0;
1483
1484 while ($line = db_fetch_assoc($result)) {
1485 $feed_url = $line["feed_url"];
1486 $subscribers = $line["subscribers"];
1487
1488 $sub_result = db_query($link, "SELECT id
1489 FROM ttrss_feeds WHERE feed_url = '$feed_url' AND owner_uid =" .
1490 $_SESSION["uid"]);
1491
1492 if (db_num_rows($sub_result) > 0) {
1493 continue; // already subscribed
1494 }
1495
1496 $det_result = db_query($link, "SELECT site_url,title,id
1497 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
1498
1499 $details = db_fetch_assoc($det_result);
1500
1501 $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
1502
1503 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1504 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
1505 "/".$details["id"].".ico\">";
1506 } else {
1507 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1508 }
1509
1510 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
1511 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
1512
1513 $class = ($feedctr % 2) ? "even" : "odd";
1514
1515 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
1516 "$feed_icon " . db_unescape_string($details["title"]) .
1517 "&nbsp;<span class='subscribers'>($subscribers)</span></li>";
1518
1519 ++$feedctr;
1520 }
1521
1522 if ($feedctr == 0) {
1523 print "<li>No feeds found to subscribe.</li>";
1524 }
1525
1526 print "</ul>";
1527
1528 print "<div align='center'>
1529 <input type=\"submit\" class=\"button\"
1530 onclick=\"feedBrowserSubscribe()\" value=\"Subscribe\">
1531 <input type='submit' class='button'
1532 onclick=\"closeInfoBox()\" value=\"Cancel\"></div>";
1533
1534 print "</div>";
1535 return;
1536 }
1537
1538 if ($subop == "editfeed") {
1539 $feed_id = db_escape_string($_GET["id"]);
1540
1541 $result = db_query($link,
1542 "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
1543 owner_uid = " . $_SESSION["uid"]);
1544
1545 $title = htmlspecialchars(db_unescape_string(db_fetch_result($result,
1546 0, "title")));
1547
1548 print "<div class=\"infoBoxContents\">";
1549
1550 $icon_file = ICONS_DIR . "/$feed_id.ico";
1551
1552 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1553 $feed_icon = "<img width=\"16\" height=\"16\"
1554 src=\"" . ICONS_URL . "/$feed_id.ico\">";
1555 } else {
1556 $feed_icon = "";
1557 }
1558
1559 print "<h1>$feed_icon $title</h1>";
1560
1561 print "<table width='100%'>";
1562
1563 $row_class = "odd";
1564
1565 print "<tr class='$row_class'><td>Title:</td>";
1566 print "<td><input id=\"iedit_title\" value=\"$title\"></td></tr>";
1567
1568 $feed_url = db_fetch_result($result, 0, "feed_url");
1569 $feed_url = htmlspecialchars(db_unescape_string(db_fetch_result($result,
1570 0, "feed_url")));
1571 $row_class = toggleEvenOdd($row_class);
1572
1573 print "<tr class='$row_class'><td>Feed URL:</td>";
1574 print "<td><input id=\"iedit_link\" value=\"$feed_url\"></td></tr>";
1575
1576 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1577
1578 $cat_id = db_fetch_result($result, 0, "cat_id");
1579
1580 $row_class = toggleEvenOdd($row_class);
1581
1582 print "<tr class='$row_class'><td>Category:</td>";
1583 print "<td>";
1584 print "<select id=\"iedit_fcat\">";
1585 print "<option id=\"0\">Uncategorized</option>";
1586
1587 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feed_categories
1588 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1589
1590 if (db_num_rows($tmp_result) > 0) {
1591 print "<option disabled>--------</option>";
1592 }
1593
1594 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1595 if ($tmp_line["id"] == $cat_id) {
1596 $is_selected = "selected";
1597 } else {
1598 $is_selected = "";
1599 }
1600 printf("<option $is_selected id='%d'>%s</option>",
1601 $tmp_line["id"], $tmp_line["title"]);
1602 }
1603
1604 print "</select></td>";
1605 print "</td></tr>";
1606
1607 }
1608
1609 $update_interval = db_fetch_result($result, 0, "update_interval");
1610 $row_class = toggleEvenOdd($row_class);
1611
1612 print "<tr class='$row_class'><td>Update Interval:</td>";
1613// print "<td><input id=\"iedit_updintl\"
1614// value=\"$update_interval\"></td></tr>";
1615
1616 print "<td>";
1617
1618 print "<select id=\"iedit_updintl\">";
1619
1620 foreach (array_keys($update_intervals) as $i) {
1621
1622 if ($i == $update_interval) {
1623 $selected = "selected";
1624 } else {
1625 $selected = "";
1626 }
1627 print "<option $selected id=\"$i\">" . $update_intervals[$i] . "</option>";
1628 }
1629
1630 print "</select>";
1631
1632 print "</td>";
1633
1634 $row_class = toggleEvenOdd($row_class);
1635 print "<tr class='$row_class'><td>Link to:</td>";
1636
1637 $tmp_result = db_query($link, "SELECT COUNT(id) AS count
1638 FROM ttrss_feeds WHERE parent_feed = '$feed_id'");
1639
1640 $linked_count = db_fetch_result($tmp_result, 0, "count");
1641
1642 $parent_feed = db_fetch_result($result, 0, "parent_feed");
1643
1644 if ($linked_count > 0) {
1645 $disabled = "disabled";
1646 }
1647
1648 print "<select $disabled id=\"iedit_parent_feed\">";
1649
1650 print "<option id=\"0\">Not linked</option>";
1651
1652 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1653 if ($cat_id) {
1654 $cat_qpart = "AND cat_id = '$cat_id'";
1655 } else {
1656 $cat_qpart = "AND cat_id IS NULL";
1657 }
1658 }
1659
1660 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
1661 WHERE id != '$feed_id' AND owner_uid = ".$_SESSION["uid"]."
1662 $cat_qpart ORDER BY title");
1663
1664 if (db_num_rows($tmp_result) > 0) {
1665 print "<option disabled>--------</option>";
1666 }
1667
1668 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1669 if ($tmp_line["id"] == $parent_feed) {
1670 $is_selected = "selected";
1671 } else {
1672 $is_selected = "";
1673 }
1674 printf("<option $is_selected id='%d'>%s</option>",
1675 $tmp_line["id"], $tmp_line["title"]);
1676 }
1677
1678 print "</select></td>";
1679 print "</td></tr>";
1680
1681 $purge_interval = db_fetch_result($result, 0, "purge_interval");
1682 $row_class = toggleEvenOdd($row_class);
1683
1684 print "<tr class='$row_class'><td>Purge Days:</td>";
1685// print "<td><input id=\"iedit_purgintl\"
1686// value=\"$purge_interval\"></td></tr>";
1687
1688 print "<td>";
1689
1690 print "<select id=\"iedit_purgintl\">";
1691
1692 foreach (array_keys($purge_intervals) as $i) {
1693
1694 if ($i == $purge_interval) {
1695 $selected = "selected";
1696 } else {
1697 $selected = "";
1698 }
1699 print "<option $selected id=\"$i\">" . $purge_intervals[$i] . "</option>";
1700 }
1701
1702 print "</select>";
1703
1704 print "</td>";
1705
1706// print "<tr><td colspan=\"2\"><b>Authentication</b></td></tr>";
1707
1708 $row_class = toggleEvenOdd($row_class);
1709 $auth_login = db_fetch_result($result, 0, "auth_login");
1710
1711 print "<tr class='$row_class'><td>Login:</td>";
1712 print "<td><input id=\"iedit_login\"
1713 value=\"$auth_login\"></td></tr>";
1714
1715 $row_class = toggleEvenOdd($row_class);
1716 $auth_pass = db_fetch_result($result, 0, "auth_pass");
1717
1718 print "<tr class='$row_class'><td>Password:</td>";
1719 print "<td><input type=\"password\" id=\"iedit_pass\"
1720 value=\"$auth_pass\"></td></tr>";
1721
1722 $row_class = toggleEvenOdd($row_class);
1723 $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
1724
1725 if ($private) {
1726 $checked = "checked";
1727 } else {
1728 $checked = "";
1729 }
1730
1731 print "<tr class='$row_class'><td valign='top'>Options:</td>";
1732 print "<td><input type=\"checkbox\" id=\"iedit_private\"
1733 $checked><label for=\"iedit_private\">Hide from feed browser</label>";
1734
1735 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
1736
1737 if ($rtl_content) {
1738 $checked = "checked";
1739 } else {
1740 $checked = "";
1741 }
1742
1743 print "<br><input type=\"checkbox\" id=\"iedit_rtl\"
1744 $checked><label for=\"iedit_rtl\">Right-to-left content</label>";
1745
1746 print "</td></tr>";
1747
1748 print "</table>";
1749 print "</div>";
1750
1751 print "<div align='center'>
1752 <input type=\"submit\" class=\"button\"
1753 onclick=\"feedEditSave()\" value=\"Save\">
1754 <input type='submit' class='button'
1755 onclick=\"feedEditCancel()\" value=\"Cancel\"></div>";
1756 return;
1757 }
1758
1759 if ($subop == "editSave") {
1760 $feed_title = db_escape_string($_POST["t"]);
1761 $feed_link = db_escape_string($_POST["l"]);
1762 $upd_intl = db_escape_string($_POST["ui"]);
1763 $purge_intl = db_escape_string($_POST["pi"]);
1764 $feed_id = db_escape_string($_POST["id"]);
1765 $cat_id = db_escape_string($_POST["catid"]);
1766 $auth_login = db_escape_string($_POST["login"]);
1767 $auth_pass = db_escape_string($_POST["pass"]);
1768 $parent_feed = db_escape_string($_POST["pfeed"]);
1769 $private = db_escape_string($_POST["is_pvt"]);
1770 $rtl_content = db_escape_string($_POST["is_rtl"]);
1771
1772 if (strtoupper($upd_intl) == "DEFAULT")
1773 $upd_intl = 0;
1774
1775 if (strtoupper($upd_intl) == "DISABLED")
1776 $upd_intl = -1;
1777
1778 if (strtoupper($purge_intl) == "DEFAULT")
1779 $purge_intl = 0;
1780
1781 if (strtoupper($purge_intl) == "DISABLED")
1782 $purge_intl = -1;
1783
1784 if ($cat_id != 0) {
1785 $category_qpart = "cat_id = '$cat_id'";
1786 } else {
1787 $category_qpart = 'cat_id = NULL';
1788 }
1789
1790 if ($parent_feed != 0) {
1791 $parent_qpart = "parent_feed = '$parent_feed'";
1792 } else {
1793 $parent_qpart = 'parent_feed = NULL';
1794 }
1795
1796 $result = db_query($link, "UPDATE ttrss_feeds SET
1797 $category_qpart,
1798 $parent_qpart,
1799 title = '$feed_title', feed_url = '$feed_link',
1800 update_interval = '$upd_intl',
1801 purge_interval = '$purge_intl',
1802 auth_login = '$auth_login',
1803 auth_pass = '$auth_pass',
1804 private = $private,
1805 rtl_content = $rtl_content
1806 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
1807 }
1808
1809 if ($subop == "saveCat") {
1810 $cat_title = db_escape_string($_GET["title"]);
1811 $cat_id = db_escape_string($_GET["id"]);
1812
1813 $result = db_query($link, "UPDATE ttrss_feed_categories SET
1814 title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
1815
1816 }
1817
1818 if ($subop == "remove") {
1819
1820 if (!WEB_DEMO_MODE) {
1821
1822 $ids = split(",", db_escape_string($_GET["ids"]));
1823
1824 foreach ($ids as $id) {
1825 db_query($link, "DELETE FROM ttrss_feeds
1826 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1827
1828 $icons_dir = ICONS_DIR;
1829
1830 if (file_exists($icons_dir . "/$id.ico")) {
1831 unlink($icons_dir . "/$id.ico");
1832 }
1833 }
1834 }
1835 }
1836
1837 if ($subop == "add") {
1838
1839 if (!WEB_DEMO_MODE) {
1840
1841 $feed_link = db_escape_string(trim($_GET["link"]));
1842 $cat_id = db_escape_string($_GET["cid"]);
1843
1844 if ($cat_id == "0" || !$cat_id) {
1845 $cat_qpart = "NULL";
1846 } else {
1847 $cat_qpart = "'$cat_id'";
1848 }
1849
1850 $result = db_query($link,
1851 "SELECT id FROM ttrss_feeds
1852 WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]);
1853
1854 if (db_num_rows($result) == 0) {
1855
1856 $result = db_query($link,
1857 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
1858 VALUES ('".$_SESSION["uid"]."', '$feed_link',
1859 '[Unknown]', $cat_qpart)");
1860
1861 $result = db_query($link,
1862 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'
1863 AND owner_uid = " . $_SESSION["uid"]);
1864
1865 $feed_id = db_fetch_result($result, 0, "id");
1866
1867 if ($feed_id) {
1868 update_rss_feed($link, $feed_link, $feed_id, true);
1869 }
1870 } else {
1871
1872 print "<div class=\"warning\">
1873 Feed <b>$feed_link</b> already exists in the database.
1874 </div>";
1875 }
1876 }
1877 }
1878
1879 if ($subop == "addCat") {
1880
1881 if (!WEB_DEMO_MODE) {
1882
1883 $feed_cat = db_escape_string(trim($_GET["cat"]));
1884
1885 $result = db_query($link,
1886 "SELECT id FROM ttrss_feed_categories
1887 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
1888
1889 if (db_num_rows($result) == 0) {
1890
1891 $result = db_query($link,
1892 "INSERT INTO ttrss_feed_categories (owner_uid,title)
1893 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
1894
1895 } else {
1896
1897 print "<div class=\"warning\">
1898 Category <b>$feed_cat</b> already exists in the database.
1899 </div>";
1900 }
1901
1902
1903 }
1904 }
1905
1906 if ($subop == "removeCats") {
1907
1908 if (!WEB_DEMO_MODE) {
1909
1910 $ids = split(",", db_escape_string($_GET["ids"]));
1911
1912 foreach ($ids as $id) {
1913
1914 db_query($link, "BEGIN");
1915
1916 $result = db_query($link,
1917 "SELECT count(id) as num_feeds FROM ttrss_feeds
1918 WHERE cat_id = '$id'");
1919
1920 $num_feeds = db_fetch_result($result, 0, "num_feeds");
1921
1922 if ($num_feeds == 0) {
1923 db_query($link, "DELETE FROM ttrss_feed_categories
1924 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1925 } else {
1926
1927 print "<div class=\"warning\">
1928 Unable to delete non empty feed categories.</div>";
1929
1930 }
1931
1932 db_query($link, "COMMIT");
1933 }
1934 }
1935 }
1936
1937 if ($subop == "categorize") {
1938
1939 if (!WEB_DEMO_MODE) {
1940
1941 $ids = split(",", db_escape_string($_GET["ids"]));
1942
1943 $cat_id = db_escape_string($_GET["cat_id"]);
1944
1945 if ($cat_id == 0) {
1946 $cat_id_qpart = 'NULL';
1947 } else {
1948 $cat_id_qpart = "'$cat_id'";
1949 }
1950
1951 db_query($link, "BEGIN");
1952
1953 foreach ($ids as $id) {
1954
1955 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
1956 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1957 }
1958
1959 db_query($link, "COMMIT");
1960 }
1961
1962 }
1963
1964 if ($quiet) return;
1965
1966// print "<h3>Edit Feeds</h3>";
1967
1968 $result = db_query($link, "SELECT id,title,feed_url,last_error
1969 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1970
1971 if (db_num_rows($result) > 0) {
1972
1973 print "<div class=\"warning\">";
1974
1975// print"<img class=\"closeButton\"
1976// onclick=\"javascript:hideParentElement(this);\" src=\"images/close.png\">";
1977
1978 print "<a href=\"javascript:showBlockElement('feedUpdateErrors')\">
1979 <b>Feeds with update errors</b> (click to expand)</a>";
1980
1981 print "<ul id=\"feedUpdateErrors\" class=\"nomarks\">";
1982
1983 while ($line = db_fetch_assoc($result)) {
1984 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
1985 $line["last_error"];
1986 }
1987
1988 print "</ul>";
1989 print "</div>";
1990
1991 }
1992
1993 $feed_search = db_escape_string($_GET["search"]);
1994
1995 if (array_key_exists("search", $_GET)) {
1996 $_SESSION["prefs_feed_search"] = $feed_search;
1997 } else {
1998 $feed_search = $_SESSION["prefs_feed_search"];
1999 }
2000
2001 print "<table width='100%' class=\"prefGenericAddBox\"
2002 cellspacing='0' cellpadding='0'><tr>
2003 <td>
2004 <input id=\"fadd_link\"
2005 onchange=\"javascript:addFeed()\"
2006 size=\"40\">
2007 <input type=\"submit\" class=\"button\"
2008 onclick=\"javascript:addFeed()\" value=\"Add feed\">";
2009
2010 if (ENABLE_FEED_BROWSER) {
2011 print "&nbsp;(<a href='javascript:browseFeeds()'>Top 50</a>)";
2012 }
2013
2014 print "</td><td align='right'>
2015 <input id=\"feed_search\" size=\"20\"
2016 onchange=\"javascript:updateFeedList()\"
2017 value=\"$feed_search\">
2018 <input type=\"submit\" class=\"button\"
2019 onclick=\"javascript:updateFeedList()\" value=\"Search\">
2020 </td>
2021 </tr></table>";
2022
2023 $feeds_sort = db_escape_string($_GET["sort"]);
2024
2025 if (!$feeds_sort || $feeds_sort == "undefined") {
2026 $feeds_sort = $_SESSION["pref_sort_feeds"];
2027 if (!$feeds_sort) $feeds_sort = "title";
2028 }
2029
2030 $_SESSION["pref_sort_feeds"] = $feeds_sort;
2031
2032 if ($feed_search) {
2033 $search_qpart = "(UPPER(F1.title) LIKE UPPER('%$feed_search%') OR
2034 UPPER(F1.feed_url) LIKE UPPER('%$feed_search%')) AND";
2035 } else {
2036 $search_qpart = "";
2037 }
2038
2039 $result = db_query($link, "SELECT
2040 F1.id,
2041 F1.title,
2042 F1.feed_url,
2043 substring(F1.last_updated,1,16) AS last_updated,
2044 F1.parent_feed,
2045 F1.update_interval,
2046 F1.purge_interval,
2047 F1.cat_id,
2048 F2.title AS parent_title,
2049 C1.title AS category
2050 FROM
2051 ttrss_feeds AS F1
2052 LEFT JOIN ttrss_feeds AS F2
2053 ON (F1.parent_feed = F2.id)
2054 LEFT JOIN ttrss_feed_categories AS C1
2055 ON (F1.cat_id = C1.id)
2056 WHERE
2057 $search_qpart F1.owner_uid = '".$_SESSION["uid"]."'
2058 ORDER by category,$feeds_sort,title");
2059
2060 if (db_num_rows($result) != 0) {
2061
2062 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2063
2064 print "<p><table width=\"100%\" cellspacing=\"0\"
2065 class=\"prefFeedList\" id=\"prefFeedList\">";
2066 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2067 Select:
2068 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
2069 'FEEDR-', 'FRCHK-', true)\">All</a>,
2070 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
2071 'FEEDR-', 'FRCHK-', false)\">None</a>
2072 </td</tr>";
2073
2074 if (!get_pref($link, 'ENABLE_FEED_CATS')) {
2075 print "<tr class=\"title\">
2076 <td width='5%' align='center'>&nbsp;</td>
2077 <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
2078 <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
2079 <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td>
2080 <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Interval</a></td></tr>";
2081 }
2082
2083 $lnum = 0;
2084
2085 $cur_cat_id = -1;
2086
2087 while ($line = db_fetch_assoc($result)) {
2088
2089 $feed_id = $line["id"];
2090 $cat_id = $line["cat_id"];
2091
2092 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
2093 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
2094 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
2095
2096// if ($line["update_interval"] == "0") $line["update_interval"] = "Default";
2097// if ($line["update_interval"] == "-1") $line["update_interval"] = "Disabled";
2098// if ($line["purge_interval"] == "0") $line["purge_interval"] = "Default";
2099// if ($line["purge_interval"] < 0) $line["purge_interval"] = "Disabled";
2100
2101 if (!$edit_cat) $edit_cat = "Uncategorized";
2102
2103 if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
2104 $lnum = 0;
2105
2106 print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>";
2107
2108 print "<tr class=\"title\">
2109 <td width='5%' align='center'>&nbsp;</td>
2110 <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
2111 <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
2112 <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td>
2113 <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Interval</a></td></tr>";
2114
2115 $cur_cat_id = $cat_id;
2116 }
2117
2118 $class = ($lnum % 2) ? "even" : "odd";
2119 $this_row_id = "id=\"FEEDR-$feed_id\"";
2120
2121 print "<tr class=\"$class\" $this_row_id>";
2122
2123 $icon_file = ICONS_DIR . "/$feed_id.ico";
2124
2125 if (file_exists($icon_file) && filesize($icon_file) > 0) {
2126 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/$feed_id.ico\">";
2127 } else {
2128 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
2129 }
2130// print "<td class='feedIcon'>$feed_icon</td>";
2131
2132 print "<td class='feedSelect'><input onclick='toggleSelectRow(this);'
2133 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
2134
2135 $edit_title = truncate_string($edit_title, 40);
2136 $edit_link = truncate_string($edit_link, 60);
2137
2138 $parent_title = $line["parent_title"];
2139 if ($parent_title) {
2140 $parent_title = "<span class='groupPrompt'>(linked to
2141 $parent_title)</span>";
2142 }
2143
2144 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
2145 "$feed_icon $edit_title $parent_title" . "</a></td>";
2146
2147 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
2148 $edit_link . "</a></td>";
2149
2150/* if (get_pref($link, 'ENABLE_FEED_CATS')) {
2151 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
2152 $edit_cat . "</a></td>";
2153 } */
2154
2155 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
2156 $update_intervals[$line["update_interval"]] . "</a></td>";
2157
2158 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
2159 $purge_intervals[$line["purge_interval"]] . "</a></td>";
2160
2161 print "</tr>";
2162
2163 ++$lnum;
2164 }
2165
2166 print "</table>";
2167
2168 print "<p>";
2169
2170 if ($subop == "edit") {
2171 print "Edit feed:&nbsp;
2172 <input type=\"submit\" class=\"button\"
2173 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
2174 <input type=\"submit\" class=\"button\"
2175 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
2176 } else {
2177
2178 print "
2179 Selection:&nbsp;
2180 <input type=\"submit\" class=\"button\"
2181 onclick=\"javascript:selectedFeedDetails()\" value=\"Details\">
2182 <input type=\"submit\" class=\"button\"
2183 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
2184 <input type=\"submit\" class=\"button\"
2185 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
2186
2187 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2188
2189 print "&nbsp;&nbsp;";
2190
2191 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2192 WHERE owner_uid = ".$_SESSION["uid"]."
2193 ORDER BY title");
2194
2195 print "<select id=\"sfeed_set_fcat\">";
2196 print "<option id=\"0\">Uncategorized</option>";
2197
2198 if (db_num_rows($result) != 0) {
2199
2200 print "<option disabled>--------</option>";
2201
2202 while ($line = db_fetch_assoc($result)) {
2203 printf("<option id='%d'>%s</option>",
2204 $line["id"], $line["title"]);
2205 }
2206 }
2207
2208 print "</select>";
2209
2210 print " <input type=\"submit\" class=\"button\"
2211 onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Set category\">";
2212
2213 }
2214
2215 if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
2216 print "
2217 <input type=\"submit\" class=\"button\"
2218 onclick=\"javascript:readSelectedFeeds(true)\" value=\"Mark as read\">
2219 <input type=\"submit\" class=\"button\"
2220 onclick=\"javascript:readSelectedFeeds(false)\"
2221 value=\"Mark as unread\">&nbsp;";
2222 }
2223
2224 print "
2225 &nbsp;All feeds: <input type=\"submit\"
2226 class=\"button\" onclick=\"gotoExportOpml()\"
2227 value=\"Export OPML\">";
2228 }
2229 } else {
2230
2231 print "<p>No feeds defined.</p>";
2232
2233 }
2234
2235 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2236
2237 print "<h3>Edit Categories</h3>";
2238
2239 // print "<h3>Categories</h3>";
2240
2241 print "<div class=\"prefGenericAddBox\">
2242 <input id=\"fadd_cat\"
2243 onchange=\"javascript:addFeedCat()\"
2244 size=\"40\">&nbsp;
2245 <input
2246 type=\"submit\" class=\"button\"
2247 onclick=\"javascript:addFeedCat()\" value=\"Add category\"></div>";
2248
2249 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2250 WHERE owner_uid = ".$_SESSION["uid"]."
2251 ORDER BY title");
2252
2253 if (db_num_rows($result) != 0) {
2254
2255 print "<p><table width=\"100%\" class=\"prefFeedCatList\"
2256 cellspacing=\"0\" id=\"prefFeedCatList\">";
2257
2258 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2259 Select:
2260 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
2261 'FCATR-', 'FCCHK-', true)\">All</a>,
2262 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
2263 'FCATR-', 'FCCHK-', false)\">None</a>
2264 </td</tr>";
2265
2266 print "<tr class=\"title\">
2267 <td width=\"5%\"></td><td width=\"80%\">Title</td>
2268 </tr>";
2269
2270 $lnum = 0;
2271
2272 while ($line = db_fetch_assoc($result)) {
2273
2274 $class = ($lnum % 2) ? "even" : "odd";
2275
2276 $cat_id = $line["id"];
2277
2278 $edit_cat_id = $_GET["id"];
2279
2280 if ($subop == "editCat" && $cat_id != $edit_cat_id) {
2281 $class .= "Grayed";
2282 $this_row_id = "";
2283 } else {
2284 $this_row_id = "id=\"FCATR-$cat_id\"";
2285 }
2286
2287 print "<tr class=\"$class\" $this_row_id>";
2288
2289 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
2290
2291 if (!$edit_cat_id || $subop != "editCat") {
2292
2293 print "<td align='center'><input onclick='toggleSelectRow(this);'
2294 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
2295
2296 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
2297 $edit_title . "</a></td>";
2298
2299 } else if ($cat_id != $edit_cat_id) {
2300
2301 print "<td><input disabled=\"true\" type=\"checkbox\"
2302 id=\"FRCHK-".$line["id"]."\"></td>";
2303
2304 print "<td>$edit_title</td>";
2305
2306 } else {
2307
2308 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2309
2310 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
2311
2312 }
2313
2314 print "</tr>";
2315
2316 ++$lnum;
2317 }
2318
2319 print "</table>";
2320
2321 print "<p>";
2322
2323 if ($subop == "editCat") {
2324 print "Edit category:&nbsp;
2325 <input type=\"submit\" class=\"button\"
2326 onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\">
2327 <input type=\"submit\" class=\"button\"
2328 onclick=\"javascript:feedCatEditSave()\" value=\"Save\">";
2329 } else {
2330
2331 print "
2332 Selection:&nbsp;
2333 <input type=\"submit\" class=\"button\"
2334 onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\">
2335 <input type=\"submit\" class=\"button\"
2336 onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">";
2337
2338 }
2339
2340 } else {
2341 print "<p>No feed categories defined.</p>";
2342 }
2343 }
2344
2345 print "<h3>Import OPML</h3>
2346 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
2347 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
2348 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
2349 type=\"submit\" value=\"Import\">
2350 </form>";
2351
2352 }
2353
2354 if ($op == "pref-filters") {
2355
2356 $subop = $_GET["subop"];
2357 $quiet = $_GET["quiet"];
2358
2359 if ($subop == "editSave") {
2360
2361 $regexp = db_escape_string($_GET["r"]);
2362 $descr = db_escape_string($_GET["d"]);
2363 $match = db_escape_string($_GET["m"]);
2364 $filter_id = db_escape_string($_GET["id"]);
2365 $feed_id = db_escape_string($_GET["fid"]);
2366 $action_id = db_escape_string($_GET["aid"]);
2367
2368 if (!$feed_id) {
2369 $feed_id = 'NULL';
2370 } else {
2371 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2372 }
2373
2374 $result = db_query($link, "UPDATE ttrss_filters SET
2375 reg_exp = '$regexp',
2376 description = '$descr',
2377 feed_id = $feed_id,
2378 action_id = '$action_id',
2379 filter_type = (SELECT id FROM ttrss_filter_types WHERE
2380 description = '$match')
2381 WHERE id = '$filter_id'");
2382 }
2383
2384 if ($subop == "remove") {
2385
2386 if (!WEB_DEMO_MODE) {
2387
2388 $ids = split(",", db_escape_string($_GET["ids"]));
2389
2390 foreach ($ids as $id) {
2391 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
2392
2393 }
2394 }
2395 }
2396
2397 if ($subop == "add") {
2398
2399 if (!WEB_DEMO_MODE) {
2400
2401 $regexp = db_escape_string(trim($_GET["regexp"]));
2402 $match = db_escape_string(trim($_GET["match"]));
2403 $feed_id = db_escape_string($_GET["fid"]);
2404 $action_id = db_escape_string($_GET["aid"]);
2405
2406 if (!$feed_id) {
2407 $feed_id = 'NULL';
2408 } else {
2409 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2410 }
2411
2412 $result = db_query($link,
2413 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
2414 action_id)
2415 VALUES
2416 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
2417 description = '$match'),'".$_SESSION["uid"]."',
2418 $feed_id, '$action_id')");
2419 }
2420 }
2421
2422 if ($quiet) return;
2423
2424 $result = db_query($link, "SELECT description
2425 FROM ttrss_filter_types ORDER BY description");
2426
2427 $filter_types = array();
2428
2429 while ($line = db_fetch_assoc($result)) {
2430 array_push($filter_types, $line["description"]);
2431 }
2432
2433 print "<div class=\"prefGenericAddBox\">
2434 <input id=\"fadd_regexp\" size=\"40\">&nbsp;";
2435
2436 print_select("fadd_match", "Title", $filter_types);
2437
2438 print "&nbsp;<select id=\"fadd_feed\">";
2439
2440 print "<option selected id=\"0\">All feeds</option>";
2441
2442 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
2443 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2444
2445 if (db_num_rows($result) > 0) {
2446 print "<option disabled>--------</option>";
2447 }
2448
2449 while ($line = db_fetch_assoc($result)) {
2450 printf("<option id='%d'>%s</option>", $line["id"], $line["title"]);
2451 }
2452
2453 print "</select>&nbsp;";
2454
2455 print "&nbsp;Action: ";
2456
2457 print "<select id=\"fadd_action\">";
2458
2459 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2460 ORDER BY name");
2461
2462 while ($line = db_fetch_assoc($result)) {
2463 printf("<option id='%d'>%s</option>", $line["id"], $line["description"]);
2464 }
2465
2466 print "</select>&nbsp;";
2467
2468/* print "<input type=\"submit\"
2469 class=\"button\" onclick=\"javascript:testFilter()\"
2470 value=\"Test filter\"> "; */
2471
2472 print "<input type=\"submit\"
2473 class=\"button\" onclick=\"javascript:addFilter()\"
2474 value=\"Add filter\">";
2475
2476 print "</div>";
2477
2478 $result = db_query($link, "SELECT
2479 ttrss_filters.id AS id,reg_exp,
2480 ttrss_filters.description AS description,
2481 ttrss_filter_types.name AS filter_type_name,
2482 ttrss_filter_types.description AS filter_type_descr,
2483 feed_id,
2484 ttrss_filter_actions.description AS action_description,
2485 ttrss_feeds.title AS feed_title
2486 FROM
2487 ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN
2488 ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id)
2489 WHERE
2490 filter_type = ttrss_filter_types.id AND
2491 ttrss_filter_actions.id = action_id AND
2492 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
2493 ORDER by reg_exp");
2494
2495 if (db_num_rows($result) != 0) {
2496
2497 print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\"
2498 id=\"prefFilterList\">";
2499
2500 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2501 Select:
2502 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
2503 'FILRR-', 'FICHK-', true)\">All</a>,
2504 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
2505 'FILRR-', 'FICHK-', false)\">None</a>
2506 </td</tr>";
2507
2508 print "<tr class=\"title\">
2509 <td align='center' width=\"5%\">&nbsp;</td>
2510 <td width=\"20%\">Filter expression</td>
2511 <td width=\"20%\">Feed</td>
2512 <td width=\"15%\">Match</td>
2513 <td width=\"15%\">Action</td>
2514 <td width=\"30%\">Description</td></tr>";
2515
2516 $lnum = 0;
2517
2518 while ($line = db_fetch_assoc($result)) {
2519
2520 $class = ($lnum % 2) ? "even" : "odd";
2521
2522 $filter_id = $line["id"];
2523 $edit_filter_id = $_GET["id"];
2524
2525 if ($subop == "edit" && $filter_id != $edit_filter_id) {
2526 $class .= "Grayed";
2527 $this_row_id = "";
2528 } else {
2529 $this_row_id = "id=\"FILRR-$filter_id\"";
2530 }
2531
2532 print "<tr class=\"$class\" $this_row_id>";
2533
2534 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
2535 $line["description"] = htmlspecialchars($line["description"]);
2536
2537 if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
2538
2539 if (!$edit_filter_id || $subop != "edit") {
2540
2541 if (!$line["description"]) $line["description"] = "[No description]";
2542
2543 print "<td align='center'><input onclick='toggleSelectRow(this);'
2544 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
2545
2546 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2547 $line["reg_exp"] . "</td>";
2548
2549 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2550 $line["feed_title"] . "</td>";
2551
2552 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2553 $line["filter_type_descr"] . "</td>";
2554
2555 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2556 $line["action_description"] . "</td>";
2557
2558 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2559 $line["description"] . "</td>";
2560
2561 } else if ($filter_id != $edit_filter_id) {
2562
2563 if (!$line["description"]) $line["description"] = "[No description]";
2564
2565 print "<td><input disabled=\"true\" type=\"checkbox\"
2566 id=\"FICHK-".$line["id"]."\"></td>";
2567
2568 print "<td>".$line["reg_exp"]."</td>";
2569 print "<td>".$line["feed_title"]."</td>";
2570 print "<td>".$line["filter_type_descr"]."</td>";
2571 print "<td>".$line["action_description"]."</td>";
2572 print "<td>".$line["description"]."</td>";
2573
2574 } else {
2575
2576 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2577
2578 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
2579 "\"></td>";
2580
2581 print "<td>";
2582 print "<select id=\"iedit_feed\">";
2583 print "<option id=\"0\">All feeds</option>";
2584
2585 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
2586 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2587
2588 if (db_num_rows($tmp_result) > 0) {
2589 print "<option disabled>--------</option>";
2590 }
2591
2592 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2593 if ($tmp_line["id"] == $line["feed_id"]) {
2594 $is_selected = "selected";
2595 } else {
2596 $is_selected = "";
2597 }
2598 printf("<option $is_selected id='%d'>%s</option>",
2599 $tmp_line["id"], $tmp_line["title"]);
2600 }
2601
2602 print "</select></td>";
2603
2604 print "<td>";
2605 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
2606 print "</td>";
2607
2608 print "<td>";
2609 print "<select id=\"iedit_filter_action\">";
2610
2611 $tmp_result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2612 ORDER BY description");
2613
2614 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2615 if ($tmp_line["description"] == $line["action_description"]) {
2616 $is_selected = "selected";
2617 } else {
2618 $is_selected = "";
2619 }
2620 printf("<option $is_selected id='%d'>%s</option>",
2621 $tmp_line["id"], $tmp_line["description"]);
2622 }
2623
2624 print "</select></td>";
2625
2626
2627 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2628 "\"></td>";
2629
2630 print "</td>";
2631 }
2632
2633 print "</tr>";
2634
2635 ++$lnum;
2636 }
2637
2638 if ($lnum == 0) {
2639 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
2640 }
2641
2642 print "</table>";
2643
2644 print "<p>";
2645
2646 if ($subop == "edit") {
2647 print "Edit filter:
2648 <input type=\"submit\" class=\"button\"
2649 onclick=\"javascript:filterEditSave()\" value=\"Save\">
2650 <input type=\"submit\" class=\"button\"
2651 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">";
2652
2653 } else {
2654
2655 print "
2656 Selection:
2657 <input type=\"submit\" class=\"button\"
2658 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
2659 <input type=\"submit\" class=\"button\"
2660 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
2661 }
2662
2663 } else {
2664
2665 print "<p>No filters defined.</p>";
2666
2667 }
2668 }
2669
2670 // We need to accept raw SQL data in label queries, so not everything is escaped
2671 // here, this is by design. If you don't like the whole idea, disable labels
2672 // altogether with GLOBAL_ENABLE_LABELS = false
2673
2674 if ($op == "pref-labels") {
2675
2676 if (!GLOBAL_ENABLE_LABELS) {
2677 return;
2678 }
2679
2680 $subop = $_GET["subop"];
2681
2682 if ($subop == "test") {
2683
2684 $expr = $_GET["expr"];
2685 $descr = $_GET["descr"];
2686
2687 print "<div class='infoBoxContents'>";
2688
2689 print "<h1>Label &laquo;$descr&raquo;</h1>";
2690
2691// print "<p><b>Expression</b>: $expr</p>";
2692
2693 $result = db_query($link,
2694 "SELECT count(id) AS num_matches
2695 FROM ttrss_entries,ttrss_user_entries
2696 WHERE ($expr) AND
2697 ttrss_user_entries.ref_id = ttrss_entries.id AND
2698 owner_uid = " . $_SESSION["uid"]);
2699
2700 $num_matches = db_fetch_result($result, 0, "num_matches");;
2701
2702 if ($num_matches > 0) {
2703
2704 print "<p>Query returned <b>$num_matches</b> matches, first 5 follow:</p>";
2705
2706 $result = db_query($link,
2707 "SELECT title,
2708 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
2709 FROM ttrss_entries,ttrss_user_entries
2710 WHERE ($expr) AND
2711 ttrss_user_entries.ref_id = ttrss_entries.id
2712 AND owner_uid = " . $_SESSION["uid"] . "
2713 ORDER BY date_entered DESC LIMIT 5");
2714
2715 print "<ul class=\"nomarks\">";
2716 while ($line = db_fetch_assoc($result)) {
2717 print "<li>".$line["title"].
2718 " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
2719 }
2720 print "</ul>";
2721
2722 } else {
2723 print "<p>Query didn't return any matches.</p>";
2724 }
2725
2726 print "</div>";
2727
2728 print "<div align='center'>
2729 <input type='submit' class='button'
2730 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2731 return;
2732 }
2733
2734 if ($subop == "editSave") {
2735
2736 $sql_exp = $_GET["s"];
2737 $descr = $_GET["d"];
2738 $label_id = db_escape_string($_GET["id"]);
2739
2740// print "$sql_exp : $descr : $label_id";
2741
2742 $result = db_query($link, "UPDATE ttrss_labels SET
2743 sql_exp = '$sql_exp',
2744 description = '$descr'
2745 WHERE id = '$label_id'");
2746 }
2747
2748 if ($subop == "remove") {
2749
2750 if (!WEB_DEMO_MODE) {
2751
2752 $ids = split(",", db_escape_string($_GET["ids"]));
2753
2754 foreach ($ids as $id) {
2755 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
2756
2757 }
2758 }
2759 }
2760
2761 if ($subop == "add") {
2762
2763 if (!WEB_DEMO_MODE) {
2764
2765 // no escaping is done here on purpose
2766 $exp = trim($_GET["exp"]);
2767
2768 $result = db_query($link,
2769 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
2770 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
2771 }
2772 }
2773
2774 print "<div class=\"prefGenericAddBox\">
2775 <input size=\"40\" id=\"ladd_expr\">&nbsp;";
2776
2777 print"<input type=\"submit\" class=\"button\"
2778 onclick=\"javascript:addLabel()\" value=\"Add label\"></div>";
2779
2780 $result = db_query($link, "SELECT
2781 id,sql_exp,description
2782 FROM
2783 ttrss_labels
2784 WHERE
2785 owner_uid = ".$_SESSION["uid"]."
2786 ORDER by description");
2787
2788 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2789
2790 if (db_num_rows($result) != 0) {
2791
2792 print "<p><table width=\"100%\" cellspacing=\"0\"
2793 class=\"prefLabelList\" id=\"prefLabelList\">";
2794
2795 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2796 Select:
2797 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2798 'LILRR-', 'LICHK-', true)\">All</a>,
2799 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2800 'LILRR-', 'LICHK-', false)\">None</a>
2801 </td</tr>";
2802
2803 print "<tr class=\"title\">
2804 <td align='center' width=\"5%\">&nbsp;</td>
2805 <td width=\"40%\">SQL expression
2806 <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a>
2807 </td>
2808 <td width=\"40%\">Caption</td></tr>";
2809
2810 $lnum = 0;
2811
2812 while ($line = db_fetch_assoc($result)) {
2813
2814 $class = ($lnum % 2) ? "even" : "odd";
2815
2816 $label_id = $line["id"];
2817 $edit_label_id = $_GET["id"];
2818
2819 if ($subop == "edit" && $label_id != $edit_label_id) {
2820 $class .= "Grayed";
2821 $this_row_id = "";
2822 } else {
2823 $this_row_id = "id=\"LILRR-$label_id\"";
2824 }
2825
2826 print "<tr class=\"$class\" $this_row_id>";
2827
2828 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
2829 $line["description"] = htmlspecialchars($line["description"]);
2830
2831 if (!$edit_label_id || $subop != "edit") {
2832
2833 if (!$line["description"]) $line["description"] = "[No caption]";
2834
2835 print "<td align='center'><input onclick='toggleSelectRow(this);'
2836 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
2837
2838 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2839 $line["sql_exp"] . "</td>";
2840
2841 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2842 $line["description"] . "</td>";
2843
2844 } else if ($label_id != $edit_label_id) {
2845
2846 if (!$line["description"]) $line["description"] = "[No description]";
2847
2848 print "<td><input disabled=\"true\" type=\"checkbox\"
2849 id=\"LICHK-".$line["id"]."\"></td>";
2850
2851 print "<td>".$line["sql_exp"]."</td>";
2852 print "<td>".$line["description"]."</td>";
2853
2854 } else {
2855
2856 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2857
2858 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
2859 "\"></td>";
2860
2861 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2862 "\"></td>";
2863
2864 }
2865
2866
2867 print "</tr>";
2868
2869 ++$lnum;
2870 }
2871
2872 if ($lnum == 0) {
2873 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
2874 }
2875
2876 print "</table>";
2877
2878 print "<p>";
2879
2880 if ($subop == "edit") {
2881 print "Edit label:
2882 <input type=\"submit\" class=\"button\"
2883 onclick=\"javascript:labelTest()\" value=\"Test\">
2884 <input type=\"submit\" class=\"button\"
2885 onclick=\"javascript:labelEditSave()\" value=\"Save\">
2886 <input type=\"submit\" class=\"button\"
2887 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">";
2888
2889 } else {
2890
2891 print "
2892 Selection:
2893 <input type=\"submit\" class=\"button\"
2894 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
2895 <input type=\"submit\" class=\"button\"
2896 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
2897 }
2898 } else {
2899 print "<p>No labels defined.</p>";
2900 }
2901 }
2902
2903 if ($op == "error") {
2904 print "<div width=\"100%\" align='center'>";
2905 $msg = $_GET["msg"];
2906 print $msg;
2907 print "</div>";
2908 }
2909
2910 if ($op == "help") {
2911 if (!$_GET["noheaders"]) {
2912 print "<html><head>
2913 <title>Tiny Tiny RSS : Help</title>
2914 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2915 <script type=\"text/javascript\" src=\"functions.js\"></script>
2916 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2917 </head><body>";
2918 }
2919
2920 $tid = sprintf("%d", $_GET["tid"]);
2921
2922 print "<div class='infoBoxContents'>";
2923
2924 if (file_exists("help/$tid.php")) {
2925 include("help/$tid.php");
2926 } else {
2927 print "<p>Help topic not found.</p>";
2928 }
2929
2930 print "</div>";
2931
2932 print "<div align='center'>
2933 <input type='submit' class='button'
2934 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2935
2936 if (!$_GET["noheaders"]) {
2937 print "</body></html>";
2938 }
2939
2940 }
2941
2942 if ($op == "dlg") {
2943 $id = $_GET["id"];
2944 $param = $_GET["param"];
2945
2946 if ($id == "quickAddFeed") {
2947 print "
2948 Feed URL: <input
2949 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2950 id=\"qafInput\">";
2951
2952 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2953 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2954 WHERE owner_uid = ".$_SESSION["uid"]."
2955 ORDER BY title");
2956
2957 print " <select id=\"qafCat\">";
2958 print "<option id=\"0\">Uncategorized</option>";
2959
2960 if (db_num_rows($result) != 0) {
2961
2962 print "<option disabled>--------</option>";
2963
2964 while ($line = db_fetch_assoc($result)) {
2965 printf("<option id='%d'>%s</option>",
2966 $line["id"], $line["title"]);
2967 }
2968 }
2969
2970 print "</select>";
2971 }
2972
2973 print "&nbsp;<input class=\"button\"
2974 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
2975 <input class=\"button\"
2976 type=\"submit\" onclick=\"javascript:closeDlg()\"
2977 value=\"Cancel\">";
2978 }
2979
2980 if ($id == "quickDelFeed") {
2981
2982 $param = db_escape_string($param);
2983
2984 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
2985
2986 if ($result) {
2987
2988 $f_title = db_fetch_result($result, 0, "title");
2989
2990 print "Remove current feed (<b>$f_title</b>)?&nbsp;
2991 <input class=\"button\"
2992 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
2993 <input class=\"button\"
2994 type=\"submit\" onclick=\"javascript:closeDlg()\"
2995 value=\"Cancel\">";
2996 } else {
2997 print "Error: Feed $param not found.&nbsp;
2998 <input class=\"button\"
2999 type=\"submit\" onclick=\"javascript:closeDlg()\"
3000 value=\"Cancel\">";
3001 }
3002 }
3003
3004 if ($id == "search") {
3005
3006 $active_feed_id = db_escape_string($_GET["param"]);
3007
3008 print "<input id=\"searchbox\" class=\"extSearch\"
3009 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
3010 onchange=\"javascript:search()\">
3011 <select id=\"searchmodebox\">
3012 <option selected>All feeds</option>";
3013
3014 if ($active_feed_id) {
3015 print "<option>This feed</option>";
3016 } else {
3017 print "<option disabled>This feed</option>";
3018 }
3019
3020 if (get_pref($link, 'ENABLE_FEED_CATS')) {
3021 print "<option>This category</option>";
3022 }
3023
3024 print "</select>
3025 <input type=\"submit\"
3026 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
3027 <input class=\"button\"
3028 type=\"submit\" onclick=\"javascript:closeDlg()\"
3029 value=\"Close\">";
3030
3031 }
3032
3033 if ($id == "quickAddFilter") {
3034
3035 $result = db_query($link, "SELECT description
3036 FROM ttrss_filter_types ORDER BY description");
3037
3038 $filter_types = array();
3039
3040 while ($line = db_fetch_assoc($result)) {
3041 array_push($filter_types, $line["description"]);
3042 }
3043
3044 print "<table>";
3045
3046 print "<tr><td>Match:</td><td><input id=\"fadd_regexp\" size=\"40\">&nbsp;";
3047
3048 print_select("fadd_match", "Title", $filter_types);
3049
3050 print "</td></tr>";
3051 print "<tr><td>Feed:</td><td><select id=\"fadd_feed\">";
3052
3053 print "<option selected id=\"0\">All feeds</option>";
3054
3055 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
3056 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
3057
3058 if (db_num_rows($result) > 0) {
3059 print "<option disabled>--------</option>";
3060 }
3061
3062 while ($line = db_fetch_assoc($result)) {
3063 if ($param == $line["id"]) {
3064 $selected = "selected";
3065 } else {
3066 $selected = "";
3067 }
3068 printf("<option id='%d' %s>%s</option>", $line["id"], $selected, $line["title"]);
3069 }
3070
3071 print "</select></td></tr>";
3072
3073 print "<tr><td>Action:</td>";
3074
3075 print "<td><select id=\"fadd_action\">";
3076
3077 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
3078 ORDER BY name");
3079
3080 while ($line = db_fetch_assoc($result)) {
3081 printf("<option id='%d'>%s</option>", $line["id"], $line["description"]);
3082 }
3083
3084 print "</select>";
3085
3086 print "</td></tr><tr><td colspan=\"2\" align=\"right\">";
3087
3088 print "<input type=\"submit\"
3089 class=\"button\" onclick=\"javascript:qaddFilter()\"
3090 value=\"Add filter\"> ";
3091
3092 print "<input class=\"button\"
3093 type=\"submit\" onclick=\"javascript:closeDlg()\"
3094 value=\"Close\">";
3095
3096 print "</td></tr></table>";
3097 }
3098 }
3099
3100 // update feeds of all users, may be used anonymously
3101 if ($op == "globalUpdateFeeds") {
3102
3103 $result = db_query($link, "SELECT id FROM ttrss_users");
3104
3105 while ($line = db_fetch_assoc($result)) {
3106 $user_id = $line["id"];
3107// print "<!-- updating feeds of uid $user_id -->";
3108 update_all_feeds($link, false, $user_id);
3109 }
3110
3111 print "<rpc-reply>
3112 <message msg=\"All feeds updated\"/>
3113 </rpc-reply>";
3114
3115 }
3116
3117 if ($op == "pref-prefs") {
3118
3119 $subop = $_REQUEST["subop"];
3120
3121 if ($subop == "Save configuration") {
3122
3123 if (WEB_DEMO_MODE) {
3124 header("Location: prefs.php");
3125 return;
3126 }
3127
3128 $_SESSION["prefs_op_result"] = "save-config";
3129
3130 $_SESSION["prefs_cache"] = false;
3131
3132 foreach (array_keys($_POST) as $pref_name) {
3133
3134 $pref_name = db_escape_string($pref_name);
3135 $value = db_escape_string($_POST[$pref_name]);
3136
3137 $result = db_query($link, "SELECT type_name
3138 FROM ttrss_prefs,ttrss_prefs_types
3139 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
3140
3141 if (db_num_rows($result) > 0) {
3142
3143 $type_name = db_fetch_result($result, 0, "type_name");
3144
3145// print "$pref_name : $type_name : $value<br>";
3146
3147 if ($type_name == "bool") {
3148 if ($value == "1") {
3149 $value = "true";
3150 } else {
3151 $value = "false";
3152 }
3153 } else if ($type_name == "integer") {
3154 $value = sprintf("%d", $value);
3155 }
3156
3157// print "$pref_name : $type_name : $value<br>";
3158
3159 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
3160 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
3161
3162 }
3163
3164 header("Location: prefs.php");
3165
3166 }
3167
3168 } else if ($subop == "getHelp") {
3169
3170 $pref_name = db_escape_string($_GET["pn"]);
3171
3172 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
3173 WHERE pref_name = '$pref_name'");
3174
3175 if (db_num_rows($result) > 0) {
3176 $help_text = db_fetch_result($result, 0, "help_text");
3177 print $help_text;
3178 } else {
3179 print "Unknown option: $pref_name";
3180 }
3181
3182 } else if ($subop == "Change e-mail") {
3183
3184 if (WEB_DEMO_MODE) {
3185 header("Location: prefs.php");
3186 return;
3187 }
3188
3189 $email = db_escape_string($_GET["email"]);
3190 $active_uid = $_SESSION["uid"];
3191
3192 if ($email) {
3193 db_query($link, "UPDATE ttrss_users SET email = '$email'
3194 WHERE id = '$active_uid'");
3195 }
3196
3197 header("Location: prefs.php");
3198
3199 } else if ($subop == "Change password") {
3200
3201 if (WEB_DEMO_MODE) {
3202 header("Location: prefs.php");
3203 return;
3204 }
3205
3206 $old_pw = $_POST["OLD_PASSWORD"];
3207 $new_pw = $_POST["OLD_PASSWORD"];
3208
3209 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
3210 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
3211
3212 $active_uid = $_SESSION["uid"];
3213
3214 if ($old_pw && $new_pw) {
3215
3216 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
3217
3218 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3219 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
3220 pwd_hash = '$old_pw_hash')");
3221
3222 if (db_num_rows($result) == 1) {
3223 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
3224 WHERE id = '$active_uid'");
3225
3226 $_SESSION["pwd_change_result"] = "ok";
3227 } else {
3228 $_SESSION["pwd_change_result"] = "failed";
3229 }
3230 }
3231
3232 header("Location: prefs.php");
3233
3234 } else if ($subop == "Reset to defaults") {
3235
3236 if (WEB_DEMO_MODE) {
3237 header("Location: prefs.php");
3238 return;
3239 }
3240
3241 $_SESSION["prefs_op_result"] = "reset-to-defaults";
3242
3243 if (DB_TYPE == "pgsql") {
3244 db_query($link,"UPDATE ttrss_user_prefs
3245 SET value = ttrss_prefs.def_value
3246 WHERE owner_uid = '".$_SESSION["uid"]."' AND
3247 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
3248 } else {
3249 db_query($link, "DELETE FROM ttrss_user_prefs
3250 WHERE owner_uid = ".$_SESSION["uid"]);
3251 initialize_user_prefs($link, $_SESSION["uid"]);
3252 }
3253
3254 header("Location: prefs.php");
3255
3256 } else if ($subop == "Change theme") {
3257
3258 $theme = db_escape_string($_POST["theme"]);
3259
3260 if ($theme == "Default") {
3261 $theme_qpart = 'NULL';
3262 } else {
3263 $theme_qpart = "'$theme'";
3264 }
3265
3266 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
3267 WHERE theme_name = '$theme'");
3268
3269 if (db_num_rows($result) == 1) {
3270 $theme_id = db_fetch_result($result, 0, "id");
3271 $theme_path = db_fetch_result($result, 0, "theme_path");
3272 } else {
3273 $theme_id = "NULL";
3274 $theme_path = "";
3275 }
3276
3277 db_query($link, "UPDATE ttrss_users SET
3278 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
3279
3280 $_SESSION["theme"] = $theme_path;
3281
3282 header("Location: prefs.php");
3283
3284 } else {
3285
3286 if (!SINGLE_USER_MODE) {
3287
3288 $result = db_query($link, "SELECT id,email FROM ttrss_users
3289 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
3290 pwd_hash = 'SHA1:".sha1("password")."')");
3291
3292 if (db_num_rows($result) != 0) {
3293 print "<div class=\"warning\">
3294 Your password is at default value, please change it.
3295 </div>";
3296 }
3297
3298 if ($_SESSION["pwd_change_result"] == "failed") {
3299 print "<div class=\"warning\">
3300 There was an error while changing your password.
3301 </div>";
3302 }
3303
3304 if ($_SESSION["pwd_change_result"] == "ok") {
3305 print "<div class=\"notice\">
3306 Password changed successfully.
3307 </div>";
3308 }
3309
3310 $_SESSION["pwd_change_result"] = "";
3311
3312 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
3313 print "<div class=\"notice\">
3314 Your configuration was reset to defaults.
3315 </div>";
3316 }
3317
3318 if ($_SESSION["prefs_op_result"] == "save-config") {
3319 print "<div class=\"notice\">
3320 Your configuration was saved successfully.
3321 </div>";
3322 }
3323
3324 $_SESSION["prefs_op_result"] = "";
3325
3326 print "<form action=\"backend.php\" method=\"GET\">";
3327
3328 print "<table width=\"100%\" class=\"prefPrefsList\">";
3329 print "<tr><td colspan='3'><h3>Personal data</h3></tr></td>";
3330
3331 $result = db_query($link, "SELECT email FROM ttrss_users
3332 WHERE id = ".$_SESSION["uid"]);
3333
3334 $email = db_fetch_result($result, 0, "email");
3335
3336 print "<tr><td width=\"40%\">E-mail</td>";
3337 print "<td><input class=\"editbox\" name=\"email\"
3338 value=\"$email\"></td></tr>";
3339
3340 print "</table>";
3341
3342 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3343
3344 print "<p><input class=\"button\" type=\"submit\"
3345 value=\"Change e-mail\" name=\"subop\">";
3346
3347 print "</form>";
3348
3349 print "<form action=\"backend.php\" method=\"POST\">";
3350
3351 print "<table width=\"100%\" class=\"prefPrefsList\">";
3352 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
3353
3354 print "<tr><td width=\"40%\">Old password</td>";
3355 print "<td><input class=\"editbox\" type=\"password\"
3356 name=\"OLD_PASSWORD\"></td></tr>";
3357
3358 print "<tr><td width=\"40%\">New password</td>";
3359
3360 print "<td><input class=\"editbox\" type=\"password\"
3361 name=\"NEW_PASSWORD\"></td></tr>";
3362
3363 print "</table>";
3364
3365 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3366
3367 print "<p><input class=\"button\" type=\"submit\"
3368 value=\"Change password\" name=\"subop\">";
3369
3370 print "</form>";
3371
3372 }
3373
3374 $result = db_query($link, "SELECT
3375 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
3376
3377 $user_theme_id = db_fetch_result($result, 0, "theme_id");
3378
3379 $result = db_query($link, "SELECT
3380 id,theme_name FROM ttrss_themes ORDER BY theme_name");
3381
3382 if (db_num_rows($result) > 0) {
3383
3384 print "<form action=\"backend.php\" method=\"POST\">";
3385 print "<table width=\"100%\" class=\"prefPrefsList\">";
3386 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
3387 print "<tr><td width=\"40%\">Select theme</td>";
3388 print "<td><select name=\"theme\">";
3389 print "<option>Default</option>";
3390 print "<option disabled>--------</option>";
3391
3392 while ($line = db_fetch_assoc($result)) {
3393 if ($line["id"] == $user_theme_id) {
3394 $selected = "selected";
3395 } else {
3396 $selected = "";
3397 }
3398 print "<option $selected>" . $line["theme_name"] . "</option>";
3399 }
3400 print "</select></td></tr>";
3401 print "</table>";
3402 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3403 print "<p><input class=\"button\" type=\"submit\"
3404 value=\"Change theme\" name=\"subop\">";
3405 print "</form>";
3406 }
3407
3408 $result = db_query($link, "SELECT
3409 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
3410 section_name,def_value
3411 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
3412 WHERE type_id = ttrss_prefs_types.id AND
3413 section_id = ttrss_prefs_sections.id AND
3414 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
3415 owner_uid = ".$_SESSION["uid"]."
3416 ORDER BY section_id,short_desc");
3417
3418 print "<form action=\"backend.php\" method=\"POST\">";
3419
3420 $lnum = 0;
3421
3422 $active_section = "";
3423
3424 while ($line = db_fetch_assoc($result)) {
3425
3426 if ($active_section != $line["section_name"]) {
3427
3428 if ($active_section != "") {
3429 print "</table>";
3430 }
3431
3432 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
3433
3434 $active_section = $line["section_name"];
3435
3436 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
3437// print "<tr class=\"title\">
3438// <td width=\"25%\">Option</td><td>Value</td></tr>";
3439
3440 $lnum = 0;
3441 }
3442
3443// $class = ($lnum % 2) ? "even" : "odd";
3444
3445 print "<tr>";
3446
3447 $type_name = $line["type_name"];
3448 $pref_name = $line["pref_name"];
3449 $value = $line["value"];
3450 $def_value = $line["def_value"];
3451 $help_text = $line["help_text"];
3452
3453 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
3454
3455 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
3456
3457 print "</td>";
3458
3459 print "<td>";
3460
3461 if ($type_name == "bool") {
3462// print_select($pref_name, $value, array("true", "false"));
3463
3464 if ($value == "true") {
3465 $value = "Yes";
3466 } else {
3467 $value = "No";
3468 }
3469
3470 print_radio($pref_name, $value, array("Yes", "No"));
3471
3472 } else {
3473 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
3474 }
3475
3476 print "</td>";
3477
3478 print "</tr>";
3479
3480 $lnum++;
3481 }
3482
3483 print "</table>";
3484
3485 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3486
3487 print "<p><input class=\"button\" type=\"submit\"
3488 name=\"subop\" value=\"Save configuration\">";
3489
3490 print "&nbsp;<input class=\"button\" type=\"submit\"
3491 name=\"subop\" onclick=\"return validatePrefsReset()\"
3492 value=\"Reset to defaults\"></p>";
3493
3494 print "</form>";
3495
3496 }
3497
3498 }
3499
3500 if ($op == "pref-users") {
3501
3502 $subop = $_GET["subop"];
3503
3504 if ($subop == "editSave") {
3505
3506 if (!WEB_DEMO_MODE) {
3507
3508 $login = db_escape_string($_GET["l"]);
3509 $uid = db_escape_string($_GET["id"]);
3510 $access_level = sprintf("%d", $_GET["al"]);
3511 $email = db_escape_string($_GET["e"]);
3512
3513 db_query($link, "UPDATE ttrss_users SET login = '$login',
3514 access_level = '$access_level', email = '$email' WHERE id = '$uid'");
3515
3516 }
3517 } else if ($subop == "remove") {
3518
3519 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3520
3521 $ids = split(",", db_escape_string($_GET["ids"]));
3522
3523 foreach ($ids as $id) {
3524 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
3525
3526 }
3527 }
3528 } else if ($subop == "add") {
3529
3530 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3531
3532 $login = db_escape_string(trim($_GET["login"]));
3533 $tmp_user_pwd = make_password(8);
3534 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3535
3536 db_query($link, "INSERT INTO ttrss_users
3537 (login,pwd_hash,access_level,last_login)
3538 VALUES ('$login', '$pwd_hash', 0, NOW())");
3539
3540
3541 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3542 login = '$login' AND pwd_hash = '$pwd_hash'");
3543
3544 if (db_num_rows($result) == 1) {
3545
3546 $new_uid = db_fetch_result($result, 0, "id");
3547
3548 print "<div class=\"notice\">Added user <b>".$_GET["login"].
3549 "</b> with password <b>$tmp_user_pwd</b>.</div>";
3550
3551 initialize_user($link, $new_uid);
3552
3553 } else {
3554
3555 print "<div class=\"warning\">Error while adding user <b>".
3556 $_GET["login"].".</b></div>";
3557
3558 }
3559 }
3560 } else if ($subop == "resetPass") {
3561
3562 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3563
3564 $uid = db_escape_string($_GET["id"]);
3565
3566 $result = db_query($link, "SELECT login,email
3567 FROM ttrss_users WHERE id = '$uid'");
3568
3569 $login = db_fetch_result($result, 0, "login");
3570 $email = db_fetch_result($result, 0, "email");
3571 $tmp_user_pwd = make_password(8);
3572 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3573
3574 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
3575 WHERE id = '$uid'");
3576
3577 print "<div class=\"notice\">Changed password of
3578 user <b>$login</b> to <b>$tmp_user_pwd</b>.";
3579
3580 if (MAIL_RESET_PASS && $email) {
3581 print " Notifying <b>$email</b>.";
3582
3583 mail("$login <$email>", "Password reset notification",
3584 "Hi, $login.\n".
3585 "\n".
3586 "Your password for this TT-RSS installation was reset by".
3587 " an administrator.\n".
3588 "\n".
3589 "Your new password is $tmp_user_pwd, please remember".
3590 " it for later reference.\n".
3591 "\n".
3592 "Sincerely, TT-RSS Mail Daemon.", "From: " . MAIL_FROM);
3593 }
3594
3595 print "</div>";
3596
3597 }
3598 }
3599
3600 print "<div class=\"prefGenericAddBox\">
3601 <input id=\"uadd_box\" onchange=\"javascript:addUser()\" size=\"40\">&nbsp;";
3602
3603 print"<input type=\"submit\" class=\"button\"
3604 onclick=\"javascript:addUser()\" value=\"Add user\"></div>";
3605
3606 $result = db_query($link, "SELECT
3607 id,login,access_level,email,
3608 SUBSTRING(last_login,1,16) as last_login
3609 FROM
3610 ttrss_users
3611 ORDER by login");
3612
3613 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
3614
3615 print "<p><table width=\"100%\" cellspacing=\"0\"
3616 class=\"prefUserList\" id=\"prefUserList\">";
3617
3618 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
3619 Select:
3620 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3621 'UMRR-', 'UMCHK-', true)\">All</a>,
3622 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3623 'UMRR-', 'UMCHK-', false)\">None</a>
3624 </td</tr>";
3625
3626 print "<tr class=\"title\">
3627 <td align='center' width=\"5%\">&nbsp;</td>
3628 <td width='20%'>Username</td>
3629 <td width='20%'>E-mail</td>
3630 <td width='20%'>Access Level</td>
3631 <td width='20%'>Last login</td></tr>";
3632
3633 $lnum = 0;
3634
3635 while ($line = db_fetch_assoc($result)) {
3636
3637 $class = ($lnum % 2) ? "even" : "odd";
3638
3639 $uid = $line["id"];
3640 $edit_uid = $_GET["id"];
3641
3642 if ($subop == "edit" && $uid != $edit_uid) {
3643 $class .= "Grayed";
3644 $this_row_id = "";
3645 } else {
3646 $this_row_id = "id=\"UMRR-$uid\"";
3647 }
3648
3649 print "<tr class=\"$class\" $this_row_id>";
3650
3651 $line["login"] = htmlspecialchars($line["login"]);
3652
3653 $line["last_login"] = date(get_pref($link, 'SHORT_DATE_FORMAT'),
3654 strtotime($line["last_login"]));
3655
3656 $access_level_names = array(0 => "User", 10 => "Administrator");
3657
3658/* if ($uid == $_SESSION["uid"]) {
3659
3660 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
3661 id=\"UMCHK-".$line["id"]."\"></td>";
3662
3663 print "<td>".$line["login"]."</td>";
3664 print "<td>".$line["email"]."</td>";
3665 print "<td>".$line["access_level"]."</td>";
3666
3667 } else */ if (!$edit_uid || $subop != "edit") {
3668
3669 print "<td align='center'><input onclick='toggleSelectRow(this);'
3670 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
3671
3672 print "<td><a href=\"javascript:editUser($uid);\">" .
3673 $line["login"] . "</td>";
3674
3675 print "<td><a href=\"javascript:editUser($uid);\">" .
3676 $line["email"] . "</td>";
3677
3678 print "<td><a href=\"javascript:editUser($uid);\">" .
3679 $access_level_names[$line["access_level"]] . "</td>";
3680
3681 } else if ($uid != $edit_uid) {
3682
3683 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
3684 id=\"UMCHK-".$line["id"]."\"></td>";
3685
3686 print "<td>".$line["login"]."</td>";
3687 print "<td>".$line["email"]."</td>";
3688 print "<td>".$access_level_names[$line["access_level"]]."</td>";
3689
3690 } else {
3691
3692 print "<td align='center'>
3693 <input disabled=\"true\" type=\"checkbox\" checked></td>";
3694
3695 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
3696 "\"></td>";
3697
3698 print "<td><input id=\"iedit_email\" value=\"".$line["email"].
3699 "\"></td>";
3700
3701// print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
3702// "\"></td>";
3703
3704 print "<td>";
3705 print "<select id=\"iedit_ulevel\">";
3706 foreach (array_keys($access_level_names) as $al) {
3707 if ($al == $line["access_level"]) {
3708 $selected = "selected";
3709 } else {
3710 $selected = "";
3711 }
3712 print "<option $selected id=\"$al\">" .
3713 $access_level_names[$al] . "</option>";
3714 }
3715 print "</select>";
3716 print "</td>";
3717
3718 }
3719
3720 print "<td>".$line["last_login"]."</td>";
3721
3722 print "</tr>";
3723
3724 ++$lnum;
3725 }
3726
3727 print "</table>";
3728
3729 print "<p>";
3730
3731 if ($subop == "edit") {
3732 print "Edit user:
3733 <input type=\"submit\" class=\"button\"
3734 onclick=\"javascript:userEditSave()\" value=\"Save\">
3735 <input type=\"submit\" class=\"button\"
3736 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">";
3737
3738 } else {
3739
3740 print "
3741 Selection:
3742 <input type=\"submit\" class=\"button\"
3743 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
3744 <input type=\"submit\" class=\"button\"
3745 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
3746 <input type=\"submit\" class=\"button\"
3747 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
3748 <input type=\"submit\" class=\"button\"
3749 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
3750
3751 }
3752 }
3753
3754 if ($op == "user-details") {
3755
3756 if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
3757 return;
3758 }
3759
3760/* print "<html><head>
3761 <title>Tiny Tiny RSS : User Details</title>
3762 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
3763 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
3764 </head><body>"; */
3765
3766 $uid = sprintf("%d", $_GET["id"]);
3767
3768 print "<div class='infoBoxContents'>";
3769
3770 $result = db_query($link, "SELECT login,
3771 SUBSTRING(last_login,1,16) AS last_login,
3772 access_level,
3773 (SELECT COUNT(int_id) FROM ttrss_user_entries
3774 WHERE owner_uid = id) AS stored_articles
3775 FROM ttrss_users
3776 WHERE id = '$uid'");
3777
3778 if (db_num_rows($result) == 0) {
3779 print "<h1>User not found</h1>";
3780 return;
3781 }
3782
3783 print "<h1>User Details</h1>";
3784
3785 print "<table width='100%'>";
3786
3787 $login = db_fetch_result($result, 0, "login");
3788 $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'),
3789 strtotime(db_fetch_result($result, 0, "last_login")));
3790 $access_level = db_fetch_result($result, 0, "access_level");
3791 $stored_articles = db_fetch_result($result, 0, "stored_articles");
3792
3793 print "<tr><td>Username</td><td>$login</td></tr>";
3794 print "<tr><td>Access level</td><td>$access_level</td></tr>";
3795 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
3796 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
3797
3798 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
3799 WHERE owner_uid = '$uid'");
3800
3801 $num_feeds = db_fetch_result($result, 0, "num_feeds");
3802
3803 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
3804
3805/* $result = db_query($link, "SELECT
3806 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
3807 FROM ttrss_user_entries,ttrss_entries
3808 WHERE owner_uid = '$uid' AND ref_id = id");
3809
3810 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
3811
3812 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
3813
3814 print "</table>";
3815
3816 print "<h1>Subscribed feeds</h1>";
3817
3818 $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
3819 WHERE owner_uid = '$uid' ORDER BY title");
3820
3821 print "<ul class=\"userFeedList\">";
3822
3823 while ($line = db_fetch_assoc($result)) {
3824
3825 $icon_file = ICONS_URL."/".$line["id"].".ico";
3826
3827 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3828 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
3829 } else {
3830 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3831 }
3832
3833 print "<li>$feed_icon&nbsp;<a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
3834 }
3835
3836 if (db_num_rows($result) < $num_feeds) {
3837 // FIXME - add link to show ALL subscribed feeds here somewhere
3838 print "<li><img
3839 class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">&nbsp;...</li>";
3840 }
3841
3842 print "</ul>";
3843
3844 print "</div>";
3845
3846 print "<div align='center'>
3847 <input type='submit' class='button'
3848 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3849
3850// print "</body></html>";
3851
3852 }
3853
3854 if ($op == "feed-details") {
3855
3856// $feed_id = $_GET["id"];
3857
3858 $feed_ids = split(",", db_escape_string($_GET["id"]));
3859
3860 print "<div class=\"infoBoxContents\">";
3861
3862 foreach ($feed_ids as $feed_id) {
3863
3864 $result = db_query($link,
3865 "SELECT
3866 title,feed_url,
3867 SUBSTRING(last_updated,1,16) as last_updated,
3868 icon_url,site_url,
3869 (SELECT COUNT(int_id) FROM ttrss_user_entries
3870 WHERE feed_id = id) AS total,
3871 (SELECT COUNT(int_id) FROM ttrss_user_entries
3872 WHERE feed_id = id AND unread = true) AS unread,
3873 (SELECT COUNT(int_id) FROM ttrss_user_entries
3874 WHERE feed_id = id AND marked = true) AS marked
3875 FROM ttrss_feeds
3876 WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]);
3877
3878 if (db_num_rows($result) == 0) return;
3879
3880 $title = db_unescape_string(db_fetch_result($result, 0, "title"));
3881 $last_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
3882 strtotime(db_fetch_result($result, 0, "last_updated")));
3883 $feed_url = db_fetch_result($result, 0, "feed_url");
3884 $icon_url = db_fetch_result($result, 0, "icon_url");
3885 $total = db_fetch_result($result, 0, "total");
3886 $unread = db_fetch_result($result, 0, "unread");
3887 $marked = db_fetch_result($result, 0, "marked");
3888 $site_url = db_fetch_result($result, 0, "site_url");
3889
3890 $result = db_query($link, "SELECT COUNT(id) AS subscribed
3891 FROM ttrss_feeds WHERE feed_url = '$feed_url' AND private = false");
3892
3893 $subscribed = db_fetch_result($result, 0, "subscribed");
3894
3895 $icon_file = ICONS_DIR . "/$feed_id.ico";
3896
3897 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3898 $feed_icon = "<img width=\"16\" height=\"16\"
3899 src=\"" . ICONS_URL . "/$feed_id.ico\">";
3900 } else {
3901 $feed_icon = "";
3902 }
3903
3904 print "<h1>$feed_icon $title</h1>";
3905
3906 print "<table width='100%'>";
3907
3908 if ($site_url) {
3909 print "<tr><td width='30%'>Link</td>
3910 <td><a href=\"$site_url\">$site_url</a>
3911 <a href=\"$feed_url\">(feed)</a></td>
3912 </td></tr>";
3913 } else {
3914 print "<tr><td width='30%'>Feed URL</td>
3915 <td><a href=\"$feed_url\">$feed_url</a></td></tr>";
3916 }
3917 print "<tr><td>Last updated</td><td>$last_updated</td></tr>";
3918 print "<tr><td>Total articles</td><td>$total</td></tr>";
3919 print "<tr><td>Unread articles</td><td>$unread</td></tr>";
3920 print "<tr><td>Starred articles</td><td>$marked</td></tr>";
3921 print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>";
3922
3923 print "</table>";
3924
3925/* $result = db_query($link, "SELECT title,
3926 SUBSTRING(updated,1,16) AS updated,unread
3927 FROM ttrss_entries,ttrss_user_entries
3928 WHERE ref_id = id AND feed_id = '$feed_id'
3929 ORDER BY date_entered DESC LIMIT 5");
3930
3931 if (db_num_rows($result) > 0) {
3932
3933 print "<h1>Latest headlines</h1>";
3934
3935 print "<ul class=\"nomarks\">";
3936
3937 while ($line = db_fetch_assoc($result)) {
3938 if ($line["unread"] == "t" || $line["unread"] == "1") {
3939 $line["title"] = "<b>" . $line["title"] . "</b>";
3940 }
3941 print "<li>" . $line["title"].
3942 "&nbsp;<span class=\"insensitive\">(" .
3943 date(get_pref($link, 'SHORT_DATE_FORMAT'),
3944 strtotime($line["updated"])).
3945 ")</span></li>";
3946 }
3947
3948 print "</ul>";
3949
3950 } */
3951 }
3952
3953 print "</div>";
3954
3955 print "<div align='center'>
3956 <input type='submit' class='button'
3957 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3958 }
3959
3960 if ($op == "pref-feed-browser") {
3961
3962 if (!ENABLE_FEED_BROWSER) {
3963 print "Feed browser is administratively disabled.";
3964 return;
3965 }
3966
3967 $subop = $_REQUEST["subop"];
3968
3969 if ($subop == "details") {
3970 $id = db_escape_string($_GET["id"]);
3971
3972 print "<div class=\"browserFeedInfo\">";
3973 print "<b>Feed information:</b>";
3974 print "<div class=\"detailsPart\">";
3975
3976 $result = db_query($link, "SELECT
3977 feed_url,site_url,
3978 SUBSTRING(last_updated,1,19) AS last_updated
3979 FROM ttrss_feeds WHERE id = '$id'");
3980
3981 $feed_url = db_fetch_result($result, 0, "feed_url");
3982 $site_url = db_fetch_result($result, 0, "site_url");
3983 $last_updated = db_fetch_result($result, 0, "last_updated");
3984
3985 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
3986 $last_updated = smart_date_time(strtotime($last_updated));
3987 } else {
3988 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
3989 $last_updated = date($short_date, strtotime($last_updated));
3990 }
3991
3992 print "Site: <a href='$site_url'>$site_url</a> ".
3993 "(<a href='$feed_url'>feed</a>), ".
3994 "Last updated: $last_updated";
3995
3996 print "</div>";
3997
3998 $result = db_query($link, "SELECT
3999 ttrss_entries.title,
4000 content,
4001 substring(date_entered,1,19) as date_entered,
4002 substring(updated,1,19) as updated
4003 FROM ttrss_entries,ttrss_user_entries
4004 WHERE ttrss_entries.id = ref_id AND feed_id = '$id'
4005 ORDER BY updated DESC LIMIT 5");
4006
4007 if (db_num_rows($result) > 0) {
4008
4009 print "<b>Last headlines:</b><br>";
4010
4011 print "<div class=\"detailsPart\">";
4012 print "<ul class=\"compact\">";
4013 while ($line = db_fetch_assoc($result)) {
4014
4015 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
4016 $entry_dt = smart_date_time(strtotime($line["updated"]));
4017 } else {
4018 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
4019 $entry_dt = date($short_date, strtotime($line["updated"]));
4020 }
4021
4022 print "<li>" . $line["title"] .
4023 "&nbsp;<span class=\"insensitive\">($entry_dt)</span></li>";
4024 }
4025 print "</ul></div>";
4026 }
4027
4028 print "</div>";
4029
4030 return;
4031 }
4032
4033 $result = db_query($link, "SELECT feed_url,count(id) AS subscribers
4034 FROM ttrss_feeds
4035 WHERE auth_login = '' AND auth_pass = '' AND private = false
4036 GROUP BY feed_url ORDER BY subscribers DESC LIMIT 100");
4037
4038 print "<ul class='nomarks' id='browseBigFeedList'>";
4039
4040 $feedctr = 0;
4041
4042 while ($line = db_fetch_assoc($result)) {
4043 $feed_url = $line["feed_url"];
4044 $subscribers = $line["subscribers"];
4045
4046 $sub_result = db_query($link, "SELECT id
4047 FROM ttrss_feeds WHERE feed_url = '$feed_url' AND owner_uid =" .
4048 $_SESSION["uid"]);
4049
4050 if (db_num_rows($sub_result) > 0) {
4051 continue; // already subscribed
4052 }
4053
4054 $det_result = db_query($link, "SELECT site_url,title,id
4055 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
4056
4057 $details = db_fetch_assoc($det_result);
4058
4059 $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
4060
4061 if (file_exists($icon_file) && filesize($icon_file) > 0) {
4062 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
4063 "/".$details["id"].".ico\">";
4064 } else {
4065 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
4066 }
4067
4068 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
4069 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
4070
4071 $class = ($feedctr % 2) ? "even" : "odd";
4072
4073 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
4074 "$feed_icon ";
4075
4076 print "<a href=\"javascript:browserToggleExpand('".$details["id"]."')\">" .
4077 $details["title"] ."</a>&nbsp;" .
4078 "<span class='subscribers'>($subscribers)</span>";
4079
4080 print "<div class=\"browserDetails\" id=\"BRDET-" . $details["id"] . "\">";
4081 print "</div>";
4082
4083 print "</li>";
4084
4085 ++$feedctr;
4086 }
4087
4088 if ($feedctr == 0) {
4089 print "<li>No feeds found to subscribe.</li>";
4090 }
4091
4092 print "</ul>";
4093
4094 print "<p>Selection:
4095 <input type='submit' class='button' onclick=\"feedBrowserSubscribe()\"
4096 value=\"Subscribe\"></p>";
4097
4098 print "</div>";
4099
4100 }
4101
4102 db_close($link);
4103?>
4104
4105<!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
4106