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