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