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