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