]> git.wh0rd.org - tt-rss.git/blob - backend.php
add persistent storage for toolbar view options, bump schema
[tt-rss.git] / backend.php
1 <?php
2 error_reporting(E_ERROR | E_WARNING | E_PARSE);
3
4 require_once "sessions.php";
5 require_once "modules/backend-rpc.php";
6
7 /* if ($_GET["debug"]) {
8 define('DEFAULT_ERROR_LEVEL', E_ALL);
9 } else {
10 define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE);
11 }
12
13 error_reporting(DEFAULT_ERROR_LEVEL); */
14
15 define('SCHEMA_VERSION', 15);
16
17 require_once "sanity_check.php";
18 require_once "config.php";
19
20 require_once "db.php";
21 require_once "db-prefs.php";
22 require_once "functions.php";
23
24 no_cache_incantation();
25 startup_gettext();
26
27 $script_started = getmicrotime();
28
29 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
30
31 if (!$link) {
32 if (DB_TYPE == "mysql") {
33 print mysql_error();
34 }
35 // PG seems to display its own errors just fine by default.
36 return;
37 }
38
39 if (DB_TYPE == "pgsql") {
40 pg_query("set client_encoding = 'UTF-8'");
41 pg_set_client_encoding("UNICODE");
42 }
43
44 $op = $_REQUEST["op"];
45
46 $print_exec_time = false;
47
48 if ((!$op || $op == "rpc" || $op == "rss" || $op == "digestSend" ||
49 $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
50 header("Content-Type: application/xml; charset=utf-8");
51 } else {
52 header("Content-Type: text/html; charset=utf-8");
53 }
54
55 if (!$op) {
56 header("Content-Type: application/xml");
57 print_error_xml(7); exit;
58 }
59
60 if (!($_SESSION["uid"] && validate_session($link)) && $op != "globalUpdateFeeds"
61 && $op != "rss" && $op != "getUnread") {
62
63 if ($op == "rpc") {
64 print_error_xml(6); die;
65 } else {
66 print "
67 <html><body>
68 <p>Error: Not logged in.</p>
69 <script type=\"text/javascript\">
70 if (parent.window != 'undefined') {
71 parent.window.location = \"tt-rss.php\";
72 } else {
73 window.location = \"tt-rss.php\";
74 }
75 </script>
76 </body></html>
77 ";
78 }
79 exit;
80 }
81
82 $purge_intervals = array(
83 0 => __("Use default"),
84 -1 => __("Never purge"),
85 5 => __("1 week old"),
86 14 => __("2 weeks old"),
87 31 => __("1 month old"),
88 60 => __("2 months old"),
89 90 => __("3 months old"));
90
91 $update_intervals = array(
92 0 => __("Use default"),
93 -1 => __("Disable updates"),
94 30 => __("Each 30 minutes"),
95 60 => __("Hourly"),
96 240 => __("Each 4 hours"),
97 720 => __("Each 12 hours"),
98 1440 => __("Daily"),
99 10080 => __("Weekly"));
100
101
102 $access_level_names = array(
103 0 => __("User"),
104 10 => __("Administrator"));
105
106 require_once "modules/pref-prefs.php";
107 require_once "modules/popup-dialog.php";
108 require_once "modules/help.php";
109 require_once "modules/pref-feeds.php";
110 require_once "modules/pref-filters.php";
111 require_once "modules/pref-labels.php";
112 require_once "modules/pref-users.php";
113 require_once "modules/pref-feed-browser.php";
114
115
116 if (!sanity_check($link)) { return; }
117
118 if ($op == "rpc") {
119 handle_rpc_request($link);
120 }
121
122 if ($op == "feeds") {
123
124 $tags = $_GET["tags"];
125
126 $subop = $_GET["subop"];
127
128 if ($subop == "catchupAll") {
129 db_query($link, "UPDATE ttrss_user_entries SET
130 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
131 }
132
133 if ($subop == "collapse") {
134 $cat_id = db_escape_string($_GET["cid"]);
135
136 db_query($link, "UPDATE ttrss_feed_categories SET
137 collapsed = NOT collapsed WHERE id = '$cat_id' AND owner_uid = " .
138 $_SESSION["uid"]);
139 return;
140 }
141
142 outputFeedList($link, $tags);
143
144 }
145
146 if ($op == "view") {
147
148 $id = db_escape_string($_GET["id"]);
149 $feed_id = db_escape_string($_GET["feed"]);
150
151 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
152 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
153
154 if (db_num_rows($result) == 1) {
155 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
156 } else {
157 $rtl_content = false;
158 }
159
160 if ($rtl_content) {
161 $rtl_tag = "dir=\"RTL\"";
162 $rtl_class = "RTL";
163 } else {
164 $rtl_tag = "";
165 $rtl_class = "";
166 }
167
168 $result = db_query($link, "UPDATE ttrss_user_entries
169 SET unread = false,last_read = NOW()
170 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
171
172 $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
173 SUBSTRING(updated,1,16) as updated,
174 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url,
175 num_comments,
176 author
177 FROM ttrss_entries,ttrss_user_entries
178 WHERE id = '$id' AND ref_id = id AND owner_uid = " . $_SESSION["uid"]);
179
180 if ($result) {
181
182 $link_target = "";
183
184 if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
185 $link_target = "target=\"_new\"";
186 }
187
188 $line = db_fetch_assoc($result);
189
190 if ($line["icon_url"]) {
191 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
192 } else {
193 $feed_icon = "&nbsp;";
194 }
195
196 /* if ($line["comments"] && $line["link"] != $line["comments"]) {
197 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
198 } else {
199 $entry_comments = "";
200 } */
201
202 $num_comments = $line["num_comments"];
203 $entry_comments = "";
204
205 if ($num_comments > 0) {
206 if ($line["comments"]) {
207 $comments_url = $line["comments"];
208 } else {
209 $comments_url = $line["link"];
210 }
211 $entry_comments = "<a $link_target href=\"$comments_url\">$num_comments comments</a>";
212 } else {
213 if ($line["comments"] && $line["link"] != $line["comments"]) {
214 $entry_comments = "<a $link_target href=\"".$line["comments"]."\">comments</a>";
215 }
216 }
217
218 print "<div class=\"postReply\">";
219
220 print "<div class=\"postHeader\">";
221
222 $entry_author = $line["author"];
223
224 if ($entry_author) {
225 $entry_author = __(" - by ") . $entry_author;
226 }
227
228 $parsed_updated = date(get_pref($link, 'LONG_DATE_FORMAT'),
229 strtotime($line["updated"]));
230
231 print "<div class=\"postDate$rtl_class\">$parsed_updated</div>";
232
233 if ($line["link"]) {
234 print "<div clear='both'><a $link_target href=\"" . $line["link"] . "\">" .
235 $line["title"] . "</a>$entry_author</div>";
236 } else {
237 print "<div clear='both'>" . $line["title"] . "$entry_author</div>";
238 }
239
240 $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
241 ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
242 ORDER BY tag_name");
243
244 $tags_str = "";
245 $f_tags_str = "";
246
247 $num_tags = 0;
248
249 while ($tmp_line = db_fetch_assoc($tmp_result)) {
250 $num_tags++;
251 $tag = $tmp_line["tag_name"];
252 $tag_str = "<a href=\"javascript:viewfeed('$tag')\">$tag</a>, ";
253
254 if ($num_tags == 6) {
255 $tags_str .= "<a href=\"javascript:showBlockElement('allEntryTags')\">...</a>";
256 } else if ($num_tags < 6) {
257 $tags_str .= $tag_str;
258 }
259 $f_tags_str .= $tag_str;
260 }
261
262 $tags_str = preg_replace("/, $/", "", $tags_str);
263 $f_tags_str = preg_replace("/, $/", "", $f_tags_str);
264
265 if (!$entry_comments) $entry_comments = "&nbsp;"; # placeholder
266
267 if (!$tags_str) $tags_str = '<span class="tagList">'.__('no tags').'</span>';
268
269 print "<div style='float : right'>$tags_str
270 <a title=\"Edit tags for this article\"
271 href=\"javascript:editArticleTags($id, $feed_id)\">(+)</a></div>
272 <div clear='both'>$entry_comments</div>";
273
274 print "</div>";
275
276 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
277 print "<div class=\"postContent\">";
278
279 if (db_num_rows($tmp_result) > 0) {
280 print "<div id=\"allEntryTags\">".__('Tags:')."$f_tags_str</div>";
281 }
282
283 if (get_pref($link, 'OPEN_LINKS_IN_NEW_WINDOW')) {
284 $line["content"] = preg_replace("/href=/i", "target=\"_new\" href=", $line["content"]);
285 }
286
287 $line["content"] = sanitize_rss($line["content"]);
288
289 print $line["content"] . "</div>";
290
291 print "</div>";
292
293 }
294 }
295
296 if ($op == "viewfeed") {
297
298 $feed = db_escape_string($_GET["feed"]);
299 $subop = db_escape_string($_GET["subop"]);
300 $view_mode = db_escape_string($_GET["view_mode"]);
301 $limit = db_escape_string($_GET["limit"]);
302 $cat_view = db_escape_string($_GET["cat"]);
303 $next_unread_feed = db_escape_string($_GET["nuf"]);
304 $offset = db_escape_string($_GET["skip"]);
305
306 if (!$offset) $offset = 0;
307
308 set_pref($link, "_DEFAULT_VIEW_MODE", $view_mode);
309 set_pref($link, "_DEFAULT_VIEW_LIMIT", $limit);
310
311 if ($subop == "undefined") $subop = "";
312
313 if ($subop == "CatchupSelected") {
314 $ids = split(",", db_escape_string($_GET["ids"]));
315 $cmode = sprintf("%d", $_GET["cmode"]);
316
317 catchupArticlesById($link, $ids, $cmode);
318 }
319
320 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
321 update_generic_feed($link, $feed, $cat_view);
322 }
323
324 if ($subop == "MarkAllRead") {
325 catchup_feed($link, $feed, $cat_view);
326
327 if (get_pref($link, 'ON_CATCHUP_SHOW_NEXT_FEED')) {
328 if ($next_unread_feed) {
329 $feed = $next_unread_feed;
330 }
331 }
332 }
333
334 if ($feed_id > 0) {
335 $result = db_query($link,
336 "SELECT id FROM ttrss_feeds WHERE id = '$feed' LIMIT 1");
337
338 if (db_num_rows($result) == 0) {
339 print "<div align='center'>".__('Feed not found.')."</div>";
340 return;
341 }
342 }
343
344 if (preg_match("/^-?[0-9][0-9]*$/", $feed) != false) {
345
346 $result = db_query($link, "SELECT rtl_content FROM ttrss_feeds
347 WHERE id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
348
349 if (db_num_rows($result) == 1) {
350 $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
351 } else {
352 $rtl_content = false;
353 }
354
355 if ($rtl_content) {
356 $rtl_tag = "dir=\"RTL\"";
357 } else {
358 $rtl_tag = "";
359 }
360 } else {
361 $rtl_tag = "";
362 $rtl_content = false;
363 }
364
365 $script_dt_add = get_script_dt_add();
366
367 /* print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
368 <script type=\"text/javascript\" src=\"prototype.js\"></script>
369 <script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
370 <script type=\"text/javascript\" src=\"viewfeed.js?$script_dt_add\"></script>
371 <!--[if gte IE 5.5000]>
372 <script type=\"text/javascript\" src=\"pngfix.js\"></script>
373 <link rel=\"stylesheet\" type=\"text/css\" href=\"tt-rss-ie.css\">
374 <![endif]-->
375 </head><body $rtl_tag>
376 <script type=\"text/javascript\">
377 if (document.addEventListener) {
378 document.addEventListener(\"DOMContentLoaded\", init, null);
379 }
380 window.onload = init;
381 </script>"; */
382
383 /// START /////////////////////////////////////////////////////////////////////////////////
384
385 $search = db_escape_string($_GET["query"]);
386 $search_mode = db_escape_string($_GET["search_mode"]);
387 $match_on = db_escape_string($_GET["match_on"]);
388
389 if (!$match_on) {
390 $match_on = "both";
391 }
392
393 $real_offset = $offset * $limit;
394
395 $qfh_ret = queryFeedHeadlines($link, $feed, $limit, $view_mode, $cat_view,
396 $search, $search_mode, $match_on, false, $real_offset);
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'>".__("Could not display feed (query failed). Please check label match syntax or local configuration.")."</div>";
409 return;
410 }
411
412 print_headline_subtoolbar($link, $feed_site_url, $feed_title, false,
413 $rtl_content, $feed, $cat_view, $search, $match_on, $search_mode,
414 $offset, $limit);
415
416 print "<div id=\"headlinesInnerContainer\">";
417
418 if (db_num_rows($result) > 0) {
419
420 # print "\{$offset}";
421
422 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
423 print "<table class=\"headlinesList\" id=\"headlinesList\"
424 cellspacing=\"0\" width=\"100%\">";
425 }
426
427 $lnum = 0;
428
429 error_reporting (DEFAULT_ERROR_LEVEL);
430
431 $num_unread = 0;
432
433 while ($line = db_fetch_assoc($result)) {
434
435 $class = ($lnum % 2) ? "even" : "odd";
436
437 $id = $line["id"];
438 $feed_id = $line["feed_id"];
439
440 if ($line["last_read"] == "" &&
441 ($line["unread"] != "t" && $line["unread"] != "1")) {
442
443 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
444 alt=\"Updated\">";
445 } else {
446 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
447 alt=\"Updated\">";
448 }
449
450 if ($line["unread"] == "t" || $line["unread"] == "1") {
451 $class .= "Unread";
452 ++$num_unread;
453 $is_unread = true;
454 } else {
455 $is_unread = false;
456 }
457
458 if ($line["marked"] == "t" || $line["marked"] == "1") {
459 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
460 class=\"markedPic\"
461 alt=\"Reset mark\" onclick='javascript:toggleMark($id)'>";
462 } else {
463 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
464 class=\"markedPic\"
465 alt=\"Set mark\" onclick='javascript:toggleMark($id)'>";
466 }
467
468 # $content_link = "<a target=\"_new\" href=\"".$line["link"]."\">" .
469 # $line["title"] . "</a>";
470
471 $content_link = "<a href=\"javascript:view($id,$feed_id);\">" .
472 $line["title"] . "</a>";
473
474 # $content_link = "<a href=\"javascript:viewContentUrl('".$line["link"]."');\">" .
475 # $line["title"] . "</a>";
476
477 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
478 $updated_fmt = smart_date_time(strtotime($line["updated"]));
479 } else {
480 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
481 $updated_fmt = date($short_date, strtotime($line["updated"]));
482 }
483
484 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
485 $content_preview = truncate_string(strip_tags($line["content_preview"]),
486 100);
487 }
488
489 $entry_author = $line["author"];
490
491 if ($entry_author) {
492 $entry_author = " - by $entry_author";
493 }
494
495 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
496
497 print "<tr class='$class' id='RROW-$id'>";
498
499 print "<td class='hlUpdatePic'>$update_pic</td>";
500
501 print "<td class='hlSelectRow'>
502 <input type=\"checkbox\" onclick=\"toggleSelectRow(this)\"
503 class=\"feedCheckBox\" id=\"RCHK-$id\">
504 </td>";
505
506 print "<td class='hlMarkedPic'>$marked_pic</td>";
507
508 if ($line["feed_title"]) {
509 print "<td class='hlContent'>$content_link</td>";
510 print "<td class='hlFeed'>
511 <a href=\"javascript:viewfeed($feed_id, '', false)\">".
512 $line["feed_title"]."</a>&nbsp;</td>";
513 } else {
514 print "<td class='hlContent' valign='middle'>";
515
516 print "<a href=\"javascript:view($id,$feed_id);\">" .
517 $line["title"];
518
519 if (get_pref($link, 'SHOW_CONTENT_PREVIEW')) {
520 if ($content_preview) {
521 print "<span class=\"contentPreview\"> - $content_preview</span>";
522 }
523 }
524
525 print "</a>";
526 print "</td>";
527 }
528
529 print "<td class=\"hlUpdated\"><nobr>$updated_fmt&nbsp;</nobr></td>";
530
531 print "</tr>";
532
533 } else {
534
535 if ($is_unread) {
536 $add_class = "Unread";
537 } else {
538 $add_class = "";
539 }
540
541 print "<div class=\"cdmArticle$add_class\" id=\"RROW-$id\">";
542
543 print "<div class=\"cdmHeader\">";
544
545 print "<div class=\"articleUpdated\">$updated_fmt</div>";
546
547 print "<a class=\"title\"
548 onclick=\"javascript:toggleUnread($id, 0)\"
549 target=\"new\" href=\"".$line["link"]."\">".$line["title"]."</a>";
550
551 print $entry_author;
552
553 if ($line["feed_title"]) {
554 print "&nbsp;(<a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a>)";
555 }
556
557 print "</div>";
558
559 print "<div class=\"cdmContent\">" . $line["content_preview"] . "</div><br clear=\"all\">";
560
561 print "<div class=\"cdmFooter\">";
562
563 print "$marked_pic";
564
565 print "<input type=\"checkbox\" onclick=\"toggleSelectRowById(this,
566 'RROW-$id')\" class=\"feedCheckBox\" id=\"RCHK-$id\">";
567
568 $tags = get_article_tags($link, $id);
569
570 $tags_str = "";
571
572 foreach ($tags as $tag) {
573 $num_tags++;
574 $tags_str .= "<a href=\"javascript:viewfeed('$tag')\">$tag</a>, ";
575 }
576
577 $tags_str = preg_replace("/, $/", "", $tags_str);
578
579 if ($tags_str == "") $tags_str = "no tags";
580
581 print " $tags_str <a title=\"Edit tags for this article\"
582 href=\"javascript:editArticleTags($id, $feed_id, true)\">(+)</a>";
583
584 print "</div>";
585
586 # print "<div align=\"center\"><a class=\"cdmToggleLink\"
587 # href=\"javascript:toggleUnread($id)\">
588 # Toggle unread</a></div>";
589
590 print "</div>";
591
592 }
593
594 ++$lnum;
595 }
596
597 if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
598 print "</table>";
599 }
600
601 // print_headline_subtoolbar($link,
602 // "javascript:catchupPage()", "Mark page as read", true, $rtl_content);
603
604
605 } else {
606 print "<div class='whiteBox'>".__('No articles found.')."</div>";
607 }
608
609 print "</div>";
610
611 print "</div>";
612 }
613
614 if ($op == "pref-feeds") {
615 module_pref_feeds($link);
616 }
617
618 if ($op == "pref-filters") {
619 module_pref_filters($link);
620 }
621
622 if ($op == "pref-labels") {
623 module_pref_labels($link);
624 }
625
626 if ($op == "pref-prefs") {
627 module_pref_prefs($link);
628 }
629
630 if ($op == "pref-users") {
631 module_pref_users($link);
632 }
633
634 if ($op == "help") {
635 module_help($link);
636 }
637
638 if ($op == "dlg") {
639 module_popup_dialog($link);
640 }
641
642 // update feeds of all users, may be used anonymously
643 if ($op == "globalUpdateFeeds") {
644
645 $result = db_query($link, "SELECT id FROM ttrss_users");
646
647 while ($line = db_fetch_assoc($result)) {
648 $user_id = $line["id"];
649 // print "<!-- updating feeds of uid $user_id -->";
650 update_all_feeds($link, false, $user_id);
651 }
652
653 print "<rpc-reply>
654 <message msg=\"All feeds updated\"/>
655 </rpc-reply>";
656
657 }
658
659 if ($op == "user-details") {
660
661 if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
662 return;
663 }
664
665 /* print "<html><head>
666 <title>Tiny Tiny RSS : User Details</title>
667 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
668 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
669 </head><body>"; */
670
671 $uid = sprintf("%d", $_GET["id"]);
672
673 print "<div id=\"infoBoxTitle\">User details</div>";
674
675 print "<div class='infoBoxContents'>";
676
677 $result = db_query($link, "SELECT login,
678 SUBSTRING(last_login,1,16) AS last_login,
679 access_level,
680 (SELECT COUNT(int_id) FROM ttrss_user_entries
681 WHERE owner_uid = id) AS stored_articles
682 FROM ttrss_users
683 WHERE id = '$uid'");
684
685 if (db_num_rows($result) == 0) {
686 print "<h1>User not found</h1>";
687 return;
688 }
689
690 # print "<h1>User Details</h1>";
691
692 $login = db_fetch_result($result, 0, "login");
693
694 # print "<h1>$login</h1>";
695
696 print "<table width='100%'>";
697
698 $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'),
699 strtotime(db_fetch_result($result, 0, "last_login")));
700 $access_level = db_fetch_result($result, 0, "access_level");
701 $stored_articles = db_fetch_result($result, 0, "stored_articles");
702
703 # print "<tr><td>Username</td><td>$login</td></tr>";
704 # print "<tr><td>Access level</td><td>$access_level</td></tr>";
705 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
706 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
707
708 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
709 WHERE owner_uid = '$uid'");
710
711 $num_feeds = db_fetch_result($result, 0, "num_feeds");
712
713 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
714
715 /* $result = db_query($link, "SELECT
716 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
717 FROM ttrss_user_entries,ttrss_entries
718 WHERE owner_uid = '$uid' AND ref_id = id");
719
720 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
721
722 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
723
724 print "</table>";
725
726 print "<h1>Subscribed feeds</h1>";
727
728 $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
729 WHERE owner_uid = '$uid' ORDER BY title");
730
731 print "<ul class=\"userFeedList\">";
732
733 $row_class = "odd";
734
735 while ($line = db_fetch_assoc($result)) {
736
737 $icon_file = ICONS_URL."/".$line["id"].".ico";
738
739 if (file_exists($icon_file) && filesize($icon_file) > 0) {
740 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
741 } else {
742 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
743 }
744
745 print "<li class=\"$row_class\">$feed_icon&nbsp;<a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
746
747 $row_class = toggleEvenOdd($row_class);
748
749 }
750
751 if (db_num_rows($result) < $num_feeds) {
752 // FIXME - add link to show ALL subscribed feeds here somewhere
753 print "<li><img
754 class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">&nbsp;...</li>";
755 }
756
757 print "</ul>";
758
759 print "</div>";
760
761 print "<div align='center'>
762 <input type='submit' class='button'
763 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
764
765 // print "</body></html>";
766
767 }
768
769 if ($op == "pref-feed-browser") {
770 module_pref_feed_browser($link);
771 }
772
773 if ($op == "rss") {
774 $feed = db_escape_string($_GET["id"]);
775 $user = db_escape_string($_GET["user"]);
776 $pass = db_escape_string($_GET["pass"]);
777 $is_cat = $_GET["is_cat"] != false;
778
779 $search = db_escape_string($_GET["q"]);
780 $match_on = db_escape_string($_GET["m"]);
781 $search_mode = db_escape_string($_GET["smode"]);
782
783 if (!$_SESSION["uid"] && $user && $pass) {
784 authenticate_user($link, $user, $pass);
785 }
786
787 if ($_SESSION["uid"] ||
788 http_authenticate_user($link)) {
789
790 generate_syndicated_feed($link, $feed, $is_cat,
791 $search, $search_mode, $match_on);
792 }
793 }
794
795 if ($op == "labelFromSearch") {
796 $search = db_escape_string($_GET["search"]);
797 $search_mode = db_escape_string($_GET["smode"]);
798 $match_on = db_escape_string($_GET["match"]);
799 $is_cat = db_escape_string($_GET["is_cat"]);
800 $title = db_escape_string($_GET["title"]);
801 $feed = sprintf("%d", $_GET["feed"]);
802
803 $label_qparts = array();
804
805 $search_expr = getSearchSql($search, $match_on);
806
807 if ($is_cat) {
808 if ($feed != 0) {
809 $search_expr .= " AND ttrss_feeds.cat_id = $feed ";
810 } else {
811 $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
812 }
813 } else {
814 if ($search_mode == "all_feeds") {
815 // NOOP
816 } else if ($search_mode == "this_cat") {
817
818 $tmp_result = db_query($link, "SELECT cat_id
819 FROM ttrss_feeds WHERE id = '$feed'");
820
821 $cat_id = db_fetch_result($tmp_result, 0, "cat_id");
822
823 if ($cat_id > 0) {
824 $search_expr .= " AND ttrss_feeds.cat_id = $cat_id ";
825 } else {
826 $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
827 }
828 } else {
829 $search_expr .= " AND ttrss_feeds.id = $feed ";
830 }
831
832 }
833
834 $search_expr = db_escape_string($search_expr);
835
836 print $search_expr;
837
838 if ($title) {
839 $result = db_query($link,
840 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
841 VALUES ('$search_expr', '$title', '".$_SESSION["uid"]."')");
842 }
843 }
844
845 if ($op == "getUnread") {
846 $login = db_escape_string($_GET["login"]);
847
848 header("Content-Type: text/plain; charset=utf-8");
849
850 $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$login'");
851
852 if (db_num_rows($result) == 1) {
853 $uid = db_fetch_result($result, 0, "id");
854 print getGlobalUnread($link, $uid);
855 } else {
856 print "-1;User not found";
857 }
858
859 $print_exec_time = false;
860 }
861
862 if ($op == "digestTest") {
863 header("Content-Type: text/plain");
864 print_r(prepare_headlines_digest($link, $_SESSION["uid"]));
865 $print_exec_time = false;
866
867 }
868
869 if ($op == "digestSend") {
870 header("Content-Type: text/plain");
871 send_headlines_digests($link);
872 $print_exec_time = false;
873
874 }
875
876 db_close($link);
877 ?>
878
879 <?php if ($print_exec_time) { ?>
880 <!-- <?php echo sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
881 <?php } ?>