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