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