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