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