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