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