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