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