]> git.wh0rd.org - tt-rss.git/blame_incremental - backend.php
get_user_theme_path()
[tt-rss.git] / backend.php
... / ...
CommitLineData
1<?
2 session_start();
3
4 if ($_GET["debug"]) {
5 define('DEFAULT_ERROR_LEVEL', E_ALL);
6 } else {
7 define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE);
8 }
9
10 error_reporting(DEFAULT_ERROR_LEVEL);
11
12 $op = $_REQUEST["op"];
13
14 if ((!$op || $op == "rpc" || $op == "globalUpdateFeeds") && !$_REQUEST["noxml"]) {
15 header("Content-Type: application/xml");
16 }
17
18 if (!$_SESSION["uid"] && $op != "globalUpdateFeeds") {
19
20 if ($op == "rpc") {
21 print "<error error-code=\"6\"/>";
22 }
23 exit;
24 }
25
26 if (!$op) {
27 print "<error error-code=\"7\"/>";
28 exit;
29 }
30
31 define('SCHEMA_VERSION', 2);
32
33 require_once "sanity_check.php";
34 require_once "config.php";
35 require_once "db.php";
36 require_once "db-prefs.php";
37 require_once "functions.php";
38 require_once "magpierss/rss_fetch.inc";
39
40 $script_started = getmicrotime();
41
42 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
43
44 if (!$link) {
45 if (DB_TYPE == "mysql") {
46 print mysql_error();
47 }
48 // PG seems to display its own errors just fine by default.
49 return;
50 }
51
52 if (DB_TYPE == "pgsql") {
53 pg_query("set client_encoding = 'utf-8'");
54 }
55
56 $fetch = $_GET["fetch"];
57
58 /* FIXME this needs reworking */
59
60 function getGlobalCounters($link) {
61 $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries,ttrss_user_entries
62 WHERE unread = true AND
63 ttrss_user_entries.ref_id = ttrss_entries.id AND
64 owner_uid = " . $_SESSION["uid"]);
65 $c_id = db_fetch_result($result, 0, "c_id");
66 print "<counter id='global-unread' counter='$c_id'/>";
67 }
68
69 function getTagCounters($link) {
70
71 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
72 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
73 ttrss_user_entries.ref_id = ttrss_entries.id AND
74 ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND
75 post_int_id = ttrss_user_entries.int_id AND unread = true GROUP BY tag_name
76 UNION
77 select tag_name,0 as count FROM ttrss_tags
78 WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]);
79
80 $tags = array();
81
82 while ($line = db_fetch_assoc($result)) {
83 $tags[$line["tag_name"]] += $line["count"];
84 }
85
86 foreach (array_keys($tags) as $tag) {
87 $unread = $tags[$tag];
88
89 $tag = htmlspecialchars($tag);
90 print "<tag id=\"$tag\" counter=\"$unread\"/>";
91 }
92 }
93
94 function getLabelCounters($link) {
95
96 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries
97 WHERE marked = true AND ttrss_user_entries.ref_id = ttrss_entries.id AND
98 unread = true AND owner_uid = ".$_SESSION["uid"]);
99
100 $count = db_fetch_result($result, 0, "count");
101
102 print "<label id=\"-1\" counter=\"$count\"/>";
103
104 $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM
105 ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description");
106
107 while ($line = db_fetch_assoc($result)) {
108
109 $id = -$line["id"] - 11;
110
111 error_reporting (0);
112
113 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_user_entries,ttrss_entries
114 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
115 ttrss_user_entries.ref_id = ttrss_entries.id AND
116 owner_uid = ".$_SESSION["uid"]);
117
118 $count = db_fetch_result($tmp_result, 0, "count");
119
120 print "<label id=\"$id\" counter=\"$count\"/>";
121
122 error_reporting (DEFAULT_ERROR_LEVEL);
123
124 }
125 }
126
127 function getFeedCounter($link, $id) {
128
129 $result = db_query($link, "SELECT
130 count(id) as count FROM ttrss_entries,ttrss_user_entries
131 WHERE feed_id = '$id' AND unread = true
132 AND ttrss_user_entries.ref_id = ttrss_entries.id");
133
134 $count = db_fetch_result($result, 0, "count");
135
136 print "<feed id=\"$id\" counter=\"$count\"/>";
137 }
138
139 function getFeedCounters($link) {
140
141 $result = db_query($link, "SELECT id,
142 (SELECT count(id)
143 FROM ttrss_entries,ttrss_user_entries
144 WHERE feed_id = ttrss_feeds.id AND ttrss_user_entries.ref_id = ttrss_entries.id
145 AND unread = true AND owner_uid = ".$_SESSION["uid"].") as count
146 FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]);
147
148 while ($line = db_fetch_assoc($result)) {
149
150 $id = $line["id"];
151 $count = $line["count"];
152
153 print "<feed id=\"$id\" counter=\"$count\"/>";
154 }
155 }
156
157 function outputFeedList($link, $tags = false) {
158
159 print "<html><head>
160 <title>Tiny Tiny RSS : Feedlist</title>
161 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
162
163 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
164 print "<link rel=\"stylesheet\" type=\"text/css\"
165 href=\"tt-rss_compact.css\"/>";
166 } else {
167 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
168 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
169 }
170
171 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
172 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
173 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
174 </head><body onload=\"init()\">";
175
176 print "<ul class=\"feedList\" id=\"feedList\">";
177
178 $owner_uid = $_SESSION["uid"];
179
180 if (!$tags) {
181
182 /* virtual feeds */
183
184 if (get_pref($link, 'ENABLE_FEED_CATS')) {
185 print "<li class=\"feedCat\">Special</li>";
186 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
187 }
188
189 $result = db_query($link, "SELECT count(id) as num_starred
190 FROM ttrss_entries,ttrss_user_entries
191 WHERE marked = true AND
192 ttrss_user_entries.ref_id = ttrss_entries.id AND
193 unread = true AND owner_uid = '$owner_uid'");
194 $num_starred = db_fetch_result($result, 0, "num_starred");
195
196 $class = "virt";
197
198 if ($num_starred > 0) $class .= "Unread";
199
200 printFeedEntry(-1, $class, "Starred articles", $num_starred,
201 "images/mark_set.png", $link);
202
203 if (get_pref($link, 'ENABLE_FEED_CATS')) {
204 print "</li></ul>";
205 }
206
207 if (get_pref($link, 'ENABLE_LABELS')) {
208
209 $result = db_query($link, "SELECT id,sql_exp,description FROM
210 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
211
212 if (db_num_rows($result) > 0) {
213 if (get_pref($link, 'ENABLE_FEED_CATS')) {
214 print "<li class=\"feedCat\">Labels</li>";
215 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
216 } else {
217 print "<li><hr></li>";
218 }
219 }
220
221 while ($line = db_fetch_assoc($result)) {
222
223 error_reporting (0);
224
225 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries
226 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
227 ttrss_user_entries.ref_id = ttrss_entries.id
228 AND owner_uid = '$owner_uid'");
229
230 $count = db_fetch_result($tmp_result, 0, "count");
231
232 $class = "label";
233
234 if ($count > 0) {
235 $class .= "Unread";
236 }
237
238 error_reporting (DEFAULT_ERROR_LEVEL);
239
240 printFeedEntry(-$line["id"]-11,
241 $class, $line["description"], $count, "images/label.png", $link);
242
243 }
244
245 if (db_num_rows($result) > 0) {
246 if (get_pref($link, 'ENABLE_FEED_CATS')) {
247 print "</li></ul>";
248 }
249 }
250
251 }
252
253// if (!get_pref($link, 'ENABLE_FEED_CATS')) {
254 print "<li><hr></li>";
255// }
256
257 if (get_pref($link, 'ENABLE_FEED_CATS')) {
258 $order_by_qpart = "category,title";
259 } else {
260 $order_by_qpart = "title";
261 }
262
263 $result = db_query($link, "SELECT *,
264 (SELECT count(id) FROM ttrss_entries,ttrss_user_entries
265 WHERE feed_id = ttrss_feeds.id AND
266 ttrss_user_entries.ref_id = ttrss_entries.id AND
267 owner_uid = '$owner_uid') AS total,
268 (SELECT count(id) FROM ttrss_entries,ttrss_user_entries
269 WHERE feed_id = ttrss_feeds.id AND unread = true
270 AND ttrss_user_entries.ref_id = ttrss_entries.id
271 AND owner_uid = '$owner_uid') as unread,
272 (SELECT title FROM ttrss_feed_categories
273 WHERE id = cat_id) AS category
274 FROM ttrss_feeds WHERE owner_uid = '$owner_uid' ORDER BY $order_by_qpart");
275
276 $actid = $_GET["actid"];
277
278 /* real feeds */
279
280 $lnum = 0;
281
282 $total_unread = 0;
283
284 $category = "";
285
286 while ($line = db_fetch_assoc($result)) {
287
288 $feed = $line["title"];
289 $feed_id = $line["id"];
290
291 $subop = $_GET["subop"];
292
293 $total = $line["total"];
294 $unread = $line["unread"];
295
296 $tmp_category = $line["category"];
297
298 if (!$tmp_category) {
299 $tmp_category = "Uncategorized";
300 }
301
302 // $class = ($lnum % 2) ? "even" : "odd";
303
304 $class = "feed";
305
306 if ($unread > 0) $class .= "Unread";
307
308 if ($actid == $feed_id) {
309 $class .= "Selected";
310 }
311
312 $total_unread += $unread;
313
314 if ($category != $tmp_category && get_pref($link, 'ENABLE_FEED_CATS')) {
315
316 if ($category) {
317 print "</li></ul></li>";
318 }
319
320 $category = $tmp_category;
321
322 print "<li class=\"feedCat\">$category</li>";
323 print "<li id=\"feedCatHolder\"><ul class=\"feedCatList\">";
324 }
325
326 printFeedEntry($feed_id, $class, $feed, $unread,
327 "icons/$feed_id.ico", $link);
328
329 ++$lnum;
330 }
331
332 } else {
333
334 // tags
335
336 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
337 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
338 post_int_id = ttrss_user_entries.int_id AND
339 unread = true AND ref_id = ttrss_entries.id
340 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
341 UNION
342 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'
343 ORDER BY tag_name");
344
345 $tags = array();
346
347 while ($line = db_fetch_assoc($result)) {
348 $tags[$line["tag_name"]] += $line["count"];
349 }
350
351 foreach (array_keys($tags) as $tag) {
352
353 $unread = $tags[$tag];
354
355 $class = "tag";
356
357 if ($unread > 0) {
358 $class .= "Unread";
359 }
360
361 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
362
363 }
364
365 }
366
367 if (db_num_rows($result) == 0) {
368 if ($tags) {
369 $what = "tags";
370 } else {
371 $what = "feeds";
372 }
373 print "<li>No $what to display.</li>";
374 }
375
376 print "</ul>";
377
378 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
379
380 }
381
382
383 if ($op == "rpc") {
384
385 $subop = $_GET["subop"];
386
387 if ($subop == "getLabelCounters") {
388 $aid = $_GET["aid"];
389 print "<rpc-reply>";
390 getLabelCounters($link);
391 if ($aid) {
392 getFeedCounter($link, $aid);
393 }
394 print "</rpc-reply>";
395 }
396
397 if ($subop == "getFeedCounters") {
398 print "<rpc-reply>";
399 getFeedCounters($link);
400 print "</rpc-reply>";
401 }
402
403 if ($subop == "getAllCounters") {
404 print "<rpc-reply>";
405 getLabelCounters($link);
406 getFeedCounters($link);
407 getTagCounters($link);
408 getGlobalCounters($link);
409 print "</rpc-reply>";
410 }
411
412 if ($subop == "mark") {
413 $mark = $_GET["mark"];
414 $id = db_escape_string($_GET["id"]);
415
416 if ($mark == "1") {
417 $mark = "true";
418 } else {
419 $mark = "false";
420 }
421
422 // FIXME this needs collision testing
423
424 $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
425 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
426 }
427
428 if ($subop == "updateFeed") {
429 $feed_id = db_escape_string($_GET["feed"]);
430
431 $result = db_query($link,
432 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'
433 AND owner_uid = " . $_SESSION["uid"]);
434
435 if (db_num_rows($result) > 0) {
436 $feed_url = db_fetch_result($result, 0, "feed_url");
437 update_rss_feed($link, $feed_url, $feed_id);
438 }
439
440 print "<rpc-reply>";
441 getFeedCounter($link, $feed_id);
442 print "</rpc-reply>";
443
444 return;
445 }
446
447 if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") {
448
449 update_all_feeds($link, $subop == "forceUpdateAllFeeds");
450
451 $omode = $_GET["omode"];
452
453 if (!$omode) $omode = "tfl";
454
455 print "<rpc-reply>";
456 if (strchr($omode, "l")) getLabelCounters($link);
457 if (strchr($omode, "f")) getFeedCounters($link);
458 if (strchr($omode, "t")) getTagCounters($link);
459 getGlobalCounters($link);
460 print "</rpc-reply>";
461 }
462
463 if ($subop == "catchupSelected") {
464
465 $ids = split(",", $_GET["ids"]);
466
467 foreach ($ids as $id) {
468
469 db_query($link, "UPDATE ttrss_user_entries SET unread=false,last_read = NOW()
470 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
471
472 }
473
474 print "Marked active page as read.";
475 }
476
477 if ($subop == "sanityCheck") {
478
479 $error_code = 0;
480
481 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
482
483 $schema_version = db_fetch_result($result, 0, "schema_version");
484
485 if ($schema_version != SCHEMA_VERSION) {
486 $error_code = 5;
487 }
488
489 print "<error error-code='$error_code'/>";
490 }
491
492 if ($subop == "globalPurge") {
493
494 print "<rpc-reply>";
495 global_purge_old_posts($link, true);
496 print "</rpc-reply>";
497
498 }
499
500 }
501
502 if ($op == "feeds") {
503
504 $tags = $_GET["tags"];
505
506 $subop = $_GET["subop"];
507
508 if ($subop == "catchupAll") {
509 db_query($link, "UPDATE ttrss_user_entries SET
510 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
511 }
512
513 outputFeedList($link, $tags);
514
515 }
516
517 if ($op == "view") {
518
519 $id = $_GET["id"];
520 $feed_id = $_GET["feed"];
521
522 $result = db_query($link, "UPDATE ttrss_user_entries
523 SET unread = false,last_read = NOW()
524 WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
525
526 $addheader = $_GET["addheader"];
527
528 $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
529 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
530 FROM ttrss_entries,ttrss_user_entries
531 WHERE id = '$id' AND ref_id = id");
532
533 if ($addheader) {
534 print "<html><head>
535 <title>Tiny Tiny RSS : Article $id</title>
536 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
537 <script type=\"text/javascript\" src=\"functions.js\"></script>
538 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
539 </head><body>";
540 }
541
542 if ($result) {
543
544 $line = db_fetch_assoc($result);
545
546 if ($line["icon_url"]) {
547 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
548 } else {
549 $feed_icon = "&nbsp;";
550 }
551
552 if ($line["comments"] && $line["link"] != $line["comments"]) {
553 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
554 } else {
555 $entry_comments = "";
556 }
557
558 print "<div class=\"postReply\">";
559
560 print "<div class=\"postHeader\"><table width=\"100%\">";
561
562 print "<tr><td colspan='2'>" . $line["title"] . "</td></tr>";
563
564 $tmp_result = db_query($link, "SELECT DISTINCT tag_name FROM
565 ttrss_tags WHERE post_int_id = " . $line["int_id"] . "
566 ORDER BY tag_name");
567
568 $tags_str = "";
569
570 while ($tmp_line = db_fetch_assoc($tmp_result)) {
571 $tag = $tmp_line["tag_name"];
572 $tags_str .= "<a href=\"javascript:parent.viewfeed('$tag')\">$tag</a>, ";
573 }
574
575 $tags_str = preg_replace("/, $/", "", $tags_str);
576
577 print "<tr><td width='50%'>
578 <a href=\"" . $line["link"] . "\">".$line["link"]."</a>
579 $entry_comments</td>
580 <td align=\"right\">$tags_str</td></tr>";
581
582/* if ($tags_str) {
583 print "<tr><td><b>Tags:</b></td>
584 <td width='100%'>$tags_str</td></tr>";
585 } */
586
587 print "</table></div>";
588
589 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
590 print "<div class=\"postContent\">" . $line["content"] . "</div>";
591
592 print "</div>";
593
594 print "<script type=\"text/javascript\">
595 update_all_counters('$feed_id');
596 </script>";
597 }
598
599 if ($addheader) {
600 print "</body></html>";
601 }
602 }
603
604 if ($op == "viewfeed") {
605
606 $feed = $_GET["feed"];
607 $skip = $_GET["skip"];
608 $subop = $_GET["subop"];
609 $view_mode = $_GET["view"];
610 $addheader = $_GET["addheader"];
611 $limit = $_GET["limit"];
612
613 if (!$feed) {
614 return;
615 }
616
617 if (!$skip) $skip = 0;
618
619 if ($subop == "undefined") $subop = "";
620
621 if ($addheader) {
622 print "<html><head>
623 <title>Tiny Tiny RSS : Feed $feed</title>
624 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
625
626 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
627 print "<link rel=\"stylesheet\"
628 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
629
630 } else {
631 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
632 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
633 }
634 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
635 <script type=\"text/javascript\" src=\"functions.js\"></script>
636 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
637 </head><body onload='init()'>";
638 }
639
640 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
641
642 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
643 WHERE id = '$feed'");
644
645 $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
646
647 update_rss_feed($link, $feed_url, $feed);
648
649 }
650
651 if ($subop == "MarkAllRead") {
652
653 if (sprintf("%d", $feed) != 0) {
654
655 if ($feed > 0) {
656 db_query($link, "UPDATE ttrss_user_entries
657 SET unread = false,last_read = NOW()
658 WHERE feed_id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
659
660 } else if ($feed < 0 && $feed > -10) { // special, like starred
661
662 if ($feed == -1) {
663 db_query($link, "UPDATE ttrss_user_entries
664 SET unread = false,last_read = NOW()
665 WHERE marked = true AND owner_uid = ".$_SESSION["uid"]);
666 }
667
668 } else if ($feed < -10) { // label
669
670 // TODO make this more efficient
671
672 $label_id = -$feed - 11;
673
674 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
675 WHERE id = '$label_id'");
676
677 if ($tmp_result) {
678 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
679
680 db_query($link, "BEGIN");
681
682 $tmp2_result = db_query($link,
683 "SELECT
684 int_id
685 FROM
686 ttrss_user_entries,ttrss_entries
687 WHERE
688 ref_id = id AND
689 $sql_exp AND
690 owner_uid = " . $_SESSION["uid"]);
691
692 while ($tmp_line = db_fetch_assoc($tmp2_result)) {
693 db_query($link, "UPDATE
694 ttrss_user_entries
695 SET
696 unread = false, last_read = NOW()
697 WHERE
698 int_id = " . $tmp_line["int_id"]);
699 }
700
701 db_query($link, "COMMIT");
702
703/* db_query($link, "UPDATE ttrss_user_entries,ttrss_entries
704 SET unread = false,last_read = NOW()
705 WHERE $sql_exp
706 AND ref_id = id
707 AND owner_uid = ".$_SESSION["uid"]); */
708 }
709 }
710 } else { // tag
711 db_query($link, "BEGIN");
712
713 $tag_name = db_escape_string($feed);
714
715 $result = db_query($link, "SELECT post_int_id FROM ttrss_tags
716 WHERE tag_name = '$tag_name' AND owner_uid = " . $_SESSION["uid"]);
717
718 while ($line = db_fetch_assoc($result)) {
719 db_query($link, "UPDATE ttrss_user_entries SET
720 unread = false, last_read = NOW()
721 WHERE int_id = " . $line["post_int_id"]);
722 }
723 db_query($link, "COMMIT");
724 }
725
726 }
727
728 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
729
730 $search = $_GET["search"];
731
732 $search_mode = $_GET["smode"];
733
734 if ($search) {
735 $search_query_part = "(upper(title) LIKE upper('%$search%')
736 OR content LIKE '%$search%') AND";
737 } else {
738 $search_query_part = "";
739 }
740
741 $view_query_part = "";
742
743 if ($view_mode == "Starred") {
744 $view_query_part = " marked = true AND ";
745 }
746
747 if ($view_mode == "Unread") {
748 $view_query_part = " unread = true AND ";
749 }
750
751 if ($view_mode == "Unread or Starred") {
752 $view_query_part = " (unread = true OR marked = true) AND ";
753 }
754
755 if ($view_mode == "Unread or Updated") {
756 $view_query_part = " (unread = true OR last_read is NULL) AND ";
757 }
758
759/* $result = db_query($link, "SELECT count(id) AS total_entries
760 FROM ttrss_entries WHERE
761 $search_query_part
762 feed_id = '$feed'");
763
764 $total_entries = db_fetch_result($result, 0, "total_entries"); */
765
766/* $result = db_query("SELECT count(id) AS unread_entries
767 FROM ttrss_entries WHERE
768 $search_query_part
769 unread = true AND
770 feed_id = '$feed'");
771
772 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
773
774 if ($limit && $limit != "All") {
775 $limit_query_part = "LIMIT " . $limit;
776 }
777
778 $vfeed_query_part = "";
779
780 // override query strategy and enable feed display when searching globally
781 if ($search && $search_mode == "All feeds") {
782 $query_strategy_part = "id > 0";
783 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
784 id = feed_id) as feed_title,";
785 } else if (sprintf("%d", $feed) == 0) {
786 $query_strategy_part = "ttrss_entries.id > 0";
787 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
788 id = feed_id) as feed_title,";
789 } else if ($feed >= 0) {
790 $query_strategy_part = "feed_id = '$feed'";
791 } else if ($feed == -1) { // starred virtual feed
792 $query_strategy_part = "marked = true";
793 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
794 id = feed_id) as feed_title,";
795 } else if ($feed <= -10) { // labels
796 $label_id = -$feed - 11;
797
798 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
799 WHERE id = '$label_id'");
800
801 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
802
803 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
804 id = feed_id) as feed_title,";
805 } else {
806 $query_strategy_part = "id > 0"; // dumb
807 }
808
809
810 $order_by = "updated DESC";
811
812// if ($feed < -10) {
813// $order_by = "feed_id,updated DESC";
814// }
815
816 if ($feed < -10) error_reporting (0);
817
818 if (sprintf("%d", $feed) != 0) {
819
820 if ($feed > 0) {
821 $feed_kind = "Feeds";
822 } else {
823 $feed_kind = "Labels";
824 }
825
826 $result = db_query($link, "SELECT
827 id,title,updated,unread,feed_id,marked,link,last_read,
828 SUBSTRING(last_read,1,19) as last_read_noms,
829 $vfeed_query_part
830 SUBSTRING(updated,1,19) as updated_noms
831 FROM
832 ttrss_entries,ttrss_user_entries
833 WHERE
834 ttrss_user_entries.ref_id = ttrss_entries.id AND
835 owner_uid = '".$_SESSION["uid"]."' AND
836 $search_query_part
837 $view_query_part
838 $query_strategy_part ORDER BY $order_by
839 $limit_query_part");
840
841 } else {
842 // browsing by tag
843
844 $feed_kind = "Tags";
845
846 $result = db_query($link, "SELECT
847 ttrss_entries.id as id,title,updated,unread,feed_id,
848 marked,link,last_read,
849 SUBSTRING(last_read,1,19) as last_read_noms,
850 $vfeed_query_part
851 SUBSTRING(updated,1,19) as updated_noms
852 FROM
853 ttrss_entries,ttrss_user_entries,ttrss_tags
854 WHERE
855 ref_id = ttrss_entries.id AND
856 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
857 post_int_id = int_id AND tag_name = '$feed' AND
858 $view_query_part
859 $search_query_part
860 $query_strategy_part ORDER BY $order_by
861 $limit_query_part");
862 }
863
864 if (!$result) {
865 print "<tr><td colspan='4' align='center'>
866 Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>";
867 return;
868 }
869
870 $lnum = 0;
871
872 error_reporting (DEFAULT_ERROR_LEVEL);
873
874 $num_unread = 0;
875
876 while ($line = db_fetch_assoc($result)) {
877
878 $class = ($lnum % 2) ? "even" : "odd";
879
880 $id = $line["id"];
881 $feed_id = $line["feed_id"];
882
883// printf("L %d (%s) &gt; U %d (%s) = %d<br>",
884// strtotime($line["last_read_noms"]), $line["last_read_noms"],
885// strtotime($line["updated"]), $line["updated"],
886// strtotime($line["last_read"]) >= strtotime($line["updated"]));
887
888/* if ($line["last_read"] != "" && $line["updated"] != "" &&
889 strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) {
890
891 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
892 alt=\"Updated\">";
893
894 } else {
895
896 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
897 alt=\"Updated\">";
898
899 } */
900
901 if ($line["last_read"] == "" &&
902 ($line["unread"] != "t" && $line["unread"] != "1")) {
903
904 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
905 alt=\"Updated\">";
906 } else {
907 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
908 alt=\"Updated\">";
909 }
910
911 if ($line["unread"] == "t" || $line["unread"] == "1") {
912 $class .= "Unread";
913 ++$num_unread;
914 }
915
916 if ($line["marked"] == "t" || $line["marked"] == "1") {
917 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
918 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
919 } else {
920 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
921 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
922 }
923
924 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
925 $line["title"] . "</a>";
926
927 print "<tr class='$class' id='RROW-$id'>";
928 // onclick=\"javascript:view($id,$feed_id)\">
929
930 print "<td valign='center' align='center'>$update_pic</td>";
931 print "<td valign='center' align='center'>$marked_pic</td>";
932
933 print "<td width='25%'>
934 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
935
936 if ($line["feed_title"]) {
937 print "<td width='50%'>$content_link</td>";
938 print "<td width='20%'>
939 <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a></td>";
940 } else {
941 print "<td width='70%'>$content_link</td>";
942 }
943
944 print "</tr>";
945
946 ++$lnum;
947 }
948
949 if ($lnum == 0) {
950 print "<tr><td align='center'>No articles found.</td></tr>";
951 }
952
953 print "</table>";
954
955 print "<script type=\"text/javascript\">
956 document.onkeydown = hotkey_handler;
957 update_all_counters('$feed');
958 </script>";
959
960 if ($addheader) {
961 print "</body></html>";
962 }
963
964 }
965
966 if ($op == "pref-rpc") {
967
968 $subop = $_GET["subop"];
969
970 if ($subop == "unread") {
971 $ids = split(",", $_GET["ids"]);
972 foreach ($ids as $id) {
973 db_query($link, "UPDATE ttrss_user_entries SET unread = true
974 WHERE feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
975 }
976
977 print "Marked selected feeds as unread.";
978 }
979
980 if ($subop == "read") {
981 $ids = split(",", $_GET["ids"]);
982 foreach ($ids as $id) {
983 db_query($link, "UPDATE ttrss_user_entries
984 SET unread = false,last_read = NOW() WHERE
985 feed_id = '$id' AND owner_uid = ".$_SESSION["uid"]);
986 }
987
988 print "Marked selected feeds as read.";
989
990 }
991
992 }
993
994 if ($op == "pref-feeds") {
995
996 $subop = $_GET["subop"];
997
998 if ($subop == "editSave") {
999 $feed_title = db_escape_string($_GET["t"]);
1000 $feed_link = db_escape_string($_GET["l"]);
1001 $upd_intl = db_escape_string($_GET["ui"]);
1002 $purge_intl = db_escape_string($_GET["pi"]);
1003 $feed_id = db_escape_string($_GET["id"]);
1004 $cat_id = db_escape_string($_GET["catid"]);
1005
1006 if (strtoupper($upd_intl) == "DEFAULT")
1007 $upd_intl = 0;
1008
1009 if (strtoupper($purge_intl) == "DEFAULT")
1010 $purge_intl = 0;
1011
1012 if (strtoupper($purge_intl) == "DISABLED")
1013 $purge_intl = -1;
1014
1015 if ($cat_id != 0) {
1016 $category_qpart = "cat_id = '$cat_id'";
1017 } else {
1018 $category_qpart = 'cat_id = NULL';
1019 }
1020
1021 $result = db_query($link, "UPDATE ttrss_feeds SET
1022 $category_qpart,
1023 title = '$feed_title', feed_url = '$feed_link',
1024 update_interval = '$upd_intl',
1025 purge_interval = '$purge_intl'
1026 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
1027
1028 }
1029
1030 if ($subop == "remove") {
1031
1032 if (!WEB_DEMO_MODE) {
1033
1034 $ids = split(",", $_GET["ids"]);
1035
1036 foreach ($ids as $id) {
1037 db_query($link, "DELETE FROM ttrss_feeds
1038 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1039
1040 $icons_dir = ICONS_DIR;
1041
1042 if (file_exists($icons_dir . "/$id.ico")) {
1043 unlink($icons_dir . "/$id.ico");
1044 }
1045 }
1046 }
1047 }
1048
1049 if ($subop == "add") {
1050
1051 if (!WEB_DEMO_MODE) {
1052
1053 $feed_link = db_escape_string(trim($_GET["link"]));
1054
1055 $result = db_query($link,
1056 "SELECT id FROM ttrss_feeds
1057 WHERE feed_url = '$feed_link' AND owner_uid = ".$_SESSION["uid"]);
1058
1059 if (db_num_rows($result) == 0) {
1060
1061 $result = db_query($link,
1062 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title)
1063 VALUES ('".$_SESSION["uid"]."', '$feed_link', '')");
1064
1065 $result = db_query($link,
1066 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'
1067 AND owner_uid = " . $_SESSION["uid"]);
1068
1069 $feed_id = db_fetch_result($result, 0, "id");
1070
1071 if ($feed_id) {
1072 update_rss_feed($link, $feed_link, $feed_id);
1073 }
1074 } else {
1075
1076 print "<div class=\"warning\">
1077 Feed <b>$feed_link</b> already exists in the database.
1078 </div>";
1079 }
1080 }
1081 }
1082
1083 if ($subop == "addCat") {
1084
1085 if (!WEB_DEMO_MODE) {
1086
1087 $feed_cat = db_escape_string(trim($_GET["cat"]));
1088
1089 $result = db_query($link,
1090 "SELECT id FROM ttrss_feed_categories
1091 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
1092
1093 if (db_num_rows($result) == 0) {
1094
1095 $result = db_query($link,
1096 "INSERT INTO ttrss_feed_categories (owner_uid,title)
1097 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
1098
1099 } else {
1100
1101 print "<div class=\"warning\">
1102 Category <b>$feed_cat</b> already exists in the database.
1103 </div>";
1104 }
1105
1106
1107 }
1108 }
1109
1110 if ($subop == "removeCats") {
1111
1112 if (!WEB_DEMO_MODE) {
1113
1114 $ids = split(",", $_GET["ids"]);
1115
1116 foreach ($ids as $id) {
1117
1118 db_query($link, "BEGIN");
1119
1120 $result = db_query($link,
1121 "SELECT count(id) as num_feeds FROM ttrss_feeds
1122 WHERE cat_id = '$id'");
1123
1124 $num_feeds = db_fetch_result($result, 0, "num_feeds");
1125
1126 if ($num_feeds == 0) {
1127 db_query($link, "DELETE FROM ttrss_feed_categories
1128 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1129 } else {
1130
1131 print "<div class=\"warning\">
1132 Unable to delete non empty feed categories.</div>";
1133
1134 }
1135
1136 db_query($link, "COMMIT");
1137 }
1138 }
1139 }
1140
1141// print "<h3>Edit Feeds</h3>";
1142
1143 $result = db_query($link, "SELECT id,title,feed_url,last_error
1144 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1145
1146 if (db_num_rows($result) > 0) {
1147
1148 print "<div class=\"warning\">";
1149
1150 print "<b>Feeds with update errors:</b>";
1151
1152 print "<ul class=\"nomarks\">";
1153
1154 while ($line = db_fetch_assoc($result)) {
1155 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
1156 $line["last_error"];
1157 }
1158
1159 print "</ul>";
1160 print "</div>";
1161
1162 }
1163
1164 print "<p><div class=\"prefGenericAddBox\">
1165 <input id=\"fadd_link\" size=\"40\">&nbsp;<input
1166 type=\"submit\" class=\"button\"
1167 onclick=\"javascript:addFeed()\" value=\"Add feed\"></div>";
1168
1169 $feeds_sort = db_escape_string($_GET["sort"]);
1170
1171 if (!$feeds_sort || $feeds_sort == "undefined") {
1172 $feeds_sort = $_SESSION["pref_sort_feeds"];
1173 if (!$feeds_sort) $feeds_sort = "title";
1174 }
1175
1176 $_SESSION["pref_sort_feeds"] = $feeds_sort;
1177
1178 $result = db_query($link, "SELECT
1179 id,title,feed_url,substring(last_updated,1,16) as last_updated,
1180 update_interval,purge_interval,
1181 (SELECT title FROM ttrss_feed_categories
1182 WHERE id = cat_id) AS category
1183 FROM
1184 ttrss_feeds WHERE owner_uid = '".$_SESSION["uid"]."'
1185 ORDER by $feeds_sort,title");
1186
1187 if (db_num_rows($result) != 0) {
1188
1189 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1190
1191 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
1192 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1193 Select:
1194 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
1195 'FEEDR-', 'FRCHK-', true)\">All</a>,
1196 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedList',
1197 'FEEDR-', 'FRCHK-', false)\">None</a>
1198 </td</tr>";
1199
1200 print "<tr class=\"title\">
1201 <td width=\"3%\">&nbsp;</td>
1202 <td width=\"3%\">Select</td>
1203 <td width=\"20%\">
1204 <a href=\"javascript:updateFeedList('title')\">Title</a></td>
1205 <td width=\"20%\">
1206 <a href=\"javascript:updateFeedList('feed_url')\">Link</a>
1207 </td>";
1208
1209 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1210 print "<td width=\"10%\">
1211 <a href=\"javascript:updateFeedList('category')\">Category</a></td>";
1212 }
1213
1214 print "
1215 <td width=\"10%\">
1216 <a href=\"javascript:updateFeedList('update_interval')\">Update Interval</a>
1217 </td>
1218 <td width=\"10%\">
1219 <a href=\"javascript:updateFeedList('purge_interval')\">Purge Days</a>
1220 </td>
1221 </tr>";
1222
1223 $lnum = 0;
1224
1225 while ($line = db_fetch_assoc($result)) {
1226
1227 $class = ($lnum % 2) ? "even" : "odd";
1228
1229 $feed_id = $line["id"];
1230
1231 $edit_feed_id = $_GET["id"];
1232
1233 if ($subop == "edit" && $feed_id != $edit_feed_id) {
1234 $class .= "Grayed";
1235 }
1236
1237 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
1238
1239 $icon_file = ICONS_DIR . "/$feed_id.ico";
1240
1241 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1242 $feed_icon = "<img width=\"16\" height=\"16\"
1243 src=\"" . ICONS_URL . "/$feed_id.ico\">";
1244 } else {
1245 $feed_icon = "&nbsp;";
1246 }
1247 print "<td align='center'>$feed_icon</td>";
1248
1249 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1250 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
1251 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
1252
1253 if (!$edit_cat) $edit_cat = "Uncategorized";
1254
1255 if (!$edit_feed_id || $subop != "edit") {
1256
1257 print "<td><input onclick='toggleSelectRow(this);'
1258 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
1259
1260 $edit_title = truncate_string($edit_title, 40);
1261 $edit_link = truncate_string($edit_link, 60);
1262
1263 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1264 $edit_title . "</a></td>";
1265
1266 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1267 $edit_link . "</a></td>";
1268
1269 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1270 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1271 $edit_cat . "</a></td>";
1272 }
1273
1274 if ($line["update_interval"] == "0")
1275 $line["update_interval"] = "Default";
1276
1277 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1278 $line["update_interval"] . "</a></td>";
1279
1280 if ($line["purge_interval"] == "0")
1281 $line["purge_interval"] = "Default";
1282
1283 if ($line["purge_interval"] < 0)
1284 $line["purge_interval"] = "Disabled";
1285
1286 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1287 $line["purge_interval"] . "</a></td>";
1288
1289 } else if ($feed_id != $edit_feed_id) {
1290
1291 print "<td><input disabled=\"true\" type=\"checkbox\"
1292 id=\"FRCHK-".$line["id"]."\"></td>";
1293
1294 $edit_title = truncate_string($edit_title, 40);
1295 $edit_link = truncate_string($edit_link, 60);
1296
1297 print "<td>$edit_title</td>";
1298 print "<td>$edit_link</td>";
1299
1300 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1301 print "<td>$edit_cat</td>";
1302 }
1303
1304 if ($line["update_interval"] == "0")
1305 $line["update_interval"] = "Default";
1306
1307 print "<td>" . $line["update_interval"] . "</td>";
1308
1309 if ($line["purge_interval"] == "0")
1310 $line["purge_interval"] = "Default";
1311
1312 if ($line["purge_interval"] < 0)
1313 $line["purge_interval"] = "Disabled";
1314
1315 print "<td>" . $line["purge_interval"] . "</td>";
1316
1317 } else {
1318
1319 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1320
1321 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
1322 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
1323
1324 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1325
1326 print "<td>";
1327 print "<select id=\"iedit_fcat\">";
1328 print "<option id=\"0\">Uncategorized</option>";
1329
1330 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feed_categories
1331 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1332
1333 if (db_num_rows($tmp_result) > 0) {
1334 print "<option disabled>--------</option>";
1335 }
1336
1337 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1338 if ($tmp_line["id"] == $line["cat_id"]) {
1339 $is_selected = "selected";
1340 } else {
1341 $is_selected = "";
1342 }
1343 printf("<option $is_selected id='%d'>%s</option>",
1344 $tmp_line["id"], $tmp_line["title"]);
1345 }
1346
1347 print "</select></td>";
1348 print "</td>";
1349
1350 }
1351
1352 print "<td><input id=\"iedit_updintl\"
1353 value=\"".$line["update_interval"]."\"></td>";
1354 print "<td><input id=\"iedit_purgintl\"
1355 value=\"".$line["purge_interval"]."\"></td>";
1356
1357 }
1358
1359/* if (!$line["last_updated"]) $line["last_updated"] = "Never";
1360
1361 print "<td>" . $line["last_updated"] . "</td>"; */
1362
1363 print "</tr>";
1364
1365 ++$lnum;
1366 }
1367
1368 print "</table>";
1369
1370 print "<p>";
1371
1372 if ($subop == "edit") {
1373 print "Edit feed:&nbsp;
1374 <input type=\"submit\" class=\"button\"
1375 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
1376 <input type=\"submit\" class=\"button\"
1377 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1378 } else {
1379
1380 print "
1381 Selection:&nbsp;
1382 <input type=\"submit\" class=\"button\"
1383 onclick=\"javascript:selectedFeedDetails()\" value=\"Details\">
1384 <input type=\"submit\" class=\"button\"
1385 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
1386 <input type=\"submit\" class=\"button\"
1387 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
1388
1389 if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
1390 print "
1391 <input type=\"submit\" class=\"button\"
1392 onclick=\"javascript:readSelectedFeeds(true)\" value=\"Mark as read\">
1393 <input type=\"submit\" class=\"button\"
1394 onclick=\"javascript:readSelectedFeeds(false)\"
1395 value=\"Mark as unread\">&nbsp;";
1396 }
1397
1398 print "
1399 All feeds: <input type=\"submit\"
1400 class=\"button\" onclick=\"gotoExportOpml()\"
1401 value=\"Export OPML\">";
1402 }
1403 } else {
1404
1405 print "<p>No feeds defined.</p>";
1406
1407 }
1408
1409 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1410
1411 print "<h3>Edit Categories</h3>";
1412
1413 // print "<h3>Categories</h3>";
1414
1415 print "<div class=\"prefGenericAddBox\">
1416 <input id=\"fadd_cat\" size=\"40\">&nbsp;<input
1417 type=\"submit\" class=\"button\"
1418 onclick=\"javascript:addFeedCat()\" value=\"Add category\"></div>";
1419
1420 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1421 WHERE owner_uid = ".$_SESSION["uid"]."
1422 ORDER BY title");
1423
1424 if (db_num_rows($result) != 0) {
1425
1426 print "<p><table width=\"100%\" class=\"prefFeedCatList\"
1427 id=\"prefFeedCatList\">";
1428
1429 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1430 Select:
1431 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
1432 'FCATR-', 'FCCHK-', true)\">All</a>,
1433 <a href=\"javascript:selectTableRowsByIdPrefix('prefFeedCatList',
1434 'FCATR-', 'FCCHK-', false)\">None</a>
1435 </td</tr>";
1436
1437 print "<tr class=\"title\">
1438 <td width=\"10%\">Select</td><td width=\"80%\">Title</td>
1439 </tr>";
1440
1441 $lnum = 0;
1442
1443 while ($line = db_fetch_assoc($result)) {
1444
1445 $class = ($lnum % 2) ? "even" : "odd";
1446
1447 $cat_id = $line["id"];
1448
1449 $edit_cat_id = $_GET["id"];
1450
1451 if ($subop == "editCat" && $cat_id != $edit_cat_id) {
1452 $class .= "Grayed";
1453 }
1454
1455 print "<tr class=\"$class\" id=\"FCATR-$cat_id\">";
1456
1457 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1458
1459 if (!$edit_cat_id || $subop != "editCat") {
1460
1461 print "<td><input onclick='toggleSelectRow(this);'
1462 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
1463
1464 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
1465 $edit_title . "</a></td>";
1466
1467 } else if ($cat_id != $edit_cat_id) {
1468
1469 print "<td><input disabled=\"true\" type=\"checkbox\"
1470 id=\"FRCHK-".$line["id"]."\"></td>";
1471
1472 print "<td>$edit_title</td>";
1473
1474 } else {
1475
1476 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1477
1478 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
1479
1480 }
1481
1482 print "</tr>";
1483
1484 ++$lnum;
1485 }
1486
1487 print "</table>";
1488
1489 print "<p>";
1490
1491 if ($subop == "editCat") {
1492 print "Edit category:&nbsp;
1493 <input type=\"submit\" class=\"button\"
1494 onclick=\"javascript:feedCatEditCancel()\" value=\"Cancel\">
1495 <input type=\"submit\" class=\"button\"
1496 onclick=\"javascript:feedCatEditSave()\" value=\"Save\">";
1497 } else {
1498
1499 print "
1500 Selection:&nbsp;
1501 <input type=\"submit\" class=\"button\"
1502 onclick=\"javascript:editSelectedFeedCat()\" value=\"Edit\">
1503 <input type=\"submit\" class=\"button\"
1504 onclick=\"javascript:removeSelectedFeedCats()\" value=\"Remove\">";
1505
1506 }
1507
1508 } else {
1509 print "<p>No feed categories defined.</p>";
1510 }
1511 }
1512
1513 print "<h3>Import OPML</h3>
1514 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1515 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1516 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
1517 type=\"submit\" value=\"Import\">
1518 </form>";
1519
1520 }
1521
1522 if ($op == "pref-filters") {
1523
1524 $subop = $_GET["subop"];
1525
1526 if ($subop == "editSave") {
1527
1528 $regexp = db_escape_string($_GET["r"]);
1529 $descr = db_escape_string($_GET["d"]);
1530 $match = db_escape_string($_GET["m"]);
1531 $filter_id = db_escape_string($_GET["id"]);
1532 $feed_id = db_escape_string($_GET["fid"]);
1533
1534 if (!$feed_id) {
1535 $feed_id = 'NULL';
1536 } else {
1537 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
1538 }
1539
1540 $result = db_query($link, "UPDATE ttrss_filters SET
1541 reg_exp = '$regexp',
1542 description = '$descr',
1543 feed_id = $feed_id,
1544 filter_type = (SELECT id FROM ttrss_filter_types WHERE
1545 description = '$match')
1546 WHERE id = '$filter_id'");
1547 }
1548
1549 if ($subop == "remove") {
1550
1551 if (!WEB_DEMO_MODE) {
1552
1553 $ids = split(",", $_GET["ids"]);
1554
1555 foreach ($ids as $id) {
1556 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
1557
1558 }
1559 }
1560 }
1561
1562 if ($subop == "add") {
1563
1564 if (!WEB_DEMO_MODE) {
1565
1566 $regexp = db_escape_string(trim($_GET["regexp"]));
1567 $match = db_escape_string(trim($_GET["match"]));
1568 $feed_id = db_escape_string($_GET["fid"]);
1569
1570 if (!$feed_id) {
1571 $feed_id = 'NULL';
1572 } else {
1573 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
1574 }
1575
1576 $result = db_query($link,
1577 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id) VALUES
1578 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
1579 description = '$match'),'".$_SESSION["uid"]."', $feed_id)");
1580 }
1581 }
1582
1583 $result = db_query($link, "SELECT description
1584 FROM ttrss_filter_types ORDER BY description");
1585
1586 $filter_types = array();
1587
1588 while ($line = db_fetch_assoc($result)) {
1589 array_push($filter_types, $line["description"]);
1590 }
1591
1592 print "<div class=\"prefGenericAddBox\">
1593 <input id=\"fadd_regexp\" size=\"40\">&nbsp;";
1594
1595 print_select("fadd_match", "Title", $filter_types);
1596
1597 print "&nbsp;<select id=\"fadd_feed\">";
1598
1599 print "<option selected id=\"0\">All feeds</option>";
1600
1601 $result = db_query($link, "SELECT id,title FROM ttrss_feeds
1602 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1603
1604 if (db_num_rows($result) > 0) {
1605 print "<option disabled>--------</option>";
1606 }
1607
1608 while ($line = db_fetch_assoc($result)) {
1609 printf("<option id='%d'>%s</option>", $line["id"], $line["title"]);
1610 }
1611
1612 print "</select>&nbsp;";
1613
1614 print "<input type=\"submit\"
1615 class=\"button\" onclick=\"javascript:addFilter()\"
1616 value=\"Add filter\">";
1617
1618 $result = db_query($link, "SELECT
1619 ttrss_filters.id AS id,reg_exp,
1620 ttrss_filters.description AS description,
1621 ttrss_filter_types.name AS filter_type_name,
1622 ttrss_filter_types.description AS filter_type_descr,
1623 feed_id,
1624 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
1625 FROM
1626 ttrss_filters,ttrss_filter_types
1627 WHERE
1628 filter_type = ttrss_filter_types.id AND
1629 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
1630 ORDER by reg_exp");
1631
1632 if (db_num_rows($result) != 0) {
1633
1634 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
1635
1636 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1637 Select:
1638 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
1639 'FILRR-', 'FICHK-', true)\">All</a>,
1640 <a href=\"javascript:selectTableRowsByIdPrefix('prefFilterList',
1641 'FILRR-', 'FICHK-', false)\">None</a>
1642 </td</tr>";
1643
1644 print "<tr class=\"title\">
1645 <td width=\"5%\">Select</td><td width=\"30%\">Filter expression</td>
1646 <td width=\"30%\">Feed</td><td width=\"10%\">Match</td>
1647 <td width=\"30%\">Description</td></tr>";
1648
1649 $lnum = 0;
1650
1651 while ($line = db_fetch_assoc($result)) {
1652
1653 $class = ($lnum % 2) ? "even" : "odd";
1654
1655 $filter_id = $line["id"];
1656 $edit_filter_id = $_GET["id"];
1657
1658 if ($subop == "edit" && $filter_id != $edit_filter_id) {
1659 $class .= "Grayed";
1660 }
1661
1662 print "<tr class=\"$class\" id=\"FILRR-$filter_id\">";
1663
1664 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
1665 $line["description"] = htmlspecialchars($line["description"]);
1666
1667 if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
1668
1669 if (!$edit_filter_id || $subop != "edit") {
1670
1671 if (!$line["description"]) $line["description"] = "[No description]";
1672
1673 print "<td><input onclick='toggleSelectRow(this);'
1674 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
1675
1676 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1677 $line["reg_exp"] . "</td>";
1678
1679 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1680 $line["feed_title"] . "</td>";
1681
1682 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1683 $line["filter_type_descr"] . "</td>";
1684
1685 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1686 $line["description"] . "</td>";
1687
1688 } else if ($filter_id != $edit_filter_id) {
1689
1690 if (!$line["description"]) $line["description"] = "[No description]";
1691
1692 print "<td><input disabled=\"true\" type=\"checkbox\"
1693 id=\"FICHK-".$line["id"]."\"></td>";
1694
1695 print "<td>".$line["reg_exp"]."</td>";
1696 print "<td>".$line["feed_title"]."</td>";
1697 print "<td>".$line["filter_type_descr"]."</td>";
1698 print "<td>".$line["description"]."</td>";
1699
1700 } else {
1701
1702 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1703
1704 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
1705 "\"></td>";
1706
1707 print "<td>";
1708
1709 print "<select id=\"iedit_feed\">";
1710
1711 print "<option id=\"0\">All feeds</option>";
1712
1713 if (db_num_rows($result) > 0) {
1714 print "<option disabled>--------</option>";
1715 }
1716
1717 $tmp_result = db_query($link, "SELECT id,title FROM ttrss_feeds
1718 WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
1719
1720 while ($tmp_line = db_fetch_assoc($tmp_result)) {
1721 if ($tmp_line["id"] == $line["feed_id"]) {
1722 $is_selected = "selected";
1723 } else {
1724 $is_selected = "";
1725 }
1726 printf("<option $is_selected id='%d'>%s</option>",
1727 $tmp_line["id"], $tmp_line["title"]);
1728 }
1729
1730 print "</select></td>";
1731
1732 print "<td>";
1733 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
1734 print "</td>";
1735
1736 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1737 "\"></td>";
1738
1739 print "</td>";
1740 }
1741
1742 print "</tr>";
1743
1744 ++$lnum;
1745 }
1746
1747 if ($lnum == 0) {
1748 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
1749 }
1750
1751 print "</table>";
1752
1753 print "<p>";
1754
1755 if ($subop == "edit") {
1756 print "Edit feed:
1757 <input type=\"submit\" class=\"button\"
1758 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
1759 <input type=\"submit\" class=\"button\"
1760 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
1761
1762 } else {
1763
1764 print "
1765 Selection:
1766 <input type=\"submit\" class=\"button\"
1767 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
1768 <input type=\"submit\" class=\"button\"
1769 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
1770 }
1771
1772 } else {
1773
1774 print "<p>No filters defined.</p>";
1775
1776 }
1777 }
1778
1779 if ($op == "pref-labels") {
1780
1781 $subop = $_GET["subop"];
1782
1783 if ($subop == "test") {
1784
1785 $expr = $_GET["expr"];
1786 $descr = $_GET["descr"];
1787
1788 print "<div class='infoBoxContents'>";
1789
1790 print "<h1>Label &laquo;$descr&raquo;</h1>";
1791
1792// print "<p><b>Expression</b>: $expr</p>";
1793
1794 $result = db_query($link,
1795 "SELECT count(id) AS num_matches
1796 FROM ttrss_entries,ttrss_user_entries
1797 WHERE ($expr) AND
1798 ttrss_user_entries.ref_id = ttrss_entries.id AND
1799 owner_uid = " . $_SESSION["uid"]);
1800
1801 $num_matches = db_fetch_result($result, 0, "num_matches");;
1802
1803 if ($num_matches > 0) {
1804
1805 print "<p>Query returned <b>$num_matches</b> matches, first 5:</p>";
1806
1807 $result = db_query($link,
1808 "SELECT title,
1809 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
1810 FROM ttrss_entries,ttrss_user_entries
1811 WHERE ($expr) AND
1812 ttrss_user_entries.ref_id = ttrss_entries.id
1813 AND owner_uid = " . $_SESSION["uid"] . "
1814 ORDER BY date_entered DESC LIMIT 5");
1815
1816 print "<ul class=\"nomarks\">";
1817 while ($line = db_fetch_assoc($result)) {
1818 print "<li>".$line["title"].
1819 " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
1820 }
1821 print "</ul>";
1822
1823 } else {
1824 print "<p>Query didn't return any matches.</p>";
1825 }
1826
1827 print "</div>";
1828
1829 print "<div align='center'>
1830 <input type='submit' class='button'
1831 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
1832 return;
1833 }
1834
1835 if ($subop == "editSave") {
1836
1837 $sql_exp = $_GET["s"];
1838 $descr = $_GET["d"];
1839 $label_id = db_escape_string($_GET["id"]);
1840
1841// print "$sql_exp : $descr : $label_id";
1842
1843 $result = db_query($link, "UPDATE ttrss_labels SET
1844 sql_exp = '$sql_exp',
1845 description = '$descr'
1846 WHERE id = '$label_id'");
1847 }
1848
1849 if ($subop == "remove") {
1850
1851 if (!WEB_DEMO_MODE) {
1852
1853 $ids = split(",", $_GET["ids"]);
1854
1855 foreach ($ids as $id) {
1856 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
1857
1858 }
1859 }
1860 }
1861
1862 if ($subop == "add") {
1863
1864 if (!WEB_DEMO_MODE) {
1865
1866 // no escaping is done here on purpose
1867 $exp = trim($_GET["exp"]);
1868
1869 $result = db_query($link,
1870 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
1871 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
1872 }
1873 }
1874
1875 print "<div class=\"prefGenericAddBox\">
1876 <input size=\"40\" id=\"ladd_expr\">&nbsp;";
1877
1878 print"<input type=\"submit\" class=\"button\"
1879 onclick=\"javascript:addLabel()\" value=\"Add label\"></div>";
1880
1881 $result = db_query($link, "SELECT
1882 id,sql_exp,description
1883 FROM
1884 ttrss_labels
1885 WHERE
1886 owner_uid = ".$_SESSION["uid"]."
1887 ORDER by description");
1888
1889 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1890
1891 if (db_num_rows($result) != 0) {
1892
1893 print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">";
1894
1895 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1896 Select:
1897 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
1898 'LILRR-', 'LICHK-', true)\">All</a>,
1899 <a href=\"javascript:selectTableRowsByIdPrefix('prefLabelList',
1900 'LILRR-', 'LICHK-', false)\">None</a>
1901 </td</tr>";
1902
1903 print "<tr class=\"title\">
1904 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
1905 <a class=\"helpLink\" href=\"javascript:popupHelp(1)\">(?)</a>
1906 </td>
1907 <td width=\"40%\">Caption</td></tr>";
1908
1909 $lnum = 0;
1910
1911 while ($line = db_fetch_assoc($result)) {
1912
1913 $class = ($lnum % 2) ? "even" : "odd";
1914
1915 $label_id = $line["id"];
1916 $edit_label_id = $_GET["id"];
1917
1918 if ($subop == "edit" && $label_id != $edit_label_id) {
1919 $class .= "Grayed";
1920 }
1921
1922 print "<tr class=\"$class\" id=\"LILRR-$label_id\">";
1923
1924 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
1925 $line["description"] = htmlspecialchars($line["description"]);
1926
1927 if (!$edit_label_id || $subop != "edit") {
1928
1929 if (!$line["description"]) $line["description"] = "[No caption]";
1930
1931 print "<td><input onclick='toggleSelectRow(this);'
1932 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
1933
1934 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1935 $line["sql_exp"] . "</td>";
1936
1937 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1938 $line["description"] . "</td>";
1939
1940 } else if ($label_id != $edit_label_id) {
1941
1942 if (!$line["description"]) $line["description"] = "[No description]";
1943
1944 print "<td><input disabled=\"true\" type=\"checkbox\"
1945 id=\"LICHK-".$line["id"]."\"></td>";
1946
1947 print "<td>".$line["sql_exp"]."</td>";
1948 print "<td>".$line["description"]."</td>";
1949
1950 } else {
1951
1952 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1953
1954 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
1955 "\"></td>";
1956
1957 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1958 "\"></td>";
1959
1960 }
1961
1962
1963 print "</tr>";
1964
1965 ++$lnum;
1966 }
1967
1968 if ($lnum == 0) {
1969 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
1970 }
1971
1972 print "</table>";
1973
1974 print "<p>";
1975
1976 if ($subop == "edit") {
1977 print "Edit label:
1978 <input type=\"submit\" class=\"button\"
1979 onclick=\"javascript:labelTest()\" value=\"Test\">
1980 <input type=\"submit\" class=\"button\"
1981 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
1982 <input type=\"submit\" class=\"button\"
1983 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
1984
1985 } else {
1986
1987 print "
1988 Selection:
1989 <input type=\"submit\" class=\"button\"
1990 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
1991 <input type=\"submit\" class=\"button\"
1992 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
1993 }
1994 } else {
1995 print "<p>No labels defined.</p>";
1996 }
1997 }
1998
1999 if ($op == "error") {
2000 print "<div width=\"100%\" align='center'>";
2001 $msg = $_GET["msg"];
2002 print $msg;
2003 print "</div>";
2004 }
2005
2006 if ($op == "help") {
2007 print "<html><head>
2008 <title>Tiny Tiny RSS : Help</title>
2009 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2010 <script type=\"text/javascript\" src=\"functions.js\"></script>
2011 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2012 </head><body>";
2013
2014 $tid = sprintf("%d", $_GET["tid"]);
2015
2016 /* FIXME this badly needs real implementation */
2017
2018 print "<div class='helpResponse'>";
2019
2020 ?>
2021
2022 <h1>Help for SQL expressions</h1>
2023
2024 <h2>Description</h2>
2025
2026 <p>The &laquo;SQL expression&raquo; is added to WHERE clause of
2027 view feed query. You can match on ttrss_entries table fields
2028 and even use subselect to query additional information. This
2029 functionality is considered to be advanced and requires basic
2030 understanding of SQL.</p>
2031
2032 <h2>Examples</h2>
2033
2034 <pre>unread = true</pre>
2035
2036 Matches all unread articles
2037
2038 <pre>title like '%Linux%'</pre>
2039
2040 Matches all articles which mention Linux in the title. You get the idea.
2041
2042 <p>See the database schema included in the distribution package for gruesome
2043 details.</p>
2044
2045 <?
2046
2047 print "<div align='center'>
2048 <a class=\"helpLink\"
2049 href=\"javascript:window.close()\">(Close this window)</a></div>";
2050
2051 print "</div>";
2052
2053 print "</body></html>";
2054
2055 }
2056
2057 if ($op == "dlg") {
2058 $id = $_GET["id"];
2059 $param = $_GET["param"];
2060
2061 if ($id == "quickAddFeed") {
2062 print "Feed URL: <input
2063 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2064 id=\"qafInput\">
2065 <input class=\"button\"
2066 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
2067 <input class=\"button\"
2068 type=\"submit\" onclick=\"javascript:closeDlg()\"
2069 value=\"Cancel\">";
2070 }
2071
2072 if ($id == "quickDelFeed") {
2073
2074 $param = db_escape_string($param);
2075
2076 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
2077
2078 if ($result) {
2079
2080 $f_title = db_fetch_result($result, 0, "title");
2081
2082 print "Remove current feed ($f_title)?&nbsp;
2083 <input class=\"button\"
2084 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
2085 <input class=\"button\"
2086 type=\"submit\" onclick=\"javascript:closeDlg()\"
2087 value=\"Cancel\">";
2088 } else {
2089 print "Error: Feed $param not found.&nbsp;
2090 <input class=\"button\"
2091 type=\"submit\" onclick=\"javascript:closeDlg()\"
2092 value=\"Cancel\">";
2093 }
2094 }
2095
2096 if ($id == "search") {
2097
2098 print "<input id=\"searchbox\" class=\"extSearch\"
2099 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
2100 onchange=\"javascript:search()\">
2101 <select id=\"searchmodebox\">
2102 <option selected>All feeds</option>
2103 <option>This feed</option>
2104 </select>
2105 <input type=\"submit\"
2106 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
2107 <input class=\"button\"
2108 type=\"submit\" onclick=\"javascript:closeDlg()\"
2109 value=\"Close\">";
2110
2111 }
2112
2113 }
2114
2115 // update feeds of all users, may be used anonymously
2116 if ($op == "globalUpdateFeeds") {
2117
2118 $result = db_query($link, "SELECT id FROM ttrss_users");
2119
2120 while ($line = db_fetch_assoc($result)) {
2121 $user_id = $line["id"];
2122// print "<!-- updating feeds of uid $user_id -->";
2123 update_all_feeds($link, false, $user_id);
2124 }
2125
2126 print "<rpc-reply>
2127 <message msg=\"All feeds updated\"/>
2128 </rpc-reply>";
2129
2130 }
2131
2132 if ($op == "pref-prefs") {
2133
2134 $subop = $_REQUEST["subop"];
2135
2136 if ($subop == "Save configuration") {
2137
2138 if (WEB_DEMO_MODE) {
2139 header("Location: prefs.php");
2140 return;
2141 }
2142
2143 $_SESSION["prefs_op_result"] = "save-config";
2144
2145 foreach (array_keys($_POST) as $pref_name) {
2146
2147 $pref_name = db_escape_string($pref_name);
2148 $value = db_escape_string($_POST[$pref_name]);
2149
2150 $result = db_query($link, "SELECT type_name
2151 FROM ttrss_prefs,ttrss_prefs_types
2152 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
2153
2154 if (db_num_rows($result) > 0) {
2155
2156 $type_name = db_fetch_result($result, 0, "type_name");
2157
2158// print "$pref_name : $type_name : $value<br>";
2159
2160 if ($type_name == "bool") {
2161 if ($value == "1") {
2162 $value = "true";
2163 } else {
2164 $value = "false";
2165 }
2166 } else if ($type_name == "integer") {
2167 $value = sprintf("%d", $value);
2168 }
2169
2170// print "$pref_name : $type_name : $value<br>";
2171
2172 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
2173 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
2174
2175 }
2176
2177 header("Location: prefs.php");
2178
2179 }
2180
2181 } else if ($subop == "getHelp") {
2182
2183 $pref_name = db_escape_string($_GET["pn"]);
2184
2185 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
2186 WHERE pref_name = '$pref_name'");
2187
2188 if (db_num_rows($result) > 0) {
2189 $help_text = db_fetch_result($result, 0, "help_text");
2190 print $help_text;
2191 } else {
2192 print "Unknown option: $pref_name";
2193 }
2194
2195 } else if ($subop == "Change password") {
2196
2197 if (WEB_DEMO_MODE) {
2198 header("Location: prefs.php");
2199 return;
2200 }
2201
2202 $old_pw = $_POST["OLD_PASSWORD"];
2203 $new_pw = $_POST["OLD_PASSWORD"];
2204
2205 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
2206 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
2207
2208 $active_uid = $_SESSION["uid"];
2209
2210 if ($old_pw && $new_pw) {
2211
2212 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
2213
2214 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
2215 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
2216 pwd_hash = '$old_pw_hash')");
2217
2218 if (db_num_rows($result) == 1) {
2219 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
2220 WHERE id = '$active_uid'");
2221
2222 $_SESSION["pwd_change_result"] = "ok";
2223 } else {
2224 $_SESSION["pwd_change_result"] = "failed";
2225 }
2226 }
2227
2228 header("Location: prefs.php");
2229
2230 } else if ($subop == "Reset to defaults") {
2231
2232 if (WEB_DEMO_MODE) {
2233 header("Location: prefs.php");
2234 return;
2235 }
2236
2237 $_SESSION["prefs_op_result"] = "reset-to-defaults";
2238
2239 if (DB_TYPE == "pgsql") {
2240 db_query($link,"UPDATE ttrss_user_prefs
2241 SET value = ttrss_prefs.def_value
2242 WHERE owner_uid = '".$_SESSION["uid"]."' AND
2243 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
2244 } else {
2245 db_query($link, "DELETE FROM ttrss_user_prefs
2246 WHERE owner_uid = ".$_SESSION["uid"]);
2247 initialize_user_prefs($link, $_SESSION["uid"]);
2248 }
2249
2250 header("Location: prefs.php");
2251
2252 } else if ($subop == "Change theme") {
2253
2254 $theme = db_escape_string($_POST["theme"]);
2255
2256 if ($theme == "Default") {
2257 $theme_qpart = 'NULL';
2258 } else {
2259 $theme_qpart = "'$theme'";
2260 }
2261
2262 db_query($link, "UPDATE ttrss_users SET
2263 theme_id = (SELECT id FROM ttrss_themes WHERE
2264 theme_name = '$theme') WHERE id = " . $_SESSION["uid"]);
2265
2266 header("Location: prefs.php");
2267
2268 } else {
2269
2270 if (!SINGLE_USER_MODE) {
2271
2272 $result = db_query($link, "SELECT id FROM ttrss_users
2273 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
2274 pwd_hash = 'SHA1:".sha1("password")."')");
2275
2276 if (db_num_rows($result) != 0) {
2277 print "<div class=\"warning\">
2278 Your password is at default value, please change it.
2279 </div>";
2280 }
2281
2282 if ($_SESSION["pwd_change_result"] == "failed") {
2283 print "<div class=\"warning\">
2284 There was an error while changing your password.
2285 </div>";
2286 }
2287
2288 if ($_SESSION["pwd_change_result"] == "ok") {
2289 print "<div class=\"notice\">
2290 Password changed successfully.
2291 </div>";
2292 }
2293
2294 $_SESSION["pwd_change_result"] = "";
2295
2296 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
2297 print "<div class=\"notice\">
2298 Your configuration was reset to defaults.
2299 </div>";
2300 }
2301
2302 if ($_SESSION["prefs_op_result"] == "save-config") {
2303 print "<div class=\"notice\">
2304 Your configuration was saved successfully.
2305 </div>";
2306 }
2307
2308 $_SESSION["prefs_op_result"] = "";
2309
2310 print "<form action=\"backend.php\" method=\"POST\">";
2311
2312 print "<table width=\"100%\" class=\"prefPrefsList\">";
2313 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
2314
2315 print "<tr><td width=\"40%\">Old password</td>";
2316 print "<td><input class=\"editbox\" type=\"password\"
2317 name=\"OLD_PASSWORD\"></td></tr>";
2318
2319 print "<tr><td width=\"40%\">New password</td>";
2320
2321 print "<td><input class=\"editbox\" type=\"password\"
2322 name=\"NEW_PASSWORD\"></td></tr>";
2323
2324 print "</table>";
2325
2326 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2327
2328 print "<p><input class=\"button\" type=\"submit\"
2329 value=\"Change password\" name=\"subop\">";
2330
2331 print "</form>";
2332
2333 }
2334
2335 print "<form action=\"backend.php\" method=\"POST\">";
2336
2337 print "<table width=\"100%\" class=\"prefPrefsList\">";
2338 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
2339
2340 print "<tr><td width=\"40%\">Select theme</td>";
2341
2342 print "<td><select name=\"theme\">";
2343
2344 print "<option>Default</option>";
2345
2346 $result = db_query($link, "SELECT
2347 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
2348
2349 $user_theme_id = db_fetch_result($result, 0, "theme_id");
2350
2351 $result = db_query($link, "SELECT
2352 id,theme_name FROM ttrss_themes ORDER BY theme_name");
2353
2354 if (db_num_rows($result) > 0) {
2355 print "<option disabled>--------</option>";
2356 while ($line = db_fetch_assoc($result)) {
2357 if ($line["id"] == $user_theme_id) {
2358 $selected = "selected";
2359 } else {
2360 $selected = "";
2361 }
2362 print "<option $selected>" . $line["theme_name"] . "</option>";
2363 }
2364 }
2365
2366 print "</select></td></tr>";
2367 print "</table>";
2368 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2369 print "<p><input class=\"button\" type=\"submit\"
2370 value=\"Change theme\" name=\"subop\">";
2371 print "</form>";
2372
2373 $result = db_query($link, "SELECT
2374 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
2375 section_name,def_value
2376 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
2377 WHERE type_id = ttrss_prefs_types.id AND
2378 section_id = ttrss_prefs_sections.id AND
2379 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
2380 owner_uid = ".$_SESSION["uid"]."
2381 ORDER BY section_id,short_desc");
2382
2383 print "<form action=\"backend.php\" method=\"POST\">";
2384
2385 $lnum = 0;
2386
2387 $active_section = "";
2388
2389 while ($line = db_fetch_assoc($result)) {
2390
2391 if ($active_section != $line["section_name"]) {
2392
2393 if ($active_section != "") {
2394 print "</table>";
2395 }
2396
2397 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
2398
2399 $active_section = $line["section_name"];
2400
2401 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
2402// print "<tr class=\"title\">
2403// <td width=\"25%\">Option</td><td>Value</td></tr>";
2404
2405 $lnum = 0;
2406 }
2407
2408// $class = ($lnum % 2) ? "even" : "odd";
2409
2410 print "<tr>";
2411
2412 $type_name = $line["type_name"];
2413 $pref_name = $line["pref_name"];
2414 $value = $line["value"];
2415 $def_value = $line["def_value"];
2416 $help_text = $line["help_text"];
2417
2418 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
2419
2420 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
2421
2422 print "</td>";
2423
2424 print "<td>";
2425
2426 if ($type_name == "bool") {
2427// print_select($pref_name, $value, array("true", "false"));
2428
2429 if ($value == "true") {
2430 $value = "Yes";
2431 } else {
2432 $value = "No";
2433 }
2434
2435 print_radio($pref_name, $value, array("Yes", "No"));
2436
2437 } else {
2438 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
2439 }
2440
2441 print "</td>";
2442
2443 print "</tr>";
2444
2445 $lnum++;
2446 }
2447
2448 print "</table>";
2449
2450 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
2451
2452 print "<p><input class=\"button\" type=\"submit\"
2453 name=\"subop\" value=\"Save configuration\">";
2454
2455 print "&nbsp;<input class=\"button\" type=\"submit\"
2456 name=\"subop\" value=\"Reset to defaults\"></p>";
2457
2458 print "</form>";
2459
2460 }
2461
2462 }
2463
2464 if ($op == "pref-users") {
2465
2466 $subop = $_GET["subop"];
2467
2468 if ($subop == "editSave") {
2469
2470 if (!WEB_DEMO_MODE) {
2471
2472 $login = db_escape_string($_GET["l"]);
2473 $uid = db_escape_string($_GET["id"]);
2474 $access_level = sprintf("%d", $_GET["al"]);
2475
2476 db_query($link, "UPDATE ttrss_users SET login = '$login', access_level = '$access_level' WHERE id = '$uid'");
2477
2478 }
2479 } else if ($subop == "remove") {
2480
2481 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
2482
2483 $ids = split(",", $_GET["ids"]);
2484
2485 foreach ($ids as $id) {
2486 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
2487
2488 }
2489 }
2490 } else if ($subop == "add") {
2491
2492 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
2493
2494 $login = db_escape_string(trim($_GET["login"]));
2495 $tmp_user_pwd = make_password(8);
2496 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
2497
2498 db_query($link, "INSERT INTO ttrss_users (login,pwd_hash,access_level)
2499 VALUES ('$login', '$pwd_hash', 0)");
2500
2501
2502 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
2503 login = '$login' AND pwd_hash = '$pwd_hash'");
2504
2505 if (db_num_rows($result) == 1) {
2506
2507 $new_uid = db_fetch_result($result, 0, "id");
2508
2509 print "<div class=\"notice\">Added user <b>".$_GET["login"].
2510 "</b> with password <b>$tmp_user_pwd</b>.</div>";
2511
2512 initialize_user($link, $new_uid);
2513
2514 } else {
2515
2516 print "<div class=\"warning\">Error while adding user <b>".
2517 $_GET["login"].".</b></div>";
2518
2519 }
2520 }
2521 } else if ($subop == "resetPass") {
2522
2523 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
2524
2525 $uid = db_escape_string($_GET["id"]);
2526
2527 $result = db_query($link, "SELECT login FROM ttrss_users WHERE id = '$uid'");
2528
2529 $login = db_fetch_result($result, 0, "login");
2530 $tmp_user_pwd = make_password(8);
2531 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
2532
2533 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
2534 WHERE id = '$uid'");
2535
2536 print "<div class=\"notice\">Changed password of
2537 user <b>$login</b> to <b>$tmp_user_pwd</b>.</div>";
2538
2539 }
2540 }
2541
2542 print "<div class=\"prefGenericAddBox\">
2543 <input id=\"uadd_box\" size=\"40\">&nbsp;";
2544
2545 print"<input type=\"submit\" class=\"button\"
2546 onclick=\"javascript:addUser()\" value=\"Add user\"></div>";
2547
2548 $result = db_query($link, "SELECT
2549 id,login,access_level,
2550 SUBSTRING(last_login,1,16) as last_login
2551 FROM
2552 ttrss_users
2553 ORDER by login");
2554
2555 print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
2556
2557 print "<p><table width=\"100%\" class=\"prefUserList\" id=\"prefUserList\">";
2558
2559 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2560 Select:
2561 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
2562 'UMRR-', 'UMCHK-', true)\">All</a>,
2563 <a href=\"javascript:selectTableRowsByIdPrefix('prefUserList',
2564 'UMRR-', 'UMCHK-', false)\">None</a>
2565 </td</tr>";
2566
2567 print "<tr class=\"title\">
2568 <td width=\"5%\">Select</td>
2569 <td width='30%'>Username</td>
2570 <td width='30%'>Access Level</td>
2571 <td width='30%'>Last login</td></tr>";
2572
2573 $lnum = 0;
2574
2575 while ($line = db_fetch_assoc($result)) {
2576
2577 $class = ($lnum % 2) ? "even" : "odd";
2578
2579 $uid = $line["id"];
2580 $edit_uid = $_GET["id"];
2581
2582 if ($uid == $_SESSION["uid"] || ($subop == "edit" && $uid != $edit_uid)) {
2583 $class .= "Grayed";
2584 }
2585
2586 print "<tr class=\"$class\" id=\"UMRR-$uid\">";
2587
2588 $line["login"] = htmlspecialchars($line["login"]);
2589
2590 if ($uid == $_SESSION["uid"]) {
2591
2592 print "<td><input disabled=\"true\" type=\"checkbox\"
2593 id=\"UMCHK-".$line["id"]."\"></td>";
2594
2595 print "<td>".$line["login"]."</td>";
2596 print "<td>".$line["access_level"]."</td>";
2597
2598 } else if (!$edit_uid || $subop != "edit") {
2599
2600 print "<td><input onclick='toggleSelectRow(this);'
2601 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
2602
2603 print "<td><a href=\"javascript:editUser($uid);\">" .
2604 $line["login"] . "</td>";
2605
2606 print "<td><a href=\"javascript:editUser($uid);\">" .
2607 $line["access_level"] . "</td>";
2608
2609 } else if ($uid != $edit_uid) {
2610
2611 print "<td><input disabled=\"true\" type=\"checkbox\"
2612 id=\"UMCHK-".$line["id"]."\"></td>";
2613
2614 print "<td>".$line["login"]."</td>";
2615 print "<td>".$line["access_level"]."</td>";
2616
2617 } else {
2618
2619 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
2620
2621 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
2622 "\"></td>";
2623
2624 print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
2625 "\"></td>";
2626
2627 }
2628
2629 print "<td>".$line["last_login"]."</td>";
2630
2631 print "</tr>";
2632
2633 ++$lnum;
2634 }
2635
2636 print "</table>";
2637
2638 print "<p>";
2639
2640 if ($subop == "edit") {
2641 print "Edit label:
2642 <input type=\"submit\" class=\"button\"
2643 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">
2644 <input type=\"submit\" class=\"button\"
2645 onclick=\"javascript:userEditSave()\" value=\"Save\">";
2646
2647 } else {
2648
2649 print "
2650 Selection:
2651 <input type=\"submit\" class=\"button\"
2652 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
2653 <input type=\"submit\" class=\"button\"
2654 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
2655 <input type=\"submit\" class=\"button\"
2656 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
2657 <input type=\"submit\" class=\"button\"
2658 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
2659
2660 }
2661 }
2662
2663 if ($op == "user-details") {
2664
2665 if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
2666 return;
2667 }
2668
2669/* print "<html><head>
2670 <title>Tiny Tiny RSS : User Details</title>
2671 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2672 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2673 </head><body>"; */
2674
2675 $uid = sprintf("%d", $_GET["id"]);
2676
2677 print "<div class='infoBoxContents'>";
2678
2679 $result = db_query($link, "SELECT login,
2680 SUBSTRING(last_login,1,16) AS last_login,
2681 access_level,
2682 (SELECT COUNT(int_id) FROM ttrss_user_entries
2683 WHERE owner_uid = id) AS stored_articles
2684 FROM ttrss_users
2685 WHERE id = '$uid'");
2686
2687 if (db_num_rows($result) == 0) {
2688 print "<h1>User not found</h1>";
2689 return;
2690 }
2691
2692 print "<h1>User Details</h1>";
2693
2694 print "<table width='100%'>";
2695
2696 $login = db_fetch_result($result, 0, "login");
2697 $last_login = db_fetch_result($result, 0, "last_login");
2698 $access_level = db_fetch_result($result, 0, "access_level");
2699 $stored_articles = db_fetch_result($result, 0, "stored_articles");
2700
2701 print "<tr><td>Username</td><td>$login</td></tr>";
2702 print "<tr><td>Access level</td><td>$access_level</td></tr>";
2703 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
2704 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
2705
2706 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
2707 WHERE owner_uid = '$uid'");
2708
2709 $num_feeds = db_fetch_result($result, 0, "num_feeds");
2710
2711 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
2712
2713/* $result = db_query($link, "SELECT
2714 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
2715 FROM ttrss_user_entries,ttrss_entries
2716 WHERE owner_uid = '$uid' AND ref_id = id");
2717
2718 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
2719
2720 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
2721
2722 print "</table>";
2723
2724 print "<h1>Subscribed feeds</h1>";
2725
2726 $result = db_query($link, "SELECT id,title,feed_url FROM ttrss_feeds
2727 WHERE owner_uid = '$uid' ORDER BY title");
2728
2729 print "<ul class=\"nomarks\">";
2730
2731 while ($line = db_fetch_assoc($result)) {
2732
2733 $icon_file = ICONS_URL."/".$line["id"].".ico";
2734
2735 if (file_exists($icon_file) && filesize($icon_file) > 0) {
2736 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
2737 } else {
2738 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
2739 }
2740
2741 print "<li>$feed_icon&nbsp;<a href=\"".$line["feed_url"]."\">".$line["title"]."</a></li>";
2742 }
2743
2744 print "</ul>";
2745
2746 print "</div>";
2747
2748 print "<div align='center'>
2749 <input type='submit' class='button'
2750 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2751
2752// print "</body></html>";
2753
2754 }
2755
2756 if ($op == "feed-details") {
2757
2758 $feed_id = $_GET["id"];
2759
2760 $result = db_query($link,
2761 "SELECT
2762 title,feed_url,last_updated,icon_url,site_url,
2763 (SELECT COUNT(int_id) FROM ttrss_user_entries
2764 WHERE feed_id = id) AS total,
2765 (SELECT COUNT(int_id) FROM ttrss_user_entries
2766 WHERE feed_id = id AND unread = true) AS unread,
2767 (SELECT COUNT(int_id) FROM ttrss_user_entries
2768 WHERE feed_id = id AND marked = true) AS marked
2769 FROM ttrss_feeds
2770 WHERE id = '$feed_id' AND owner_uid = ".$_SESSION["uid"]);
2771
2772 if (db_num_rows($result) == 0) return;
2773
2774 $title = db_fetch_result($result, 0, "title");
2775 $last_updated = db_fetch_result($result, 0, "last_updated");
2776 $feed_url = db_fetch_result($result, 0, "feed_url");
2777 $icon_url = db_fetch_result($result, 0, "icon_url");
2778 $total = db_fetch_result($result, 0, "total");
2779 $unread = db_fetch_result($result, 0, "unread");
2780 $marked = db_fetch_result($result, 0, "marked");
2781 $site_url = db_fetch_result($result, 0, "site_url");
2782
2783 $result = db_query($link, "SELECT COUNT(id) AS subscribed
2784 FROM ttrss_feeds WHERE feed_url = '$feed_url'");
2785
2786 $subscribed = db_fetch_result($result, 0, "subscribed");
2787
2788 print "<div class=\"infoBoxContents\">";
2789
2790 $icon_file = ICONS_DIR . "/$feed_id.ico";
2791
2792 if (file_exists($icon_file) && filesize($icon_file) > 0) {
2793 $feed_icon = "<img width=\"16\" height=\"16\"
2794 src=\"" . ICONS_URL . "/$feed_id.ico\">";
2795 } else {
2796 $feed_icon = "";
2797 }
2798
2799 print "<h1>$feed_icon $title</h1>";
2800
2801 print "<table width='100%'>";
2802
2803 if ($site_url) {
2804 print "<tr><td width='30%'>Link</td>
2805 <td><a href=\"$site_url\">$site_url</a>
2806 <a href=\"$feed_url\">(feed)</a></td>
2807 </td></tr>";
2808 } else {
2809 print "<tr><td width='30%'>Feed URL</td>
2810 <td><a href=\"$feed_url\">$feed_url</a></td></tr>";
2811 }
2812 print "<tr><td>Last updated</td><td>$last_updated</td></tr>";
2813 print "<tr><td>Total articles</td><td>$total</td></tr>";
2814 print "<tr><td>Unread articles</td><td>$unread</td></tr>";
2815 print "<tr><td>Starred articles</td><td>$marked</td></tr>";
2816 print "<tr><td>Subscribed users</td><td>$subscribed</td></tr>";
2817
2818 print "</table>";
2819
2820 $result = db_query($link, "SELECT title,
2821 SUBSTRING(updated,1,16) AS updated,unread
2822 FROM ttrss_entries,ttrss_user_entries
2823 WHERE ref_id = id AND feed_id = '$feed_id'
2824 ORDER BY date_entered DESC LIMIT 5");
2825
2826 if (db_num_rows($result) > 0) {
2827
2828 print "<h1>Latest headlines</h1>";
2829
2830 print "<ul class=\"nomarks\">";
2831
2832 while ($line = db_fetch_assoc($result)) {
2833 if ($line["unread"] == "t" || $line["unread"] == "1") {
2834 $line["title"] = "<b>" . $line["title"] . "</b>";
2835 }
2836 print "<li>" . $line["title"].
2837 "&nbsp;<span class=\"insensitive\">(" .$line["updated"].")</span></li>";
2838 }
2839
2840 print "</ul>";
2841
2842 print "</div>";
2843
2844 print "<div align='center'>
2845 <input type='submit' class='button'
2846 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
2847 }
2848 }
2849
2850 db_close($link);
2851?>
2852
2853<!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
2854