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