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