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