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