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