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