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