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