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