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