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