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