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