]> git.wh0rd.org - tt-rss.git/blob - backend.php
move out some functions from backend.php
[tt-rss.git] / backend.php
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 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
875 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
876
877 if (db_num_rows($result) == 1) {
878 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
879 } else {
880 $rtl_content = false;
881 }
882
883 if ($rtl_content) {
884 $rtl_tag = "dir=\"RTL\"";
885 } else {
886 $rtl_tag = "";
887 }
888
889 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
890 <script type=\"text/javascript\" src=\"functions.js\"></script>
891 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
892 <!--[if gte IE 5.5000]>
893 <script type=\"text/javascript\" src=\"pngfix.js\"></script>
894 <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
895 <![endif]-->
896 </head><body $rtl_tag>
897 <script type=\"text/javascript\">
898 if (document.addEventListener) {
899 document.addEventListener(\"DOMContentLoaded\", init, null);
900 }
901 window.onload = init;
902 </script>";
903
904 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
905 update_generic_feed($link, $feed, $cat_view);
906 }
907
908 if ($subop == "MarkAllRead") {
909 catchup_feed($link, $feed, $cat_view);
910 }
911
912 $search = db_escape_string($_GET["search"]);
913 $search_mode = db_escape_string($_GET["smode"]);
914
915 if ($search) {
916 $search_query_part = "(upper(ttrss_entries.title) LIKE upper('%$search%')
917 OR ttrss_entries.content LIKE '%$search%') AND";
918 } else {
919 $search_query_part = "";
920 }
921
922 $view_query_part = "";
923
924 if ($view_mode == "Adaptive") {
925 if ($search) {
926 $view_query_part = " ";
927 } else if ($feed != -1) {
928 $unread = getFeedUnread($link, $feed);
929 if ($unread > 0) {
930 $view_query_part = " unread = true AND ";
931 }
932 }
933 }
934
935 if ($view_mode == "Starred") {
936 $view_query_part = " marked = true AND ";
937 }
938
939 if ($view_mode == "Unread") {
940 $view_query_part = " unread = true AND ";
941 }
942
943 if ($limit && $limit != "All") {
944 $limit_query_part = "LIMIT " . $limit;
945 }
946
947 $vfeed_query_part = "";
948
949 // override query strategy and enable feed display when searching globally
950 if ($search && $search_mode == "All feeds") {
951 $query_strategy_part = "ttrss_entries.id > 0";
952 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
953 } else if (preg_match("/^-?[0-9][0-9]*$/", $feed) == false) {
954 $query_strategy_part = "ttrss_entries.id > 0";
955 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
956 id = feed_id) as feed_title,";
957 } else if ($feed >= 0 && $search && $search_mode == "This category") {
958
959 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
960
961 $tmp_result = db_query($link, "SELECT id
962 FROM ttrss_feeds WHERE cat_id =
963 (SELECT cat_id FROM ttrss_feeds WHERE id = '$feed') AND id != '$feed'");
964
965 $cat_siblings = array();
966
967 if (db_num_rows($tmp_result) > 0) {
968 while ($p = db_fetch_assoc($tmp_result)) {
969 array_push($cat_siblings, "feed_id = " . $p["id"]);
970 }
971
972 $query_strategy_part = sprintf("(feed_id = %d OR %s)",
973 $feed, implode(" OR ", $cat_siblings));
974
975 } else {
976 $query_strategy_part = "ttrss_entries.id > 0";
977 }
978
979 } else if ($feed >= 0) {
980
981 if ($cat_view) {
982
983 if ($feed > 0) {
984 $query_strategy_part = "cat_id = '$feed'";
985 } else {
986 $query_strategy_part = "cat_id IS NULL";
987 }
988
989 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
990
991 } else {
992 $tmp_result = db_query($link, "SELECT id
993 FROM ttrss_feeds WHERE parent_feed = '$feed'
994 ORDER BY cat_id,title");
995
996 $parent_ids = array();
997
998 if (db_num_rows($tmp_result) > 0) {
999 while ($p = db_fetch_assoc($tmp_result)) {
1000 array_push($parent_ids, "feed_id = " . $p["id"]);
1001 }
1002
1003 $query_strategy_part = sprintf("(feed_id = %d OR %s)",
1004 $feed, implode(" OR ", $parent_ids));
1005
1006 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1007 } else {
1008 $query_strategy_part = "feed_id = '$feed'";
1009 }
1010 }
1011 } else if ($feed == -1) { // starred virtual feed
1012 $query_strategy_part = "marked = true";
1013 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1014 } else if ($feed <= -10) { // labels
1015 $label_id = -$feed - 11;
1016
1017 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
1018 WHERE id = '$label_id'");
1019
1020 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
1021
1022 $vfeed_query_part = "ttrss_feeds.title AS feed_title,";
1023 } else {
1024 $query_strategy_part = "id > 0"; // dumb
1025 }
1026
1027 $order_by = "updated DESC";
1028
1029 // if ($feed < -10) {
1030 // $order_by = "feed_id,updated DESC";
1031 // }
1032
1033 $feed_title = "";
1034
1035 if ($search && $search_mode == "All feeds") {
1036 $feed_title = "Global search results ($search)";
1037 } else if ($search && preg_match('/^-?[0-9][0-9]*$/', $feed) == false) {
1038 $feed_title = "Feed search results ($search, $feed)";
1039 } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) == false) {
1040 $feed_title = $feed;
1041 } else if (preg_match('/^-?[0-9][0-9]*$/', $feed) != false && $feed >= 0) {
1042
1043 if ($cat_view) {
1044
1045 if ($feed != 0) {
1046 $result = db_query($link, "SELECT title FROM ttrss_feed_categories
1047 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
1048 $feed_title = db_fetch_result($result, 0, "title");
1049 } else {
1050 $feed_title = "Uncategorized";
1051 }
1052 } else {
1053
1054 $result = db_query($link, "SELECT title,site_url,last_error FROM ttrss_feeds
1055 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
1056
1057 $feed_title = db_fetch_result($result, 0, "title");
1058 $feed_site_url = db_fetch_result($result, 0, "site_url");
1059 $last_error = db_fetch_result($result, 0, "last_error");
1060
1061 }
1062
1063 } else if ($feed == -1) {
1064 $feed_title = "Starred articles";
1065 } else if ($feed < -10) {
1066 $label_id = -$feed - 11;
1067 $result = db_query($link, "SELECT description FROM ttrss_labels
1068 WHERE id = '$label_id'");
1069 $feed_title = db_fetch_result($result, 0, "description");
1070 } else {
1071 $feed_title = "?";
1072 }
1073
1074 if ($feed < -10) error_reporting (0);
1075
1076 print "<div id=\"headlinesContainer\">";
1077
1078 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
1079
1080 if ($feed >= 0) {
1081 $feed_kind = "Feeds";
1082 } else {
1083 $feed_kind = "Labels";
1084 }
1085
1086 // if (!$vfeed_query_part) {
1087 $content_query_part = "content as content_preview,";
1088 // } else {
1089 // $content_query_part = "";
1090 // }
1091
1092 $query = "SELECT
1093 ttrss_entries.id,ttrss_entries.title,
1094 SUBSTRING(updated,1,16) as updated,
1095 unread,feed_id,marked,link,last_read,
1096 SUBSTRING(last_read,1,19) as last_read_noms,
1097 $vfeed_query_part
1098 $content_query_part
1099 SUBSTRING(updated,1,19) as updated_noms
1100 FROM
1101 ttrss_entries,ttrss_user_entries,ttrss_feeds
1102 WHERE
1103 ttrss_user_entries.feed_id = ttrss_feeds.id AND
1104 ttrss_user_entries.ref_id = ttrss_entries.id AND
1105 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
1106 $search_query_part
1107 $view_query_part
1108 $query_strategy_part ORDER BY $order_by
1109 $limit_query_part";
1110
1111 $result = db_query($link, $query);
1112
1113 if ($_GET["debug"]) print $query;
1114
1115 } else {
1116 // browsing by tag
1117
1118 $feed_kind = "Tags";
1119
1120 $result = db_query($link, "SELECT
1121 ttrss_entries.id as id,title,
1122 SUBSTRING(updated,1,16) as updated,
1123 unread,feed_id,
1124 marked,link,last_read,
1125 SUBSTRING(last_read,1,19) as last_read_noms,
1126 $vfeed_query_part
1127 $content_query_part
1128 SUBSTRING(updated,1,19) as updated_noms
1129 FROM
1130 ttrss_entries,ttrss_user_entries,ttrss_tags
1131 WHERE
1132 ref_id = ttrss_entries.id AND
1133 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
1134 post_int_id = int_id AND tag_name = '$feed' AND
1135 $view_query_part
1136 $search_query_part
1137 $query_strategy_part ORDER BY $order_by
1138 $limit_query_part");
1139 }
1140
1141 if (!$result) {
1142 print "<div align='center'>
1143 Could not display feed (query failed). Please check label match syntax or local configuration.</div>";
1144 return;
1145 }
1146
1147 function print_headline_subtoolbar($link, $feed_site_url, $feed_title,
1148 $bottom = false, $rtl_content = false) {
1149
1150 if (!$bottom) {
1151 $class = "headlinesSubToolbar";
1152 $tid = "headlineActionsTop";
1153 } else {
1154 $class = "invisible";
1155 $tid = "headlineActionsBottom";
1156 }
1157
1158 print "<table class=\"$class\" id=\"$tid\"
1159 width=\"100%\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
1160
1161 if ($rtl_content) {
1162 $rtl_cpart = "RTL";
1163 } else {
1164 $rtl_cpart = "";
1165 }
1166
1167 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1168
1169 print "<td class=\"headlineActions$rtl_cpart\">
1170 Select:
1171 <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, '', true)\">All</a>,
1172 <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true)\">Unread</a>,
1173 <a href='#' onclick=\"javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false)\">None</a>
1174 &nbsp;&nbsp;
1175 Toggle: <a href='#' onclick=\"javascript:selectionToggleUnread()\">Unread</a>,
1176 <a href='#' onclick=\"javascript:selectionToggleMarked()\">Starred</a>";
1177 print "</td>";
1178
1179 } else {
1180
1181 print "<td class=\"headlineActions$rtl_cpart\">
1182 Select:
1183 <a href=\"#\" onclick=\"javascript:cdmSelectArticles('all')\">All</a>,
1184 <a href=\"#\" onclick=\"javascript:cdmSelectArticles('unread')\">Unread</a>,
1185 <a href=\"#\" onclick=\"javascript:cdmSelectArticles('none')\">None</a>
1186 &nbsp;&nbsp;
1187 Toggle: <a href=\"#\" onclick=\"javascript:selectionToggleUnread(true)\">Unread</a>,
1188 <a href=\"#\" onclick=\"javascript:selectionToggleMarked(true)\">Starred</a>";
1189
1190 print "</td>";
1191
1192 }
1193
1194 print "<td class=\"headlineTitle$rtl_cpart\">";
1195
1196 if ($feed_site_url) {
1197 if (!$bottom) {
1198 $target = "target=\"_blank\"";
1199 }
1200 print "<a $target href=\"$feed_site_url\">$feed_title</a>";
1201 } else {
1202 print $feed_title;
1203 }
1204
1205 print "</td>";
1206 print "</tr></table>";
1207
1208 }
1209
1210 if (db_num_rows($result) > 0) {
1211
1212 print_headline_subtoolbar($link, $feed_site_url, $feed_title, false,
1213 $rtl_content);
1214
1215 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1216 print "<table class=\"headlinesList\" id=\"headlinesList\"
1217 cellspacing=\"0\" width=\"100%\">";
1218 }
1219
1220 $lnum = 0;
1221
1222 error_reporting (DEFAULT_ERROR_LEVEL);
1223
1224 $num_unread = 0;
1225
1226 while ($line = db_fetch_assoc($result)) {
1227
1228 $class = ($lnum % 2) ? "even" : "odd";
1229
1230 $id = $line["id"];
1231 $feed_id = $line["feed_id"];
1232
1233 if ($line["last_read"] == "" &&
1234 ($line["unread"] != "t" && $line["unread"] != "1")) {
1235
1236 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
1237 alt=\"Updated\">";
1238 } else {
1239 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
1240 alt=\"Updated\">";
1241 }
1242
1243 if ($line["unread"] == "t" || $line["unread"] == "1") {
1244 $class .= "Unread";
1245 ++$num_unread;
1246 $is_unread = true;
1247 } else {
1248 $is_unread = false;
1249 }
1250
1251 if ($line["marked"] == "t" || $line["marked"] == "1") {
1252 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
1253 alt=\"Reset mark\" onclick='javascript:toggleMark($id)'>";
1254 } else {
1255 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
1256 alt=\"Set mark\" onclick='javascript:toggleMark($id)'>";
1257 }
1258
1259 $content_link = "<a href=\"javascript:view($id,$feed_id);\">" .
1260 $line["title"] . "</a>";
1261
1262 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1263 $updated_fmt = smart_date_time(strtotime($line["updated"]));
1264 } else {
1265 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1266 $updated_fmt = date($short_date, strtotime($line["updated"]));
1267 }
1268
1269 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
1270 $content_preview = truncate_string(strip_tags($line["content_preview"]),
1271 100);
1272 }
1273
1274 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1275
1276 print "<tr class='$class' id='RROW-$id'>";
1277
1278 print "<td class='hlUpdatePic'>$update_pic</td>";
1279
1280 print "<td class='hlSelectRow'>
1281 <input type=\"checkbox\" onclick=\"toggleSelectRow(this)\"
1282 class=\"feedCheckBox\" id=\"RCHK-$id\">
1283 </td>";
1284
1285 print "<td class='hlMarkedPic'>$marked_pic</td>";
1286
1287 if ($line["feed_title"]) {
1288 print "<td class='hlContent'>$content_link</td>";
1289 print "<td class='hlFeed'>
1290 <a href='javascript:viewfeed($feed_id)'>".
1291 $line["feed_title"]."</a>&nbsp;</td>";
1292 } else {
1293 print "<td class='hlContent' valign='middle'>";
1294
1295 print "<a href=\"javascript:view($id,$feed_id);\">" .
1296 $line["title"];
1297
1298 if (get_pref($link, 'SHOW_CONTENT_PREVIEW') && !$rtl_tag) {
1299 if ($content_preview) {
1300 print "<span class=\"contentPreview\"> - $content_preview</span>";
1301 }
1302 }
1303
1304 print "</a>";
1305 print "</td>";
1306 }
1307
1308 print "<td class=\"hlUpdated\"><nobr>$updated_fmt&nbsp;</nobr></td>";
1309
1310 print "</tr>";
1311
1312 } else {
1313
1314 if ($is_unread) {
1315 $add_class = "Unread";
1316 } else {
1317 $add_class = "";
1318 }
1319
1320 print "<div class=\"cdmArticle$add_class\" id=\"RROW-$id\">";
1321
1322 print "<div class=\"cdmHeader\">";
1323
1324 print "<div style=\"float : right\">$updated_fmt</div>";
1325
1326 print "<a target=\"new\" href=\"".$line["link"]."\">".$line["title"]."</a>";
1327
1328 if ($line["feed_title"]) {
1329 print "&nbsp;(<a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>)";
1330 }
1331
1332 print "</div>";
1333
1334 print "<div class=\"cdmContent\">" . $line["content_preview"] . "</div>";
1335
1336 print "<div style=\"float : right\">$marked_pic</div>
1337 <div class=\"cdmFooter\">
1338 <input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
1339 'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\"></div>";
1340
1341 print "</div>";
1342
1343 }
1344
1345 ++$lnum;
1346 }
1347
1348 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
1349 print "</table>";
1350 }
1351
1352 print_headline_subtoolbar($link,
1353 "javascript:catchupPage()", "Mark page as read", true, $rtl_content);
1354
1355
1356 } else {
1357 print "<div width='100%' align='center'>No articles found.</div>";
1358 }
1359
1360 print "</div>";
1361
1362 print "<script type=\"text/javascript\">
1363 document.onkeydown = hotkey_handler;
1364 // if (parent.daemon_enabled) parent.updateTitle('$feed_title');
1365 update_all_counters('$feed');
1366 </script>";
1367
1368 print '
1369 <script type="text/javascript">
1370 /* for IE */
1371 function statechange() {
1372 if (document.readyState == "interactive") init();
1373 }
1374
1375 if (document.readyState) {
1376 if (document.readyState == "interactive" || document.readyState == "complete") {
1377 init();
1378 } else {
1379 document.onreadystatechange = statechange;
1380 }
1381 }
1382 </script>';
1383
1384 print "</body></html>";
1385 }
1386
1387 if ($op == "pref-rpc") {
1388
1389 $subop = $_GET["subop"];
1390
1391 if ($subop == "unread") {
1392 $ids = split(",", db_escape_string($_GET["ids"]));
1393 foreach ($ids as $id) {
1394 db_query($link, "UPDATE ttrss_user_entries SET unread = true
1395 WHERE feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
1396 }
1397
1398 print "Marked selected feeds as unread.";
1399 }
1400
1401 if ($subop == "read") {
1402 $ids = split(",", db_escape_string($_GET["ids"]));
1403 foreach ($ids as $id) {
1404 db_query($link, "UPDATE ttrss_user_entries
1405 SET unread = false,last_read = NOW() WHERE
1406 feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
1407 }
1408
1409 print "Marked selected feeds as read.";
1410
1411 }
1412
1413 }
1414
1415 if ($op == "pref-feeds") {
1416
1417 $subop = $_REQUEST["subop"];
1418 $quiet = $_REQUEST["quiet"];
1419
1420 if ($subop == "massSubscribe") {
1421 $ids = split(",", db_escape_string($_GET["ids"]));
1422
1423 $subscribed = array();
1424
1425 foreach ($ids as $id) {
1426 $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds
1427 WHERE id = '$id'");
1428
1429 $feed_url = db_fetch_result($result, 0, "feed_url");
1430 $title = db_fetch_result($result, 0, "title");
1431
1432 $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE
1433 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
1434
1435 if (db_num_rows($result) == 0) {
1436 $result = db_query($link,
1437 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
1438 VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)");
1439
1440 array_push($subscribed, $title);
1441 }
1442 }
1443
1444 if (count($subscribed) > 0) {
1445 print "<div class=\"notice\">";
1446 print "<b>Subscribed to feeds:</b>";
1447 print "<ul class=\"nomarks\">";
1448 foreach ($subscribed as $title) {
1449 print "<li>$title</li>";
1450 }
1451 print "</ul>";
1452 print "</div>";
1453 }
1454 }
1455
1456 if ($subop == "browse") {
1457
1458 if (!ENABLE_FEED_BROWSER) {
1459 print "Feed browser is administratively disabled.";
1460 return;
1461 }
1462
1463 print "<div class=\"infoBoxContents\">";
1464
1465 print "<h1>Feed browser</h1>";
1466
1467 print "<p>Showing top 50 registered feeds, sorted by popularity:</p>";
1468
1469 $result = db_query($link, "SELECT feed_url,count(id) AS subscribers
1470 FROM ttrss_feeds
1471 WHERE auth_login = '' AND auth_pass = '' AND private = false
1472 GROUP BY feed_url ORDER BY subscribers DESC LIMIT 50");
1473
1474 print "<ul class='browseFeedList' id='browseFeedList'>";
1475
1476 $feedctr = 0;
1477
1478 while ($line = db_fetch_assoc($result)) {
1479 $feed_url = $line["feed_url"];
1480 $subscribers = $line["subscribers"];
1481
1482 $sub_result = db_query($link, "SELECT id
1483 FROM ttrss_feeds WHERE feed_url = '$feed_url' AND owner_uid =" .
1484 $_SESSION["uid"]);
1485
1486 if (db_num_rows($sub_result) > 0) {
1487 continue; // already subscribed
1488 }
1489
1490 $det_result = db_query($link, "SELECT site_url,title,id
1491 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
1492
1493 $details = db_fetch_assoc($det_result);
1494
1495 $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
1496
1497 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1498 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
1499 "/".$details["id"].".ico\">";
1500 } else {
1501 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1502 }
1503
1504 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
1505 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
1506
1507 $class = ($feedctr % 2) ? "even" : "odd";
1508
1509 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
1510 "$feed_icon " . db_unescape_string($details["title"]) .
1511 "&nbsp;<span class='subscribers'>($subscribers)</span></li>";
1512
1513 ++$feedctr;
1514 }
1515
1516 if ($feedctr == 0) {
1517 print "<li>No feeds found to subscribe.</li>";
1518 }
1519
1520 print "</ul>";
1521
1522 print "<div align='center'>
1523 <input type=\"submit\" class=\"button\"
1524 onclick=\"feedBrowserSubscribe()\" value=\"Subscribe\">
1525 <input type='submit' class='button'
1526 onclick=\"closeInfoBox()\" value=\"Cancel\"></div>";
1527
1528 print "</div>";
1529 return;
1530 }
1531
1532 if ($subop == "editfeed") {
1533 $feed_id = db_escape_string($_GET["id"]);
1534
1535 $result = db_query($link,
1536 "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND
1537 owner_uid = " . $_SESSION["uid"]);
1538
1539 $title = htmlspecialchars(db_unescape_string(db_fetch_result($result,
1540 0, "title")));
1541
1542 print "<div class=\"infoBoxContents\">";
1543
1544 $icon_file = ICONS_DIR . "/$feed_id.ico";
1545
1546 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1547 $feed_icon = "<img width=\"16\" height=\"16\"
1548 src=\"" . ICONS_URL . "/$feed_id.ico\">";
1549 } else {
1550 $feed_icon = "";
1551 }
1552
1553 print "<h1>$feed_icon $title</h1>";
1554
1555 print "<table width='100%'>";
1556
1557 $row_class = "odd";
1558
1559 print "<tr class='$row_class'><td>Title:</td>";
1560 print "<td><input id=\"iedit_title\" value=\"$title\"></td></tr>";
1561
1562 $feed_url = db_fetch_result($result, 0, "feed_url");
1563 $feed_url = htmlspecialchars(db_unescape_string(db_fetch_result($result,
1564 0, "feed_url")));
1565 $row_class = toggleEvenOdd($row_class);
1566
1567 print "<tr class='$row_class'><td>Feed URL:</td>";
1568 print "<td><input id=\"iedit_link\" value=\"$feed_url\"></td></tr>";
1569
1570 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1571
1572 $cat_id = db_fetch_result($result, 0, "cat_id");
1573
1574 $row_class = toggleEvenOdd($row_class);
1575
1576 print "<tr class='$row_class'><td>Category:</td>";
1577 print "<td>";
1578 print "<select id=\"iedit_fcat\">";
1579 print "<option id=\"0\">Uncategorized</option>";
1580
1581 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feed_categories
1582 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1583
1584 if (db_num_rows($tmp_result) > 0) {
1585 print "<option disabled>--------</option>";
1586 }
1587
1588 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1589 if ($tmp_line["id"] == $cat_id) {
1590 $is_selected = "selected";
1591 } else {
1592 $is_selected = "";
1593 }
1594 printf("<option $is_selected id='%d'>%s</option>",
1595 $tmp_line["id"], $tmp_line["title"]);
1596 }
1597
1598 print "</select></td>";
1599 print "</td></tr>";
1600
1601 }
1602
1603 $update_interval = db_fetch_result($result, 0, "update_interval");
1604 $row_class = toggleEvenOdd($row_class);
1605
1606 print "<tr class='$row_class'><td>Update Interval:</td>";
1607 // print "<td><input id=\"iedit_updintl\"
1608 // value=\"$update_interval\"></td></tr>";
1609
1610 print "<td>";
1611
1612 print "<select id=\"iedit_updintl\">";
1613
1614 foreach (array_keys($update_intervals) as $i) {
1615
1616 if ($i == $update_interval) {
1617 $selected = "selected";
1618 } else {
1619 $selected = "";
1620 }
1621 print "<option $selected id=\"$i\">" . $update_intervals[$i] . "</option>";
1622 }
1623
1624 print "</select>";
1625
1626 print "</td>";
1627
1628 $row_class = toggleEvenOdd($row_class);
1629 print "<tr class='$row_class'><td>Link to:</td>";
1630
1631 $tmp_result = db_query($link, "SELECT COUNT(id) AS count
1632 FROM ttrss_feeds WHERE parent_feed = '$feed_id'");
1633
1634 $linked_count = db_fetch_result($tmp_result, 0, "count");
1635
1636 $parent_feed = db_fetch_result($result, 0, "parent_feed");
1637
1638 if ($linked_count > 0) {
1639 $disabled = "disabled";
1640 }
1641
1642 print "<select $disabled id=\"iedit_parent_feed\">";
1643
1644 print "<option id=\"0\">Not linked</option>";
1645
1646 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1647 if ($cat_id) {
1648 $cat_qpart = "AND cat_id = '$cat_id'";
1649 } else {
1650 $cat_qpart = "AND cat_id IS NULL";
1651 }
1652 }
1653
1654 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
1655 WHERE id != '$feed_id' AND owner_uid = ".$_SESSION["uid"]."
1656 $cat_qpart ORDER BY title");
1657
1658 if (db_num_rows($tmp_result) > 0) {
1659 print "<option disabled>--------</option>";
1660 }
1661
1662 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1663 if ($tmp_line["id"] == $parent_feed) {
1664 $is_selected = "selected";
1665 } else {
1666 $is_selected = "";
1667 }
1668 printf("<option $is_selected id='%d'>%s</option>",
1669 $tmp_line["id"], $tmp_line["title"]);
1670 }
1671
1672 print "</select></td>";
1673 print "</td></tr>";
1674
1675 $purge_interval = db_fetch_result($result, 0, "purge_interval");
1676 $row_class = toggleEvenOdd($row_class);
1677
1678 print "<tr class='$row_class'><td>Purge Days:</td>";
1679 // print "<td><input id=\"iedit_purgintl\"
1680 // value=\"$purge_interval\"></td></tr>";
1681
1682 print "<td>";
1683
1684 print "<select id=\"iedit_purgintl\">";
1685
1686 foreach (array_keys($purge_intervals) as $i) {
1687
1688 if ($i == $purge_interval) {
1689 $selected = "selected";
1690 } else {
1691 $selected = "";
1692 }
1693 print "<option $selected id=\"$i\">" . $purge_intervals[$i] . "</option>";
1694 }
1695
1696 print "</select>";
1697
1698 print "</td>";
1699
1700 // print "<tr><td colspan=\"2\"><b>Authentication</b></td></tr>";
1701
1702 $row_class = toggleEvenOdd($row_class);
1703 $auth_login = db_fetch_result($result, 0, "auth_login");
1704
1705 print "<tr class='$row_class'><td>Login:</td>";
1706 print "<td><input id=\"iedit_login\"
1707 value=\"$auth_login\"></td></tr>";
1708
1709 $row_class = toggleEvenOdd($row_class);
1710 $auth_pass = db_fetch_result($result, 0, "auth_pass");
1711
1712 print "<tr class='$row_class'><td>Password:</td>";
1713 print "<td><input type=\"password\" id=\"iedit_pass\"
1714 value=\"$auth_pass\"></td></tr>";
1715
1716 $row_class = toggleEvenOdd($row_class);
1717 $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
1718
1719 if ($private) {
1720 $checked = "checked";
1721 } else {
1722 $checked = "";
1723 }
1724
1725 print "<tr class='$row_class'><td valign='top'>Options:</td>";
1726 print "<td><input type=\"checkbox\" id=\"iedit_private\"
1727 $checked><label for=\"iedit_private\">Hide from feed browser</label>";
1728
1729 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
1730
1731 if ($rtl_content) {
1732 $checked = "checked";
1733 } else {
1734 $checked = "";
1735 }
1736
1737 print "<br><input type=\"checkbox\" id=\"iedit_rtl\"
1738 $checked><label for=\"iedit_rtl\">Right-to-left content</label>";
1739
1740 print "</td></tr>";
1741
1742 print "</table>";
1743 print "</div>";
1744
1745 print "<div align='center'>
1746 <input type=\"submit\" class=\"button\"
1747 onclick=\"feedEditSave()\" value=\"Save\">
1748 <input type='submit' class='button'
1749 onclick=\"feedEditCancel()\" value=\"Cancel\"></div>";
1750 return;
1751 }
1752
1753 if ($subop == "editSave") {
1754 $feed_title = db_escape_string($_POST["t"]);
1755 $feed_link = db_escape_string($_POST["l"]);
1756 $upd_intl = db_escape_string($_POST["ui"]);
1757 $purge_intl = db_escape_string($_POST["pi"]);
1758 $feed_id = db_escape_string($_POST["id"]);
1759 $cat_id = db_escape_string($_POST["catid"]);
1760 $auth_login = db_escape_string($_POST["login"]);
1761 $auth_pass = db_escape_string($_POST["pass"]);
1762 $parent_feed = db_escape_string($_POST["pfeed"]);
1763 $private = db_escape_string($_POST["is_pvt"]);
1764 $rtl_content = db_escape_string($_POST["is_rtl"]);
1765
1766 if (strtoupper($upd_intl) == "DEFAULT")
1767 $upd_intl = 0;
1768
1769 if (strtoupper($upd_intl) == "DISABLED")
1770 $upd_intl = -1;
1771
1772 if (strtoupper($purge_intl) == "DEFAULT")
1773 $purge_intl = 0;
1774
1775 if (strtoupper($purge_intl) == "DISABLED")
1776 $purge_intl = -1;
1777
1778 if ($cat_id != 0) {
1779 $category_qpart = "cat_id = '$cat_id'";
1780 } else {
1781 $category_qpart = 'cat_id = NULL';
1782 }
1783
1784 if ($parent_feed != 0) {
1785 $parent_qpart = "parent_feed = '$parent_feed'";
1786 } else {
1787 $parent_qpart = 'parent_feed = NULL';
1788 }
1789
1790 $result = db_query($link, "UPDATE ttrss_feeds SET
1791 $category_qpart,
1792 $parent_qpart,
1793 title = '$feed_title', feed_url = '$feed_link',
1794 update_interval = '$upd_intl',
1795 purge_interval = '$purge_intl',
1796 auth_login = '$auth_login',
1797 auth_pass = '$auth_pass',
1798 private = $private,
1799 rtl_content = $rtl_content
1800 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
1801 }
1802
1803 if ($subop == "saveCat") {
1804 $cat_title = db_escape_string($_GET["title"]);
1805 $cat_id = db_escape_string($_GET["id"]);
1806
1807 $result = db_query($link, "UPDATE ttrss_feed_categories SET
1808 title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
1809
1810 }
1811
1812 if ($subop == "remove") {
1813
1814 if (!WEB_DEMO_MODE) {
1815
1816 $ids = split(",", db_escape_string($_GET["ids"]));
1817
1818 foreach ($ids as $id) {
1819 db_query($link, "DELETE FROM ttrss_feeds
1820 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1821
1822 $icons_dir = ICONS_DIR;
1823
1824 if (file_exists($icons_dir . "/$id.ico")) {
1825 unlink($icons_dir . "/$id.ico");
1826 }
1827 }
1828 }
1829 }
1830
1831 if ($subop == "add") {
1832
1833 if (!WEB_DEMO_MODE) {
1834
1835 $feed_link = db_escape_string(trim($_GET["link"]));
1836 $cat_id = db_escape_string($_GET["cid"]);
1837
1838 if ($cat_id == "0" || !$cat_id) {
1839 $cat_qpart = "NULL";
1840 } else {
1841 $cat_qpart = "'$cat_id'";
1842 }
1843
1844 $result = db_query($link,
1845 "SELECT id FROM ttrss_feeds
1846 WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]);
1847
1848 if (db_num_rows($result) == 0) {
1849
1850 $result = db_query($link,
1851 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id)
1852 VALUES ('".$_SESSION["uid"]."', '$feed_link',
1853 '[Unknown]', $cat_qpart)");
1854
1855 $result = db_query($link,
1856 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'
1857 AND owner_uid = " . $_SESSION["uid"]);
1858
1859 $feed_id = db_fetch_result($result, 0, "id");
1860
1861 if ($feed_id) {
1862 update_rss_feed($link, $feed_link, $feed_id, true);
1863 }
1864 } else {
1865
1866 print "<div class=\"warning\">
1867 Feed <b>$feed_link</b> already exists in the database.
1868 </div>";
1869 }
1870 }
1871 }
1872
1873 if ($subop == "addCat") {
1874
1875 if (!WEB_DEMO_MODE) {
1876
1877 $feed_cat = db_escape_string(trim($_GET["cat"]));
1878
1879 $result = db_query($link,
1880 "SELECT id FROM ttrss_feed_categories
1881 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
1882
1883 if (db_num_rows($result) == 0) {
1884
1885 $result = db_query($link,
1886 "INSERT INTO ttrss_feed_categories (owner_uid,title)
1887 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
1888
1889 } else {
1890
1891 print "<div class=\"warning\">
1892 Category <b>$feed_cat</b> already exists in the database.
1893 </div>";
1894 }
1895
1896
1897 }
1898 }
1899
1900 if ($subop == "removeCats") {
1901
1902 if (!WEB_DEMO_MODE) {
1903
1904 $ids = split(",", db_escape_string($_GET["ids"]));
1905
1906 foreach ($ids as $id) {
1907
1908 db_query($link, "BEGIN");
1909
1910 $result = db_query($link,
1911 "SELECT count(id) as num_feeds FROM ttrss_feeds
1912 WHERE cat_id = '$id'");
1913
1914 $num_feeds = db_fetch_result($result, 0, "num_feeds");
1915
1916 if ($num_feeds == 0) {
1917 db_query($link, "DELETE FROM ttrss_feed_categories
1918 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1919 } else {
1920
1921 print "<div class=\"warning\">
1922 Unable to delete non empty feed categories.</div>";
1923
1924 }
1925
1926 db_query($link, "COMMIT");
1927 }
1928 }
1929 }
1930
1931 if ($subop == "categorize") {
1932
1933 if (!WEB_DEMO_MODE) {
1934
1935 $ids = split(",", db_escape_string($_GET["ids"]));
1936
1937 $cat_id = db_escape_string($_GET["cat_id"]);
1938
1939 if ($cat_id == 0) {
1940 $cat_id_qpart = 'NULL';
1941 } else {
1942 $cat_id_qpart = "'$cat_id'";
1943 }
1944
1945 db_query($link, "BEGIN");
1946
1947 foreach ($ids as $id) {
1948
1949 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
1950 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1951 }
1952
1953 db_query($link, "COMMIT");
1954 }
1955
1956 }
1957
1958 if ($quiet) return;
1959
1960 // print "<h3>Edit Feeds</h3>";
1961
1962 $result = db_query($link, "SELECT id,title,feed_url,last_error
1963 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1964
1965 if (db_num_rows($result) > 0) {
1966
1967 print "<div class=\"warning\">";
1968
1969 // print"<img class=\"closeButton\"
1970 // onclick=\"javascript:hideParentElement(this);\" src=\"images/close.png\">";
1971
1972 print "<a href=\"javascript:showBlockElement('feedUpdateErrors')\">
1973 <b>Feeds with update errors</b> (click to expand)</a>";
1974
1975 print "<ul id=\"feedUpdateErrors\" class=\"nomarks\">";
1976
1977 while ($line = db_fetch_assoc($result)) {
1978 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
1979 $line["last_error"];
1980 }
1981
1982 print "</ul>";
1983 print "</div>";
1984
1985 }
1986
1987 $feed_search = db_escape_string($_GET["search"]);
1988
1989 if (array_key_exists("search", $_GET)) {
1990 $_SESSION["prefs_feed_search"] = $feed_search;
1991 } else {
1992 $feed_search = $_SESSION["prefs_feed_search"];
1993 }
1994
1995 print "<table width='100%' class=\"prefGenericAddBox\"
1996 cellspacing='0' cellpadding='0'><tr>
1997 <td>
1998 <input id=\"fadd_link\"
1999 onchange=\"javascript:addFeed()\"
2000 size=\"40\">
2001 <input type=\"submit\" class=\"button\"
2002 onclick=\"javascript:addFeed()\" value=\"Add feed\">";
2003
2004 if (ENABLE_FEED_BROWSER) {
2005 print "&nbsp;(<a href='javascript:browseFeeds()'>Top 50</a>)";
2006 }
2007
2008 print "</td><td align='right'>
2009 <input id=\"feed_search\" size=\"20\"
2010 onchange=\"javascript:updateFeedList()\"
2011 value=\"$feed_search\">
2012 <input type=\"submit\" class=\"button\"
2013 onclick=\"javascript:updateFeedList()\" value=\"Search\">
2014 </td>
2015 </tr></table>";
2016
2017 $feeds_sort = db_escape_string($_GET["sort"]);
2018
2019 if (!$feeds_sort || $feeds_sort == "undefined") {
2020 $feeds_sort = $_SESSION["pref_sort_feeds"];
2021 if (!$feeds_sort) $feeds_sort = "title";
2022 }
2023
2024 $_SESSION["pref_sort_feeds"] = $feeds_sort;
2025
2026 if ($feed_search) {
2027 $search_qpart = "(UPPER(F1.title) LIKE UPPER('%$feed_search%') OR
2028 UPPER(F1.feed_url) LIKE UPPER('%$feed_search%')) AND";
2029 } else {
2030 $search_qpart = "";
2031 }
2032
2033 $result = db_query($link, "SELECT
2034 F1.id,
2035 F1.title,
2036 F1.feed_url,
2037 substring(F1.last_updated,1,16) AS last_updated,
2038 F1.parent_feed,
2039 F1.update_interval,
2040 F1.purge_interval,
2041 F1.cat_id,
2042 F2.title AS parent_title,
2043 C1.title AS category
2044 FROM
2045 ttrss_feeds AS F1
2046 LEFT JOIN ttrss_feeds AS F2
2047 ON (F1.parent_feed = F2.id)
2048 LEFT JOIN ttrss_feed_categories AS C1
2049 ON (F1.cat_id = C1.id)
2050 WHERE
2051 $search_qpart F1.owner_uid = '".$_SESSION["uid"]."'
2052 ORDER by category,$feeds_sort,title");
2053
2054 if (db_num_rows($result) != 0) {
2055
2056 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2057
2058 print "<p><table width=\"100%\" cellspacing=\"0\"
2059 class=\"prefFeedList\" id=\"prefFeedList\">";
2060 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2061 Select:
2062 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
2063 'FEEDR-', 'FRCHK-', true)\">All</a>,
2064 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
2065 'FEEDR-', 'FRCHK-', false)\">None</a>
2066 </td</tr>";
2067
2068 if (!get_pref($link, 'ENABLE_FEED_CATS')) {
2069 print "<tr class=\"title\">
2070 <td width='5%' align='center'>&nbsp;</td>
2071 <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
2072 <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
2073 <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td>
2074 <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Interval</a></td></tr>";
2075 }
2076
2077 $lnum = 0;
2078
2079 $cur_cat_id = -1;
2080
2081 while ($line = db_fetch_assoc($result)) {
2082
2083 $feed_id = $line["id"];
2084 $cat_id = $line["cat_id"];
2085
2086 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
2087 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
2088 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
2089
2090 // if ($line["update_interval"] == "0") $line["update_interval"] = "Default";
2091 // if ($line["update_interval"] == "-1") $line["update_interval"] = "Disabled";
2092 // if ($line["purge_interval"] == "0") $line["purge_interval"] = "Default";
2093 // if ($line["purge_interval"] < 0) $line["purge_interval"] = "Disabled";
2094
2095 if (!$edit_cat) $edit_cat = "Uncategorized";
2096
2097 if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
2098 $lnum = 0;
2099
2100 print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>";
2101
2102 print "<tr class=\"title\">
2103 <td width='5%' align='center'>&nbsp;</td>
2104 <td width='30%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
2105 <td width='30%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
2106 <td width='15%'><a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a></td>
2107 <td width='15%'><a href=\"javascript:updateFeedList('purge_interval')\">Purge Interval</a></td></tr>";
2108
2109 $cur_cat_id = $cat_id;
2110 }
2111
2112 $class = ($lnum % 2) ? "even" : "odd";
2113 $this_row_id = "id=\"FEEDR-$feed_id\"";
2114
2115 print "<tr class=\"$class\" $this_row_id>";
2116
2117 $icon_file = ICONS_DIR . "/$feed_id.ico";
2118
2119 if (file_exists($icon_file) && filesize($icon_file) > 0) {
2120 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/$feed_id.ico\">";
2121 } else {
2122 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
2123 }
2124 // print "<td class='feedIcon'>$feed_icon</td>";
2125
2126 print "<td class='feedSelect'><input onclick='toggleSelectRow(this);'
2127 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
2128
2129 $edit_title = truncate_string($edit_title, 40);
2130 $edit_link = truncate_string($edit_link, 60);
2131
2132 $parent_title = $line["parent_title"];
2133 if ($parent_title) {
2134 $parent_title = "<span class='groupPrompt'>(linked to
2135 $parent_title)</span>";
2136 }
2137
2138 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
2139 "$feed_icon $edit_title $parent_title" . "</a></td>";
2140
2141 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
2142 $edit_link . "</a></td>";
2143
2144 /* if (get_pref($link, 'ENABLE_FEED_CATS')) {
2145 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
2146 $edit_cat . "</a></td>";
2147 } */
2148
2149 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
2150 $update_intervals[$line["update_interval"]] . "</a></td>";
2151
2152 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
2153 $purge_intervals[$line["purge_interval"]] . "</a></td>";
2154
2155 print "</tr>";
2156
2157 ++$lnum;
2158 }
2159
2160 print "</table>";
2161
2162 print "<p>";
2163
2164 if ($subop == "edit") {
2165 print "Edit feed:&nbsp;
2166 <input type=\"submit\" class=\"button\"
2167 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
2168 <input type=\"submit\" class=\"button\"
2169 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
2170 } else {
2171
2172 print "
2173 Selection:&nbsp;
2174 <input type=\"submit\" class=\"button\"
2175 onclick=\"javascript:selectedFeedDetails()\" value=\"Details\">
2176 <input type=\"submit\" class=\"button\"
2177 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
2178 <input type=\"submit\" class=\"button\"
2179 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
2180
2181 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2182
2183 print "&nbsp;&nbsp;";
2184
2185 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2186 WHERE owner_uid = ".$_SESSION["uid"]."
2187 ORDER BY title");
2188
2189 print "<select id=\"sfeed_set_fcat\">";
2190 print "<option id=\"0\">Uncategorized</option>";
2191
2192 if (db_num_rows($result) != 0) {
2193
2194 print "<option disabled>--------</option>";
2195
2196 while ($line = db_fetch_assoc($result)) {
2197 printf("<option id='%d'>%s</option>",
2198 $line["id"], $line["title"]);
2199 }
2200 }
2201
2202 print "</select>";
2203
2204 print " <input type=\"submit\" class=\"button\"
2205 onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Set category\">";
2206
2207 }
2208
2209 if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
2210 print "
2211 <input type=\"submit\" class=\"button\"
2212 onclick=\"javascript:readSelectedFeeds(true)\" value=\"Mark as read\">
2213 <input type=\"submit\" class=\"button\"
2214 onclick=\"javascript:readSelectedFeeds(false)\"
2215 value=\"Mark as unread\">&nbsp;";
2216 }
2217
2218 print "
2219 &nbsp;All feeds: <input type=\"submit\"
2220 class=\"button\" onclick=\"gotoExportOpml()\"
2221 value=\"Export OPML\">";
2222 }
2223 } else {
2224
2225 print "<p>No feeds defined.</p>";
2226
2227 }
2228
2229 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2230
2231 print "<h3>Edit Categories</h3>";
2232
2233 // print "<h3>Categories</h3>";
2234
2235 print "<div class=\"prefGenericAddBox\">
2236 <input id=\"fadd_cat\"
2237 onchange=\"javascript:addFeedCat()\"
2238 size=\"40\">&nbsp;
2239 <input
2240 type=\"submit\" class=\"button\"
2241 onclick=\"javascript:addFeedCat()\" value=\"Add category\"></div>";
2242
2243 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2244 WHERE owner_uid = ".$_SESSION["uid"]."
2245 ORDER BY title");
2246
2247 if (db_num_rows($result) != 0) {
2248
2249 print "<p><table width=\"100%\" class=\"prefFeedCatList\"
2250 cellspacing=\"0\" id=\"prefFeedCatList\">";
2251
2252 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2253 Select:
2254 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
2255 'FCATR-', 'FCCHK-', true)\">All</a>,
2256 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
2257 'FCATR-', 'FCCHK-', false)\">None</a>
2258 </td</tr>";
2259
2260 print "<tr class=\"title\">
2261 <td width=\"5%\"></td><td width=\"80%\">Title</td>
2262 </tr>";
2263
2264 $lnum = 0;
2265
2266 while ($line = db_fetch_assoc($result)) {
2267
2268 $class = ($lnum % 2) ? "even" : "odd";
2269
2270 $cat_id = $line["id"];
2271
2272 $edit_cat_id = $_GET["id"];
2273
2274 if ($subop == "editCat" && $cat_id != $edit_cat_id) {
2275 $class .= "Grayed";
2276 $this_row_id = "";
2277 } else {
2278 $this_row_id = "id=\"FCATR-$cat_id\"";
2279 }
2280
2281 print "<tr class=\"$class\" $this_row_id>";
2282
2283 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
2284
2285 if (!$edit_cat_id || $subop != "editCat") {
2286
2287 print "<td align='center'><input onclick='toggleSelectRow(this);'
2288 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
2289
2290 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
2291 $edit_title . "</a></td>";
2292
2293 } else if ($cat_id != $edit_cat_id) {
2294
2295 print "<td><input disabled=\"true\" type=\"checkbox\"
2296 id=\"FRCHK-".$line["id"]."\"></td>";
2297
2298 print "<td>$edit_title</td>";
2299
2300 } else {
2301
2302 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2303
2304 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
2305
2306 }
2307
2308 print "</tr>";
2309
2310 ++$lnum;
2311 }
2312
2313 print "</table>";
2314
2315 print "<p>";
2316
2317 if ($subop == "editCat") {
2318 print "Edit category:&nbsp;
2319 <input type=\"submit\" class=\"button\"
2320 onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\">
2321 <input type=\"submit\" class=\"button\"
2322 onclick=\"javascript:feedCatEditSave()\" value=\"Save\">";
2323 } else {
2324
2325 print "
2326 Selection:&nbsp;
2327 <input type=\"submit\" class=\"button\"
2328 onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\">
2329 <input type=\"submit\" class=\"button\"
2330 onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">";
2331
2332 }
2333
2334 } else {
2335 print "<p>No feed categories defined.</p>";
2336 }
2337 }
2338
2339 print "<h3>Import OPML</h3>
2340 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
2341 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
2342 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
2343 type=\"submit\" value=\"Import\">
2344 </form>";
2345
2346 }
2347
2348 if ($op == "pref-filters") {
2349
2350 $subop = $_GET["subop"];
2351 $quiet = $_GET["quiet"];
2352
2353 if ($subop == "editSave") {
2354
2355 $regexp = db_escape_string($_GET["r"]);
2356 $descr = db_escape_string($_GET["d"]);
2357 $match = db_escape_string($_GET["m"]);
2358 $filter_id = db_escape_string($_GET["id"]);
2359 $feed_id = db_escape_string($_GET["fid"]);
2360 $action_id = db_escape_string($_GET["aid"]);
2361
2362 if (!$feed_id) {
2363 $feed_id = 'NULL';
2364 } else {
2365 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2366 }
2367
2368 $result = db_query($link, "UPDATE ttrss_filters SET
2369 reg_exp = '$regexp',
2370 description = '$descr',
2371 feed_id = $feed_id,
2372 action_id = '$action_id',
2373 filter_type = (SELECT id FROM ttrss_filter_types WHERE
2374 description = '$match')
2375 WHERE id = '$filter_id'");
2376 }
2377
2378 if ($subop == "remove") {
2379
2380 if (!WEB_DEMO_MODE) {
2381
2382 $ids = split(",", db_escape_string($_GET["ids"]));
2383
2384 foreach ($ids as $id) {
2385 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
2386
2387 }
2388 }
2389 }
2390
2391 if ($subop == "add") {
2392
2393 if (!WEB_DEMO_MODE) {
2394
2395 $regexp = db_escape_string(trim($_GET["regexp"]));
2396 $match = db_escape_string(trim($_GET["match"]));
2397 $feed_id = db_escape_string($_GET["fid"]);
2398 $action_id = db_escape_string($_GET["aid"]);
2399
2400 if (!$feed_id) {
2401 $feed_id = 'NULL';
2402 } else {
2403 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2404 }
2405
2406 $result = db_query($link,
2407 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
2408 action_id)
2409 VALUES
2410 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
2411 description = '$match'),'".$_SESSION["uid"]."',
2412 $feed_id, '$action_id')");
2413 }
2414 }
2415
2416 if ($quiet) return;
2417
2418 $result = db_query($link, "SELECT description
2419 FROM ttrss_filter_types ORDER BY description");
2420
2421 $filter_types = array();
2422
2423 while ($line = db_fetch_assoc($result)) {
2424 array_push($filter_types, $line["description"]);
2425 }
2426
2427 print "<div class=\"prefGenericAddBox\">
2428 <input id=\"fadd_regexp\" size=\"40\">&nbsp;";
2429
2430 print_select("fadd_match", "Title", $filter_types);
2431
2432 print "&nbsp;<select id=\"fadd_feed\">";
2433
2434 print "<option selected id=\"0\">All feeds</option>";
2435
2436 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
2437 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2438
2439 if (db_num_rows($result) > 0) {
2440 print "<option disabled>--------</option>";
2441 }
2442
2443 while ($line = db_fetch_assoc($result)) {
2444 printf("<option id='%d'>%s</option>", $line["id"], $line["title"]);
2445 }
2446
2447 print "</select>&nbsp;";
2448
2449 print "&nbsp;Action: ";
2450
2451 print "<select id=\"fadd_action\">";
2452
2453 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2454 ORDER BY name");
2455
2456 while ($line = db_fetch_assoc($result)) {
2457 printf("<option id='%d'>%s</option>", $line["id"], $line["description"]);
2458 }
2459
2460 print "</select>&nbsp;";
2461
2462 /* print "<input type=\"submit\"
2463 class=\"button\" onclick=\"javascript:testFilter()\"
2464 value=\"Test filter\"> "; */
2465
2466 print "<input type=\"submit\"
2467 class=\"button\" onclick=\"javascript:addFilter()\"
2468 value=\"Add filter\">";
2469
2470 print "</div>";
2471
2472 $result = db_query($link, "SELECT
2473 ttrss_filters.id AS id,reg_exp,
2474 ttrss_filters.description AS description,
2475 ttrss_filter_types.name AS filter_type_name,
2476 ttrss_filter_types.description AS filter_type_descr,
2477 feed_id,
2478 ttrss_filter_actions.description AS action_description,
2479 ttrss_feeds.title AS feed_title
2480 FROM
2481 ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN
2482 ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id)
2483 WHERE
2484 filter_type = ttrss_filter_types.id AND
2485 ttrss_filter_actions.id = action_id AND
2486 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
2487 ORDER by reg_exp");
2488
2489 if (db_num_rows($result) != 0) {
2490
2491 print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\"
2492 id=\"prefFilterList\">";
2493
2494 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2495 Select:
2496 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
2497 'FILRR-', 'FICHK-', true)\">All</a>,
2498 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
2499 'FILRR-', 'FICHK-', false)\">None</a>
2500 </td</tr>";
2501
2502 print "<tr class=\"title\">
2503 <td align='center' width=\"5%\">&nbsp;</td>
2504 <td width=\"20%\">Filter expression</td>
2505 <td width=\"20%\">Feed</td>
2506 <td width=\"15%\">Match</td>
2507 <td width=\"15%\">Action</td>
2508 <td width=\"30%\">Description</td></tr>";
2509
2510 $lnum = 0;
2511
2512 while ($line = db_fetch_assoc($result)) {
2513
2514 $class = ($lnum % 2) ? "even" : "odd";
2515
2516 $filter_id = $line["id"];
2517 $edit_filter_id = $_GET["id"];
2518
2519 if ($subop == "edit" && $filter_id != $edit_filter_id) {
2520 $class .= "Grayed";
2521 $this_row_id = "";
2522 } else {
2523 $this_row_id = "id=\"FILRR-$filter_id\"";
2524 }
2525
2526 print "<tr class=\"$class\" $this_row_id>";
2527
2528 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
2529 $line["description"] = htmlspecialchars($line["description"]);
2530
2531 if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
2532
2533 if (!$edit_filter_id || $subop != "edit") {
2534
2535 if (!$line["description"]) $line["description"] = "[No description]";
2536
2537 print "<td align='center'><input onclick='toggleSelectRow(this);'
2538 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
2539
2540 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2541 $line["reg_exp"] . "</td>";
2542
2543 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2544 $line["feed_title"] . "</td>";
2545
2546 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2547 $line["filter_type_descr"] . "</td>";
2548
2549 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2550 $line["action_description"] . "</td>";
2551
2552 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2553 $line["description"] . "</td>";
2554
2555 } else if ($filter_id != $edit_filter_id) {
2556
2557 if (!$line["description"]) $line["description"] = "[No description]";
2558
2559 print "<td><input disabled=\"true\" type=\"checkbox\"
2560 id=\"FICHK-".$line["id"]."\"></td>";
2561
2562 print "<td>".$line["reg_exp"]."</td>";
2563 print "<td>".$line["feed_title"]."</td>";
2564 print "<td>".$line["filter_type_descr"]."</td>";
2565 print "<td>".$line["action_description"]."</td>";
2566 print "<td>".$line["description"]."</td>";
2567
2568 } else {
2569
2570 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2571
2572 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
2573 "\"></td>";
2574
2575 print "<td>";
2576 print "<select id=\"iedit_feed\">";
2577 print "<option id=\"0\">All feeds</option>";
2578
2579 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
2580 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
2581
2582 if (db_num_rows($tmp_result) > 0) {
2583 print "<option disabled>--------</option>";
2584 }
2585
2586 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2587 if ($tmp_line["id"] == $line["feed_id"]) {
2588 $is_selected = "selected";
2589 } else {
2590 $is_selected = "";
2591 }
2592 printf("<option $is_selected id='%d'>%s</option>",
2593 $tmp_line["id"], $tmp_line["title"]);
2594 }
2595
2596 print "</select></td>";
2597
2598 print "<td>";
2599 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
2600 print "</td>";
2601
2602 print "<td>";
2603 print "<select id=\"iedit_filter_action\">";
2604
2605 $tmp_result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2606 ORDER BY description");
2607
2608 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2609 if ($tmp_line["description"] == $line["action_description"]) {
2610 $is_selected = "selected";
2611 } else {
2612 $is_selected = "";
2613 }
2614 printf("<option $is_selected id='%d'>%s</option>",
2615 $tmp_line["id"], $tmp_line["description"]);
2616 }
2617
2618 print "</select></td>";
2619
2620
2621 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2622 "\"></td>";
2623
2624 print "</td>";
2625 }
2626
2627 print "</tr>";
2628
2629 ++$lnum;
2630 }
2631
2632 if ($lnum == 0) {
2633 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
2634 }
2635
2636 print "</table>";
2637
2638 print "<p>";
2639
2640 if ($subop == "edit") {
2641 print "Edit filter:
2642 <input type=\"submit\" class=\"button\"
2643 onclick=\"javascript:filterEditSave()\" value=\"Save\">
2644 <input type=\"submit\" class=\"button\"
2645 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">";
2646
2647 } else {
2648
2649 print "
2650 Selection:
2651 <input type=\"submit\" class=\"button\"
2652 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
2653 <input type=\"submit\" class=\"button\"
2654 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
2655 }
2656
2657 } else {
2658
2659 print "<p>No filters defined.</p>";
2660
2661 }
2662 }
2663
2664 // We need to accept raw SQL data in label queries, so not everything is escaped
2665 // here, this is by design. If you don't like the whole idea, disable labels
2666 // altogether with GLOBAL_ENABLE_LABELS = false
2667
2668 if ($op == "pref-labels") {
2669
2670 if (!GLOBAL_ENABLE_LABELS) {
2671 return;
2672 }
2673
2674 $subop = $_GET["subop"];
2675
2676 if ($subop == "test") {
2677
2678 $expr = $_GET["expr"];
2679 $descr = $_GET["descr"];
2680
2681 print "<div class='infoBoxContents'>";
2682
2683 print "<h1>Label &laquo;$descr&raquo;</h1>";
2684
2685 // print "<p><b>Expression</b>: $expr</p>";
2686
2687 $result = db_query($link,
2688 "SELECT count(id) AS num_matches
2689 FROM ttrss_entries,ttrss_user_entries
2690 WHERE ($expr) AND
2691 ttrss_user_entries.ref_id = ttrss_entries.id AND
2692 owner_uid = " . $_SESSION["uid"]);
2693
2694 $num_matches = db_fetch_result($result, 0, "num_matches");;
2695
2696 if ($num_matches > 0) {
2697
2698 print "<p>Query returned <b>$num_matches</b> matches, first 5 follow:</p>";
2699
2700 $result = db_query($link,
2701 "SELECT title,
2702 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
2703 FROM ttrss_entries,ttrss_user_entries
2704 WHERE ($expr) AND
2705 ttrss_user_entries.ref_id = ttrss_entries.id
2706 AND owner_uid = " . $_SESSION["uid"] . "
2707 ORDER BY date_entered DESC LIMIT 5");
2708
2709 print "<ul class=\"nomarks\">";
2710 while ($line = db_fetch_assoc($result)) {
2711 print "<li>".$line["title"].
2712 " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
2713 }
2714 print "</ul>";
2715
2716 } else {
2717 print "<p>Query didn't return any matches.</p>";
2718 }
2719
2720 print "</div>";
2721
2722 print "<div align='center'>
2723 <input type='submit' class='button'
2724 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2725 return;
2726 }
2727
2728 if ($subop == "editSave") {
2729
2730 $sql_exp = $_GET["s"];
2731 $descr = $_GET["d"];
2732 $label_id = db_escape_string($_GET["id"]);
2733
2734 // print "$sql_exp : $descr : $label_id";
2735
2736 $result = db_query($link, "UPDATE ttrss_labels SET
2737 sql_exp = '$sql_exp',
2738 description = '$descr'
2739 WHERE id = '$label_id'");
2740 }
2741
2742 if ($subop == "remove") {
2743
2744 if (!WEB_DEMO_MODE) {
2745
2746 $ids = split(",", db_escape_string($_GET["ids"]));
2747
2748 foreach ($ids as $id) {
2749 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
2750
2751 }
2752 }
2753 }
2754
2755 if ($subop == "add") {
2756
2757 if (!WEB_DEMO_MODE) {
2758
2759 // no escaping is done here on purpose
2760 $exp = trim($_GET["exp"]);
2761
2762 $result = db_query($link,
2763 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
2764 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
2765 }
2766 }
2767
2768 print "<div class=\"prefGenericAddBox\">
2769 <input size=\"40\" id=\"ladd_expr\">&nbsp;";
2770
2771 print"<input type=\"submit\" class=\"button\"
2772 onclick=\"javascript:addLabel()\" value=\"Add label\"></div>";
2773
2774 $result = db_query($link, "SELECT
2775 id,sql_exp,description
2776 FROM
2777 ttrss_labels
2778 WHERE
2779 owner_uid = ".$_SESSION["uid"]."
2780 ORDER by description");
2781
2782 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2783
2784 if (db_num_rows($result) != 0) {
2785
2786 print "<p><table width=\"100%\" cellspacing=\"0\"
2787 class=\"prefLabelList\" id=\"prefLabelList\">";
2788
2789 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2790 Select:
2791 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2792 'LILRR-', 'LICHK-', true)\">All</a>,
2793 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
2794 'LILRR-', 'LICHK-', false)\">None</a>
2795 </td</tr>";
2796
2797 print "<tr class=\"title\">
2798 <td align='center' width=\"5%\">&nbsp;</td>
2799 <td width=\"40%\">SQL expression
2800 <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a>
2801 </td>
2802 <td width=\"40%\">Caption</td></tr>";
2803
2804 $lnum = 0;
2805
2806 while ($line = db_fetch_assoc($result)) {
2807
2808 $class = ($lnum % 2) ? "even" : "odd";
2809
2810 $label_id = $line["id"];
2811 $edit_label_id = $_GET["id"];
2812
2813 if ($subop == "edit" && $label_id != $edit_label_id) {
2814 $class .= "Grayed";
2815 $this_row_id = "";
2816 } else {
2817 $this_row_id = "id=\"LILRR-$label_id\"";
2818 }
2819
2820 print "<tr class=\"$class\" $this_row_id>";
2821
2822 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
2823 $line["description"] = htmlspecialchars($line["description"]);
2824
2825 if (!$edit_label_id || $subop != "edit") {
2826
2827 if (!$line["description"]) $line["description"] = "[No caption]";
2828
2829 print "<td align='center'><input onclick='toggleSelectRow(this);'
2830 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
2831
2832 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2833 $line["sql_exp"] . "</td>";
2834
2835 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2836 $line["description"] . "</td>";
2837
2838 } else if ($label_id != $edit_label_id) {
2839
2840 if (!$line["description"]) $line["description"] = "[No description]";
2841
2842 print "<td><input disabled=\"true\" type=\"checkbox\"
2843 id=\"LICHK-".$line["id"]."\"></td>";
2844
2845 print "<td>".$line["sql_exp"]."</td>";
2846 print "<td>".$line["description"]."</td>";
2847
2848 } else {
2849
2850 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2851
2852 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
2853 "\"></td>";
2854
2855 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2856 "\"></td>";
2857
2858 }
2859
2860
2861 print "</tr>";
2862
2863 ++$lnum;
2864 }
2865
2866 if ($lnum == 0) {
2867 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
2868 }
2869
2870 print "</table>";
2871
2872 print "<p>";
2873
2874 if ($subop == "edit") {
2875 print "Edit label:
2876 <input type=\"submit\" class=\"button\"
2877 onclick=\"javascript:labelTest()\" value=\"Test\">
2878 <input type=\"submit\" class=\"button\"
2879 onclick=\"javascript:labelEditSave()\" value=\"Save\">
2880 <input type=\"submit\" class=\"button\"
2881 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">";
2882
2883 } else {
2884
2885 print "
2886 Selection:
2887 <input type=\"submit\" class=\"button\"
2888 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
2889 <input type=\"submit\" class=\"button\"
2890 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
2891 }
2892 } else {
2893 print "<p>No labels defined.</p>";
2894 }
2895 }
2896
2897 if ($op == "error") {
2898 print "<div width=\"100%\" align='center'>";
2899 $msg = $_GET["msg"];
2900 print $msg;
2901 print "</div>";
2902 }
2903
2904 if ($op == "help") {
2905 if (!$_GET["noheaders"]) {
2906 print "<html><head>
2907 <title>Tiny Tiny RSS : Help</title>
2908 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2909 <script type=\"text/javascript\" src=\"functions.js\"></script>
2910 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2911 </head><body>";
2912 }
2913
2914 $tid = sprintf("%d", $_GET["tid"]);
2915
2916 print "<div class='infoBoxContents'>";
2917
2918 if (file_exists("help/$tid.php")) {
2919 include("help/$tid.php");
2920 } else {
2921 print "<p>Help topic not found.</p>";
2922 }
2923
2924 print "</div>";
2925
2926 print "<div align='center'>
2927 <input type='submit' class='button'
2928 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2929
2930 if (!$_GET["noheaders"]) {
2931 print "</body></html>";
2932 }
2933
2934 }
2935
2936 if ($op == "dlg") {
2937 $id = $_GET["id"];
2938 $param = $_GET["param"];
2939
2940 if ($id == "quickAddFeed") {
2941 print "
2942 Feed URL: <input
2943 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2944 id=\"qafInput\">";
2945
2946 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2947 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2948 WHERE owner_uid = ".$_SESSION["uid"]."
2949 ORDER BY title");
2950
2951 print " <select id=\"qafCat\">";
2952 print "<option id=\"0\">Uncategorized</option>";
2953
2954 if (db_num_rows($result) != 0) {
2955
2956 print "<option disabled>--------</option>";
2957
2958 while ($line = db_fetch_assoc($result)) {
2959 printf("<option id='%d'>%s</option>",
2960 $line["id"], $line["title"]);
2961 }
2962 }
2963
2964 print "</select>";
2965 }
2966
2967 print "&nbsp;<input class=\"button\"
2968 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
2969 <input class=\"button\"
2970 type=\"submit\" onclick=\"javascript:closeDlg()\"
2971 value=\"Cancel\">";
2972 }
2973
2974 if ($id == "quickDelFeed") {
2975
2976 $param = db_escape_string($param);
2977
2978 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
2979
2980 if ($result) {
2981
2982 $f_title = db_fetch_result($result, 0, "title");
2983
2984 print "Remove current feed (<b>$f_title</b>)?&nbsp;
2985 <input class=\"button\"
2986 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
2987 <input class=\"button\"
2988 type=\"submit\" onclick=\"javascript:closeDlg()\"
2989 value=\"Cancel\">";
2990 } else {
2991 print "Error: Feed $param not found.&nbsp;
2992 <input class=\"button\"
2993 type=\"submit\" onclick=\"javascript:closeDlg()\"
2994 value=\"Cancel\">";
2995 }
2996 }
2997
2998 if ($id == "search") {
2999
3000 $active_feed_id = db_escape_string($_GET["param"]);
3001
3002 print "<input id=\"searchbox\" class=\"extSearch\"
3003 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
3004 onchange=\"javascript:search()\">
3005 <select id=\"searchmodebox\">
3006 <option selected>All feeds</option>";
3007
3008 if ($active_feed_id) {
3009 print "<option>This feed</option>";
3010 } else {
3011 print "<option disabled>This feed</option>";
3012 }
3013
3014 if (get_pref($link, 'ENABLE_FEED_CATS')) {
3015 print "<option>This category</option>";
3016 }
3017
3018 print "</select>
3019 <input type=\"submit\"
3020 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
3021 <input class=\"button\"
3022 type=\"submit\" onclick=\"javascript:closeDlg()\"
3023 value=\"Close\">";
3024
3025 }
3026
3027 if ($id == "quickAddFilter") {
3028
3029 $result = db_query($link, "SELECT description
3030 FROM ttrss_filter_types ORDER BY description");
3031
3032 $filter_types = array();
3033
3034 while ($line = db_fetch_assoc($result)) {
3035 array_push($filter_types, $line["description"]);
3036 }
3037
3038 print "<table>";
3039
3040 print "<tr><td>Match:</td><td><input id=\"fadd_regexp\" size=\"40\">&nbsp;";
3041
3042 print_select("fadd_match", "Title", $filter_types);
3043
3044 print "</td></tr>";
3045 print "<tr><td>Feed:</td><td><select id=\"fadd_feed\">";
3046
3047 print "<option selected id=\"0\">All feeds</option>";
3048
3049 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
3050 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
3051
3052 if (db_num_rows($result) > 0) {
3053 print "<option disabled>--------</option>";
3054 }
3055
3056 while ($line = db_fetch_assoc($result)) {
3057 if ($param == $line["id"]) {
3058 $selected = "selected";
3059 } else {
3060 $selected = "";
3061 }
3062 printf("<option id='%d' %s>%s</option>", $line["id"], $selected, $line["title"]);
3063 }
3064
3065 print "</select></td></tr>";
3066
3067 print "<tr><td>Action:</td>";
3068
3069 print "<td><select id=\"fadd_action\">";
3070
3071 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
3072 ORDER BY name");
3073
3074 while ($line = db_fetch_assoc($result)) {
3075 printf("<option id='%d'>%s</option>", $line["id"], $line["description"]);
3076 }
3077
3078 print "</select>";
3079
3080 print "</td></tr><tr><td colspan=\"2\" align=\"right\">";
3081
3082 print "<input type=\"submit\"
3083 class=\"button\" onclick=\"javascript:qaddFilter()\"
3084 value=\"Add filter\"> ";
3085
3086 print "<input class=\"button\"
3087 type=\"submit\" onclick=\"javascript:closeDlg()\"
3088 value=\"Close\">";
3089
3090 print "</td></tr></table>";
3091 }
3092 }
3093
3094 // update feeds of all users, may be used anonymously
3095 if ($op == "globalUpdateFeeds") {
3096
3097 $result = db_query($link, "SELECT id FROM ttrss_users");
3098
3099 while ($line = db_fetch_assoc($result)) {
3100 $user_id = $line["id"];
3101 // print "<!-- updating feeds of uid $user_id -->";
3102 update_all_feeds($link, false, $user_id);
3103 }
3104
3105 print "<rpc-reply>
3106 <message msg=\"All feeds updated\"/>
3107 </rpc-reply>";
3108
3109 }
3110
3111 if ($op == "pref-prefs") {
3112
3113 $subop = $_REQUEST["subop"];
3114
3115 if ($subop == "Save configuration") {
3116
3117 if (WEB_DEMO_MODE) {
3118 header("Location: prefs.php");
3119 return;
3120 }
3121
3122 $_SESSION["prefs_op_result"] = "save-config";
3123
3124 $_SESSION["prefs_cache"] = false;
3125
3126 foreach (array_keys($_POST) as $pref_name) {
3127
3128 $pref_name = db_escape_string($pref_name);
3129 $value = db_escape_string($_POST[$pref_name]);
3130
3131 $result = db_query($link, "SELECT type_name
3132 FROM ttrss_prefs,ttrss_prefs_types
3133 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
3134
3135 if (db_num_rows($result) > 0) {
3136
3137 $type_name = db_fetch_result($result, 0, "type_name");
3138
3139 // print "$pref_name : $type_name : $value<br>";
3140
3141 if ($type_name == "bool") {
3142 if ($value == "1") {
3143 $value = "true";
3144 } else {
3145 $value = "false";
3146 }
3147 } else if ($type_name == "integer") {
3148 $value = sprintf("%d", $value);
3149 }
3150
3151 // print "$pref_name : $type_name : $value<br>";
3152
3153 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
3154 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
3155
3156 }
3157
3158 header("Location: prefs.php");
3159
3160 }
3161
3162 } else if ($subop == "getHelp") {
3163
3164 $pref_name = db_escape_string($_GET["pn"]);
3165
3166 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
3167 WHERE pref_name = '$pref_name'");
3168
3169 if (db_num_rows($result) > 0) {
3170 $help_text = db_fetch_result($result, 0, "help_text");
3171 print $help_text;
3172 } else {
3173 print "Unknown option: $pref_name";
3174 }
3175
3176 } else if ($subop == "Change e-mail") {
3177
3178 if (WEB_DEMO_MODE) {
3179 header("Location: prefs.php");
3180 return;
3181 }
3182
3183 $email = db_escape_string($_GET["email"]);
3184 $active_uid = $_SESSION["uid"];
3185
3186 if ($email) {
3187 db_query($link, "UPDATE ttrss_users SET email = '$email'
3188 WHERE id = '$active_uid'");
3189 }
3190
3191 header("Location: prefs.php");
3192
3193 } else if ($subop == "Change password") {
3194
3195 if (WEB_DEMO_MODE) {
3196 header("Location: prefs.php");
3197 return;
3198 }
3199
3200 $old_pw = $_POST["OLD_PASSWORD"];
3201 $new_pw = $_POST["OLD_PASSWORD"];
3202
3203 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
3204 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
3205
3206 $active_uid = $_SESSION["uid"];
3207
3208 if ($old_pw && $new_pw) {
3209
3210 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
3211
3212 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3213 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
3214 pwd_hash = '$old_pw_hash')");
3215
3216 if (db_num_rows($result) == 1) {
3217 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
3218 WHERE id = '$active_uid'");
3219
3220 $_SESSION["pwd_change_result"] = "ok";
3221 } else {
3222 $_SESSION["pwd_change_result"] = "failed";
3223 }
3224 }
3225
3226 header("Location: prefs.php");
3227
3228 } else if ($subop == "Reset to defaults") {
3229
3230 if (WEB_DEMO_MODE) {
3231 header("Location: prefs.php");
3232 return;
3233 }
3234
3235 $_SESSION["prefs_op_result"] = "reset-to-defaults";
3236
3237 if (DB_TYPE == "pgsql") {
3238 db_query($link,"UPDATE ttrss_user_prefs
3239 SET value = ttrss_prefs.def_value
3240 WHERE owner_uid = '".$_SESSION["uid"]."' AND
3241 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
3242 } else {
3243 db_query($link, "DELETE FROM ttrss_user_prefs
3244 WHERE owner_uid = ".$_SESSION["uid"]);
3245 initialize_user_prefs($link, $_SESSION["uid"]);
3246 }
3247
3248 header("Location: prefs.php");
3249
3250 } else if ($subop == "Change theme") {
3251
3252 $theme = db_escape_string($_POST["theme"]);
3253
3254 if ($theme == "Default") {
3255 $theme_qpart = 'NULL';
3256 } else {
3257 $theme_qpart = "'$theme'";
3258 }
3259
3260 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
3261 WHERE theme_name = '$theme'");
3262
3263 if (db_num_rows($result) == 1) {
3264 $theme_id = db_fetch_result($result, 0, "id");
3265 $theme_path = db_fetch_result($result, 0, "theme_path");
3266 } else {
3267 $theme_id = "NULL";
3268 $theme_path = "";
3269 }
3270
3271 db_query($link, "UPDATE ttrss_users SET
3272 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
3273
3274 $_SESSION["theme"] = $theme_path;
3275
3276 header("Location: prefs.php");
3277
3278 } else {
3279
3280 if (!SINGLE_USER_MODE) {
3281
3282 $result = db_query($link, "SELECT id,email FROM ttrss_users
3283 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
3284 pwd_hash = 'SHA1:".sha1("password")."')");
3285
3286 if (db_num_rows($result) != 0) {
3287 print "<div class=\"warning\">
3288 Your password is at default value, please change it.
3289 </div>";
3290 }
3291
3292 if ($_SESSION["pwd_change_result"] == "failed") {
3293 print "<div class=\"warning\">
3294 There was an error while changing your password.
3295 </div>";
3296 }
3297
3298 if ($_SESSION["pwd_change_result"] == "ok") {
3299 print "<div class=\"notice\">
3300 Password changed successfully.
3301 </div>";
3302 }
3303
3304 $_SESSION["pwd_change_result"] = "";
3305
3306 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
3307 print "<div class=\"notice\">
3308 Your configuration was reset to defaults.
3309 </div>";
3310 }
3311
3312 if ($_SESSION["prefs_op_result"] == "save-config") {
3313 print "<div class=\"notice\">
3314 Your configuration was saved successfully.
3315 </div>";
3316 }
3317
3318 $_SESSION["prefs_op_result"] = "";
3319
3320 print "<form action=\"backend.php\" method=\"GET\">";
3321
3322 print "<table width=\"100%\" class=\"prefPrefsList\">";
3323 print "<tr><td colspan='3'><h3>Personal data</h3></tr></td>";
3324
3325 $result = db_query($link, "SELECT email FROM ttrss_users
3326 WHERE id = ".$_SESSION["uid"]);
3327
3328 $email = db_fetch_result($result, 0, "email");
3329
3330 print "<tr><td width=\"40%\">E-mail</td>";
3331 print "<td><input class=\"editbox\" name=\"email\"
3332 value=\"$email\"></td></tr>";
3333
3334 print "</table>";
3335
3336 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3337
3338 print "<p><input class=\"button\" type=\"submit\"
3339 value=\"Change e-mail\" name=\"subop\">";
3340
3341 print "</form>";
3342
3343 print "<form action=\"backend.php\" method=\"POST\">";
3344
3345 print "<table width=\"100%\" class=\"prefPrefsList\">";
3346 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
3347
3348 print "<tr><td width=\"40%\">Old password</td>";
3349 print "<td><input class=\"editbox\" type=\"password\"
3350 name=\"OLD_PASSWORD\"></td></tr>";
3351
3352 print "<tr><td width=\"40%\">New password</td>";
3353
3354 print "<td><input class=\"editbox\" type=\"password\"
3355 name=\"NEW_PASSWORD\"></td></tr>";
3356
3357 print "</table>";
3358
3359 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3360
3361 print "<p><input class=\"button\" type=\"submit\"
3362 value=\"Change password\" name=\"subop\">";
3363
3364 print "</form>";
3365
3366 }
3367
3368 $result = db_query($link, "SELECT
3369 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
3370
3371 $user_theme_id = db_fetch_result($result, 0, "theme_id");
3372
3373 $result = db_query($link, "SELECT
3374 id,theme_name FROM ttrss_themes ORDER BY theme_name");
3375
3376 if (db_num_rows($result) > 0) {
3377
3378 print "<form action=\"backend.php\" method=\"POST\">";
3379 print "<table width=\"100%\" class=\"prefPrefsList\">";
3380 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
3381 print "<tr><td width=\"40%\">Select theme</td>";
3382 print "<td><select name=\"theme\">";
3383 print "<option>Default</option>";
3384 print "<option disabled>--------</option>";
3385
3386 while ($line = db_fetch_assoc($result)) {
3387 if ($line["id"] == $user_theme_id) {
3388 $selected = "selected";
3389 } else {
3390 $selected = "";
3391 }
3392 print "<option $selected>" . $line["theme_name"] . "</option>";
3393 }
3394 print "</select></td></tr>";
3395 print "</table>";
3396 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3397 print "<p><input class=\"button\" type=\"submit\"
3398 value=\"Change theme\" name=\"subop\">";
3399 print "</form>";
3400 }
3401
3402 $result = db_query($link, "SELECT
3403 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
3404 section_name,def_value
3405 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
3406 WHERE type_id = ttrss_prefs_types.id AND
3407 section_id = ttrss_prefs_sections.id AND
3408 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
3409 owner_uid = ".$_SESSION["uid"]."
3410 ORDER BY section_id,short_desc");
3411
3412 print "<form action=\"backend.php\" method=\"POST\">";
3413
3414 $lnum = 0;
3415
3416 $active_section = "";
3417
3418 while ($line = db_fetch_assoc($result)) {
3419
3420 if ($active_section != $line["section_name"]) {
3421
3422 if ($active_section != "") {
3423 print "</table>";
3424 }
3425
3426 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
3427
3428 $active_section = $line["section_name"];
3429
3430 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
3431 // print "<tr class=\"title\">
3432 // <td width=\"25%\">Option</td><td>Value</td></tr>";
3433
3434 $lnum = 0;
3435 }
3436
3437 // $class = ($lnum % 2) ? "even" : "odd";
3438
3439 print "<tr>";
3440
3441 $type_name = $line["type_name"];
3442 $pref_name = $line["pref_name"];
3443 $value = $line["value"];
3444 $def_value = $line["def_value"];
3445 $help_text = $line["help_text"];
3446
3447 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
3448
3449 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
3450
3451 print "</td>";
3452
3453 print "<td>";
3454
3455 if ($type_name == "bool") {
3456 // print_select($pref_name, $value, array("true", "false"));
3457
3458 if ($value == "true") {
3459 $value = "Yes";
3460 } else {
3461 $value = "No";
3462 }
3463
3464 print_radio($pref_name, $value, array("Yes", "No"));
3465
3466 } else {
3467 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
3468 }
3469
3470 print "</td>";
3471
3472 print "</tr>";
3473
3474 $lnum++;
3475 }
3476
3477 print "</table>";
3478
3479 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3480
3481 print "<p><input class=\"button\" type=\"submit\"
3482 name=\"subop\" value=\"Save configuration\">";
3483
3484 print "&nbsp;<input class=\"button\" type=\"submit\"
3485 name=\"subop\" onclick=\"return validatePrefsReset()\"
3486 value=\"Reset to defaults\"></p>";
3487
3488 print "</form>";
3489
3490 }
3491
3492 }
3493
3494 if ($op == "pref-users") {
3495
3496 $subop = $_GET["subop"];
3497
3498 if ($subop == "editSave") {
3499
3500 if (!WEB_DEMO_MODE) {
3501
3502 $login = db_escape_string($_GET["l"]);
3503 $uid = db_escape_string($_GET["id"]);
3504 $access_level = sprintf("%d", $_GET["al"]);
3505 $email = db_escape_string($_GET["e"]);
3506
3507 db_query($link, "UPDATE ttrss_users SET login = '$login',
3508 access_level = '$access_level', email = '$email' WHERE id = '$uid'");
3509
3510 }
3511 } else if ($subop == "remove") {
3512
3513 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3514
3515 $ids = split(",", db_escape_string($_GET["ids"]));
3516
3517 foreach ($ids as $id) {
3518 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
3519
3520 }
3521 }
3522 } else if ($subop == "add") {
3523
3524 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3525
3526 $login = db_escape_string(trim($_GET["login"]));
3527 $tmp_user_pwd = make_password(8);
3528 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3529
3530 db_query($link, "INSERT INTO ttrss_users
3531 (login,pwd_hash,access_level,last_login)
3532 VALUES ('$login', '$pwd_hash', 0, NOW())");
3533
3534
3535 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3536 login = '$login' AND pwd_hash = '$pwd_hash'");
3537
3538 if (db_num_rows($result) == 1) {
3539
3540 $new_uid = db_fetch_result($result, 0, "id");
3541
3542 print "<div class=\"notice\">Added user <b>".$_GET["login"].
3543 "</b> with password <b>$tmp_user_pwd</b>.</div>";
3544
3545 initialize_user($link, $new_uid);
3546
3547 } else {
3548
3549 print "<div class=\"warning\">Error while adding user <b>".
3550 $_GET["login"].".</b></div>";
3551
3552 }
3553 }
3554 } else if ($subop == "resetPass") {
3555
3556 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3557
3558 $uid = db_escape_string($_GET["id"]);
3559
3560 $result = db_query($link, "SELECT login,email
3561 FROM ttrss_users WHERE id = '$uid'");
3562
3563 $login = db_fetch_result($result, 0, "login");
3564 $email = db_fetch_result($result, 0, "email");
3565 $tmp_user_pwd = make_password(8);
3566 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3567
3568 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
3569 WHERE id = '$uid'");
3570
3571 print "<div class=\"notice\">Changed password of
3572 user <b>$login</b> to <b>$tmp_user_pwd</b>.";
3573
3574 if (MAIL_RESET_PASS && $email) {
3575 print " Notifying <b>$email</b>.";
3576
3577 mail("$login <$email>", "Password reset notification",
3578 "Hi, $login.\n".
3579 "\n".
3580 "Your password for this TT-RSS installation was reset by".
3581 " an administrator.\n".
3582 "\n".
3583 "Your new password is $tmp_user_pwd, please remember".
3584 " it for later reference.\n".
3585 "\n".
3586 "Sincerely, TT-RSS Mail Daemon.", "From: " . MAIL_FROM);
3587 }
3588
3589 print "</div>";
3590
3591 }
3592 }
3593
3594 print "<div class=\"prefGenericAddBox\">
3595 <input id=\"uadd_box\" onchange=\"javascript:addUser()\" size=\"40\">&nbsp;";
3596
3597 print"<input type=\"submit\" class=\"button\"
3598 onclick=\"javascript:addUser()\" value=\"Add user\"></div>";
3599
3600 $result = db_query($link, "SELECT
3601 id,login,access_level,email,
3602 SUBSTRING(last_login,1,16) as last_login
3603 FROM
3604 ttrss_users
3605 ORDER by login");
3606
3607 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
3608
3609 print "<p><table width=\"100%\" cellspacing=\"0\"
3610 class=\"prefUserList\" id=\"prefUserList\">";
3611
3612 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
3613 Select:
3614 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3615 'UMRR-', 'UMCHK-', true)\">All</a>,
3616 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
3617 'UMRR-', 'UMCHK-', false)\">None</a>
3618 </td</tr>";
3619
3620 print "<tr class=\"title\">
3621 <td align='center' width=\"5%\">&nbsp;</td>
3622 <td width='20%'>Username</td>
3623 <td width='20%'>E-mail</td>
3624 <td width='20%'>Access Level</td>
3625 <td width='20%'>Last login</td></tr>";
3626
3627 $lnum = 0;
3628
3629 while ($line = db_fetch_assoc($result)) {
3630
3631 $class = ($lnum % 2) ? "even" : "odd";
3632
3633 $uid = $line["id"];
3634 $edit_uid = $_GET["id"];
3635
3636 if ($subop == "edit" && $uid != $edit_uid) {
3637 $class .= "Grayed";
3638 $this_row_id = "";
3639 } else {
3640 $this_row_id = "id=\"UMRR-$uid\"";
3641 }
3642
3643 print "<tr class=\"$class\" $this_row_id>";
3644
3645 $line["login"] = htmlspecialchars($line["login"]);
3646
3647 $line["last_login"] = date(get_pref($link, 'SHORT_DATE_FORMAT'),
3648 strtotime($line["last_login"]));
3649
3650 $access_level_names = array(0 => "User", 10 => "Administrator");
3651
3652 /* if ($uid == $_SESSION["uid"]) {
3653
3654 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
3655 id=\"UMCHK-".$line["id"]."\"></td>";
3656
3657 print "<td>".$line["login"]."</td>";
3658 print "<td>".$line["email"]."</td>";
3659 print "<td>".$line["access_level"]."</td>";
3660
3661 } else */ if (!$edit_uid || $subop != "edit") {
3662
3663 print "<td align='center'><input onclick='toggleSelectRow(this);'
3664 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
3665
3666 print "<td><a href=\"javascript:editUser($uid);\">" .
3667 $line["login"] . "</td>";
3668
3669 print "<td><a href=\"javascript:editUser($uid);\">" .
3670 $line["email"] . "</td>";
3671
3672 print "<td><a href=\"javascript:editUser($uid);\">" .
3673 $access_level_names[$line["access_level"]] . "</td>";
3674
3675 } else if ($uid != $edit_uid) {
3676
3677 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
3678 id=\"UMCHK-".$line["id"]."\"></td>";
3679
3680 print "<td>".$line["login"]."</td>";
3681 print "<td>".$line["email"]."</td>";
3682 print "<td>".$access_level_names[$line["access_level"]]."</td>";
3683
3684 } else {
3685
3686 print "<td align='center'>
3687 <input disabled=\"true\" type=\"checkbox\" checked></td>";
3688
3689 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
3690 "\"></td>";
3691
3692 print "<td><input id=\"iedit_email\" value=\"".$line["email"].
3693 "\"></td>";
3694
3695 // print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
3696 // "\"></td>";
3697
3698 print "<td>";
3699 print "<select id=\"iedit_ulevel\">";
3700 foreach (array_keys($access_level_names) as $al) {
3701 if ($al == $line["access_level"]) {
3702 $selected = "selected";
3703 } else {
3704 $selected = "";
3705 }
3706 print "<option $selected id=\"$al\">" .
3707 $access_level_names[$al] . "</option>";
3708 }
3709 print "</select>";
3710 print "</td>";
3711
3712 }
3713
3714 print "<td>".$line["last_login"]."</td>";
3715
3716 print "</tr>";
3717
3718 ++$lnum;
3719 }
3720
3721 print "</table>";
3722
3723 print "<p>";
3724
3725 if ($subop == "edit") {
3726 print "Edit user:
3727 <input type=\"submit\" class=\"button\"
3728 onclick=\"javascript:userEditSave()\" value=\"Save\">
3729 <input type=\"submit\" class=\"button\"
3730 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">";
3731
3732 } else {
3733
3734 print "
3735 Selection:
3736 <input type=\"submit\" class=\"button\"
3737 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
3738 <input type=\"submit\" class=\"button\"
3739 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
3740 <input type=\"submit\" class=\"button\"
3741 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
3742 <input type=\"submit\" class=\"button\"
3743 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
3744
3745 }
3746 }
3747
3748 if ($op == "user-details") {
3749
3750 if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
3751 return;
3752 }
3753
3754 /* print "<html><head>
3755 <title>Tiny Tiny RSS : User Details</title>
3756 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
3757 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
3758 </head><body>"; */
3759
3760 $uid = sprintf("%d", $_GET["id"]);
3761
3762 print "<div class='infoBoxContents'>";
3763
3764 $result = db_query($link, "SELECT login,
3765 SUBSTRING(last_login,1,16) AS last_login,
3766 access_level,
3767 (SELECT COUNT(int_id) FROM ttrss_user_entries
3768 WHERE owner_uid = id) AS stored_articles
3769 FROM ttrss_users
3770 WHERE id = '$uid'");
3771
3772 if (db_num_rows($result) == 0) {
3773 print "<h1>User not found</h1>";
3774 return;
3775 }
3776
3777 print "<h1>User Details</h1>";
3778
3779 print "<table width='100%'>";
3780
3781 $login = db_fetch_result($result, 0, "login");
3782 $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'),
3783 strtotime(db_fetch_result($result, 0, "last_login")));
3784 $access_level = db_fetch_result($result, 0, "access_level");
3785 $stored_articles = db_fetch_result($result, 0, "stored_articles");
3786
3787 print "<tr><td>Username</td><td>$login</td></tr>";
3788 print "<tr><td>Access level</td><td>$access_level</td></tr>";
3789 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
3790 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
3791
3792 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
3793 WHERE owner_uid = '$uid'");
3794
3795 $num_feeds = db_fetch_result($result, 0, "num_feeds");
3796
3797 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
3798
3799 /* $result = db_query($link, "SELECT
3800 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
3801 FROM ttrss_user_entries,ttrss_entries
3802 WHERE owner_uid = '$uid' AND ref_id = id");
3803
3804 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
3805
3806 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
3807
3808 print "</table>";
3809
3810 print "<h1>Subscribed feeds</h1>";
3811
3812 $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
3813 WHERE owner_uid = '$uid' ORDER BY title");
3814
3815 print "<ul class=\"userFeedList\">";
3816
3817 while ($line = db_fetch_assoc($result)) {
3818
3819 $icon_file = ICONS_URL."/".$line["id"].".ico";
3820
3821 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3822 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
3823 } else {
3824 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3825 }
3826
3827 print "<li>$feed_icon&nbsp;<a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
3828 }
3829
3830 if (db_num_rows($result) < $num_feeds) {
3831 // FIXME - add link to show ALL subscribed feeds here somewhere
3832 print "<li><img
3833 class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">&nbsp;...</li>";
3834 }
3835
3836 print "</ul>";
3837
3838 print "</div>";
3839
3840 print "<div align='center'>
3841 <input type='submit' class='button'
3842 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3843
3844 // print "</body></html>";
3845
3846 }
3847
3848 if ($op == "feed-details") {
3849
3850 // $feed_id = $_GET["id"];
3851
3852 $feed_ids = split(",", db_escape_string($_GET["id"]));
3853
3854 print "<div class=\"infoBoxContents\">";
3855
3856 foreach ($feed_ids as $feed_id) {
3857
3858 $result = db_query($link,
3859 "SELECT
3860 title,feed_url,
3861 SUBSTRING(last_updated,1,16) as last_updated,
3862 icon_url,site_url,
3863 (SELECT COUNT(int_id) FROM ttrss_user_entries
3864 WHERE feed_id = id) AS total,
3865 (SELECT COUNT(int_id) FROM ttrss_user_entries
3866 WHERE feed_id = id AND unread = true) AS unread,
3867 (SELECT COUNT(int_id) FROM ttrss_user_entries
3868 WHERE feed_id = id AND marked = true) AS marked
3869 FROM ttrss_feeds
3870 WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]);
3871
3872 if (db_num_rows($result) == 0) return;
3873
3874 $title = db_unescape_string(db_fetch_result($result, 0, "title"));
3875 $last_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
3876 strtotime(db_fetch_result($result, 0, "last_updated")));
3877 $feed_url = db_fetch_result($result, 0, "feed_url");
3878 $icon_url = db_fetch_result($result, 0, "icon_url");
3879 $total = db_fetch_result($result, 0, "total");
3880 $unread = db_fetch_result($result, 0, "unread");
3881 $marked = db_fetch_result($result, 0, "marked");
3882 $site_url = db_fetch_result($result, 0, "site_url");
3883
3884 $result = db_query($link, "SELECT COUNT(id) AS subscribed
3885 FROM ttrss_feeds WHERE feed_url = '$feed_url' AND private = false");
3886
3887 $subscribed = db_fetch_result($result, 0, "subscribed");
3888
3889 $icon_file = ICONS_DIR . "/$feed_id.ico";
3890
3891 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3892 $feed_icon = "<img width=\"16\" height=\"16\"
3893 src=\"" . ICONS_URL . "/$feed_id.ico\">";
3894 } else {
3895 $feed_icon = "";
3896 }
3897
3898 print "<h1>$feed_icon $title</h1>";
3899
3900 print "<table width='100%'>";
3901
3902 if ($site_url) {
3903 print "<tr><td width='30%'>Link</td>
3904 <td><a href=\"$site_url\">$site_url</a>
3905 <a href=\"$feed_url\">(feed)</a></td>
3906 </td></tr>";
3907 } else {
3908 print "<tr><td width='30%'>Feed URL</td>
3909 <td><a href=\"$feed_url\">$feed_url</a></td></tr>";
3910 }
3911 print "<tr><td>Last updated</td><td>$last_updated</td></tr>";
3912 print "<tr><td>Total articles</td><td>$total</td></tr>";
3913 print "<tr><td>Unread articles</td><td>$unread</td></tr>";
3914 print "<tr><td>Starred articles</td><td>$marked</td></tr>";
3915 print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>";
3916
3917 print "</table>";
3918
3919 /* $result = db_query($link, "SELECT title,
3920 SUBSTRING(updated,1,16) AS updated,unread
3921 FROM ttrss_entries,ttrss_user_entries
3922 WHERE ref_id = id AND feed_id = '$feed_id'
3923 ORDER BY date_entered DESC LIMIT 5");
3924
3925 if (db_num_rows($result) > 0) {
3926
3927 print "<h1>Latest headlines</h1>";
3928
3929 print "<ul class=\"nomarks\">";
3930
3931 while ($line = db_fetch_assoc($result)) {
3932 if ($line["unread"] == "t" || $line["unread"] == "1") {
3933 $line["title"] = "<b>" . $line["title"] . "</b>";
3934 }
3935 print "<li>" . $line["title"].
3936 "&nbsp;<span class=\"insensitive\">(" .
3937 date(get_pref($link, 'SHORT_DATE_FORMAT'),
3938 strtotime($line["updated"])).
3939 ")</span></li>";
3940 }
3941
3942 print "</ul>";
3943
3944 } */
3945 }
3946
3947 print "</div>";
3948
3949 print "<div align='center'>
3950 <input type='submit' class='button'
3951 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3952 }
3953
3954 if ($op == "pref-feed-browser") {
3955
3956 if (!ENABLE_FEED_BROWSER) {
3957 print "Feed browser is administratively disabled.";
3958 return;
3959 }
3960
3961 $subop = $_REQUEST["subop"];
3962
3963 if ($subop == "details") {
3964 $id = db_escape_string($_GET["id"]);
3965
3966 print "<div class=\"browserFeedInfo\">";
3967 print "<b>Feed information:</b>";
3968 print "<div class=\"detailsPart\">";
3969
3970 $result = db_query($link, "SELECT
3971 feed_url,site_url,
3972 SUBSTRING(last_updated,1,19) AS last_updated
3973 FROM ttrss_feeds WHERE id = '$id'");
3974
3975 $feed_url = db_fetch_result($result, 0, "feed_url");
3976 $site_url = db_fetch_result($result, 0, "site_url");
3977 $last_updated = db_fetch_result($result, 0, "last_updated");
3978
3979 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
3980 $last_updated = smart_date_time(strtotime($last_updated));
3981 } else {
3982 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
3983 $last_updated = date($short_date, strtotime($last_updated));
3984 }
3985
3986 print "Site: <a href='$site_url'>$site_url</a> ".
3987 "(<a href='$feed_url'>feed</a>), ".
3988 "Last updated: $last_updated";
3989
3990 print "</div>";
3991
3992 $result = db_query($link, "SELECT
3993 ttrss_entries.title,
3994 content,
3995 substring(date_entered,1,19) as date_entered,
3996 substring(updated,1,19) as updated
3997 FROM ttrss_entries,ttrss_user_entries
3998 WHERE ttrss_entries.id = ref_id AND feed_id = '$id'
3999 ORDER BY updated DESC LIMIT 5");
4000
4001 if (db_num_rows($result) > 0) {
4002
4003 print "<b>Last headlines:</b><br>";
4004
4005 print "<div class=\"detailsPart\">";
4006 print "<ul class=\"compact\">";
4007 while ($line = db_fetch_assoc($result)) {
4008
4009 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
4010 $entry_dt = smart_date_time(strtotime($line["updated"]));
4011 } else {
4012 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
4013 $entry_dt = date($short_date, strtotime($line["updated"]));
4014 }
4015
4016 print "<li>" . $line["title"] .
4017 "&nbsp;<span class=\"insensitive\">($entry_dt)</span></li>";
4018 }
4019 print "</ul></div>";
4020 }
4021
4022 print "</div>";
4023
4024 return;
4025 }
4026
4027 $result = db_query($link, "SELECT feed_url,count(id) AS subscribers
4028 FROM ttrss_feeds
4029 WHERE auth_login = '' AND auth_pass = '' AND private = false
4030 GROUP BY feed_url ORDER BY subscribers DESC LIMIT 100");
4031
4032 print "<ul class='nomarks' id='browseBigFeedList'>";
4033
4034 $feedctr = 0;
4035
4036 while ($line = db_fetch_assoc($result)) {
4037 $feed_url = $line["feed_url"];
4038 $subscribers = $line["subscribers"];
4039
4040 $sub_result = db_query($link, "SELECT id
4041 FROM ttrss_feeds WHERE feed_url = '$feed_url' AND owner_uid =" .
4042 $_SESSION["uid"]);
4043
4044 if (db_num_rows($sub_result) > 0) {
4045 continue; // already subscribed
4046 }
4047
4048 $det_result = db_query($link, "SELECT site_url,title,id
4049 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
4050
4051 $details = db_fetch_assoc($det_result);
4052
4053 $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
4054
4055 if (file_exists($icon_file) && filesize($icon_file) > 0) {
4056 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
4057 "/".$details["id"].".ico\">";
4058 } else {
4059 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
4060 }
4061
4062 $check_box = "<input onclick='toggleSelectListRow(this)' class='feedBrowseCB'
4063 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
4064
4065 $class = ($feedctr % 2) ? "even" : "odd";
4066
4067 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
4068 "$feed_icon ";
4069
4070 print "<a href=\"javascript:browserToggleExpand('".$details["id"]."')\">" .
4071 $details["title"] ."</a>&nbsp;" .
4072 "<span class='subscribers'>($subscribers)</span>";
4073
4074 print "<div class=\"browserDetails\" id=\"BRDET-" . $details["id"] . "\">";
4075 print "</div>";
4076
4077 print "</li>";
4078
4079 ++$feedctr;
4080 }
4081
4082 if ($feedctr == 0) {
4083 print "<li>No feeds found to subscribe.</li>";
4084 }
4085
4086 print "</ul>";
4087
4088 print "<p>Selection:
4089 <input type='submit' class='button' onclick=\"feedBrowserSubscribe()\"
4090 value=\"Subscribe\"></p>";
4091
4092 print "</div>";
4093
4094 }
4095
4096 db_close($link);
4097 ?>
4098
4099 <!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
4100