]> git.wh0rd.org - tt-rss.git/blob - backend.php
f51e9c1a73d47ffbac678070f7499f5116ef886d
[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 "<form id=\"edit_feed_form\">";
1405
1406 print "<input type=\"hidden\" name=\"id\" value=\"$feed_id\">";
1407 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
1408 print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
1409
1410 print "<table width='100%'>";
1411
1412 print "<tr><td>Title:</td>";
1413 print "<td><input class=\"iedit\" name=\"title\" value=\"$title\"></td></tr>";
1414
1415 $feed_url = db_fetch_result($result, 0, "feed_url");
1416 $feed_url = htmlspecialchars(db_unescape_string(db_fetch_result($result,
1417 0, "feed_url")));
1418
1419 print "<tr><td>Feed URL:</td>";
1420 print "<td><input class=\"iedit\" name=\"feed_url\" value=\"$feed_url\"></td></tr>";
1421
1422 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1423
1424 $cat_id = db_fetch_result($result, 0, "cat_id");
1425
1426 print "<tr><td>Category:</td>";
1427 print "<td>";
1428
1429 print_feed_cat_select($link, "cat_id", $cat_id);
1430
1431 print "</td>";
1432 print "</td></tr>";
1433
1434 }
1435
1436 $update_interval = db_fetch_result($result, 0, "update_interval");
1437
1438 print "<tr><td>Update Interval:</td>";
1439
1440 print "<td>";
1441
1442 print "<select name=\"update_interval\">";
1443
1444 foreach (array_keys($update_intervals) as $i) {
1445
1446 if ($i == $update_interval) {
1447 $selected = "selected";
1448 } else {
1449 $selected = "";
1450 }
1451 print "<option $selected value=\"$i\">" . $update_intervals[$i] . "</option>";
1452 }
1453
1454 print "</select>";
1455
1456 print "</td>";
1457
1458 print "<tr><td>Link to:</td><td>";
1459
1460 $tmp_result = db_query($link, "SELECT COUNT(id) AS count
1461 FROM ttrss_feeds WHERE parent_feed = '$feed_id'");
1462
1463 $linked_count = db_fetch_result($tmp_result, 0, "count");
1464
1465 $parent_feed = db_fetch_result($result, 0, "parent_feed");
1466
1467 if ($linked_count > 0) {
1468 $disabled = "disabled";
1469 }
1470
1471 print "<select $disabled name=\"parent_feed\">";
1472
1473 print "<option value=\"0\">Not linked</option>";
1474
1475 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1476 if ($cat_id) {
1477 $cat_qpart = "AND cat_id = '$cat_id'";
1478 } else {
1479 $cat_qpart = "AND cat_id IS NULL";
1480 }
1481 }
1482
1483 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
1484 WHERE id != '$feed_id' AND owner_uid = ".$_SESSION["uid"]."
1485 $cat_qpart ORDER BY title");
1486
1487 if (db_num_rows($tmp_result) > 0) {
1488 print "<option disabled>--------</option>";
1489 }
1490
1491 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1492 if ($tmp_line["id"] == $parent_feed) {
1493 $is_selected = "selected";
1494 } else {
1495 $is_selected = "";
1496 }
1497 printf("<option $is_selected value='%d'>%s</option>",
1498 $tmp_line["id"], $tmp_line["title"]);
1499 }
1500
1501 print "</select>";
1502 print "</td></tr>";
1503
1504 $purge_interval = db_fetch_result($result, 0, "purge_interval");
1505
1506 print "<tr><td>Article purging:</td>";
1507
1508 print "<td>";
1509
1510 print "<select name=\"purge_interval\">";
1511
1512 foreach (array_keys($purge_intervals) as $i) {
1513
1514 if ($i == $purge_interval) {
1515 $selected = "selected";
1516 } else {
1517 $selected = "";
1518 }
1519 print "<option $selected value=\"$i\">" . $purge_intervals[$i] . "</option>";
1520 }
1521
1522 print "</select>";
1523
1524 print "</td>";
1525
1526 $auth_login = db_fetch_result($result, 0, "auth_login");
1527
1528 print "<tr><td>Login:</td>";
1529 print "<td><input class=\"iedit\" name=\"auth_login\" value=\"$auth_login\"></td></tr>";
1530
1531 $auth_pass = db_fetch_result($result, 0, "auth_pass");
1532
1533 print "<tr><td>Password:</td>";
1534 print "<td><input class=\"iedit\" type=\"password\" name=\"auth_pass\"
1535 value=\"$auth_pass\"></td></tr>";
1536
1537 $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
1538
1539 if ($private) {
1540 $checked = "checked";
1541 } else {
1542 $checked = "";
1543 }
1544
1545 print "<tr><td valign='top'>Options:</td>";
1546 print "<td><input type=\"checkbox\" name=\"private\" id=\"private\"
1547 $checked><label for=\"private\">Hide from feed browser</label>";
1548
1549 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
1550
1551 if ($rtl_content) {
1552 $checked = "checked";
1553 } else {
1554 $checked = "";
1555 }
1556
1557 print "<br><input type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\"
1558 $checked><label for=\"rtl_content\">Right-to-left content</label>";
1559
1560 print "</td></tr>";
1561
1562 print "</table>";
1563
1564 print "</form>";
1565
1566 print "</div>";
1567
1568 print "<div align='center'>
1569 <input type=\"submit\" class=\"button\"
1570 onclick=\"return feedEditSave()\" value=\"Save\">
1571 <input type='submit' class='button'
1572 onclick=\"return feedEditCancel()\" value=\"Cancel\"></div>";
1573 return;
1574 }
1575
1576 if ($subop == "editSave") {
1577
1578 $feed_title = db_escape_string(trim($_POST["title"]));
1579 $feed_link = db_escape_string(trim($_POST["feed_url"]));
1580 $upd_intl = db_escape_string($_POST["update_interval"]);
1581 $purge_intl = db_escape_string($_POST["purge_interval"]);
1582 $feed_id = db_escape_string($_POST["id"]);
1583 $cat_id = db_escape_string($_POST["cat_id"]);
1584 $auth_login = db_escape_string(trim($_POST["auth_login"]));
1585 $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
1586 $parent_feed = db_escape_string($_POST["parent_feed"]);
1587 $private = checkbox_to_sql_bool(db_escape_string($_POST["private"]));
1588 $rtl_content = checkbox_to_sql_bool(db_escape_string($_POST["rtl_content"]));
1589
1590 if ($cat_id && $cat_id != 0) {
1591 $category_qpart = "cat_id = '$cat_id'";
1592 } else {
1593 $category_qpart = 'cat_id = NULL';
1594 }
1595
1596 if ($parent_feed && $parent_feed != 0) {
1597 $parent_qpart = "parent_feed = '$parent_feed'";
1598 } else {
1599 $parent_qpart = 'parent_feed = NULL';
1600 }
1601
1602 $result = db_query($link, "UPDATE ttrss_feeds SET
1603 $category_qpart,
1604 $parent_qpart,
1605 title = '$feed_title', feed_url = '$feed_link',
1606 update_interval = '$upd_intl',
1607 purge_interval = '$purge_intl',
1608 auth_login = '$auth_login',
1609 auth_pass = '$auth_pass',
1610 private = $private,
1611 rtl_content = $rtl_content
1612 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
1613 }
1614
1615 if ($subop == "saveCat") {
1616 $cat_title = db_escape_string(trim($_GET["title"]));
1617 $cat_id = db_escape_string($_GET["id"]);
1618
1619 $result = db_query($link, "UPDATE ttrss_feed_categories SET
1620 title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
1621
1622 }
1623
1624 if ($subop == "remove") {
1625
1626 if (!WEB_DEMO_MODE) {
1627
1628 $ids = split(",", db_escape_string($_GET["ids"]));
1629
1630 foreach ($ids as $id) {
1631 db_query($link, "DELETE FROM ttrss_feeds
1632 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1633
1634 $icons_dir = ICONS_DIR;
1635
1636 if (file_exists($icons_dir . "/$id.ico")) {
1637 unlink($icons_dir . "/$id.ico");
1638 }
1639 }
1640 }
1641 }
1642
1643 if ($subop == "add") {
1644
1645 if (!WEB_DEMO_MODE) {
1646
1647 $feed_link = db_escape_string(trim($_GET["link"]));
1648 $cat_id = db_escape_string($_GET["cid"]);
1649
1650 if (subscribe_to_feed($link, $feed_link, $cat_id)) {
1651 print "Added feed.";
1652 } else {
1653 print "<div class=\"warning\">
1654 Feed <b>$feed_link</b> already exists in the database.
1655 </div>";
1656 }
1657 }
1658 }
1659
1660 if ($subop == "addCat") {
1661
1662 if (!WEB_DEMO_MODE) {
1663
1664 $feed_cat = db_escape_string(trim($_GET["cat"]));
1665
1666 $result = db_query($link,
1667 "SELECT id FROM ttrss_feed_categories
1668 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
1669
1670 if (db_num_rows($result) == 0) {
1671
1672 $result = db_query($link,
1673 "INSERT INTO ttrss_feed_categories (owner_uid,title)
1674 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
1675
1676 } else {
1677
1678 print "<div class=\"warning\">
1679 Category <b>$feed_cat</b> already exists in the database.
1680 </div>";
1681 }
1682
1683
1684 }
1685 }
1686
1687 if ($subop == "removeCats") {
1688
1689 if (!WEB_DEMO_MODE) {
1690
1691 $ids = split(",", db_escape_string($_GET["ids"]));
1692
1693 foreach ($ids as $id) {
1694
1695 db_query($link, "BEGIN");
1696
1697 $result = db_query($link,
1698 "SELECT count(id) as num_feeds FROM ttrss_feeds
1699 WHERE cat_id = '$id'");
1700
1701 $num_feeds = db_fetch_result($result, 0, "num_feeds");
1702
1703 if ($num_feeds == 0) {
1704 db_query($link, "DELETE FROM ttrss_feed_categories
1705 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1706 } else {
1707
1708 print "<div class=\"warning\">
1709 Unable to delete non empty feed categories.</div>";
1710
1711 }
1712
1713 db_query($link, "COMMIT");
1714 }
1715 }
1716 }
1717
1718 if ($subop == "categorize") {
1719
1720 if (!WEB_DEMO_MODE) {
1721
1722 $ids = split(",", db_escape_string($_GET["ids"]));
1723
1724 $cat_id = db_escape_string($_GET["cat_id"]);
1725
1726 if ($cat_id == 0) {
1727 $cat_id_qpart = 'NULL';
1728 } else {
1729 $cat_id_qpart = "'$cat_id'";
1730 }
1731
1732 db_query($link, "BEGIN");
1733
1734 foreach ($ids as $id) {
1735
1736 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
1737 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1738 }
1739
1740 db_query($link, "COMMIT");
1741 }
1742
1743 }
1744
1745 if ($quiet) return;
1746
1747 // print "<h3>Edit Feeds</h3>";
1748
1749 $result = db_query($link, "SELECT id,title,feed_url,last_error
1750 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1751
1752 if (db_num_rows($result) > 0) {
1753
1754 print "<div class=\"warning\">";
1755
1756 // print"<img class=\"closeButton\"
1757 // onclick=\"javascript:hideParentElement(this);\" src=\"images/close.png\">";
1758
1759 print "<a href=\"javascript:showBlockElement('feedUpdateErrors')\">
1760 <b>Some feeds have update errors (click for details)</b></a>";
1761
1762 print "<ul id=\"feedUpdateErrors\" class=\"nomarks\">";
1763
1764 while ($line = db_fetch_assoc($result)) {
1765 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
1766 $line["last_error"];
1767 }
1768
1769 print "</ul>";
1770 print "</div>";
1771
1772 }
1773
1774 $feed_search = db_escape_string($_GET["search"]);
1775
1776 if (array_key_exists("search", $_GET)) {
1777 $_SESSION["prefs_feed_search"] = $feed_search;
1778 } else {
1779 $feed_search = $_SESSION["prefs_feed_search"];
1780 }
1781
1782 print "<table width='100%' class=\"prefGenericAddBox\"
1783 cellspacing='0' cellpadding='0'><tr>
1784 <td>
1785 <input id=\"fadd_link\"
1786 onkeyup=\"toggleSubmitNotEmpty(this, 'fadd_submit_btn')\"
1787 size=\"40\">
1788 <input type=\"submit\" class=\"button\"
1789 disabled=\"true\" id=\"fadd_submit_btn\"
1790 onclick=\"addFeed()\" value=\"Subscribe\">";
1791
1792 if (ENABLE_FEED_BROWSER && !SINGLE_USER_MODE) {
1793 print " <input type=\"submit\" class=\"button\"
1794 onclick=\"javascript:browseFeeds()\" value=\"Top 25\">";
1795 }
1796
1797 print "</td><td align='right'>
1798 <input id=\"feed_search\" size=\"20\"
1799 onchange=\"javascript:updateFeedList()\" value=\"$feed_search\">
1800 <input type=\"submit\" class=\"button\"
1801 onclick=\"javascript:updateFeedList()\" value=\"Search\">
1802 </td>
1803 </tr></table>";
1804
1805 $feeds_sort = db_escape_string($_GET["sort"]);
1806
1807 if (!$feeds_sort || $feeds_sort == "undefined") {
1808 $feeds_sort = $_SESSION["pref_sort_feeds"];
1809 if (!$feeds_sort) $feeds_sort = "title";
1810 }
1811
1812 $_SESSION["pref_sort_feeds"] = $feeds_sort;
1813
1814 if ($feed_search) {
1815 $search_qpart = "(UPPER(F1.title) LIKE UPPER('%$feed_search%') OR
1816 UPPER(F1.feed_url) LIKE UPPER('%$feed_search%')) AND";
1817 } else {
1818 $search_qpart = "";
1819 }
1820
1821 $result = db_query($link, "SELECT
1822 F1.id,
1823 F1.title,
1824 F1.feed_url,
1825 substring(F1.last_updated,1,16) AS last_updated,
1826 F1.parent_feed,
1827 F1.update_interval,
1828 F1.purge_interval,
1829 F1.cat_id,
1830 F2.title AS parent_title,
1831 C1.title AS category
1832 FROM
1833 ttrss_feeds AS F1
1834 LEFT JOIN ttrss_feeds AS F2
1835 ON (F1.parent_feed = F2.id)
1836 LEFT JOIN ttrss_feed_categories AS C1
1837 ON (F1.cat_id = C1.id)
1838 WHERE
1839 $search_qpart F1.owner_uid = '".$_SESSION["uid"]."'
1840 ORDER by category,$feeds_sort,title");
1841
1842 if (db_num_rows($result) != 0) {
1843
1844 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1845
1846 print "<p><table width=\"100%\" cellspacing=\"0\"
1847 class=\"prefFeedList\" id=\"prefFeedList\">";
1848 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1849 Select:
1850 <a href=\"javascript:selectPrefRows('feed', true)\">All</a>,
1851 <a href=\"javascript:selectPrefRows('feed', false)\">None</a>
1852 </td</tr>";
1853
1854 if (!get_pref($link, 'ENABLE_FEED_CATS')) {
1855 print "<tr class=\"title\">
1856 <td width='5%' align='center'>&nbsp;</td>
1857 <td width='40%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
1858 <td width='45%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
1859 <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
1860 }
1861
1862 $lnum = 0;
1863
1864 $cur_cat_id = -1;
1865
1866 while ($line = db_fetch_assoc($result)) {
1867
1868 $feed_id = $line["id"];
1869 $cat_id = $line["cat_id"];
1870
1871 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1872 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
1873 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
1874
1875 if (!$edit_cat) $edit_cat = "Uncategorized";
1876
1877 $last_updated = $line["last_updated"];
1878
1879 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1880 $last_updated = smart_date_time(strtotime($last_updated));
1881 } else {
1882 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1883 $last_updated = date($short_date, strtotime($last_updated));
1884 }
1885
1886 if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
1887 $lnum = 0;
1888
1889 print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>";
1890
1891 print "<tr class=\"title\">
1892 <td width='5%'>&nbsp;</td>";
1893
1894 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1895 print "<td width='3%'>&nbsp;</td>";
1896 }
1897
1898 print "<td width='40%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
1899 <td width='45%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
1900 <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
1901
1902 $cur_cat_id = $cat_id;
1903 }
1904
1905 $class = ($lnum % 2) ? "even" : "odd";
1906 $this_row_id = "id=\"FEEDR-$feed_id\"";
1907
1908 print "<tr class=\"$class\" $this_row_id>";
1909
1910 $icon_file = ICONS_DIR . "/$feed_id.ico";
1911
1912 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1913 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/$feed_id.ico\">";
1914 } else {
1915 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
1916 }
1917
1918 print "<td class='feedSelect'><input onclick='toggleSelectPrefRow(this, \"feed\");'
1919 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
1920
1921 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1922 print "<td class='feedIcon'>$feed_icon</td>";
1923 }
1924
1925 $edit_title = truncate_string($edit_title, 40);
1926 $edit_link = truncate_string($edit_link, 60);
1927
1928 $parent_title = $line["parent_title"];
1929 if ($parent_title) {
1930 $parent_title = "<span class='groupPrompt'>(linked to
1931 $parent_title)</span>";
1932 }
1933
1934 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1935 "$edit_title $parent_title" . "</a></td>";
1936
1937 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1938 $edit_link . "</a></td>";
1939
1940 print "<td align='right'><a href=\"javascript:editFeed($feed_id);\">" .
1941 "$last_updated</a></td>";
1942
1943 print "</tr>";
1944
1945 ++$lnum;
1946 }
1947
1948 print "</table>";
1949
1950 print "<p><span id=\"feedOpToolbar\">";
1951
1952 if ($subop == "edit") {
1953 print "Edit feed:&nbsp;
1954 <input type=\"submit\" class=\"button\"
1955 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
1956 <input type=\"submit\" class=\"button\"
1957 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1958 } else {
1959
1960 print "
1961 Selection:&nbsp;
1962 <input type=\"submit\" class=\"button\" disabled=\"true\"
1963 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
1964 <input type=\"submit\" class=\"button\" disabled=\"true\"
1965 onclick=\"javascript:removeSelectedFeeds()\" value=\"Unsubscribe\">";
1966
1967 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1968
1969 print "&nbsp;|&nbsp;";
1970
1971 print_feed_cat_select($link, "sfeed_set_fcat", "", "disabled");
1972
1973 print " <input type=\"submit\" class=\"button\" disabled=\"true\"
1974 onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Recategorize\">";
1975
1976 }
1977
1978 print "</span>
1979 &nbsp;All feeds: <input type=\"submit\"
1980 class=\"button\" onclick=\"gotoExportOpml()\"
1981 value=\"Export OPML\">";
1982 }
1983 } else {
1984
1985 print "<p>No feeds defined.</p>";
1986
1987 }
1988
1989 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1990
1991 print "<h3>Edit Categories</h3>";
1992
1993 print "<div class=\"prefGenericAddBox\">
1994 <input id=\"fadd_cat\"
1995 onkeyup=\"toggleSubmitNotEmpty(this, 'catadd_submit_btn')\"
1996 size=\"40\">&nbsp;
1997 <input
1998 type=\"submit\" class=\"button\" disabled=\"true\" id=\"catadd_submit_btn\"
1999 onclick=\"javascript:addFeedCat()\" value=\"Create category\"></div>";
2000
2001 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2002 WHERE owner_uid = ".$_SESSION["uid"]."
2003 ORDER BY title");
2004
2005 if (db_num_rows($result) != 0) {
2006
2007 print "<p><table width=\"100%\" class=\"prefFeedCatList\"
2008 cellspacing=\"0\" id=\"prefFeedCatList\">";
2009
2010 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2011 Select:
2012 <a href=\"javascript:selectPrefRows('fcat', true)\">All</a>,
2013 <a href=\"javascript:selectPrefRows('fcat', false)\">None</a>
2014 </td</tr>";
2015
2016 print "<tr class=\"title\">
2017 <td width=\"5%\">&nbsp;</td><td width=\"80%\">Title</td>
2018 </tr>";
2019
2020 $lnum = 0;
2021
2022 while ($line = db_fetch_assoc($result)) {
2023
2024 $class = ($lnum % 2) ? "even" : "odd";
2025
2026 $cat_id = $line["id"];
2027
2028 $edit_cat_id = $_GET["id"];
2029
2030 if ($subop == "editCat" && $cat_id != $edit_cat_id) {
2031 $class .= "Grayed";
2032 $this_row_id = "";
2033 } else {
2034 $this_row_id = "id=\"FCATR-$cat_id\"";
2035 }
2036
2037 print "<tr class=\"$class\" $this_row_id>";
2038
2039 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
2040
2041 if (!$edit_cat_id || $subop != "editCat") {
2042
2043 print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"fcat\");'
2044 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
2045
2046 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
2047 $edit_title . "</a></td>";
2048
2049 } else if ($cat_id != $edit_cat_id) {
2050
2051 print "<td><input disabled=\"true\" type=\"checkbox\"
2052 id=\"FRCHK-".$line["id"]."\"></td>";
2053
2054 print "<td>$edit_title</td>";
2055
2056 } else {
2057
2058 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2059
2060 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
2061
2062 }
2063
2064 print "</tr>";
2065
2066 ++$lnum;
2067 }
2068
2069 print "</table>";
2070
2071 print "<p id=\"catOpToolbar\">";
2072
2073 if ($subop == "editCat") {
2074 print "Edit category:&nbsp;
2075 <input type=\"submit\" class=\"button\"
2076 onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\">
2077 <input type=\"submit\" class=\"button\"
2078 onclick=\"javascript:feedCatEditSave()\" value=\"Save\">";
2079 } else {
2080
2081 print "
2082 Selection:&nbsp;
2083 <input type=\"submit\" class=\"button\" disabled=\"true\"
2084 onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\">
2085 <input type=\"submit\" class=\"button\" disabled=\"true\"
2086 onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">";
2087
2088 }
2089
2090 } else {
2091 print "<p>No feed categories defined.</p>";
2092 }
2093 }
2094
2095 print "<h3>Import OPML</h3>
2096 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
2097 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
2098 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
2099 type=\"submit\" value=\"Import\">
2100 </form>";
2101
2102 }
2103
2104 if ($op == "pref-filters") {
2105
2106 $subop = $_GET["subop"];
2107 $quiet = $_GET["quiet"];
2108
2109 if ($subop == "editSave") {
2110
2111 $regexp = db_escape_string(trim($_GET["r"]));
2112 $match = db_escape_string(trim($_GET["m"]));
2113 $filter_id = db_escape_string($_GET["id"]);
2114 $feed_id = db_escape_string($_GET["fid"]);
2115 $action_id = db_escape_string($_GET["aid"]);
2116
2117 if (!$feed_id) {
2118 $feed_id = 'NULL';
2119 } else {
2120 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2121 }
2122
2123 $result = db_query($link, "UPDATE ttrss_filters SET
2124 reg_exp = '$regexp',
2125 feed_id = $feed_id,
2126 action_id = '$action_id',
2127 filter_type = (SELECT id FROM ttrss_filter_types WHERE
2128 description = '$match')
2129 WHERE id = '$filter_id'");
2130 }
2131
2132 if ($subop == "remove") {
2133
2134 if (!WEB_DEMO_MODE) {
2135
2136 $ids = split(",", db_escape_string($_GET["ids"]));
2137
2138 foreach ($ids as $id) {
2139 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
2140
2141 }
2142 }
2143 }
2144
2145 if ($subop == "add") {
2146
2147 if (!WEB_DEMO_MODE) {
2148
2149 $regexp = db_escape_string(trim($_GET["reg_exp"]));
2150 $match_id = db_escape_string(trim($_GET["match_id"]));
2151 $feed_id = db_escape_string($_GET["feed_id"]);
2152 $action_id = db_escape_string($_GET["action_id"]);
2153
2154 if (!$feed_id) {
2155 $feed_id = 'NULL';
2156 } else {
2157 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2158 }
2159
2160 $result = db_query($link,
2161 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
2162 action_id)
2163 VALUES
2164 ('$regexp', '$match_id','".$_SESSION["uid"]."',
2165 $feed_id, '$action_id')");
2166 }
2167 }
2168
2169 if ($quiet) return;
2170
2171 print "<div id=\"infoBoxShadow\">
2172 <div id=\"infoBox\">PLACEHOLDER</div></div>";
2173
2174 $result = db_query($link, "SELECT description
2175 FROM ttrss_filter_types ORDER BY description");
2176
2177 $filter_types = array();
2178
2179 while ($line = db_fetch_assoc($result)) {
2180 array_push($filter_types, $line["description"]);
2181 }
2182
2183 print "<input type=\"submit\"
2184 class=\"button\"
2185 onclick=\"javascript:displayDlg('quickAddFilter', false)\"
2186 value=\"Create filter\">";
2187
2188 $result = db_query($link, "SELECT
2189 ttrss_filters.id AS id,reg_exp,
2190 ttrss_filter_types.name AS filter_type_name,
2191 ttrss_filter_types.description AS filter_type_descr,
2192 feed_id,
2193 ttrss_filter_actions.description AS action_description,
2194 ttrss_feeds.title AS feed_title
2195 FROM
2196 ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN
2197 ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id)
2198 WHERE
2199 filter_type = ttrss_filter_types.id AND
2200 ttrss_filter_actions.id = action_id AND
2201 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
2202 ORDER by reg_exp");
2203
2204 if (db_num_rows($result) != 0) {
2205
2206 print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\"
2207 id=\"prefFilterList\">";
2208
2209 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2210 Select:
2211 <a href=\"javascript:selectPrefRows('filter', true)\">All</a>,
2212 <a href=\"javascript:selectPrefRows('filter', false)\">None</a>
2213 </td</tr>";
2214
2215 print "<tr class=\"title\">
2216 <td align='center' width=\"5%\">&nbsp;</td>
2217 <td width=\"20%\">Filter expression</td>
2218 <td width=\"20%\">Feed</td>
2219 <td width=\"15%\">Match</td>
2220 <td width=\"15%\">Action</td>";
2221
2222 $lnum = 0;
2223
2224 while ($line = db_fetch_assoc($result)) {
2225
2226 $class = ($lnum % 2) ? "even" : "odd";
2227
2228 $filter_id = $line["id"];
2229 $edit_filter_id = $_GET["id"];
2230
2231 if ($subop == "edit" && $filter_id != $edit_filter_id) {
2232 $class .= "Grayed";
2233 $this_row_id = "";
2234 } else {
2235 $this_row_id = "id=\"FILRR-$filter_id\"";
2236 }
2237
2238 print "<tr class=\"$class\" $this_row_id>";
2239
2240 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
2241
2242 if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
2243
2244 if (!$edit_filter_id || $subop != "edit") {
2245
2246 print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"filter\");'
2247 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
2248
2249 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2250 $line["reg_exp"] . "</td>";
2251
2252 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2253 $line["feed_title"] . "</td>";
2254
2255 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2256 $line["filter_type_descr"] . "</td>";
2257
2258 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2259 $line["action_description"] . "</td>";
2260
2261 } else if ($filter_id != $edit_filter_id) {
2262
2263 if (!$line["description"]) $line["description"] = "[No description]";
2264
2265 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
2266 id=\"FICHK-".$line["id"]."\"></td>";
2267
2268 print "<td>".$line["reg_exp"]."</td>";
2269 print "<td>".$line["feed_title"]."</td>";
2270 print "<td>".$line["filter_type_descr"]."</td>";
2271 print "<td>".$line["action_description"]."</td>";
2272
2273 } else {
2274
2275 print "<td align='center'><input disabled=\"true\" type=\"checkbox\" checked></td>";
2276
2277 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
2278 "\"></td>";
2279
2280 print "<td>";
2281 print_feed_select($link, "iedit_feed", $line["feed_id"]);
2282 print "</td>";
2283
2284 print "<td>";
2285 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
2286 print "</td>";
2287
2288 print "<td>";
2289 print "<select id=\"iedit_filter_action\">";
2290
2291 $tmp_result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2292 ORDER BY description");
2293
2294 while ($tmp_line = db_fetch_assoc($tmp_result)) {
2295 if ($tmp_line["description"] == $line["action_description"]) {
2296 $is_selected = "selected";
2297 } else {
2298 $is_selected = "";
2299 }
2300 printf("<option $is_selected id='%d'>%s</option>",
2301 $tmp_line["id"], $tmp_line["description"]);
2302 }
2303
2304 print "</select></td>";
2305
2306 print "</td>";
2307 }
2308
2309 print "</tr>";
2310
2311 ++$lnum;
2312 }
2313
2314 if ($lnum == 0) {
2315 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
2316 }
2317
2318 print "</table>";
2319
2320 print "<p id=\"filterOpToolbar\">";
2321
2322 if ($subop == "edit") {
2323 print "Edit filter:
2324 <input type=\"submit\" class=\"button\"
2325 onclick=\"javascript:filterEditSave()\" value=\"Save\">
2326 <input type=\"submit\" class=\"button\"
2327 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">";
2328
2329 } else {
2330
2331 print "
2332 Selection:
2333 <input type=\"submit\" class=\"button\" disabled=\"true\"
2334 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
2335 <input type=\"submit\" class=\"button\" disabled=\"true\"
2336 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
2337 }
2338
2339 } else {
2340
2341 print "<p>No filters defined.</p>";
2342
2343 }
2344 }
2345
2346 // We need to accept raw SQL data in label queries, so not everything is escaped
2347 // here, this is by design. If you don't like the whole idea, disable labels
2348 // altogether with GLOBAL_ENABLE_LABELS = false
2349
2350 if ($op == "pref-labels") {
2351
2352 if (!GLOBAL_ENABLE_LABELS) {
2353 return;
2354 }
2355
2356 $subop = $_GET["subop"];
2357
2358 if ($subop == "test") {
2359
2360 $expr = trim($_GET["expr"]);
2361 $descr = trim($_GET["descr"]);
2362
2363 print "<div id=\"infoBoxTitle\">Test label: $descr</div>";
2364
2365 print "<div class='infoBoxContents'>";
2366
2367 # print "<h1>Label &laquo;$descr&raquo;</h1>";
2368
2369 // print "<p><b>Expression</b>: $expr</p>";
2370
2371 $result = db_query($link,
2372 "SELECT count(id) AS num_matches
2373 FROM ttrss_entries,ttrss_user_entries
2374 WHERE ($expr) AND
2375 ttrss_user_entries.ref_id = ttrss_entries.id AND
2376 owner_uid = " . $_SESSION["uid"]);
2377
2378 $num_matches = db_fetch_result($result, 0, "num_matches");;
2379
2380 if ($num_matches > 0) {
2381
2382 print "<p>Query returned <b>$num_matches</b> matches, showing first 15:</p>";
2383
2384 $result = db_query($link,
2385 "SELECT title,
2386 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
2387 FROM ttrss_entries,ttrss_user_entries
2388 WHERE ($expr) AND
2389 ttrss_user_entries.ref_id = ttrss_entries.id
2390 AND owner_uid = " . $_SESSION["uid"] . "
2391 ORDER BY date_entered DESC LIMIT 15");
2392
2393 print "<ul class=\"filterTestResults\">";
2394
2395 $row_class = "even";
2396
2397 while ($line = db_fetch_assoc($result)) {
2398 $row_class = toggleEvenOdd($row_class);
2399
2400 print "<li class=\"$row_class\">".$line["title"].
2401 " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
2402 }
2403 print "</ul>";
2404
2405 } else {
2406 print "<p>Query didn't return any matches.</p>";
2407 }
2408
2409 print "</div>";
2410
2411 print "<div align='center'>
2412 <input type='submit' class='button'
2413 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2414 return;
2415 }
2416
2417 if ($subop == "editSave") {
2418
2419 $sql_exp = trim($_GET["s"]);
2420 $descr = trim($_GET["d"]);
2421 $label_id = db_escape_string($_GET["id"]);
2422
2423 // print "$sql_exp : $descr : $label_id";
2424
2425 $result = db_query($link, "UPDATE ttrss_labels SET
2426 sql_exp = '$sql_exp',
2427 description = '$descr'
2428 WHERE id = '$label_id'");
2429 }
2430
2431 if ($subop == "remove") {
2432
2433 if (!WEB_DEMO_MODE) {
2434
2435 $ids = split(",", db_escape_string($_GET["ids"]));
2436
2437 foreach ($ids as $id) {
2438 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
2439
2440 }
2441 }
2442 }
2443
2444 if ($subop == "add") {
2445
2446 if (!WEB_DEMO_MODE) {
2447
2448 // no escaping is done here on purpose
2449 $exp = trim($_GET["exp"]);
2450
2451 $result = db_query($link,
2452 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
2453 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
2454 }
2455 }
2456
2457 print "<div class=\"prefGenericAddBox\">
2458 <input size=\"40\"
2459 onkeyup=\"toggleSubmitNotEmpty(this, 'label_create_btn')\"
2460 id=\"ladd_expr\">&nbsp;";
2461
2462 print"<input type=\"submit\" class=\"button\"
2463 disabled=\"true\" id=\"label_create_btn\"
2464 onclick=\"javascript:addLabel()\" value=\"Create label\"></div>";
2465
2466 $result = db_query($link, "SELECT
2467 id,sql_exp,description
2468 FROM
2469 ttrss_labels
2470 WHERE
2471 owner_uid = ".$_SESSION["uid"]."
2472 ORDER by description");
2473
2474 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2475
2476 if (db_num_rows($result) != 0) {
2477
2478 print "<p><table width=\"100%\" cellspacing=\"0\"
2479 class=\"prefLabelList\" id=\"prefLabelList\">";
2480
2481 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2482 Select:
2483 <a href=\"javascript:selectPrefRows('label', true)\">All</a>,
2484 <a href=\"javascript:selectPrefRows('label', false)\">None</a>
2485 </td</tr>";
2486
2487 print "<tr class=\"title\">
2488 <td width=\"5%\">&nbsp;</td>
2489 <td width=\"40%\">SQL expression
2490 <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a>
2491 </td>
2492 <td width=\"40%\">Caption</td></tr>";
2493
2494 $lnum = 0;
2495
2496 while ($line = db_fetch_assoc($result)) {
2497
2498 $class = ($lnum % 2) ? "even" : "odd";
2499
2500 $label_id = $line["id"];
2501 $edit_label_id = $_GET["id"];
2502
2503 if ($subop == "edit" && $label_id != $edit_label_id) {
2504 $class .= "Grayed";
2505 $this_row_id = "";
2506 } else {
2507 $this_row_id = "id=\"LILRR-$label_id\"";
2508 }
2509
2510 print "<tr class=\"$class\" $this_row_id>";
2511
2512 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
2513 $line["description"] = htmlspecialchars($line["description"]);
2514
2515 if (!$edit_label_id || $subop != "edit") {
2516
2517 if (!$line["description"]) $line["description"] = "[No caption]";
2518
2519 print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"label\");'
2520 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
2521
2522 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2523 $line["sql_exp"] . "</td>";
2524
2525 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2526 $line["description"] . "</td>";
2527
2528 } else if ($label_id != $edit_label_id) {
2529
2530 if (!$line["description"]) $line["description"] = "[No description]";
2531
2532 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
2533 id=\"LICHK-".$line["id"]."\"></td>";
2534
2535 print "<td>".$line["sql_exp"]."</td>";
2536 print "<td>".$line["description"]."</td>";
2537
2538 } else {
2539
2540 print "<td align='center'><input disabled=\"true\" type=\"checkbox\" checked></td>";
2541
2542 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
2543 "\"></td>";
2544
2545 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
2546 "\"></td>";
2547 }
2548
2549
2550 print "</tr>";
2551
2552 ++$lnum;
2553 }
2554
2555 if ($lnum == 0) {
2556 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
2557 }
2558
2559 print "</table>";
2560
2561 print "<p id=\"labelOpToolbar\">";
2562
2563 if ($subop == "edit") {
2564 print "Edit label:
2565 <input type=\"submit\" class=\"button\"
2566 onclick=\"javascript:labelTest()\" value=\"Test\">
2567 <input type=\"submit\" class=\"button\"
2568 onclick=\"javascript:labelEditSave()\" value=\"Save\">
2569 <input type=\"submit\" class=\"button\"
2570 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">";
2571
2572 } else {
2573 print "
2574 Selection:
2575 <input type=\"submit\" class=\"button\" disabled=\"true\"
2576 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
2577 <input type=\"submit\" class=\"button\" disabled=\"true\"
2578 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
2579 }
2580 } else {
2581 print "<p>No labels defined.</p>";
2582 }
2583 }
2584
2585 if ($op == "error") {
2586 print "<div width=\"100%\" align='center'>";
2587 $msg = $_GET["msg"];
2588 print $msg;
2589 print "</div>";
2590 }
2591
2592 if ($op == "help") {
2593 if (!$_GET["noheaders"]) {
2594 print "<html><head>
2595 <title>Tiny Tiny RSS : Help</title>
2596 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2597 <script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
2598 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2599 </head><body>";
2600 }
2601
2602 $tid = sprintf("%d", $_GET["tid"]);
2603
2604 print "<div id=\"infoBoxTitle\">Help</div>";
2605
2606 print "<div class='infoBoxContents'>";
2607
2608 if (file_exists("help/$tid.php")) {
2609 include("help/$tid.php");
2610 } else {
2611 print "<p>Help topic not found.</p>";
2612 }
2613
2614 print "</div>";
2615
2616 print "<div align='center'>
2617 <input type='submit' class='button'
2618 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2619
2620 if (!$_GET["noheaders"]) {
2621 print "</body></html>";
2622 }
2623
2624 }
2625
2626 if ($op == "dlg") {
2627 $id = $_GET["id"];
2628 $param = $_GET["param"];
2629
2630 if ($id == "quickAddFeed") {
2631
2632 print "<div id=\"infoBoxTitle\">Subscribe to feed</div>";
2633 print "<div class=\"infoBoxContents\">";
2634
2635 print "<table width='100%'>
2636 <tr><td>Feed URL:</td><td>
2637 <input onblur=\"javascript:enableHotkeys()\"
2638 onkeyup=\"toggleSubmitNotEmpty(this, 'fadd_submit_btn')\"
2639 onfocus=\"javascript:disableHotkeys()\" id=\"qafInput\"></td></tr>";
2640
2641 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2642 print "<tr><td>Category:</td><td>";
2643
2644 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
2645 WHERE owner_uid = ".$_SESSION["uid"]."
2646 ORDER BY title");
2647
2648 print "<select id=\"qafCat\">";
2649 print "<option id=\"0\">Uncategorized</option>";
2650
2651 if (db_num_rows($result) != 0) {
2652
2653 print "<option disabled>--------</option>";
2654
2655 while ($line = db_fetch_assoc($result)) {
2656 printf("<option id='%d'>%s</option>",
2657 $line["id"], $line["title"]);
2658 }
2659 }
2660
2661 print "</select>";
2662 print "</td></tr>";
2663 }
2664
2665 print "<tr><td colspan='2' align='right'>
2666 <input class=\"button\"
2667 id=\"fadd_submit_btn\" disabled=\"true\"
2668 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Subscribe\">
2669 <input class=\"button\"
2670 type=\"submit\" onclick=\"javascript:feedEditCancel()\"
2671 value=\"Cancel\"></td></tr></table>";
2672
2673 }
2674
2675 if ($id == "quickDelFeed") {
2676
2677 $param = db_escape_string($param);
2678
2679 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
2680
2681 if ($result) {
2682
2683 $f_title = db_fetch_result($result, 0, "title");
2684
2685 print "Remove current feed (<b>$f_title</b>)?&nbsp;
2686 <input class=\"button\"
2687 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
2688 <input class=\"button\"
2689 type=\"submit\" onclick=\"javascript:closeInfoBox()\"
2690 value=\"Cancel\">";
2691 } else {
2692 print "Error: Feed $param not found.&nbsp;
2693 <input class=\"button\"
2694 type=\"submit\" onclick=\"javascript:closeInfoBox()\"
2695 value=\"Cancel\">";
2696 }
2697 }
2698
2699 if ($id == "search") {
2700
2701 print "<div id=\"infoBoxTitle\">Search</div>";
2702 print "<div class=\"infoBoxContents\">";
2703
2704 $active_feed_id = db_escape_string($_GET["param"]);
2705
2706 print "<table width='100%'><tr><td>Search:</td><td>";
2707
2708 print "<input id=\"searchbox\" class=\"extSearch\"
2709 onblur=\"javascript:enableHotkeys()\"
2710 onfocus=\"javascript:disableHotkeys()\"
2711 onkeyup=\"toggleSubmitNotEmpty(this, 'search_submit_btn')\"
2712 onchange=\"javascript:search()\">
2713 </td></tr><tr><td>Where:</td><td>
2714 <select id=\"searchmodebox\">
2715 <option selected>All feeds</option>";
2716
2717 if ($active_feed_id) {
2718 print "<option>This feed</option>";
2719 } else {
2720 print "<option disabled>This feed</option>";
2721 }
2722
2723 if (get_pref($link, 'ENABLE_FEED_CATS')) {
2724 print "<option>This category</option>";
2725 }
2726
2727 print "</select></td></tr>
2728
2729 <tr><td colspan='2' align='right'>
2730 <input type=\"submit\"
2731 class=\"button\" onclick=\"javascript:search()\"
2732 id=\"search_submit_btn\" disabled=\"true\"
2733 value=\"Search\">
2734 <input class=\"button\"
2735 type=\"submit\" onclick=\"javascript:closeInfoBox()\"
2736 value=\"Cancel\"></td></tr></table>";
2737
2738 }
2739
2740 if ($id == "quickAddFilter") {
2741
2742 print "<div id=\"infoBoxTitle\">Create filter</div>";
2743 print "<div class=\"infoBoxContents\">";
2744
2745 print "<form id=\"filter_add_form\">";
2746
2747 print "<input type=\"hidden\" name=\"op\" value=\"pref-filters\">";
2748 print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
2749 print "<input type=\"hidden\" name=\"subop\" value=\"add\">";
2750
2751 // print "<div class=\"notice\"><b>Note:</b> filter will only apply to new articles.</div>";
2752
2753 $result = db_query($link, "SELECT id,description
2754 FROM ttrss_filter_types ORDER BY description");
2755
2756 $filter_types = array();
2757
2758 while ($line = db_fetch_assoc($result)) {
2759 //array_push($filter_types, $line["description"]);
2760 $filter_types[$line["id"]] = $line["description"];
2761 }
2762
2763 print "<table width='100%'>";
2764
2765 print "<tr><td>Match:</td>
2766 <td><input onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
2767 name=\"reg_exp\" size=\"30\">&nbsp;";
2768
2769 print_select_hash("match_id", 1, $filter_types);
2770
2771 print "</td></tr>";
2772 print "<tr><td>Feed:</td><td>";
2773
2774 print_feed_select($link, "feed_id");
2775
2776 print "</td></tr>";
2777
2778 print "<tr><td>Action:</td>";
2779
2780 print "<td><select name=\"action_id\">";
2781
2782 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2783 ORDER BY name");
2784
2785 while ($line = db_fetch_assoc($result)) {
2786 printf("<option value='%d'>%s</option>", $line["id"], $line["description"]);
2787 }
2788
2789 print "</select>";
2790
2791 print "</td></tr></table>";
2792
2793 print "</form>";
2794
2795 print "<div align='right'>";
2796
2797 print "<input type=\"submit\"
2798 id=\"infobox_submit\"
2799 class=\"button\" onclick=\"qaddFilter()\"
2800 disabled=\"true\" value=\"Create\"> ";
2801
2802 print "<input class=\"button\"
2803 type=\"submit\" onclick=\"closeInfoBox()\"
2804 value=\"Cancel\">";
2805
2806 print "</div>";
2807
2808 // print "</td></tr></table>";
2809
2810 }
2811
2812 print "</div>";
2813
2814 }
2815
2816 // update feeds of all users, may be used anonymously
2817 if ($op == "globalUpdateFeeds") {
2818
2819 $result = db_query($link, "SELECT id FROM ttrss_users");
2820
2821 while ($line = db_fetch_assoc($result)) {
2822 $user_id = $line["id"];
2823 // print "<!-- updating feeds of uid $user_id -->";
2824 update_all_feeds($link, false, $user_id);
2825 }
2826
2827 print "<rpc-reply>
2828 <message msg=\"All feeds updated\"/>
2829 </rpc-reply>";
2830
2831 }
2832
2833 if ($op == "pref-prefs") {
2834
2835 $subop = $_REQUEST["subop"];
2836
2837 if ($subop == "Save configuration") {
2838
2839 if (WEB_DEMO_MODE) {
2840 header("Location: prefs.php");
2841 return;
2842 }
2843
2844 $_SESSION["prefs_op_result"] = "save-config";
2845
2846 $_SESSION["prefs_cache"] = false;
2847
2848 foreach (array_keys($_POST) as $pref_name) {
2849
2850 $pref_name = db_escape_string($pref_name);
2851 $value = db_escape_string($_POST[$pref_name]);
2852
2853 $result = db_query($link, "SELECT type_name
2854 FROM ttrss_prefs,ttrss_prefs_types
2855 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
2856
2857 if (db_num_rows($result) > 0) {
2858
2859 $type_name = db_fetch_result($result, 0, "type_name");
2860
2861 // print "$pref_name : $type_name : $value<br>";
2862
2863 if ($type_name == "bool") {
2864 if ($value == "1") {
2865 $value = "true";
2866 } else {
2867 $value = "false";
2868 }
2869 } else if ($type_name == "integer") {
2870 $value = sprintf("%d", $value);
2871 }
2872
2873 // print "$pref_name : $type_name : $value<br>";
2874
2875 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
2876 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
2877
2878 }
2879
2880 header("Location: prefs.php");
2881
2882 }
2883
2884 } else if ($subop == "getHelp") {
2885
2886 $pref_name = db_escape_string($_GET["pn"]);
2887
2888 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
2889 WHERE pref_name = '$pref_name'");
2890
2891 if (db_num_rows($result) > 0) {
2892 $help_text = db_fetch_result($result, 0, "help_text");
2893 print $help_text;
2894 } else {
2895 print "Unknown option: $pref_name";
2896 }
2897
2898 } else if ($subop == "Change e-mail") {
2899
2900 if (WEB_DEMO_MODE) {
2901 header("Location: prefs.php");
2902 return;
2903 }
2904
2905 $email = db_escape_string($_GET["email"]);
2906 $active_uid = $_SESSION["uid"];
2907
2908 if ($email) {
2909 db_query($link, "UPDATE ttrss_users SET email = '$email'
2910 WHERE id = '$active_uid'");
2911 }
2912
2913 header("Location: prefs.php");
2914
2915 } else if ($subop == "Change password") {
2916
2917 if (WEB_DEMO_MODE) {
2918 header("Location: prefs.php");
2919 return;
2920 }
2921
2922 $old_pw = $_POST["OLD_PASSWORD"];
2923 $new_pw = $_POST["OLD_PASSWORD"];
2924
2925 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
2926 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
2927
2928 $active_uid = $_SESSION["uid"];
2929
2930 if ($old_pw && $new_pw) {
2931
2932 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
2933
2934 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
2935 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
2936 pwd_hash = '$old_pw_hash')");
2937
2938 if (db_num_rows($result) == 1) {
2939 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
2940 WHERE id = '$active_uid'");
2941
2942 $_SESSION["pwd_change_result"] = "ok";
2943 } else {
2944 $_SESSION["pwd_change_result"] = "failed";
2945 }
2946 }
2947
2948 header("Location: prefs.php");
2949
2950 } else if ($subop == "Reset to defaults") {
2951
2952 if (WEB_DEMO_MODE) {
2953 header("Location: prefs.php");
2954 return;
2955 }
2956
2957 $_SESSION["prefs_op_result"] = "reset-to-defaults";
2958
2959 if (DB_TYPE == "pgsql") {
2960 db_query($link,"UPDATE ttrss_user_prefs
2961 SET value = ttrss_prefs.def_value
2962 WHERE owner_uid = '".$_SESSION["uid"]."' AND
2963 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
2964 } else {
2965 db_query($link, "DELETE FROM ttrss_user_prefs
2966 WHERE owner_uid = ".$_SESSION["uid"]);
2967 initialize_user_prefs($link, $_SESSION["uid"]);
2968 }
2969
2970 header("Location: prefs.php");
2971
2972 } else if ($subop == "Change theme") {
2973
2974 $theme = db_escape_string($_POST["theme"]);
2975
2976 if ($theme == "Default") {
2977 $theme_qpart = 'NULL';
2978 } else {
2979 $theme_qpart = "'$theme'";
2980 }
2981
2982 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
2983 WHERE theme_name = '$theme'");
2984
2985 if (db_num_rows($result) == 1) {
2986 $theme_id = db_fetch_result($result, 0, "id");
2987 $theme_path = db_fetch_result($result, 0, "theme_path");
2988 } else {
2989 $theme_id = "NULL";
2990 $theme_path = "";
2991 }
2992
2993 db_query($link, "UPDATE ttrss_users SET
2994 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
2995
2996 $_SESSION["theme"] = $theme_path;
2997
2998 header("Location: prefs.php");
2999
3000 } else {
3001
3002 if (!SINGLE_USER_MODE) {
3003
3004 $result = db_query($link, "SELECT id,email FROM ttrss_users
3005 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
3006 pwd_hash = 'SHA1:".sha1("password")."')");
3007
3008 if (db_num_rows($result) != 0) {
3009 print "<div class=\"warning\">
3010 Your password is at default value, please change it.
3011 </div>";
3012 }
3013
3014 if ($_SESSION["pwd_change_result"] == "failed") {
3015 print "<div class=\"warning\">
3016 There was an error while changing your password.
3017 </div>";
3018 }
3019
3020 if ($_SESSION["pwd_change_result"] == "ok") {
3021 print "<div class=\"notice\">
3022 Password changed successfully.
3023 </div>";
3024 }
3025
3026 $_SESSION["pwd_change_result"] = "";
3027
3028 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
3029 print "<div class=\"notice\">
3030 Your configuration was reset to defaults.
3031 </div>";
3032 }
3033
3034 if ($_SESSION["prefs_op_result"] == "save-config") {
3035 print "<div class=\"notice\">
3036 Your configuration was saved successfully.
3037 </div>";
3038 }
3039
3040 $_SESSION["prefs_op_result"] = "";
3041
3042 print "<form action=\"backend.php\" method=\"GET\">";
3043
3044 print "<table width=\"100%\" class=\"prefPrefsList\">";
3045 print "<tr><td colspan='3'><h3>Personal data</h3></tr></td>";
3046
3047 $result = db_query($link, "SELECT email FROM ttrss_users
3048 WHERE id = ".$_SESSION["uid"]);
3049
3050 $email = db_fetch_result($result, 0, "email");
3051
3052 print "<tr><td width=\"40%\">E-mail</td>";
3053 print "<td><input class=\"editbox\" name=\"email\"
3054 value=\"$email\"></td></tr>";
3055
3056 print "</table>";
3057
3058 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3059
3060 print "<p><input class=\"button\" type=\"submit\"
3061 value=\"Change e-mail\" name=\"subop\">";
3062
3063 print "</form>";
3064
3065 print "<form action=\"backend.php\" method=\"POST\" name=\"changePassForm\">";
3066
3067 print "<table width=\"100%\" class=\"prefPrefsList\">";
3068 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
3069
3070 print "<tr><td width=\"40%\">Old password</td>";
3071 print "<td><input class=\"editbox\" type=\"password\"
3072 name=\"OLD_PASSWORD\"></td></tr>";
3073
3074 print "<tr><td width=\"40%\">New password</td>";
3075
3076 print "<td><input class=\"editbox\" type=\"password\"
3077 name=\"NEW_PASSWORD\"></td></tr>";
3078
3079 print "</table>";
3080
3081 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3082
3083 print "<p><input class=\"button\" type=\"submit\"
3084 onclick=\"return validateNewPassword(this.form)\"
3085 value=\"Change password\" name=\"subop\">";
3086
3087 print "</form>";
3088
3089 }
3090
3091 $result = db_query($link, "SELECT
3092 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
3093
3094 $user_theme_id = db_fetch_result($result, 0, "theme_id");
3095
3096 $result = db_query($link, "SELECT
3097 id,theme_name FROM ttrss_themes ORDER BY theme_name");
3098
3099 if (db_num_rows($result) > 0) {
3100
3101 print "<form action=\"backend.php\" method=\"POST\">";
3102 print "<table width=\"100%\" class=\"prefPrefsList\">";
3103 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
3104 print "<tr><td width=\"40%\">Select theme</td>";
3105 print "<td><select name=\"theme\">";
3106 print "<option>Default</option>";
3107 print "<option disabled>--------</option>";
3108
3109 while ($line = db_fetch_assoc($result)) {
3110 if ($line["id"] == $user_theme_id) {
3111 $selected = "selected";
3112 } else {
3113 $selected = "";
3114 }
3115 print "<option $selected>" . $line["theme_name"] . "</option>";
3116 }
3117 print "</select></td></tr>";
3118 print "</table>";
3119 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3120 print "<p><input class=\"button\" type=\"submit\"
3121 value=\"Change theme\" name=\"subop\">";
3122 print "</form>";
3123 }
3124
3125 $result = db_query($link, "SELECT
3126 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
3127 section_name,def_value
3128 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
3129 WHERE type_id = ttrss_prefs_types.id AND
3130 section_id = ttrss_prefs_sections.id AND
3131 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
3132 owner_uid = ".$_SESSION["uid"]."
3133 ORDER BY section_id,short_desc");
3134
3135 print "<form action=\"backend.php\" method=\"POST\">";
3136
3137 $lnum = 0;
3138
3139 $active_section = "";
3140
3141 while ($line = db_fetch_assoc($result)) {
3142
3143 if ($active_section != $line["section_name"]) {
3144
3145 if ($active_section != "") {
3146 print "</table>";
3147 }
3148
3149 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
3150
3151 $active_section = $line["section_name"];
3152
3153 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
3154 // print "<tr class=\"title\">
3155 // <td width=\"25%\">Option</td><td>Value</td></tr>";
3156
3157 $lnum = 0;
3158 }
3159
3160 // $class = ($lnum % 2) ? "even" : "odd";
3161
3162 print "<tr>";
3163
3164 $type_name = $line["type_name"];
3165 $pref_name = $line["pref_name"];
3166 $value = $line["value"];
3167 $def_value = $line["def_value"];
3168 $help_text = $line["help_text"];
3169
3170 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
3171
3172 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
3173
3174 print "</td>";
3175
3176 print "<td>";
3177
3178 if ($type_name == "bool") {
3179 // print_select($pref_name, $value, array("true", "false"));
3180
3181 if ($value == "true") {
3182 $value = "Yes";
3183 } else {
3184 $value = "No";
3185 }
3186
3187 print_radio($pref_name, $value, array("Yes", "No"));
3188
3189 } else {
3190 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
3191 }
3192
3193 print "</td>";
3194
3195 print "</tr>";
3196
3197 $lnum++;
3198 }
3199
3200 print "</table>";
3201
3202 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3203
3204 print "<p><input class=\"button\" type=\"submit\"
3205 name=\"subop\" value=\"Save configuration\">";
3206
3207 print "&nbsp;<input class=\"button\" type=\"submit\"
3208 name=\"subop\" onclick=\"return validatePrefsReset()\"
3209 value=\"Reset to defaults\"></p>";
3210
3211 print "</form>";
3212
3213 }
3214
3215 }
3216
3217 if ($op == "pref-users") {
3218
3219 $subop = $_GET["subop"];
3220
3221 if ($subop == "editSave") {
3222
3223 if (!WEB_DEMO_MODE) {
3224
3225 $login = db_escape_string($_GET["l"]);
3226 $uid = db_escape_string($_GET["id"]);
3227 $access_level = sprintf("%d", $_GET["al"]);
3228 $email = db_escape_string($_GET["e"]);
3229
3230 db_query($link, "UPDATE ttrss_users SET login = '$login',
3231 access_level = '$access_level', email = '$email' WHERE id = '$uid'");
3232
3233 }
3234 } else if ($subop == "remove") {
3235
3236 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3237
3238 $ids = split(",", db_escape_string($_GET["ids"]));
3239
3240 foreach ($ids as $id) {
3241 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
3242
3243 }
3244 }
3245 } else if ($subop == "add") {
3246
3247 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3248
3249 $login = db_escape_string(trim($_GET["login"]));
3250 $tmp_user_pwd = make_password(8);
3251 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3252
3253 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3254 login = '$login'");
3255
3256 if (db_num_rows($result) == 0) {
3257
3258 db_query($link, "INSERT INTO ttrss_users
3259 (login,pwd_hash,access_level,last_login)
3260 VALUES ('$login', '$pwd_hash', 0, NOW())");
3261
3262
3263 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3264 login = '$login' AND pwd_hash = '$pwd_hash'");
3265
3266 if (db_num_rows($result) == 1) {
3267
3268 $new_uid = db_fetch_result($result, 0, "id");
3269
3270 print "<div class=\"notice\">Added user <b>".$_GET["login"].
3271 "</b> with password <b>$tmp_user_pwd</b>.</div>";
3272
3273 initialize_user($link, $new_uid);
3274
3275 } else {
3276
3277 print "<div class=\"warning\">Could not create user <b>".
3278 $_GET["login"]."</b></div>";
3279
3280 }
3281 } else {
3282 print "<div class=\"warning\">User <b>".
3283 $_GET["login"]."</b> already exists.</div>";
3284 }
3285 }
3286 } else if ($subop == "resetPass") {
3287
3288 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3289
3290 $uid = db_escape_string($_GET["id"]);
3291
3292 $result = db_query($link, "SELECT login,email
3293 FROM ttrss_users WHERE id = '$uid'");
3294
3295 $login = db_fetch_result($result, 0, "login");
3296 $email = db_fetch_result($result, 0, "email");
3297 $tmp_user_pwd = make_password(8);
3298 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3299
3300 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
3301 WHERE id = '$uid'");
3302
3303 print "<div class=\"notice\">Changed password of
3304 user <b>$login</b> to <b>$tmp_user_pwd</b>.";
3305
3306 if (MAIL_RESET_PASS && $email) {
3307 print " Notifying <b>$email</b>.";
3308
3309 mail("$login <$email>", "Password reset notification",
3310 "Hi, $login.\n".
3311 "\n".
3312 "Your password for this TT-RSS installation was reset by".
3313 " an administrator.\n".
3314 "\n".
3315 "Your new password is $tmp_user_pwd, please remember".
3316 " it for later reference.\n".
3317 "\n".
3318 "Sincerely, TT-RSS Mail Daemon.", "From: " . MAIL_FROM);
3319 }
3320
3321 print "</div>";
3322
3323 }
3324 }
3325
3326 print "<div class=\"prefGenericAddBox\">
3327 <input id=\"uadd_box\"
3328 onkeyup=\"toggleSubmitNotEmpty(this, 'user_add_btn')\"
3329 size=\"40\">&nbsp;";
3330
3331 print"<input type=\"submit\" class=\"button\"
3332 id=\"user_add_btn\" disabled=\"true\"
3333 onclick=\"javascript:addUser()\" value=\"Create user\"></div>";
3334
3335 $result = db_query($link, "SELECT
3336 id,login,access_level,email,
3337 SUBSTRING(last_login,1,16) as last_login
3338 FROM
3339 ttrss_users
3340 ORDER by login");
3341
3342 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
3343
3344 print "<p><table width=\"100%\" cellspacing=\"0\"
3345 class=\"prefUserList\" id=\"prefUserList\">";
3346
3347 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
3348 Select:
3349 <a href=\"javascript:selectPrefRows('user', true)\">All</a>,
3350 <a href=\"javascript:selectPrefRows('user', false)\">None</a>
3351 </td</tr>";
3352
3353 print "<tr class=\"title\">
3354 <td align='center' width=\"5%\">&nbsp;</td>
3355 <td width='20%'>Login</td>
3356 <td width='20%'>E-mail</td>
3357 <td width='20%'>Access Level</td>
3358 <td width='20%'>Last login</td></tr>";
3359
3360 $lnum = 0;
3361
3362 while ($line = db_fetch_assoc($result)) {
3363
3364 $class = ($lnum % 2) ? "even" : "odd";
3365
3366 $uid = $line["id"];
3367 $edit_uid = $_GET["id"];
3368
3369 if ($subop == "edit" && $uid != $edit_uid) {
3370 $class .= "Grayed";
3371 $this_row_id = "";
3372 } else {
3373 $this_row_id = "id=\"UMRR-$uid\"";
3374 }
3375
3376 print "<tr class=\"$class\" $this_row_id>";
3377
3378 $line["login"] = htmlspecialchars($line["login"]);
3379
3380 $line["last_login"] = date(get_pref($link, 'SHORT_DATE_FORMAT'),
3381 strtotime($line["last_login"]));
3382
3383 $access_level_names = array(0 => "User", 10 => "Administrator");
3384
3385 if (!$edit_uid || $subop != "edit") {
3386
3387 print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"user\");'
3388 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
3389
3390 print "<td><a href=\"javascript:editUser($uid);\">" .
3391 $line["login"] . "</td>";
3392
3393 if (!$line["email"]) $line["email"] = "&nbsp;";
3394
3395 print "<td><a href=\"javascript:editUser($uid);\">" .
3396 $line["email"] . "</td>";
3397
3398 print "<td><a href=\"javascript:editUser($uid);\">" .
3399 $access_level_names[$line["access_level"]] . "</td>";
3400
3401 } else if ($uid != $edit_uid) {
3402
3403 if (!$line["email"]) $line["email"] = "&nbsp;";
3404
3405 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
3406 id=\"UMCHK-".$line["id"]."\"></td>";
3407
3408 print "<td>".$line["login"]."</td>";
3409 print "<td>".$line["email"]."</td>";
3410 print "<td>".$access_level_names[$line["access_level"]]."</td>";
3411
3412 } else {
3413
3414 print "<td align='center'>
3415 <input disabled=\"true\" type=\"checkbox\" checked></td>";
3416
3417 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
3418 "\"></td>";
3419
3420 print "<td><input id=\"iedit_email\" value=\"".$line["email"].
3421 "\"></td>";
3422
3423 print "<td>";
3424 print "<select id=\"iedit_ulevel\">";
3425 foreach (array_keys($access_level_names) as $al) {
3426 if ($al == $line["access_level"]) {
3427 $selected = "selected";
3428 } else {
3429 $selected = "";
3430 }
3431 print "<option $selected id=\"$al\">" .
3432 $access_level_names[$al] . "</option>";
3433 }
3434 print "</select>";
3435 print "</td>";
3436
3437 }
3438
3439 print "<td>".$line["last_login"]."</td>";
3440
3441 print "</tr>";
3442
3443 ++$lnum;
3444 }
3445
3446 print "</table>";
3447
3448 print "<p id='userOpToolbar'>";
3449
3450 if ($subop == "edit") {
3451 print "Edit user:
3452 <input type=\"submit\" class=\"button\"
3453 onclick=\"javascript:userEditSave()\" value=\"Save\">
3454 <input type=\"submit\" class=\"button\"
3455 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">";
3456
3457 } else {
3458
3459 print "
3460 Selection:
3461 <input type=\"submit\" class=\"button\" disabled=\"true\"
3462 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
3463 <input type=\"submit\" class=\"button\" disabled=\"true\"
3464 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
3465 <input type=\"submit\" class=\"button\" disabled=\"true\"
3466 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
3467 <input type=\"submit\" class=\"button\" disabled=\"true\"
3468 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
3469
3470 }
3471 }
3472
3473 if ($op == "user-details") {
3474
3475 if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
3476 return;
3477 }
3478
3479 /* print "<html><head>
3480 <title>Tiny Tiny RSS : User Details</title>
3481 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
3482 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
3483 </head><body>"; */
3484
3485 $uid = sprintf("%d", $_GET["id"]);
3486
3487 print "<div id=\"infoBoxTitle\">User details</div>";
3488
3489 print "<div class='infoBoxContents'>";
3490
3491 $result = db_query($link, "SELECT login,
3492 SUBSTRING(last_login,1,16) AS last_login,
3493 access_level,
3494 (SELECT COUNT(int_id) FROM ttrss_user_entries
3495 WHERE owner_uid = id) AS stored_articles
3496 FROM ttrss_users
3497 WHERE id = '$uid'");
3498
3499 if (db_num_rows($result) == 0) {
3500 print "<h1>User not found</h1>";
3501 return;
3502 }
3503
3504 # print "<h1>User Details</h1>";
3505
3506 $login = db_fetch_result($result, 0, "login");
3507
3508 # print "<h1>$login</h1>";
3509
3510 print "<table width='100%'>";
3511
3512 $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'),
3513 strtotime(db_fetch_result($result, 0, "last_login")));
3514 $access_level = db_fetch_result($result, 0, "access_level");
3515 $stored_articles = db_fetch_result($result, 0, "stored_articles");
3516
3517 # print "<tr><td>Username</td><td>$login</td></tr>";
3518 # print "<tr><td>Access level</td><td>$access_level</td></tr>";
3519 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
3520 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
3521
3522 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
3523 WHERE owner_uid = '$uid'");
3524
3525 $num_feeds = db_fetch_result($result, 0, "num_feeds");
3526
3527 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
3528
3529 /* $result = db_query($link, "SELECT
3530 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
3531 FROM ttrss_user_entries,ttrss_entries
3532 WHERE owner_uid = '$uid' AND ref_id = id");
3533
3534 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
3535
3536 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
3537
3538 print "</table>";
3539
3540 print "<h1>Subscribed feeds</h1>";
3541
3542 $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
3543 WHERE owner_uid = '$uid' ORDER BY title");
3544
3545 print "<ul class=\"userFeedList\">";
3546
3547 $row_class = "odd";
3548
3549 while ($line = db_fetch_assoc($result)) {
3550
3551 $icon_file = ICONS_URL."/".$line["id"].".ico";
3552
3553 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3554 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
3555 } else {
3556 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3557 }
3558
3559 print "<li class=\"$row_class\">$feed_icon&nbsp;<a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
3560
3561 $row_class = toggleEvenOdd($row_class);
3562
3563 }
3564
3565 if (db_num_rows($result) < $num_feeds) {
3566 // FIXME - add link to show ALL subscribed feeds here somewhere
3567 print "<li><img
3568 class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">&nbsp;...</li>";
3569 }
3570
3571 print "</ul>";
3572
3573 print "</div>";
3574
3575 print "<div align='center'>
3576 <input type='submit' class='button'
3577 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
3578
3579 // print "</body></html>";
3580
3581 }
3582
3583 if ($op == "pref-feed-browser") {
3584
3585 if (!ENABLE_FEED_BROWSER) {
3586 print "Feed browser is administratively disabled.";
3587 return;
3588 }
3589
3590 $subop = $_REQUEST["subop"];
3591
3592 if ($subop == "details") {
3593 $id = db_escape_string($_GET["id"]);
3594
3595 print "<div class=\"browserFeedInfo\">";
3596 print "<b>Feed information:</b>";
3597 print "<div class=\"detailsPart\">";
3598
3599 $result = db_query($link, "SELECT
3600 feed_url,site_url,
3601 SUBSTRING(last_updated,1,19) AS last_updated
3602 FROM ttrss_feeds WHERE id = '$id'");
3603
3604 $feed_url = db_fetch_result($result, 0, "feed_url");
3605 $site_url = db_fetch_result($result, 0, "site_url");
3606 $last_updated = db_fetch_result($result, 0, "last_updated");
3607
3608 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
3609 $last_updated = smart_date_time(strtotime($last_updated));
3610 } else {
3611 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
3612 $last_updated = date($short_date, strtotime($last_updated));
3613 }
3614
3615 print "Site: <a href='$site_url'>$site_url</a> ".
3616 "(<a href='$feed_url'>feed</a>), ".
3617 "Last updated: $last_updated";
3618
3619 print "</div>";
3620
3621 $result = db_query($link, "SELECT
3622 ttrss_entries.title,
3623 content,
3624 substring(date_entered,1,19) as date_entered,
3625 substring(updated,1,19) as updated
3626 FROM ttrss_entries,ttrss_user_entries
3627 WHERE ttrss_entries.id = ref_id AND feed_id = '$id'
3628 ORDER BY updated DESC LIMIT 5");
3629
3630 if (db_num_rows($result) > 0) {
3631
3632 print "<b>Last headlines:</b><br>";
3633
3634 print "<div class=\"detailsPart\">";
3635 print "<ul class=\"compact\">";
3636 while ($line = db_fetch_assoc($result)) {
3637
3638 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
3639 $entry_dt = smart_date_time(strtotime($line["updated"]));
3640 } else {
3641 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
3642 $entry_dt = date($short_date, strtotime($line["updated"]));
3643 }
3644
3645 print "<li>" . $line["title"] .
3646 "&nbsp;<span class=\"insensitive\">($entry_dt)</span></li>";
3647 }
3648 print "</ul></div>";
3649 }
3650
3651 print "</div>";
3652
3653 return;
3654 }
3655
3656 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>";
3657
3658 $limit = db_escape_string($_GET["limit"]);
3659
3660 if (!$limit) $limit = 25;
3661
3662 $result = db_query($link, "SELECT feed_url,count(id) AS subscribers
3663 FROM ttrss_feeds
3664 WHERE auth_login = '' AND auth_pass = '' AND private = false
3665 GROUP BY feed_url ORDER BY subscribers DESC LIMIT $limit");
3666
3667 print "<div style=\"float : right\">
3668 Top <select id=\"feedBrowserLimit\">";
3669
3670 foreach (array(25, 50, 100) as $l) {
3671 $issel = ($l == $limit) ? "selected" : "";
3672 print "<option $issel>$l</option>";
3673 }
3674
3675 print "</select>
3676 <input type=\"submit\" class=\"button\"
3677 onclick=\"updateBigFeedBrowser()\" value=\"Show\">
3678 </div>";
3679
3680 print "<p id=\"fbrOpToolbar\">Selection:
3681 <input type='submit' class='button' onclick=\"feedBrowserSubscribe()\"
3682 disabled=\"true\" value=\"Subscribe\">";
3683
3684 print "<ul class='nomarks' id='browseBigFeedList'>";
3685
3686 $feedctr = 0;
3687
3688 while ($line = db_fetch_assoc($result)) {
3689 $feed_url = $line["feed_url"];
3690 $subscribers = $line["subscribers"];
3691
3692 $sub_result = db_query($link, "SELECT id
3693 FROM ttrss_feeds WHERE feed_url = '$feed_url' AND owner_uid =" .
3694 $_SESSION["uid"]);
3695
3696 if (db_num_rows($sub_result) > 0) {
3697 continue; // already subscribed
3698 }
3699
3700 $det_result = db_query($link, "SELECT site_url,title,id
3701 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
3702
3703 $details = db_fetch_assoc($det_result);
3704
3705 $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
3706
3707 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3708 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
3709 "/".$details["id"].".ico\">";
3710 } else {
3711 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3712 }
3713
3714 $check_box = "<input onclick='toggleSelectFBListRow(this)' class='feedBrowseCB'
3715 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
3716
3717 $class = ($feedctr % 2) ? "even" : "odd";
3718
3719 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
3720 "$feed_icon ";
3721
3722 print "<a href=\"javascript:browserToggleExpand('".$details["id"]."')\">" .
3723 $details["title"] ."</a>&nbsp;" .
3724 "<span class='subscribers'>($subscribers)</span>";
3725
3726 print "<div class=\"browserDetails\" id=\"BRDET-" . $details["id"] . "\">";
3727 print "</div>";
3728
3729 print "</li>";
3730
3731 ++$feedctr;
3732 }
3733
3734 if ($feedctr == 0) {
3735 print "<li>No feeds found to subscribe.</li>";
3736 }
3737
3738 print "</ul>";
3739
3740 print "</div>";
3741
3742 }
3743
3744 function check_configuration_variables() {
3745 if (!defined('SESSION_EXPIRE_TIME')) {
3746 return "config: SESSION_EXPIRE_TIME is undefined";
3747 }
3748
3749 if (SESSION_EXPIRE_TIME < 60) {
3750 return "config: SESSION_EXPIRE_TIME is too low (less than 60)";
3751 }
3752
3753 if (SESSION_EXPIRE_TIME < SESSION_COOKIE_LIFETIME_REMEMBER) {
3754 return "config: SESSION_EXPIRE_TIME should be greater or equal to" .
3755 "SESSION_COOKIE_LIFETIME_REMEMBER";
3756 }
3757
3758 if (defined('DISABLE_SESSIONS')) {
3759 return "config: you have enabled DISABLE_SESSIONS. Please disable this option.";
3760 }
3761
3762 if (DATABASE_BACKED_SESSIONS && SINGLE_USER_MODE) {
3763 return "config: DATABASE_BACKED_SESSIONS is incompatible with SINGLE_USER_MODE";
3764 }
3765
3766 return false;
3767 }
3768
3769 db_close($link);
3770 ?>
3771
3772 <!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
3773