]> git.wh0rd.org - tt-rss.git/blob - backend.php
blank notify box on showDlg()
[tt-rss.git] / backend.php
1 <?
2 $op = $_GET["op"];
3
4 if ($op == "rpc") {
5 header("Content-Type: application/xml");
6 }
7
8 require_once "config.php";
9 require_once "db.php";
10 require_once "functions.php";
11 require_once "magpierss/rss_fetch.inc";
12
13 $script_started = getmicrotime();
14
15 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
16
17 if (!$link) {
18 if (DB_TYPE == "mysql") {
19 print mysql_error();
20 }
21 // PG seems to display its own errors just fine by default.
22 return;
23 }
24
25 if (DB_TYPE == "pgsql") {
26 pg_query("set client_encoding = 'utf-8'");
27 }
28
29 $fetch = $_GET["fetch"];
30
31 /* FIXME this needs reworking */
32
33 function getGlobalCounters($link) {
34 $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries
35 WHERE unread = true");
36 $c_id = db_fetch_result($result, 0, "c_id");
37 print "<counter id='global-unread' counter='$c_id'/>";
38 }
39
40 function getTagCounters($link) {
41 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
42 FROM ttrss_tags,ttrss_entries WHERE
43 post_id = ttrss_entries.id AND unread = true GROUP BY tag_name
44 UNION
45 select tag_name,0 as count FROM ttrss_tags");
46
47 $tags = array();
48
49 while ($line = db_fetch_assoc($result)) {
50 $tags[$line["tag_name"]] += $line["count"];
51 }
52
53 foreach (array_keys($tags) as $tag) {
54 $unread = $tags[$tag];
55
56 $tag = htmlspecialchars($tag);
57 print "<tag id=\"$tag\" counter=\"$unread\"/>";
58 }
59 }
60
61 function getLabelCounters($link) {
62
63 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
64 WHERE marked = true AND unread = true");
65
66 $count = db_fetch_result($result, 0, "count");
67
68 print "<label id=\"-1\" counter=\"$count\"/>";
69
70 $result = db_query($link, "SELECT id,sql_exp,description FROM
71 ttrss_labels ORDER by description");
72
73 while ($line = db_fetch_assoc($result)) {
74
75 $id = -$line["id"] - 11;
76
77 error_reporting (0);
78
79 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
80 WHERE (" . $line["sql_exp"] . ") AND unread = true");
81
82 $count = db_fetch_result($tmp_result, 0, "count");
83
84 print "<label id=\"$id\" counter=\"$count\"/>";
85
86 error_reporting (E_ERROR | E_WARNING | E_PARSE);
87
88 }
89 }
90
91 function getFeedCounter($link, $id) {
92
93 $result = db_query($link, "SELECT
94 count(id) as count FROM ttrss_entries
95 WHERE feed_id = '$id' AND unread = true");
96
97 $count = db_fetch_result($result, 0, "count");
98
99 print "<feed id=\"$id\" counter=\"$count\"/>";
100 }
101
102 function getFeedCounters($link) {
103
104 $result = db_query($link, "SELECT id,
105 (SELECT count(id) FROM ttrss_entries WHERE feed_id = ttrss_feeds.id
106 AND unread = true) as count
107 FROM ttrss_feeds");
108
109 while ($line = db_fetch_assoc($result)) {
110
111 $id = $line["id"];
112 $count = $line["count"];
113
114 print "<feed id=\"$id\" counter=\"$count\"/>";
115 }
116 }
117
118 function outputFeedList($link, $tags = false) {
119
120 print "<html><head>
121 <title>Tiny Tiny RSS : Feedlist</title>
122 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
123 <script type=\"text/javascript\" src=\"functions.js\"></script>
124 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
125 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
126 </head><body>";
127
128 print "<ul class=\"feedList\" id=\"feedList\">";
129
130 if (!$tags) {
131
132 /* virtual feeds */
133
134 $result = db_query($link, "SELECT count(id) as num_starred
135 FROM ttrss_entries WHERE marked = true AND unread = true");
136 $num_starred = db_fetch_result($result, 0, "num_starred");
137
138 $class = "odd";
139
140 if ($num_starred > 0) $class .= "Unread";
141
142 printFeedEntry(-1, $class, "Starred articles", $num_starred,
143 "images/mark_set.png");
144
145 if (ENABLE_LABELS) {
146
147 $result = db_query($link, "SELECT id,sql_exp,description FROM
148 ttrss_labels ORDER by description");
149
150 if (db_num_rows($result) > 0) {
151 print "<li><hr></li>";
152 }
153
154 while ($line = db_fetch_assoc($result)) {
155
156 error_reporting (0);
157
158 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
159 WHERE (" . $line["sql_exp"] . ") AND unread = true");
160
161 $count = db_fetch_result($tmp_result, 0, "count");
162
163 $class = "odd";
164
165 if ($count > 0) {
166 $class .= "Unread";
167 }
168
169 error_reporting (E_ERROR | E_WARNING | E_PARSE);
170
171 printFeedEntry(-$line["id"]-11,
172 $class, $line["description"], $count, "images/label.png");
173
174 }
175 }
176
177 print "<li><hr></li>";
178
179 $result = db_query($link, "SELECT *,
180 (SELECT count(id) FROM ttrss_entries
181 WHERE feed_id = ttrss_feeds.id) AS total,
182 (SELECT count(id) FROM ttrss_entries
183 WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
184 FROM ttrss_feeds ORDER BY title");
185
186 $actid = $_GET["actid"];
187
188 /* real feeds */
189
190 $lnum = 0;
191
192 $total_unread = 0;
193
194 while ($line = db_fetch_assoc($result)) {
195
196 $feed = $line["title"];
197 $feed_id = $line["id"];
198
199 $subop = $_GET["subop"];
200
201 $total = $line["total"];
202 $unread = $line["unread"];
203
204 // $class = ($lnum % 2) ? "even" : "odd";
205
206 $class = "odd";
207
208 if ($unread > 0) $class .= "Unread";
209
210 if ($actid == $feed_id) {
211 $class .= "Selected";
212 }
213
214 $total_unread += $unread;
215
216 printFeedEntry($feed_id, $class, $feed, $unread, "icons/$feed_id.ico");
217
218 ++$lnum;
219 }
220 } else {
221
222 // tags
223
224 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
225 FROM ttrss_tags,ttrss_entries WHERE
226 post_id = ttrss_entries.id AND unread = true GROUP BY tag_name
227 UNION
228 select tag_name,0 as count FROM ttrss_tags");
229
230 $tags = array();
231
232 while ($line = db_fetch_assoc($result)) {
233 $tags[$line["tag_name"]] += $line["count"];
234 }
235
236 foreach (array_keys($tags) as $tag) {
237
238 $unread = $tags[$tag];
239
240 $class = "odd";
241
242 if ($unread > 0) {
243 $class .= "Unread";
244 }
245
246 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png");
247
248 }
249
250 }
251
252 if (db_num_rows($result) == 0) {
253 print "<li>No tags to display.</li>";
254 }
255
256 print "</ul>";
257
258 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
259
260 }
261
262
263 if ($op == "rpc") {
264
265 $subop = $_GET["subop"];
266
267 if ($subop == "getLabelCounters") {
268 $aid = $_GET["aid"];
269 print "<rpc-reply>";
270 getLabelCounters($link);
271 if ($aid) {
272 getFeedCounter($link, $aid);
273 }
274 print "</rpc-reply>";
275 }
276
277 if ($subop == "getFeedCounters") {
278 print "<rpc-reply>";
279 getFeedCounters($link);
280 print "</rpc-reply>";
281 }
282
283 if ($subop == "getAllCounters") {
284 print "<rpc-reply>";
285 getLabelCounters($link);
286 getFeedCounters($link);
287 getTagCounters($link);
288 getGlobalCounters($link);
289 print "</rpc-reply>";
290 }
291
292 if ($subop == "mark") {
293 $mark = $_GET["mark"];
294 $id = db_escape_string($_GET["id"]);
295
296 if ($mark == "1") {
297 $mark = "true";
298 } else {
299 $mark = "false";
300 }
301
302 $result = db_query($link, "UPDATE ttrss_entries SET marked = $mark
303 WHERE id = '$id'");
304 }
305
306 if ($subop == "updateFeed") {
307 $feed_id = db_escape_string($_GET["feed"]);
308
309 $result = db_query($link,
310 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'");
311
312 if (db_num_rows($result) > 0) {
313 $feed_url = db_fetch_result($result, 0, "feed_url");
314 // update_rss_feed($link, $feed_url, $feed_id);
315 }
316
317 print "DONE-$feed_id";
318
319 return;
320 }
321
322 if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") {
323 update_all_feeds($link, true);
324
325 $omode = $_GET["omode"];
326
327 if (!$omode) $omode = "tfl";
328
329 print "<rpc-reply>";
330 if (strchr($omode, "l")) getLabelCounters($link);
331 if (strchr($omode, "f")) getFeedCounters($link);
332 if (strchr($omode, "t")) getTagCounters($link);
333 getGlobalCounters($link);
334 print "</rpc-reply>";
335 }
336
337 if ($subop == "catchupPage") {
338
339 $ids = split(",", $_GET["ids"]);
340
341 foreach ($ids as $id) {
342
343 db_query($link, "UPDATE ttrss_entries SET unread=false,last_read = NOW()
344 WHERE id = '$id'");
345
346 }
347
348 print "Marked active page as read.";
349 }
350 }
351
352 if ($op == "feeds") {
353
354 $tags = $_GET["tags"];
355
356 $subop = $_GET["subop"];
357
358 if ($subop == "catchupAll") {
359 db_query($link, "UPDATE ttrss_entries SET last_read = NOW(),unread = false");
360 }
361
362 outputFeedList($link, $tags);
363
364 }
365
366 if ($op == "view") {
367
368 $id = $_GET["id"];
369 $feed_id = $_GET["feed"];
370
371 $result = db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'");
372
373 $addheader = $_GET["addheader"];
374
375 $result = db_query($link, "SELECT title,link,content,feed_id,comments,
376 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
377 FROM ttrss_entries
378 WHERE id = '$id'");
379
380 if ($addheader) {
381 print "<html><head>
382 <title>Tiny Tiny RSS : Article $id</title>
383 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
384 <script type=\"text/javascript\" src=\"functions.js\"></script>
385 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
386 </head><body>";
387 }
388
389 if ($result) {
390
391 $line = db_fetch_assoc($result);
392
393 if ($line["icon_url"]) {
394 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
395 } else {
396 $feed_icon = "&nbsp;";
397 }
398
399 if ($line["comments"] && $line["link"] != $line["comments"]) {
400 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
401 } else {
402 $entry_comments = "";
403 }
404
405 print "<div class=\"postReply\">";
406
407 print "<div class=\"postHeader\"><table>";
408
409 print "<tr><td><b>Title:</b></td>
410 <td width='100%'>" . $line["title"] . "</td></tr>";
411
412 print "<tr><td><b>Link:</b></td>
413 <td width='100%'>
414 <a href=\"" . $line["link"] . "\">".$line["link"]."</a>
415 $entry_comments</td></tr>";
416
417 print "</table></div>";
418
419 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
420 print "<div class=\"postContent\">" . $line["content"] . "</div>";
421
422 print "</div>";
423
424 print "<script type=\"text/javascript\">
425 update_label_counters('$feed_id');
426 </script>";
427 }
428
429 if ($addheader) {
430 print "</body></html>";
431 }
432 }
433
434 if ($op == "viewfeed") {
435
436 $feed = $_GET["feed"];
437 $skip = $_GET["skip"];
438 $subop = $_GET["subop"];
439 $view_mode = $_GET["view"];
440 $addheader = $_GET["addheader"];
441 $limit = $_GET["limit"];
442
443 if (!$feed) {
444 print "Error: no feed to display.";
445 return;
446 }
447
448 if (!$skip) $skip = 0;
449
450 if ($subop == "undefined") $subop = "";
451
452 if ($addheader) {
453 print "<html><head>
454 <title>Tiny Tiny RSS : Feed $feed</title>
455 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
456 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
457 <script type=\"text/javascript\" src=\"functions.js\"></script>
458 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
459 </head><body>";
460 }
461
462 if ($subop == "MarkAllRead") {
463
464 if (sprintf("%d", $feed) != 0) {
465
466 if ($feed > 0) {
467 db_query($link, "UPDATE ttrss_entries
468 SET unread = false,last_read = NOW()
469 WHERE feed_id = '$feed'");
470
471 } else if ($feed < 0 && $feed > -10) { // special, like starred
472
473 if ($feed == -1) {
474 db_query($link, "UPDATE ttrss_entries
475 SET unread = false,last_read = NOW()
476 WHERE marked = true");
477 }
478
479 } else if ($feed < -10) { // label
480
481 $label_id = -$feed - 11;
482
483 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
484 WHERE id = '$label_id'");
485
486 if ($tmp_result) {
487 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
488
489 db_query($link, "UPDATE ttrss_entries
490 SET unread = false,last_read = NOW()
491 WHERE $sql_exp");
492 }
493 }
494 } else { // tag
495 // FIXME, implement catchup for tags
496 }
497
498 }
499
500 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
501
502 $search = $_GET["search"];
503
504 $search_mode = $_GET["smode"];
505
506 if ($search) {
507 $search_query_part = "(upper(title) LIKE upper('%$search%')
508 OR content LIKE '%$search%') AND";
509 } else {
510 $search_query_part = "";
511 }
512
513 $view_query_part = "";
514
515 if ($view_mode == "Starred") {
516 $view_query_part = " marked = true AND ";
517 }
518
519 if ($view_mode == "Unread") {
520 $view_query_part = " unread = true AND ";
521 }
522
523 if ($view_mode == "Unread or Starred") {
524 $view_query_part = " (unread = true OR marked = true) AND ";
525 }
526
527 if ($view_mode == "Unread or Updated") {
528 $view_query_part = " (unread = true OR last_read is NULL) AND ";
529 }
530
531 /* $result = db_query($link, "SELECT count(id) AS total_entries
532 FROM ttrss_entries WHERE
533 $search_query_part
534 feed_id = '$feed'");
535
536 $total_entries = db_fetch_result($result, 0, "total_entries"); */
537
538 /* $result = db_query("SELECT count(id) AS unread_entries
539 FROM ttrss_entries WHERE
540 $search_query_part
541 unread = true AND
542 feed_id = '$feed'");
543
544 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
545
546 if ($limit && $limit != "All") {
547 $limit_query_part = "LIMIT " . $limit;
548 }
549
550 $vfeed_query_part = "";
551
552 // override query strategy and enable feed display when searching globally
553 if ($search_mode == "All feeds") {
554 $query_strategy_part = "id > 0";
555 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
556 id = feed_id) as feed_title,";
557 } else if (sprintf("%d", $feed) == 0) {
558 $query_strategy_part = "ttrss_entries.id > 0";
559 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
560 id = feed_id) as feed_title,";
561 } else if ($feed >= 0) {
562 $query_strategy_part = "feed_id = '$feed'";
563 } else if ($feed == -1) { // starred virtual feed
564 $query_strategy_part = "marked = true";
565 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
566 id = feed_id) as feed_title,";
567 } else if ($feed <= -10) { // labels
568 $label_id = -$feed - 11;
569
570 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
571 WHERE id = '$label_id'");
572
573 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
574
575 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
576 id = feed_id) as feed_title,";
577 } else {
578 $query_strategy_part = "id > 0"; // dumb
579 }
580
581
582 $order_by = "updated DESC";
583
584 // if ($feed < -10) {
585 // $order_by = "feed_id,updated DESC";
586 // }
587
588 if ($feed < -10) error_reporting (0);
589
590 if (sprintf("%d", $feed) != 0) {
591
592 $result = db_query($link, "SELECT
593 id,title,updated,unread,feed_id,marked,link,last_read,
594 SUBSTRING(last_read,1,19) as last_read_noms,
595 $vfeed_query_part
596 SUBSTRING(updated,1,19) as updated_noms
597 FROM
598 ttrss_entries
599 WHERE
600 $search_query_part
601 $view_query_part
602 $query_strategy_part ORDER BY $order_by
603 $limit_query_part");
604
605 } else {
606 // browsing by tag
607
608 $result = db_query($link, "SELECT
609 ttrss_entries.id as id,title,updated,unread,feed_id,
610 marked,link,last_read,
611 SUBSTRING(last_read,1,19) as last_read_noms,
612 $vfeed_query_part
613 SUBSTRING(updated,1,19) as updated_noms
614 FROM
615 ttrss_entries,ttrss_tags
616 WHERE
617 post_id = ttrss_entries.id AND tag_name = '$feed' AND
618 $view_query_part
619 $search_query_part
620 $query_strategy_part ORDER BY $order_by
621 $limit_query_part");
622 }
623
624 if (!$result) {
625 print "<tr><td colspan='4' align='center'>
626 Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>";
627 return;
628 }
629
630 $lnum = 0;
631
632 error_reporting (E_ERROR | E_WARNING | E_PARSE);
633
634 $num_unread = 0;
635
636 while ($line = db_fetch_assoc($result)) {
637
638 $class = ($lnum % 2) ? "even" : "odd";
639
640 $id = $line["id"];
641 $feed_id = $line["feed_id"];
642
643 // printf("L %d (%s) &gt; U %d (%s) = %d<br>",
644 // strtotime($line["last_read_noms"]), $line["last_read_noms"],
645 // strtotime($line["updated"]), $line["updated"],
646 // strtotime($line["last_read"]) >= strtotime($line["updated"]));
647
648 /* if ($line["last_read"] != "" && $line["updated"] != "" &&
649 strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) {
650
651 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
652 alt=\"Updated\">";
653
654 } else {
655
656 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
657 alt=\"Updated\">";
658
659 } */
660
661 if ($line["last_read"] == "" &&
662 ($line["unread"] != "t" && $line["unread"] != "1")) {
663
664 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
665 alt=\"Updated\">";
666 } else {
667 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
668 alt=\"Updated\">";
669 }
670
671 if ($line["unread"] == "t" || $line["unread"] == "1") {
672 $class .= "Unread";
673 ++$num_unread;
674 }
675
676 if ($line["marked"] == "t" || $line["marked"] == "1") {
677 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
678 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
679 } else {
680 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
681 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
682 }
683
684 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
685 $line["title"] . "</a>";
686
687 print "<tr class='$class' id='RROW-$id'>";
688 // onclick=\"javascript:view($id,$feed_id)\">
689
690 print "<td valign='center' align='center'>$update_pic</td>";
691 print "<td valign='center' align='center'>$marked_pic</td>";
692
693 print "<td width='25%'>
694 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
695
696 if ($line["feed_title"]) {
697 print "<td width='50%'>$content_link</td>";
698 print "<td width='20%'>".$line["feed_title"]."</td>";
699 } else {
700 print "<td width='70%'>$content_link</td>";
701 }
702
703 print "</tr>";
704
705 ++$lnum;
706 }
707
708 if ($lnum == 0) {
709 print "<tr><td align='center'>No articles found.</td></tr>";
710 }
711
712 print "</table>";
713
714 print "<script type=\"text/javascript\">
715 document.onkeydown = hotkey_handler;
716 update_label_counters('$feed');
717 </script>";
718
719 if ($addheader) {
720 print "</body></html>";
721 }
722
723 }
724
725 if ($op == "pref-rpc") {
726
727 $subop = $_GET["subop"];
728
729 if ($subop == "unread") {
730 $ids = split(",", $_GET["ids"]);
731 foreach ($ids as $id) {
732 db_query($link, "UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'");
733 }
734
735 print "Marked selected feeds as read.";
736 }
737
738 if ($subop == "read") {
739 $ids = split(",", $_GET["ids"]);
740 foreach ($ids as $id) {
741 db_query($link, "UPDATE ttrss_entries
742 SET unread = false,last_read = NOW() WHERE feed_id = '$id'");
743 }
744
745 print "Marked selected feeds as unread.";
746
747 }
748
749 }
750
751 if ($op == "pref-feeds") {
752
753 $subop = $_GET["subop"];
754
755 if ($subop == "editSave") {
756 $feed_title = db_escape_string($_GET["t"]);
757 $feed_link = db_escape_string($_GET["l"]);
758 $upd_intl = db_escape_string($_GET["ui"]);
759 $feed_id = $_GET["id"];
760
761 if (strtoupper($upd_intl) == "DEFAULT")
762 $upd_intl = 0;
763
764 $result = db_query($link, "UPDATE ttrss_feeds SET
765 title = '$feed_title', feed_url = '$feed_link',
766 update_interval = '$upd_intl' WHERE id = '$feed_id'");
767
768 }
769
770 if ($subop == "remove") {
771
772 if (!WEB_DEMO_MODE) {
773
774 $ids = split(",", $_GET["ids"]);
775
776 foreach ($ids as $id) {
777 db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'");
778
779 if (file_exists(ICONS_DIR . "/$id.ico")) {
780 unlink(ICONS_DIR . "/$id.ico");
781 }
782 }
783 }
784 }
785
786 if ($subop == "add") {
787
788 if (!WEB_DEMO_MODE) {
789
790 $feed_link = db_escape_string($_GET["link"]);
791
792 $result = db_query($link,
793 "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')");
794
795 $result = db_query($link,
796 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'");
797
798 $feed_id = db_fetch_result($result, 0, "id");
799
800 if ($feed_id) {
801 update_rss_feed($link, $feed_link, $feed_id);
802 }
803 }
804 }
805
806 print "<table class=\"prefAddFeed\"><tr>
807 <td><input id=\"fadd_link\"></td>
808 <td colspan=\"4\" align=\"right\">
809 <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr>
810 </table>";
811
812 $result = db_query($link, "SELECT
813 id,title,feed_url,substring(last_updated,1,16) as last_updated,
814 update_interval
815 FROM
816 ttrss_feeds ORDER by title");
817
818 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
819 print "<tr class=\"title\">
820 <td>&nbsp;</td><td>Select</td><td width=\"40%\">Title</td>
821 <td width=\"30%\">Link</td><td width=\"10%\">Update Interval</td>
822 <td>Last updated</td></tr>";
823
824 $lnum = 0;
825
826 while ($line = db_fetch_assoc($result)) {
827
828 $class = ($lnum % 2) ? "even" : "odd";
829
830 $feed_id = $line["id"];
831
832 $edit_feed_id = $_GET["id"];
833
834 if ($subop == "edit" && $feed_id != $edit_feed_id) {
835 $class .= "Grayed";
836 }
837
838 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
839
840 $icon_file = ICONS_DIR . "/$feed_id.ico";
841
842 if (file_exists($icon_file) && filesize($icon_file) > 0) {
843 $feed_icon = "<img width=\"16\" height=\"16\"
844 src=\"" . ICONS_URL . "/$feed_id.ico\">";
845 } else {
846 $feed_icon = "&nbsp;";
847 }
848 print "<td align='center'>$feed_icon</td>";
849
850 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
851 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
852
853 if (!$edit_feed_id || $subop != "edit") {
854
855 print "<td><input onclick='toggleSelectRow(this);'
856 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
857
858 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
859 $edit_title . "</td>";
860 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
861 $edit_link . "</td>";
862
863 if ($line["update_interval"] == "0")
864 $line["update_interval"] = "Default";
865
866 print "<td>" . $line["update_interval"] . "</td>";
867
868
869 } else if ($feed_id != $edit_feed_id) {
870
871 print "<td><input disabled=\"true\" type=\"checkbox\"
872 id=\"FRCHK-".$line["id"]."\"></td>";
873
874 print "<td>$edit_title</td>";
875 print "<td>$edit_link</td>";
876
877 if ($line["update_interval"] == "0")
878 $line["update_interval"] = "Default";
879
880 print "<td>" . $line["update_interval"] . "</td>";
881
882 } else {
883
884 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
885
886 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
887 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
888 print "<td><input id=\"iedit_updintl\" value=\"".$line["update_interval"]."\"></td>";
889
890 }
891
892 if (!$line["last_updated"]) $line["last_updated"] = "Never";
893
894 print "<td>" . $line["last_updated"] . "</td>";
895
896 print "</tr>";
897
898 ++$lnum;
899 }
900
901 if ($lnum == 0) {
902 print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>";
903 }
904
905 print "</table>";
906
907 print "<p>";
908
909 if ($subop == "edit") {
910 print "Edit feed:&nbsp;
911 <input type=\"submit\" class=\"button\"
912 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
913 <input type=\"submit\" class=\"button\"
914 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
915 } else {
916
917 print "
918 Selection:&nbsp;
919 <input type=\"submit\" class=\"button\"
920 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
921 <input type=\"submit\" class=\"button\"
922 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
923
924 if (ENABLE_PREFS_CATCHUP_UNCATCHUP) {
925 print "
926 <input type=\"submit\" class=\"button\"
927 onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\">
928 <input type=\"submit\" class=\"button\"
929 onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\">&nbsp;";
930 }
931 print "
932 All feeds:
933 <input type=\"submit\"
934 class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">";
935
936 }
937
938 }
939
940 if ($op == "pref-filters") {
941
942 $subop = $_GET["subop"];
943
944 if ($subop == "editSave") {
945
946 $regexp = db_escape_string($_GET["r"]);
947 $descr = db_escape_string($_GET["d"]);
948 $match = db_escape_string($_GET["m"]);
949 $filter_id = db_escape_string($_GET["id"]);
950
951 $result = db_query($link, "UPDATE ttrss_filters SET
952 reg_exp = '$regexp',
953 description = '$descr',
954 filter_type = (SELECT id FROM ttrss_filter_types WHERE
955 description = '$match')
956 WHERE id = '$filter_id'");
957 }
958
959 if ($subop == "remove") {
960
961 if (!WEB_DEMO_MODE) {
962
963 $ids = split(",", $_GET["ids"]);
964
965 foreach ($ids as $id) {
966 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
967
968 }
969 }
970 }
971
972 if ($subop == "add") {
973
974 if (!WEB_DEMO_MODE) {
975
976 $regexp = db_escape_string($_GET["regexp"]);
977 $match = db_escape_string($_GET["match"]);
978
979 $result = db_query($link,
980 "INSERT INTO ttrss_filters (reg_exp,filter_type) VALUES
981 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
982 description = '$match'))");
983 }
984 }
985
986 $result = db_query($link, "SELECT description
987 FROM ttrss_filter_types ORDER BY description");
988
989 $filter_types = array();
990
991 while ($line = db_fetch_assoc($result)) {
992 array_push($filter_types, $line["description"]);
993 }
994
995 print "<table class=\"prefAddFeed\"><tr>
996 <td><input id=\"fadd_regexp\"></td>
997 <td>";
998 print_select("fadd_match", "Title", $filter_types);
999
1000 print"</td><td colspan=\"4\" align=\"right\">
1001 <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr>
1002 </table>";
1003
1004 $result = db_query($link, "SELECT
1005 id,reg_exp,description,
1006 (SELECT name FROM ttrss_filter_types WHERE
1007 id = filter_type) as filter_type_name,
1008 (SELECT description FROM ttrss_filter_types
1009 WHERE id = filter_type) as filter_type_descr
1010 FROM
1011 ttrss_filters ORDER by reg_exp");
1012
1013 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
1014
1015 print "<tr class=\"title\">
1016 <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td>
1017 <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>";
1018
1019 $lnum = 0;
1020
1021 while ($line = db_fetch_assoc($result)) {
1022
1023 $class = ($lnum % 2) ? "even" : "odd";
1024
1025 $filter_id = $line["id"];
1026 $edit_filter_id = $_GET["id"];
1027
1028 if ($subop == "edit" && $filter_id != $edit_filter_id) {
1029 $class .= "Grayed";
1030 }
1031
1032 print "<tr class=\"$class\" id=\"FILRR-$filter_id\">";
1033
1034 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
1035 $line["description"] = htmlspecialchars($line["description"]);
1036
1037 if (!$edit_filter_id || $subop != "edit") {
1038
1039 if (!$line["description"]) $line["description"] = "[No description]";
1040
1041 print "<td><input onclick='toggleSelectRow(this);'
1042 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
1043
1044 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1045 $line["reg_exp"] . "</td>";
1046
1047 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1048 $line["description"] . "</td>";
1049
1050 print "<td>".$line["filter_type_descr"]."</td>";
1051
1052 } else if ($filter_id != $edit_filter_id) {
1053
1054 if (!$line["description"]) $line["description"] = "[No description]";
1055
1056 print "<td><input disabled=\"true\" type=\"checkbox\"
1057 id=\"FICHK-".$line["id"]."\"></td>";
1058
1059 print "<td>".$line["reg_exp"]."</td>";
1060 print "<td>".$line["description"]."</td>";
1061 print "<td>".$line["filter_type_descr"]."</td>";
1062
1063 } else {
1064
1065 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
1066
1067 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
1068 "\"></td>";
1069
1070 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1071 "\"></td>";
1072
1073 print "<td>";
1074 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
1075 print "</td>";
1076
1077 }
1078
1079
1080 print "</tr>";
1081
1082 ++$lnum;
1083 }
1084
1085 if ($lnum == 0) {
1086 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
1087 }
1088
1089 print "</table>";
1090
1091 print "<p>";
1092
1093 if ($subop == "edit") {
1094 print "Edit feed:
1095 <input type=\"submit\" class=\"button\"
1096 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
1097 <input type=\"submit\" class=\"button\"
1098 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
1099
1100 } else {
1101
1102 print "
1103 Selection:
1104 <input type=\"submit\" class=\"button\"
1105 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
1106 <input type=\"submit\" class=\"button\"
1107 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
1108 }
1109 }
1110
1111 if ($op == "pref-labels") {
1112
1113 $subop = $_GET["subop"];
1114
1115 if ($subop == "editSave") {
1116
1117 $sql_exp = $_GET["s"];
1118 $descr = $_GET["d"];
1119 $label_id = db_escape_string($_GET["id"]);
1120
1121 // print "$sql_exp : $descr : $label_id";
1122
1123 $result = db_query($link, "UPDATE ttrss_labels SET
1124 sql_exp = '$sql_exp',
1125 description = '$descr'
1126 WHERE id = '$label_id'");
1127 }
1128
1129 if ($subop == "remove") {
1130
1131 if (!WEB_DEMO_MODE) {
1132
1133 $ids = split(",", $_GET["ids"]);
1134
1135 foreach ($ids as $id) {
1136 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
1137
1138 }
1139 }
1140 }
1141
1142 if ($subop == "add") {
1143
1144 if (!WEB_DEMO_MODE) {
1145
1146 $exp = $_GET["exp"];
1147
1148 $result = db_query($link,
1149 "INSERT INTO ttrss_labels (sql_exp,description)
1150 VALUES ('$exp', '$exp')");
1151 }
1152 }
1153
1154 print "<table class=\"prefAddFeed\"><tr>
1155 <td><input id=\"ladd_expr\"></td>";
1156
1157 print"<td colspan=\"4\" align=\"right\">
1158 <a class=\"button\" href=\"javascript:addLabel()\">Add label</a></td></tr>
1159 </table>";
1160
1161 $result = db_query($link, "SELECT
1162 id,sql_exp,description
1163 FROM
1164 ttrss_labels ORDER by description");
1165
1166 print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">";
1167
1168 print "<tr class=\"title\">
1169 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
1170 <a class=\"helpLink\" href=\"javascript:popupHelp(1)\">(?)</a>
1171 </td>
1172 <td width=\"40%\">Caption</td></tr>";
1173
1174 $lnum = 0;
1175
1176 while ($line = db_fetch_assoc($result)) {
1177
1178 $class = ($lnum % 2) ? "even" : "odd";
1179
1180 $label_id = $line["id"];
1181 $edit_label_id = $_GET["id"];
1182
1183 if ($subop == "edit" && $label_id != $edit_label_id) {
1184 $class .= "Grayed";
1185 }
1186
1187 print "<tr class=\"$class\" id=\"LILRR-$label_id\">";
1188
1189 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
1190 $line["description"] = htmlspecialchars($line["description"]);
1191
1192 if (!$edit_label_id || $subop != "edit") {
1193
1194 if (!$line["description"]) $line["description"] = "[No caption]";
1195
1196 print "<td><input onclick='toggleSelectRow(this);'
1197 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
1198
1199 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1200 $line["sql_exp"] . "</td>";
1201
1202 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1203 $line["description"] . "</td>";
1204
1205 } else if ($label_id != $edit_label_id) {
1206
1207 if (!$line["description"]) $line["description"] = "[No description]";
1208
1209 print "<td><input disabled=\"true\" type=\"checkbox\"
1210 id=\"LICHK-".$line["id"]."\"></td>";
1211
1212 print "<td>".$line["sql_exp"]."</td>";
1213 print "<td>".$line["description"]."</td>";
1214
1215 } else {
1216
1217 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
1218
1219 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
1220 "\"></td>";
1221
1222 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1223 "\"></td>";
1224
1225 }
1226
1227
1228 print "</tr>";
1229
1230 ++$lnum;
1231 }
1232
1233 if ($lnum == 0) {
1234 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
1235 }
1236
1237 print "</table>";
1238
1239 print "<p>";
1240
1241 if ($subop == "edit") {
1242 print "Edit label:
1243 <input type=\"submit\" class=\"button\"
1244 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
1245 <input type=\"submit\" class=\"button\"
1246 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
1247
1248 } else {
1249
1250 print "
1251 Selection:
1252 <input type=\"submit\" class=\"button\"
1253 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
1254 <input type=\"submit\" class=\"button\"
1255 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
1256 }
1257 }
1258
1259 if ($op == "error") {
1260 print "<div width=\"100%\" align='center'>";
1261 $msg = $_GET["msg"];
1262 print $msg;
1263 print "</div>";
1264 }
1265
1266 if ($op == "help") {
1267 print "<html><head>
1268 <title>Tiny Tiny RSS : Help</title>
1269 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
1270 <script type=\"text/javascript\" src=\"functions.js\"></script>
1271 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
1272 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1273 </head><body>";
1274
1275 $tid = sprintf("%d", $_GET["tid"]);
1276
1277 /* FIXME this badly needs real implementation */
1278
1279 print "<div class='helpResponse'>";
1280
1281 ?>
1282
1283 <h1>Help for SQL expressions</h1>
1284
1285 <h2>Description</h2>
1286
1287 <p>The &laquo;SQL expression&raquo; is added to WHERE clause of
1288 view feed query. You can match on ttrss_entries table fields
1289 and even use subselect to query additional information. This
1290 functionality is considered to be advanced and requires basic
1291 understanding of SQL.</p>
1292
1293 <h2>Examples</h2>
1294
1295 <pre>unread = true</pre>
1296
1297 Matches all unread articles
1298
1299 <pre>title like '%Linux%'</pre>
1300
1301 Matches all articles which mention Linux in the title. You get the idea.
1302
1303 <p>See the database schema included in the distribution package for gruesome
1304 details.</p>
1305
1306 <?
1307
1308 print "<div align='center'>
1309 <a class=\"helpLink\"
1310 href=\"javascript:window.close()\">(Close this window)</a></div>";
1311
1312 print "</div>";
1313
1314 print "</body></html>";
1315
1316 }
1317
1318 if ($op == "dlg") {
1319 $id = $_GET["id"];
1320 $param = $_GET["param"];
1321
1322 if ($id == "quickAddFeed") {
1323 print "Feed URL: <input id=\"qafInput\">
1324 <input class=\"button\"
1325 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
1326 <input class=\"button\"
1327 type=\"submit\" onclick=\"javascript:closeDlg()\"
1328 value=\"Cancel\">";
1329 }
1330
1331 if ($id == "quickDelFeed") {
1332
1333 $param = db_escape_string($param);
1334
1335 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
1336
1337 if ($result) {
1338
1339 $f_title = db_fetch_result($result, 0, "title");
1340
1341 print "Remove current feed ($f_title)?&nbsp;
1342 <input class=\"button\"
1343 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
1344 <input class=\"button\"
1345 type=\"submit\" onclick=\"javascript:closeDlg()\"
1346 value=\"Cancel\">";
1347 } else {
1348 print "Error: Feed $param not found.&nbsp;
1349 <input class=\"button\"
1350 type=\"submit\" onclick=\"javascript:closeDlg()\"
1351 value=\"Cancel\">";
1352 }
1353 }
1354
1355 }
1356
1357 db_close($link);
1358 ?>
1359
1360 <!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
1361