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