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