]> git.wh0rd.org - tt-rss.git/blob - backend.php
update help text
[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 "<label 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 $omode = $_GET["omode"];
317
318 if (!$omode) $omode = "tfl";
319
320 print "<rpc-reply>";
321 if (strchr($omode, "l")) getLabelCounters($link);
322 if (strchr($omode, "f")) getFeedCounters($link);
323 if (strchr($omode, "t")) getTagCounters($link);
324 print "</rpc-reply>";
325 }
326
327 if ($subop == "catchupPage") {
328
329 $ids = split(",", $_GET["ids"]);
330
331 foreach ($ids as $id) {
332
333 db_query($link, "UPDATE ttrss_entries SET unread=false,last_read = NOW()
334 WHERE id = '$id'");
335
336 }
337
338 print "Marked active page as read.";
339 }
340 }
341
342 if ($op == "feeds") {
343
344 $tags = $_GET["tags"];
345
346 $subop = $_GET["subop"];
347
348 if ($subop == "catchupAll") {
349 db_query($link, "UPDATE ttrss_entries SET last_read = NOW(),unread = false");
350 }
351
352 outputFeedList($link, $tags);
353
354 }
355
356 if ($op == "view") {
357
358 $id = $_GET["id"];
359 $feed_id = $_GET["feed"];
360
361 $result = db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'");
362
363 $addheader = $_GET["addheader"];
364
365 $result = db_query($link, "SELECT title,link,content,feed_id,comments,
366 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
367 FROM ttrss_entries
368 WHERE id = '$id'");
369
370 if ($addheader) {
371 print "<html><head>
372 <title>Tiny Tiny RSS : Article $id</title>
373 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
374 <script type=\"text/javascript\" src=\"functions.js\"></script>
375 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
376 </head><body>";
377 }
378
379 if ($result) {
380
381 $line = db_fetch_assoc($result);
382
383 if ($line["icon_url"]) {
384 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
385 } else {
386 $feed_icon = "&nbsp;";
387 }
388
389 if ($line["comments"] && $line["link"] != $line["comments"]) {
390 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
391 } else {
392 $entry_comments = "";
393 }
394
395 print "<div class=\"postReply\">";
396
397 print "<div class=\"postHeader\"><table>";
398
399 print "<tr><td><b>Title:</b></td>
400 <td width='100%'>" . $line["title"] . "</td></tr>";
401
402 print "<tr><td><b>Link:</b></td>
403 <td width='100%'>
404 <a href=\"" . $line["link"] . "\">".$line["link"]."</a>
405 $entry_comments</td></tr>";
406
407 print "</table></div>";
408
409 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
410 print "<div class=\"postContent\">" . $line["content"] . "</div>";
411
412 print "</div>";
413
414 print "<script type=\"text/javascript\">
415 update_label_counters('$feed_id');
416 </script>";
417 }
418
419 if ($addheader) {
420 print "</body></html>";
421 }
422 }
423
424 if ($op == "viewfeed") {
425
426 $feed = $_GET["feed"];
427 $skip = $_GET["skip"];
428 $subop = $_GET["subop"];
429 $view_mode = $_GET["view"];
430 $addheader = $_GET["addheader"];
431 $limit = $_GET["limit"];
432
433 if (!$feed) {
434 print "Error: no feed to display.";
435 return;
436 }
437
438 if (!$skip) $skip = 0;
439
440 if ($subop == "undefined") $subop = "";
441
442 if ($addheader) {
443 print "<html><head>
444 <title>Tiny Tiny RSS : Feed $feed</title>
445 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
446 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
447 <script type=\"text/javascript\" src=\"functions.js\"></script>
448 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
449 </head><body>";
450 }
451
452 if (sprintf("%d", $feed) != 0 && $feed >= 0) {
453
454 $result = db_query($link,
455 "SELECT *,SUBSTRING(last_updated,1,16) as last_updated_s
456 FROM ttrss_feeds WHERE id = '$feed'");
457
458 if ($result) {
459
460 // $line = db_fetch_assoc($result);
461 // update_rss_feed($link, $line["feed_url"], $feed);
462
463 if ($subop == "MarkAllRead") {
464
465 db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW()
466 WHERE feed_id = '$feed'");
467 }
468 }
469 }
470
471 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
472
473 $search = $_GET["search"];
474
475 if ($search) {
476 $search_query_part = "(upper(title) LIKE upper('%$search%')
477 OR content LIKE '%$search%') AND";
478 } else {
479 $search_query_part = "";
480 }
481
482 $view_query_part = "";
483
484 if ($view_mode == "Starred") {
485 $view_query_part = " marked = true AND ";
486 }
487
488 if ($view_mode == "Unread") {
489 $view_query_part = " unread = true AND ";
490 }
491
492 if ($view_mode == "Unread or Starred") {
493 $view_query_part = " (unread = true OR marked = true) AND ";
494 }
495
496 /* $result = db_query($link, "SELECT count(id) AS total_entries
497 FROM ttrss_entries WHERE
498 $search_query_part
499 feed_id = '$feed'");
500
501 $total_entries = db_fetch_result($result, 0, "total_entries"); */
502
503 /* $result = db_query("SELECT count(id) AS unread_entries
504 FROM ttrss_entries WHERE
505 $search_query_part
506 unread = true AND
507 feed_id = '$feed'");
508
509 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
510
511 if ($limit && $limit != "All") {
512 $limit_query_part = "LIMIT " . $limit;
513 }
514
515 $vfeed_query_part = "";
516
517 if (sprintf("%d", $feed) == 0) {
518 $query_strategy_part = "ttrss_entries.id > 0";
519 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
520 id = feed_id) as feed_title,";
521 } else if ($feed >= 0) {
522 $query_strategy_part = "feed_id = '$feed'";
523 } else if ($feed == -1) { // starred virtual feed
524 $query_strategy_part = "marked = true";
525 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
526 id = feed_id) as feed_title,";
527 } else if ($feed <= -10) { // labels
528 $label_id = -$feed - 11;
529
530 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
531 WHERE id = '$label_id'");
532
533 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
534
535 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
536 id = feed_id) as feed_title,";
537 } else {
538 $query_strategy_part = "id > 0"; // dumb
539 }
540
541 $order_by = "updated DESC";
542
543 // if ($feed < -10) {
544 // $order_by = "feed_id,updated DESC";
545 // }
546
547 if ($feed < -10) error_reporting (0);
548
549 if (sprintf("%d", $feed) != 0) {
550
551 $result = db_query($link, "SELECT
552 id,title,updated,unread,feed_id,marked,link,last_read,
553 SUBSTRING(last_read,1,19) as last_read_noms,
554 $vfeed_query_part
555 SUBSTRING(updated,1,19) as updated_noms
556 FROM
557 ttrss_entries
558 WHERE
559 $search_query_part
560 $view_query_part
561 $query_strategy_part ORDER BY $order_by
562 $limit_query_part");
563
564 } else {
565 // browsing by tag
566
567 $result = db_query($link, "SELECT
568 ttrss_entries.id as id,title,updated,unread,feed_id,
569 marked,link,last_read,
570 SUBSTRING(last_read,1,19) as last_read_noms,
571 $vfeed_query_part
572 SUBSTRING(updated,1,19) as updated_noms
573 FROM
574 ttrss_entries,ttrss_tags
575 WHERE
576 post_id = ttrss_entries.id AND tag_name = '$feed' AND
577 $view_query_part
578 $search_query_part
579 $query_strategy_part ORDER BY $order_by
580 $limit_query_part");
581 }
582
583 if (!$result) {
584 print "<tr><td colspan='4' align='center'>
585 Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>";
586 return;
587 }
588
589 $lnum = 0;
590
591 error_reporting (E_ERROR | E_WARNING | E_PARSE);
592
593 $num_unread = 0;
594
595 while ($line = db_fetch_assoc($result)) {
596
597 $class = ($lnum % 2) ? "even" : "odd";
598
599 $id = $line["id"];
600 $feed_id = $line["feed_id"];
601
602 // printf("L %d (%s) &gt; U %d (%s) = %d<br>",
603 // strtotime($line["last_read_noms"]), $line["last_read_noms"],
604 // strtotime($line["updated"]), $line["updated"],
605 // strtotime($line["last_read"]) >= strtotime($line["updated"]));
606
607 /* if ($line["last_read"] != "" && $line["updated"] != "" &&
608 strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) {
609
610 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
611 alt=\"Updated\">";
612
613 } else {
614
615 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
616 alt=\"Updated\">";
617
618 } */
619
620 if ($line["last_read"] == "" &&
621 ($line["unread"] != "t" && $line["unread"] != "1")) {
622
623 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
624 alt=\"Updated\">";
625 } else {
626 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
627 alt=\"Updated\">";
628 }
629
630 if ($line["unread"] == "t" || $line["unread"] == "1") {
631 $class .= "Unread";
632 ++$num_unread;
633 }
634
635 if ($line["marked"] == "t" || $line["marked"] == "1") {
636 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
637 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
638 } else {
639 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
640 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
641 }
642
643 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
644 $line["title"] . "</a>";
645
646 print "<tr class='$class' id='RROW-$id'>";
647 // onclick=\"javascript:view($id,$feed_id)\">
648
649 print "<td valign='center' align='center'>$update_pic</td>";
650 print "<td valign='center' align='center'>$marked_pic</td>";
651
652 print "<td width='25%'>
653 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
654
655 if ($line["feed_title"]) {
656 print "<td width='50%'>$content_link</td>";
657 print "<td width='20%'>".$line["feed_title"]."</td>";
658 } else {
659 print "<td width='70%'>$content_link</td>";
660 }
661
662 print "</tr>";
663
664 ++$lnum;
665 }
666
667 if ($lnum == 0) {
668 print "<tr><td align='center'>No articles found.</td></tr>";
669 }
670
671 print "</table>";
672
673 print "<script type=\"text/javascript\">
674 document.onkeydown = hotkey_handler;
675 update_label_counters('$feed');
676 </script>";
677
678 if ($addheader) {
679 print "</body></html>";
680 }
681
682 }
683
684 if ($op == "pref-rpc") {
685
686 $subop = $_GET["subop"];
687
688 if ($subop == "unread") {
689 $ids = split(",", $_GET["ids"]);
690 foreach ($ids as $id) {
691 db_query($link, "UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'");
692 }
693
694 print "Marked selected feeds as read.";
695 }
696
697 if ($subop == "read") {
698 $ids = split(",", $_GET["ids"]);
699 foreach ($ids as $id) {
700 db_query($link, "UPDATE ttrss_entries
701 SET unread = false,last_read = NOW() WHERE feed_id = '$id'");
702 }
703
704 print "Marked selected feeds as unread.";
705
706 }
707
708 }
709
710 if ($op == "pref-feeds") {
711
712 $subop = $_GET["subop"];
713
714 if ($subop == "editSave") {
715 $feed_title = db_escape_string($_GET["t"]);
716 $feed_link = db_escape_string($_GET["l"]);
717 $upd_intl = db_escape_string($_GET["ui"]);
718 $feed_id = $_GET["id"];
719
720 if (strtoupper($upd_intl) == "DEFAULT")
721 $upd_intl = 0;
722
723 $result = db_query($link, "UPDATE ttrss_feeds SET
724 title = '$feed_title', feed_url = '$feed_link',
725 update_interval = '$upd_intl' WHERE id = '$feed_id'");
726
727 }
728
729 if ($subop == "remove") {
730
731 if (!WEB_DEMO_MODE) {
732
733 $ids = split(",", $_GET["ids"]);
734
735 foreach ($ids as $id) {
736 db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'");
737
738 if (file_exists(ICONS_DIR . "/$id.ico")) {
739 unlink(ICONS_DIR . "/$id.ico");
740 }
741 }
742 }
743 }
744
745 if ($subop == "add") {
746
747 if (!WEB_DEMO_MODE) {
748
749 $feed_link = db_escape_string($_GET["link"]);
750
751 $result = db_query($link,
752 "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')");
753
754 $result = db_query($link,
755 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'");
756
757 $feed_id = db_fetch_result($result, 0, "id");
758
759 if ($feed_id) {
760 update_rss_feed($link, $feed_link, $feed_id);
761 }
762 }
763 }
764
765 print "<table class=\"prefAddFeed\"><tr>
766 <td><input id=\"fadd_link\"></td>
767 <td colspan=\"4\" align=\"right\">
768 <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr>
769 </table>";
770
771 $result = db_query($link, "SELECT
772 id,title,feed_url,substring(last_updated,1,16) as last_updated,
773 update_interval
774 FROM
775 ttrss_feeds ORDER by title");
776
777 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
778 print "<tr class=\"title\">
779 <td>&nbsp;</td><td>Select</td><td width=\"40%\">Title</td>
780 <td width=\"30%\">Link</td><td width=\"10%\">Update Interval</td>
781 <td>Last updated</td></tr>";
782
783 $lnum = 0;
784
785 while ($line = db_fetch_assoc($result)) {
786
787 $class = ($lnum % 2) ? "even" : "odd";
788
789 $feed_id = $line["id"];
790
791 $edit_feed_id = $_GET["id"];
792
793 if ($subop == "edit" && $feed_id != $edit_feed_id) {
794 $class .= "Grayed";
795 }
796
797 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
798
799 $icon_file = ICONS_DIR . "/$feed_id.ico";
800
801 if (file_exists($icon_file) && filesize($icon_file) > 0) {
802 $feed_icon = "<img width=\"16\" height=\"16\"
803 src=\"" . ICONS_URL . "/$feed_id.ico\">";
804 } else {
805 $feed_icon = "&nbsp;";
806 }
807 print "<td align='center'>$feed_icon</td>";
808
809 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
810 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
811
812 if (!$edit_feed_id || $subop != "edit") {
813
814 print "<td><input onclick='toggleSelectRow(this);'
815 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
816
817 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
818 $edit_title . "</td>";
819 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
820 $edit_link . "</td>";
821
822 if ($line["update_interval"] == "0")
823 $line["update_interval"] = "Default";
824
825 print "<td>" . $line["update_interval"] . "</td>";
826
827
828 } else if ($feed_id != $edit_feed_id) {
829
830 print "<td><input disabled=\"true\" type=\"checkbox\"
831 id=\"FRCHK-".$line["id"]."\"></td>";
832
833 print "<td>$edit_title</td>";
834 print "<td>$edit_link</td>";
835
836 if ($line["update_interval"] == "0")
837 $line["update_interval"] = "Default";
838
839 print "<td>" . $line["update_interval"] . "</td>";
840
841 } else {
842
843 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
844
845 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
846 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
847 print "<td><input id=\"iedit_updintl\" value=\"".$line["update_interval"]."\"></td>";
848
849 }
850
851 if (!$line["last_updated"]) $line["last_updated"] = "Never";
852
853 print "<td>" . $line["last_updated"] . "</td>";
854
855 print "</tr>";
856
857 ++$lnum;
858 }
859
860 if ($lnum == 0) {
861 print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>";
862 }
863
864 print "</table>";
865
866 print "<p>";
867
868 if ($subop == "edit") {
869 print "Edit feed:&nbsp;
870 <input type=\"submit\" class=\"button\"
871 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
872 <input type=\"submit\" class=\"button\"
873 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
874 } else {
875
876 print "
877 Selection:&nbsp;
878 <input type=\"submit\" class=\"button\"
879 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
880 <input type=\"submit\" class=\"button\"
881 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
882
883 if (ENABLE_PREFS_CATCHUP_UNCATCHUP) {
884 print "
885 <input type=\"submit\" class=\"button\"
886 onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\">
887 <input type=\"submit\" class=\"button\"
888 onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\">&nbsp;";
889 }
890 print "
891 All feeds:
892 <input type=\"submit\"
893 class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">";
894
895 }
896
897 }
898
899 if ($op == "pref-filters") {
900
901 $subop = $_GET["subop"];
902
903 if ($subop == "editSave") {
904
905 $regexp = db_escape_string($_GET["r"]);
906 $descr = db_escape_string($_GET["d"]);
907 $match = db_escape_string($_GET["m"]);
908 $filter_id = db_escape_string($_GET["id"]);
909
910 $result = db_query($link, "UPDATE ttrss_filters SET
911 reg_exp = '$regexp',
912 description = '$descr',
913 filter_type = (SELECT id FROM ttrss_filter_types WHERE
914 description = '$match')
915 WHERE id = '$filter_id'");
916 }
917
918 if ($subop == "remove") {
919
920 if (!WEB_DEMO_MODE) {
921
922 $ids = split(",", $_GET["ids"]);
923
924 foreach ($ids as $id) {
925 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
926
927 }
928 }
929 }
930
931 if ($subop == "add") {
932
933 if (!WEB_DEMO_MODE) {
934
935 $regexp = db_escape_string($_GET["regexp"]);
936 $match = db_escape_string($_GET["match"]);
937
938 $result = db_query($link,
939 "INSERT INTO ttrss_filters (reg_exp,filter_type) VALUES
940 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
941 description = '$match'))");
942 }
943 }
944
945 $result = db_query($link, "SELECT description
946 FROM ttrss_filter_types ORDER BY description");
947
948 $filter_types = array();
949
950 while ($line = db_fetch_assoc($result)) {
951 array_push($filter_types, $line["description"]);
952 }
953
954 print "<table class=\"prefAddFeed\"><tr>
955 <td><input id=\"fadd_regexp\"></td>
956 <td>";
957 print_select("fadd_match", "Title", $filter_types);
958
959 print"</td><td colspan=\"4\" align=\"right\">
960 <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr>
961 </table>";
962
963 $result = db_query($link, "SELECT
964 id,reg_exp,description,
965 (SELECT name FROM ttrss_filter_types WHERE
966 id = filter_type) as filter_type_name,
967 (SELECT description FROM ttrss_filter_types
968 WHERE id = filter_type) as filter_type_descr
969 FROM
970 ttrss_filters ORDER by reg_exp");
971
972 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
973
974 print "<tr class=\"title\">
975 <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td>
976 <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>";
977
978 $lnum = 0;
979
980 while ($line = db_fetch_assoc($result)) {
981
982 $class = ($lnum % 2) ? "even" : "odd";
983
984 $filter_id = $line["id"];
985 $edit_filter_id = $_GET["id"];
986
987 if ($subop == "edit" && $filter_id != $edit_filter_id) {
988 $class .= "Grayed";
989 }
990
991 print "<tr class=\"$class\" id=\"FILRR-$filter_id\">";
992
993 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
994 $line["description"] = htmlspecialchars($line["description"]);
995
996 if (!$edit_filter_id || $subop != "edit") {
997
998 if (!$line["description"]) $line["description"] = "[No description]";
999
1000 print "<td><input onclick='toggleSelectRow(this);'
1001 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
1002
1003 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1004 $line["reg_exp"] . "</td>";
1005
1006 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1007 $line["description"] . "</td>";
1008
1009 print "<td>".$line["filter_type_descr"]."</td>";
1010
1011 } else if ($filter_id != $edit_filter_id) {
1012
1013 if (!$line["description"]) $line["description"] = "[No description]";
1014
1015 print "<td><input disabled=\"true\" type=\"checkbox\"
1016 id=\"FICHK-".$line["id"]."\"></td>";
1017
1018 print "<td>".$line["reg_exp"]."</td>";
1019 print "<td>".$line["description"]."</td>";
1020 print "<td>".$line["filter_type_descr"]."</td>";
1021
1022 } else {
1023
1024 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
1025
1026 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
1027 "\"></td>";
1028
1029 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1030 "\"></td>";
1031
1032 print "<td>";
1033 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
1034 print "</td>";
1035
1036 }
1037
1038
1039 print "</tr>";
1040
1041 ++$lnum;
1042 }
1043
1044 if ($lnum == 0) {
1045 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
1046 }
1047
1048 print "</table>";
1049
1050 print "<p>";
1051
1052 if ($subop == "edit") {
1053 print "Edit feed:
1054 <input type=\"submit\" class=\"button\"
1055 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
1056 <input type=\"submit\" class=\"button\"
1057 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
1058
1059 } else {
1060
1061 print "
1062 Selection:
1063 <input type=\"submit\" class=\"button\"
1064 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
1065 <input type=\"submit\" class=\"button\"
1066 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
1067 }
1068 }
1069
1070 if ($op == "pref-labels") {
1071
1072 $subop = $_GET["subop"];
1073
1074 if ($subop == "editSave") {
1075
1076 $sql_exp = $_GET["s"];
1077 $descr = $_GET["d"];
1078 $label_id = db_escape_string($_GET["id"]);
1079
1080 // print "$sql_exp : $descr : $label_id";
1081
1082 $result = db_query($link, "UPDATE ttrss_labels SET
1083 sql_exp = '$sql_exp',
1084 description = '$descr'
1085 WHERE id = '$label_id'");
1086 }
1087
1088 if ($subop == "remove") {
1089
1090 if (!WEB_DEMO_MODE) {
1091
1092 $ids = split(",", $_GET["ids"]);
1093
1094 foreach ($ids as $id) {
1095 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
1096
1097 }
1098 }
1099 }
1100
1101 if ($subop == "add") {
1102
1103 if (!WEB_DEMO_MODE) {
1104
1105 $exp = $_GET["exp"];
1106
1107 $result = db_query($link,
1108 "INSERT INTO ttrss_labels (sql_exp,description)
1109 VALUES ('$exp', '$exp')");
1110 }
1111 }
1112
1113 print "<table class=\"prefAddFeed\"><tr>
1114 <td><input id=\"ladd_expr\"></td>";
1115
1116 print"<td colspan=\"4\" align=\"right\">
1117 <a class=\"button\" href=\"javascript:addLabel()\">Add label</a></td></tr>
1118 </table>";
1119
1120 $result = db_query($link, "SELECT
1121 id,sql_exp,description
1122 FROM
1123 ttrss_labels ORDER by description");
1124
1125 print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">";
1126
1127 print "<tr class=\"title\">
1128 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
1129 <a class=\"helpLink\" href=\"javascript:popupHelp(1)\">(?)</a>
1130 </td>
1131 <td width=\"40%\">Caption</td></tr>";
1132
1133 $lnum = 0;
1134
1135 while ($line = db_fetch_assoc($result)) {
1136
1137 $class = ($lnum % 2) ? "even" : "odd";
1138
1139 $label_id = $line["id"];
1140 $edit_label_id = $_GET["id"];
1141
1142 if ($subop == "edit" && $label_id != $edit_label_id) {
1143 $class .= "Grayed";
1144 }
1145
1146 print "<tr class=\"$class\" id=\"LILRR-$label_id\">";
1147
1148 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
1149 $line["description"] = htmlspecialchars($line["description"]);
1150
1151 if (!$edit_label_id || $subop != "edit") {
1152
1153 if (!$line["description"]) $line["description"] = "[No caption]";
1154
1155 print "<td><input onclick='toggleSelectRow(this);'
1156 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
1157
1158 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1159 $line["sql_exp"] . "</td>";
1160
1161 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1162 $line["description"] . "</td>";
1163
1164 } else if ($label_id != $edit_label_id) {
1165
1166 if (!$line["description"]) $line["description"] = "[No description]";
1167
1168 print "<td><input disabled=\"true\" type=\"checkbox\"
1169 id=\"LICHK-".$line["id"]."\"></td>";
1170
1171 print "<td>".$line["sql_exp"]."</td>";
1172 print "<td>".$line["description"]."</td>";
1173
1174 } else {
1175
1176 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
1177
1178 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
1179 "\"></td>";
1180
1181 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1182 "\"></td>";
1183
1184 }
1185
1186
1187 print "</tr>";
1188
1189 ++$lnum;
1190 }
1191
1192 if ($lnum == 0) {
1193 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
1194 }
1195
1196 print "</table>";
1197
1198 print "<p>";
1199
1200 if ($subop == "edit") {
1201 print "Edit label:
1202 <input type=\"submit\" class=\"button\"
1203 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
1204 <input type=\"submit\" class=\"button\"
1205 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
1206
1207 } else {
1208
1209 print "
1210 Selection:
1211 <input type=\"submit\" class=\"button\"
1212 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
1213 <input type=\"submit\" class=\"button\"
1214 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
1215 }
1216 }
1217
1218 if ($op == "error") {
1219 print "<div width=\"100%\" align='center'>";
1220 $msg = $_GET["msg"];
1221 print $msg;
1222 print "</div>";
1223 }
1224
1225 if ($op == "help") {
1226 print "<html><head>
1227 <title>Tiny Tiny RSS : Help</title>
1228 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
1229 <script type=\"text/javascript\" src=\"functions.js\"></script>
1230 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
1231 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1232 </head><body>";
1233
1234 $tid = sprintf("%d", $_GET["tid"]);
1235
1236 /* FIXME this badly needs real implementation */
1237
1238 print "<div class='helpResponse'>";
1239
1240 ?>
1241
1242 <h1>Help for SQL expressions</h1>
1243
1244 <h2>Description</h2>
1245
1246 <p>The &laquo;SQL expression&raquo; is added to WHERE clause of
1247 view feed query. You can match on ttrss_entries table fields
1248 and even use subselect to query additional information. This
1249 functionality is considered to be advanced and requires basic
1250 understanding of SQL.</p>
1251
1252 <h2>Examples</h2>
1253
1254 <pre>unread = true</pre>
1255
1256 Matches all unread articles
1257
1258 <pre>title like '%Linux%'</pre>
1259
1260 Matches all articles which mention Linux in the title. You get the idea.
1261
1262 <p>See the database schema included in the distribution package for gruesome
1263 details.</p>
1264
1265 <?
1266
1267 print "<div align='center'>
1268 <a class=\"helpLink\"
1269 href=\"javascript:window.close()\">(Close this window)</a></div>";
1270
1271 print "</div>";
1272
1273 print "</body></html>";
1274
1275 }
1276
1277 db_close($link);
1278 ?>