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