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