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