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