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