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