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