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