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