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