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