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