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