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