]> git.wh0rd.org - tt-rss.git/blob - backend.php
remove obsolete code from updateFeed()
[tt-rss.git] / backend.php
1 <?
2 session_start();
3
4 if (!$_SESSION["uid"]) { exit; }
5
6 define(SCHEMA_VERSION, 2);
7
8 require_once "config.php";
9 require_once "db.php";
10 require_once "db-prefs.php";
11 require_once "functions.php";
12 require_once "magpierss/rss_fetch.inc";
13
14 $op = $_REQUEST["op"];
15
16 if (($op == "rpc" || $op == "updateAllFeeds") && !$_REQUEST["noxml"]) {
17 header("Content-Type: application/xml");
18 }
19
20 $script_started = getmicrotime();
21
22 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
23
24 if (!$link) {
25 if (DB_TYPE == "mysql") {
26 print mysql_error();
27 }
28 // PG seems to display its own errors just fine by default.
29 return;
30 }
31
32 if (DB_TYPE == "pgsql") {
33 pg_query("set client_encoding = 'utf-8'");
34 }
35
36 /*
37 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
38
39 $schema_version = db_fetch_result($result, 0, "schema_version");
40
41 if ($schema_version != SCHEMA_VERSION) {
42 print "Error: database schema is invalid
43 (got version $schema_version; expected ".SCHEMA_VERSION.")";
44 return;
45 }
46 */
47
48 $fetch = $_GET["fetch"];
49
50 /* FIXME this needs reworking */
51
52 function getGlobalCounters($link) {
53 $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries,ttrss_user_entries
54 WHERE unread = true AND
55 ttrss_user_entries.ref_id = ttrss_entries.id AND
56 owner_uid = " . $_SESSION["uid"]);
57 $c_id = db_fetch_result($result, 0, "c_id");
58 print "<counter id='global-unread' counter='$c_id'/>";
59 }
60
61 function getTagCounters($link) {
62
63 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
64 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
65 ttrss_user_entries.ref_id = ttrss_entries.id AND
66 ttrss_tags.owner_uid = ".$_SESSION["uid"]." AND
67 post_int_id = ttrss_user_entries.int_id AND unread = true GROUP BY tag_name
68 UNION
69 select tag_name,0 as count FROM ttrss_tags
70 WHERE ttrss_tags.owner_uid = ".$_SESSION["uid"]);
71
72 $tags = array();
73
74 while ($line = db_fetch_assoc($result)) {
75 $tags[$line["tag_name"]] += $line["count"];
76 }
77
78 foreach (array_keys($tags) as $tag) {
79 $unread = $tags[$tag];
80
81 $tag = htmlspecialchars($tag);
82 print "<tag id=\"$tag\" counter=\"$unread\"/>";
83 }
84 }
85
86 function getLabelCounters($link) {
87
88 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries
89 WHERE marked = true AND ttrss_user_entries.ref_id = ttrss_entries.id AND
90 unread = true AND owner_uid = ".$_SESSION["uid"]);
91
92 $count = db_fetch_result($result, 0, "count");
93
94 print "<label id=\"-1\" counter=\"$count\"/>";
95
96 $result = db_query($link, "SELECT owner_uid,id,sql_exp,description FROM
97 ttrss_labels WHERE owner_uid = ".$_SESSION["uid"]." ORDER by description");
98
99 while ($line = db_fetch_assoc($result)) {
100
101 $id = -$line["id"] - 11;
102
103 error_reporting (0);
104
105 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_user_entries,ttrss_entries
106 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
107 ttrss_user_entries.ref_id = ttrss_entries.id AND
108 owner_uid = ".$_SESSION["uid"]);
109
110 $count = db_fetch_result($tmp_result, 0, "count");
111
112 print "<label id=\"$id\" counter=\"$count\"/>";
113
114 error_reporting (E_ERROR | E_WARNING | E_PARSE);
115
116 }
117 }
118
119 function getFeedCounter($link, $id) {
120
121 $result = db_query($link, "SELECT
122 count(id) as count FROM ttrss_entries,ttrss_user_entries
123 WHERE feed_id = '$id' AND unread = true
124 AND ttrss_user_entries.ref_id = ttrss_entries.id");
125
126 $count = db_fetch_result($result, 0, "count");
127
128 print "<feed id=\"$id\" counter=\"$count\"/>";
129 }
130
131 function getFeedCounters($link) {
132
133 $result = db_query($link, "SELECT id,
134 (SELECT count(id)
135 FROM ttrss_entries,ttrss_user_entries
136 WHERE feed_id = ttrss_feeds.id AND ttrss_user_entries.ref_id = ttrss_entries.id
137 AND unread = true AND owner_uid = ".$_SESSION["uid"].") as count
138 FROM ttrss_feeds WHERE owner_uid = ".$_SESSION["uid"]);
139
140 while ($line = db_fetch_assoc($result)) {
141
142 $id = $line["id"];
143 $count = $line["count"];
144
145 print "<feed id=\"$id\" counter=\"$count\"/>";
146 }
147 }
148
149 function outputFeedList($link, $tags = false) {
150
151 print "<html><head>
152 <title>Tiny Tiny RSS : Feedlist</title>
153 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
154
155 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
156 print "<link rel=\"stylesheet\" type=\"text/css\"
157 href=\"tt-rss_compact.css\"/>";
158 } else {
159 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
160 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
161 }
162
163 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
164 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
165 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
166 </head><body onload=\"init()\">";
167
168 print "<ul class=\"feedList\" id=\"feedList\">";
169
170 $owner_uid = $_SESSION["uid"];
171
172 if (!$tags) {
173
174 /* virtual feeds */
175
176 $result = db_query($link, "SELECT count(id) as num_starred
177 FROM ttrss_entries,ttrss_user_entries
178 WHERE marked = true AND
179 ttrss_user_entries.ref_id = ttrss_entries.id AND
180 unread = true AND owner_uid = '$owner_uid'");
181 $num_starred = db_fetch_result($result, 0, "num_starred");
182
183 $class = "virt";
184
185 if ($num_starred > 0) $class .= "Unread";
186
187 printFeedEntry(-1, $class, "Starred articles", $num_starred,
188 "images/mark_set.png", $link);
189
190 if (get_pref($link, 'ENABLE_LABELS')) {
191
192 $result = db_query($link, "SELECT id,sql_exp,description FROM
193 ttrss_labels WHERE owner_uid = '$owner_uid' ORDER by description");
194
195 if (db_num_rows($result) > 0) {
196 print "<li><hr></li>";
197 }
198
199 while ($line = db_fetch_assoc($result)) {
200
201 error_reporting (0);
202
203 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries,ttrss_user_entries
204 WHERE (" . $line["sql_exp"] . ") AND unread = true AND
205 ttrss_user_entries.ref_id = ttrss_entries.id
206 AND owner_uid = '$owner_uid'");
207
208 $count = db_fetch_result($tmp_result, 0, "count");
209
210 $class = "label";
211
212 if ($count > 0) {
213 $class .= "Unread";
214 }
215
216 error_reporting (E_ERROR | E_WARNING | E_PARSE);
217
218 printFeedEntry(-$line["id"]-11,
219 $class, $line["description"], $count, "images/label.png", $link);
220
221 }
222 }
223
224 print "<li><hr></li>";
225
226 $result = db_query($link, "SELECT *,
227 (SELECT count(id) FROM ttrss_entries,ttrss_user_entries
228 WHERE feed_id = ttrss_feeds.id AND
229 ttrss_user_entries.ref_id = ttrss_entries.id AND
230 owner_uid = '$owner_uid') AS total,
231 (SELECT count(id) FROM ttrss_entries,ttrss_user_entries
232 WHERE feed_id = ttrss_feeds.id AND unread = true
233 AND ttrss_user_entries.ref_id = ttrss_entries.id
234 AND owner_uid = '$owner_uid') as unread
235 FROM ttrss_feeds WHERE owner_uid = '$owner_uid' ORDER BY title");
236
237 $actid = $_GET["actid"];
238
239 /* real feeds */
240
241 $lnum = 0;
242
243 $total_unread = 0;
244
245 while ($line = db_fetch_assoc($result)) {
246
247 $feed = $line["title"];
248 $feed_id = $line["id"];
249
250 $subop = $_GET["subop"];
251
252 $total = $line["total"];
253 $unread = $line["unread"];
254
255 // $class = ($lnum % 2) ? "even" : "odd";
256
257 $class = "feed";
258
259 if ($unread > 0) $class .= "Unread";
260
261 if ($actid == $feed_id) {
262 $class .= "Selected";
263 }
264
265 $total_unread += $unread;
266
267 printFeedEntry($feed_id, $class, $feed, $unread, "icons/$feed_id.ico", $link);
268
269 ++$lnum;
270 }
271 } else {
272
273 // tags
274
275 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
276 FROM ttrss_tags,ttrss_entries,ttrss_user_entries WHERE
277 post_int_id = ttrss_user_entries.int_id AND
278 unread = true AND ref_id = ttrss_entries.id
279 AND ttrss_tags.owner_uid = '$owner_uid' GROUP BY tag_name
280 UNION
281 select tag_name,0 as count FROM ttrss_tags WHERE owner_uid = '$owner_uid'
282 ORDER BY tag_name");
283
284 $tags = array();
285
286 while ($line = db_fetch_assoc($result)) {
287 $tags[$line["tag_name"]] += $line["count"];
288 }
289
290 foreach (array_keys($tags) as $tag) {
291
292 $unread = $tags[$tag];
293
294 $class = "odd";
295
296 if ($unread > 0) {
297 $class .= "Unread";
298 }
299
300 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png", $link);
301
302 }
303
304 }
305
306 if (db_num_rows($result) == 0) {
307 print "<li>No tags/feeds to display.</li>";
308 }
309
310 print "</ul>";
311
312 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
313
314 }
315
316
317 if ($op == "rpc") {
318
319 $subop = $_GET["subop"];
320
321 if ($subop == "getLabelCounters") {
322 $aid = $_GET["aid"];
323 print "<rpc-reply>";
324 getLabelCounters($link);
325 if ($aid) {
326 getFeedCounter($link, $aid);
327 }
328 print "</rpc-reply>";
329 }
330
331 if ($subop == "getFeedCounters") {
332 print "<rpc-reply>";
333 getFeedCounters($link);
334 print "</rpc-reply>";
335 }
336
337 if ($subop == "getAllCounters") {
338 print "<rpc-reply>";
339 getLabelCounters($link);
340 getFeedCounters($link);
341 getTagCounters($link);
342 getGlobalCounters($link);
343 print "</rpc-reply>";
344 }
345
346 if ($subop == "mark") {
347 $mark = $_GET["mark"];
348 $id = db_escape_string($_GET["id"]);
349
350 if ($mark == "1") {
351 $mark = "true";
352 } else {
353 $mark = "false";
354 }
355
356 // FIXME this needs collision testing
357
358 $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark
359 WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
360 }
361
362 if ($subop == "updateFeed") {
363 $feed_id = db_escape_string($_GET["feed"]);
364
365 $result = db_query($link,
366 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'");
367
368 if (db_num_rows($result) > 0) {
369 $feed_url = db_fetch_result($result, 0, "feed_url");
370 // update_rss_feed($link, $feed_url, $feed_id);
371 }
372
373 print "DONE-$feed_id";
374
375 return;
376 }
377
378 if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") {
379
380 update_all_feeds($link, $subop == "forceUpdateAllFeeds");
381
382 $omode = $_GET["omode"];
383
384 if (!$omode) $omode = "tfl";
385
386 print "<rpc-reply>";
387 if (strchr($omode, "l")) getLabelCounters($link);
388 if (strchr($omode, "f")) getFeedCounters($link);
389 if (strchr($omode, "t")) getTagCounters($link);
390 getGlobalCounters($link);
391 print "</rpc-reply>";
392 }
393
394 if ($subop == "catchupPage") {
395
396 $ids = split(",", $_GET["ids"]);
397
398 foreach ($ids as $id) {
399
400 db_query($link, "UPDATE ttrss_entries SET unread=false,last_read = NOW()
401 WHERE id = '$id'");
402
403 }
404
405 print "Marked active page as read.";
406 }
407
408 if ($subop == "sanityCheck") {
409
410 $error_code = 0;
411
412 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
413
414 $schema_version = db_fetch_result($result, 0, "schema_version");
415
416 if ($schema_version != SCHEMA_VERSION) {
417 $error_code = 5;
418 }
419
420 print "<error code='$error_code'/>";
421 }
422
423 if ($subop == "globalPurge") {
424
425 print "<rpc-reply>";
426 global_purge_old_posts($link, true);
427 print "</rpc-reply>";
428
429 }
430
431 }
432
433 if ($op == "feeds") {
434
435 $tags = $_GET["tags"];
436
437 $subop = $_GET["subop"];
438
439 if ($subop == "catchupAll") {
440 db_query($link, "UPDATE ttrss_entries SET
441 last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]);
442 }
443
444 outputFeedList($link, $tags);
445
446 }
447
448 if ($op == "view") {
449
450 $id = $_GET["id"];
451 $feed_id = $_GET["feed"];
452
453 $result = db_query($link, "UPDATE ttrss_user_entries
454 SET unread = false,last_read = NOW()
455 WHERE ref_id = '$id' AND feed_id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
456
457 $addheader = $_GET["addheader"];
458
459 $result = db_query($link, "SELECT title,link,content,feed_id,comments,
460 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
461 FROM ttrss_entries,ttrss_user_entries
462 WHERE id = '$id' AND ref_id = id");
463
464 if ($addheader) {
465 print "<html><head>
466 <title>Tiny Tiny RSS : Article $id</title>
467 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
468 <script type=\"text/javascript\" src=\"functions.js\"></script>
469 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
470 </head><body>";
471 }
472
473 if ($result) {
474
475 $line = db_fetch_assoc($result);
476
477 if ($line["icon_url"]) {
478 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
479 } else {
480 $feed_icon = "&nbsp;";
481 }
482
483 if ($line["comments"] && $line["link"] != $line["comments"]) {
484 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
485 } else {
486 $entry_comments = "";
487 }
488
489 print "<div class=\"postReply\">";
490
491 print "<div class=\"postHeader\"><table>";
492
493 print "<tr><td><b>Title:</b></td>
494 <td width='100%'>" . $line["title"] . "</td></tr>";
495
496 print "<tr><td><b>Link:</b></td>
497 <td width='100%'>
498 <a href=\"" . $line["link"] . "\">".$line["link"]."</a>
499 $entry_comments</td></tr>";
500
501 print "</table></div>";
502
503 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
504 print "<div class=\"postContent\">" . $line["content"] . "</div>";
505
506 print "</div>";
507
508 print "<script type=\"text/javascript\">
509 update_label_counters('$feed_id');
510 </script>";
511 }
512
513 if ($addheader) {
514 print "</body></html>";
515 }
516 }
517
518 if ($op == "viewfeed") {
519
520 $feed = $_GET["feed"];
521 $skip = $_GET["skip"];
522 $subop = $_GET["subop"];
523 $view_mode = $_GET["view"];
524 $addheader = $_GET["addheader"];
525 $limit = $_GET["limit"];
526
527 if (!$feed) {
528 print "Error: no feed to display.";
529 return;
530 }
531
532 if (!$skip) $skip = 0;
533
534 if ($subop == "undefined") $subop = "";
535
536 if ($addheader) {
537 print "<html><head>
538 <title>Tiny Tiny RSS : Feed $feed</title>
539 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
540
541 if (get_pref($link, 'USE_COMPACT_STYLESHEET')) {
542 print "<link rel=\"stylesheet\"
543 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
544
545 } else {
546 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
547 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
548 }
549 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
550 <script type=\"text/javascript\" src=\"functions.js\"></script>
551 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
552 </head><body onload='init()'>";
553 }
554
555 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
556
557 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
558 WHERE id = '$feed'");
559
560 $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
561
562 update_rss_feed($link, $feed_url, $feed);
563
564 }
565
566 if ($subop == "MarkAllRead") {
567
568 if (sprintf("%d", $feed) != 0) {
569
570 if ($feed > 0) {
571 db_query($link, "UPDATE ttrss_user_entries
572 SET unread = false,last_read = NOW()
573 WHERE feed_id = '$feed' AND owner_uid = " . $_SESSION["uid"]);
574
575 } else if ($feed < 0 && $feed > -10) { // special, like starred
576
577 if ($feed == -1) {
578 db_query($link, "UPDATE ttrss_user_entries
579 SET unread = false,last_read = NOW()
580 WHERE marked = true AND owner_uid = ".$_SESSION["uid"]);
581 }
582
583 } else if ($feed < -10) { // label
584
585 // TODO make this more efficient
586
587 $label_id = -$feed - 11;
588
589 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
590 WHERE id = '$label_id'");
591
592 if ($tmp_result) {
593 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
594
595 db_query($link, "BEGIN");
596
597 $tmp2_result = db_query($link,
598 "SELECT
599 int_id
600 FROM
601 ttrss_user_entries,ttrss_entries
602 WHERE
603 ref_id = id AND
604 $sql_exp AND
605 owner_uid = " . $_SESSION["uid"]);
606
607 while ($tmp_line = db_fetch_assoc($tmp2_result)) {
608 db_query($link, "UPDATE
609 ttrss_user_entries
610 SET
611 unread = false, last_read = NOW()
612 WHERE
613 int_id = " . $tmp_line["int_id"]);
614 }
615
616 db_query($link, "COMMIT");
617
618 /* db_query($link, "UPDATE ttrss_user_entries,ttrss_entries
619 SET unread = false,last_read = NOW()
620 WHERE $sql_exp
621 AND ref_id = id
622 AND owner_uid = ".$_SESSION["uid"]); */
623 }
624 }
625 } else { // tag
626 // FIXME, implement catchup for tags
627 }
628
629 }
630
631 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
632
633 $search = $_GET["search"];
634
635 $search_mode = $_GET["smode"];
636
637 if ($search) {
638 $search_query_part = "(upper(title) LIKE upper('%$search%')
639 OR content LIKE '%$search%') AND";
640 } else {
641 $search_query_part = "";
642 }
643
644 $view_query_part = "";
645
646 if ($view_mode == "Starred") {
647 $view_query_part = " marked = true AND ";
648 }
649
650 if ($view_mode == "Unread") {
651 $view_query_part = " unread = true AND ";
652 }
653
654 if ($view_mode == "Unread or Starred") {
655 $view_query_part = " (unread = true OR marked = true) AND ";
656 }
657
658 if ($view_mode == "Unread or Updated") {
659 $view_query_part = " (unread = true OR last_read is NULL) AND ";
660 }
661
662 /* $result = db_query($link, "SELECT count(id) AS total_entries
663 FROM ttrss_entries WHERE
664 $search_query_part
665 feed_id = '$feed'");
666
667 $total_entries = db_fetch_result($result, 0, "total_entries"); */
668
669 /* $result = db_query("SELECT count(id) AS unread_entries
670 FROM ttrss_entries WHERE
671 $search_query_part
672 unread = true AND
673 feed_id = '$feed'");
674
675 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
676
677 if ($limit && $limit != "All") {
678 $limit_query_part = "LIMIT " . $limit;
679 }
680
681 $vfeed_query_part = "";
682
683 // override query strategy and enable feed display when searching globally
684 if ($search_mode == "All feeds") {
685 $query_strategy_part = "id > 0";
686 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
687 id = feed_id) as feed_title,";
688 } else if (sprintf("%d", $feed) == 0) {
689 $query_strategy_part = "ttrss_entries.id > 0";
690 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
691 id = feed_id) as feed_title,";
692 } else if ($feed >= 0) {
693 $query_strategy_part = "feed_id = '$feed'";
694 } else if ($feed == -1) { // starred virtual feed
695 $query_strategy_part = "marked = true";
696 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
697 id = feed_id) as feed_title,";
698 } else if ($feed <= -10) { // labels
699 $label_id = -$feed - 11;
700
701 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
702 WHERE id = '$label_id'");
703
704 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
705
706 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
707 id = feed_id) as feed_title,";
708 } else {
709 $query_strategy_part = "id > 0"; // dumb
710 }
711
712
713 $order_by = "updated DESC";
714
715 // if ($feed < -10) {
716 // $order_by = "feed_id,updated DESC";
717 // }
718
719 if ($feed < -10) error_reporting (0);
720
721 if (sprintf("%d", $feed) != 0) {
722
723 $result = db_query($link, "SELECT
724 id,title,updated,unread,feed_id,marked,link,last_read,
725 SUBSTRING(last_read,1,19) as last_read_noms,
726 $vfeed_query_part
727 SUBSTRING(updated,1,19) as updated_noms
728 FROM
729 ttrss_entries,ttrss_user_entries
730 WHERE
731 ttrss_user_entries.ref_id = ttrss_entries.id AND
732 owner_uid = '".$_SESSION["uid"]."' AND
733 $search_query_part
734 $view_query_part
735 $query_strategy_part ORDER BY $order_by
736 $limit_query_part");
737
738 } else {
739 // browsing by tag
740
741 $result = db_query($link, "SELECT
742 ttrss_entries.id as id,title,updated,unread,feed_id,
743 marked,link,last_read,
744 SUBSTRING(last_read,1,19) as last_read_noms,
745 $vfeed_query_part
746 SUBSTRING(updated,1,19) as updated_noms
747 FROM
748 ttrss_entries,ttrss_user_entries,ttrss_tags
749 WHERE
750 ref_id = ttrss_entries.id AND
751 ttrss_user_entries.owner_uid = '".$_SESSION["uid"]."' AND
752 post_int_id = int_id AND tag_name = '$feed' AND
753 $view_query_part
754 $search_query_part
755 $query_strategy_part ORDER BY $order_by
756 $limit_query_part");
757 }
758
759 if (!$result) {
760 print "<tr><td colspan='4' align='center'>
761 Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>";
762 return;
763 }
764
765 $lnum = 0;
766
767 error_reporting (E_ERROR | E_WARNING | E_PARSE);
768
769 $num_unread = 0;
770
771 while ($line = db_fetch_assoc($result)) {
772
773 $class = ($lnum % 2) ? "even" : "odd";
774
775 $id = $line["id"];
776 $feed_id = $line["feed_id"];
777
778 // printf("L %d (%s) &gt; U %d (%s) = %d<br>",
779 // strtotime($line["last_read_noms"]), $line["last_read_noms"],
780 // strtotime($line["updated"]), $line["updated"],
781 // strtotime($line["last_read"]) >= strtotime($line["updated"]));
782
783 /* if ($line["last_read"] != "" && $line["updated"] != "" &&
784 strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) {
785
786 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
787 alt=\"Updated\">";
788
789 } else {
790
791 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
792 alt=\"Updated\">";
793
794 } */
795
796 if ($line["last_read"] == "" &&
797 ($line["unread"] != "t" && $line["unread"] != "1")) {
798
799 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
800 alt=\"Updated\">";
801 } else {
802 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
803 alt=\"Updated\">";
804 }
805
806 if ($line["unread"] == "t" || $line["unread"] == "1") {
807 $class .= "Unread";
808 ++$num_unread;
809 }
810
811 if ($line["marked"] == "t" || $line["marked"] == "1") {
812 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
813 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
814 } else {
815 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
816 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
817 }
818
819 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
820 $line["title"] . "</a>";
821
822 print "<tr class='$class' id='RROW-$id'>";
823 // onclick=\"javascript:view($id,$feed_id)\">
824
825 print "<td valign='center' align='center'>$update_pic</td>";
826 print "<td valign='center' align='center'>$marked_pic</td>";
827
828 print "<td width='25%'>
829 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
830
831 if ($line["feed_title"]) {
832 print "<td width='50%'>$content_link</td>";
833 print "<td width='20%'>
834 <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a></td>";
835 } else {
836 print "<td width='70%'>$content_link</td>";
837 }
838
839 print "</tr>";
840
841 ++$lnum;
842 }
843
844 if ($lnum == 0) {
845 print "<tr><td align='center'>No articles found.</td></tr>";
846 }
847
848 print "</table>";
849
850 print "<script type=\"text/javascript\">
851 document.onkeydown = hotkey_handler;
852 update_label_counters('$feed');
853 </script>";
854
855 if ($addheader) {
856 print "</body></html>";
857 }
858
859 }
860
861 if ($op == "pref-rpc") {
862
863 $subop = $_GET["subop"];
864
865 if ($subop == "unread") {
866 $ids = split(",", $_GET["ids"]);
867 foreach ($ids as $id) {
868 db_query($link, "UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'");
869 }
870
871 print "Marked selected feeds as read.";
872 }
873
874 if ($subop == "read") {
875 $ids = split(",", $_GET["ids"]);
876 foreach ($ids as $id) {
877 db_query($link, "UPDATE ttrss_entries
878 SET unread = false,last_read = NOW() WHERE feed_id = '$id'");
879 }
880
881 print "Marked selected feeds as unread.";
882
883 }
884
885 }
886
887 if ($op == "pref-feeds") {
888
889 $subop = $_GET["subop"];
890
891 if ($subop == "editSave") {
892 $feed_title = db_escape_string($_GET["t"]);
893 $feed_link = db_escape_string($_GET["l"]);
894 $upd_intl = db_escape_string($_GET["ui"]);
895 $purge_intl = db_escape_string($_GET["pi"]);
896 $feed_id = $_GET["id"];
897
898 if (strtoupper($upd_intl) == "DEFAULT")
899 $upd_intl = 0;
900
901 if (strtoupper($purge_intl) == "DEFAULT")
902 $purge_intl = 0;
903
904 if (strtoupper($purge_intl) == "DISABLED")
905 $purge_intl = -1;
906
907 $result = db_query($link, "UPDATE ttrss_feeds SET
908 title = '$feed_title', feed_url = '$feed_link',
909 update_interval = '$upd_intl',
910 purge_interval = '$purge_intl'
911 WHERE id = '$feed_id'");
912
913 }
914
915 if ($subop == "remove") {
916
917 if (!WEB_DEMO_MODE) {
918
919 $ids = split(",", $_GET["ids"]);
920
921 foreach ($ids as $id) {
922 db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'");
923
924 $icons_dir = ICONS_DIR;
925
926 if (file_exists($icons_dir . "/$id.ico")) {
927 unlink($icons_dir . "/$id.ico");
928 }
929 }
930 }
931 }
932
933 if ($subop == "add") {
934
935 if (!WEB_DEMO_MODE) {
936
937 $feed_link = db_escape_string($_GET["link"]);
938
939 $result = db_query($link,
940 "INSERT INTO ttrss_feeds (owner_uid,feed_url,title) VALUES ('".$_SESSION["uid"]."', '$feed_link', '')");
941
942 $result = db_query($link,
943 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'");
944
945 $feed_id = db_fetch_result($result, 0, "id");
946
947 if ($feed_id) {
948 update_rss_feed($link, $feed_link, $feed_id);
949 }
950 }
951 }
952
953 $result = db_query($link, "SELECT id,title,feed_url,last_error
954 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
955
956 if (db_num_rows($result) > 0) {
957
958 print "<div class=\"warning\">";
959
960 print "<b>Feeds with update errors:</b>";
961
962 print "<ul class=\"nomarks\">";
963
964 while ($line = db_fetch_assoc($result)) {
965 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
966 $line["last_error"];
967 }
968
969 print "</ul>";
970 print "</div>";
971
972 }
973
974 print "<table class=\"prefAddFeed\"><tr>
975 <td><input id=\"fadd_link\"></td>
976 <td colspan=\"4\" align=\"right\">
977 <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr>
978 </table>";
979
980 $result = db_query($link, "SELECT
981 id,title,feed_url,substring(last_updated,1,16) as last_updated,
982 update_interval,purge_interval
983 FROM
984 ttrss_feeds WHERE owner_uid = '".$_SESSION["uid"]."' ORDER by title");
985
986 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
987 print "<tr class=\"title\">
988 <td>&nbsp;</td><td>Select</td><td width=\"30%\">Title</td>
989 <td width=\"30%\">Link</td>
990 <td width=\"10%\">Update Interval</td>
991 <td width=\"10%\">Purge Days</td>
992 <td>Last updated</td></tr>";
993
994 $lnum = 0;
995
996 while ($line = db_fetch_assoc($result)) {
997
998 $class = ($lnum % 2) ? "even" : "odd";
999
1000 $feed_id = $line["id"];
1001
1002 $edit_feed_id = $_GET["id"];
1003
1004 if ($subop == "edit" && $feed_id != $edit_feed_id) {
1005 $class .= "Grayed";
1006 }
1007
1008 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
1009
1010 $icon_file = ICONS_DIR . "/$feed_id.ico";
1011
1012 if (file_exists($icon_file) && filesize($icon_file) > 0) {
1013 $feed_icon = "<img width=\"16\" height=\"16\"
1014 src=\"" . ICONS_URL . "/$feed_id.ico\">";
1015 } else {
1016 $feed_icon = "&nbsp;";
1017 }
1018 print "<td align='center'>$feed_icon</td>";
1019
1020 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1021 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
1022
1023 if (!$edit_feed_id || $subop != "edit") {
1024
1025 print "<td><input onclick='toggleSelectRow(this);'
1026 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
1027
1028 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1029 $edit_title . "</a></td>";
1030 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1031 $edit_link . "</a></td>";
1032
1033 if ($line["update_interval"] == "0")
1034 $line["update_interval"] = "Default";
1035
1036 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1037 $line["update_interval"] . "</a></td>";
1038
1039 if ($line["purge_interval"] == "0")
1040 $line["purge_interval"] = "Default";
1041
1042 if ($line["purge_interval"] < 0)
1043 $line["purge_interval"] = "Disabled";
1044
1045 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1046 $line["purge_interval"] . "</a></td>";
1047
1048 } else if ($feed_id != $edit_feed_id) {
1049
1050 print "<td><input disabled=\"true\" type=\"checkbox\"
1051 id=\"FRCHK-".$line["id"]."\"></td>";
1052
1053 print "<td>$edit_title</td>";
1054 print "<td>$edit_link</td>";
1055
1056 if ($line["update_interval"] == "0")
1057 $line["update_interval"] = "Default";
1058
1059 print "<td>" . $line["update_interval"] . "</td>";
1060
1061 if ($line["purge_interval"] == "0")
1062 $line["purge_interval"] = "Default";
1063
1064 if ($line["purge_interval"] < 0)
1065 $line["purge_interval"] = "Disabled";
1066
1067 print "<td>" . $line["purge_interval"] . "</td>";
1068
1069 } else {
1070
1071 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1072
1073 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
1074 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
1075 print "<td><input id=\"iedit_updintl\" value=\"".$line["update_interval"]."\"></td>";
1076 print "<td><input id=\"iedit_purgintl\" value=\"".$line["purge_interval"]."\"></td>";
1077
1078 }
1079
1080 if (!$line["last_updated"]) $line["last_updated"] = "Never";
1081
1082 print "<td>" . $line["last_updated"] . "</td>";
1083
1084 print "</tr>";
1085
1086 ++$lnum;
1087 }
1088
1089 if ($lnum == 0) {
1090 print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>";
1091 }
1092
1093 print "</table>";
1094
1095 print "<p>";
1096
1097 if ($subop == "edit") {
1098 print "Edit feed:&nbsp;
1099 <input type=\"submit\" class=\"button\"
1100 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
1101 <input type=\"submit\" class=\"button\"
1102 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1103 } else {
1104
1105 print "
1106 Selection:&nbsp;
1107 <input type=\"submit\" class=\"button\"
1108 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
1109 <input type=\"submit\" class=\"button\"
1110 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
1111
1112 if (get_pref($link, 'ENABLE_PREFS_CATCHUP_UNCATCHUP')) {
1113 print "
1114 <input type=\"submit\" class=\"button\"
1115 onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\">
1116 <input type=\"submit\" class=\"button\"
1117 onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\">&nbsp;";
1118 }
1119 print "
1120 All feeds:
1121 <input type=\"submit\"
1122 class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">";
1123
1124 }
1125
1126 print "<h3>OPML Import</h3>
1127 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1128 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1129 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
1130 type=\"submit\" value=\"Import\">
1131 </form>";
1132
1133 }
1134
1135 if ($op == "pref-filters") {
1136
1137 $subop = $_GET["subop"];
1138
1139 if ($subop == "editSave") {
1140
1141 $regexp = db_escape_string($_GET["r"]);
1142 $descr = db_escape_string($_GET["d"]);
1143 $match = db_escape_string($_GET["m"]);
1144 $filter_id = db_escape_string($_GET["id"]);
1145
1146 $result = db_query($link, "UPDATE ttrss_filters SET
1147 reg_exp = '$regexp',
1148 description = '$descr',
1149 filter_type = (SELECT id FROM ttrss_filter_types WHERE
1150 description = '$match')
1151 WHERE id = '$filter_id'");
1152 }
1153
1154 if ($subop == "remove") {
1155
1156 if (!WEB_DEMO_MODE) {
1157
1158 $ids = split(",", $_GET["ids"]);
1159
1160 foreach ($ids as $id) {
1161 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
1162
1163 }
1164 }
1165 }
1166
1167 if ($subop == "add") {
1168
1169 if (!WEB_DEMO_MODE) {
1170
1171 $regexp = db_escape_string($_GET["regexp"]);
1172 $match = db_escape_string($_GET["match"]);
1173
1174 $result = db_query($link,
1175 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid) VALUES
1176 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
1177 description = '$match'),'".$_SESSION["uid"]."')");
1178 }
1179 }
1180
1181 $result = db_query($link, "SELECT description
1182 FROM ttrss_filter_types ORDER BY description");
1183
1184 $filter_types = array();
1185
1186 while ($line = db_fetch_assoc($result)) {
1187 array_push($filter_types, $line["description"]);
1188 }
1189
1190 print "<table class=\"prefAddFeed\"><tr>
1191 <td><input id=\"fadd_regexp\"></td>
1192 <td>";
1193 print_select("fadd_match", "Title", $filter_types);
1194
1195 print"</td><td colspan=\"4\" align=\"right\">
1196 <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr>
1197 </table>";
1198
1199 $result = db_query($link, "SELECT
1200 id,reg_exp,description,
1201 (SELECT name FROM ttrss_filter_types WHERE
1202 id = filter_type) as filter_type_name,
1203 (SELECT description FROM ttrss_filter_types
1204 WHERE id = filter_type) as filter_type_descr
1205 FROM
1206 ttrss_filters
1207 WHERE
1208 owner_uid = ".$_SESSION["uid"]."
1209 ORDER by reg_exp");
1210
1211 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
1212
1213 print "<tr class=\"title\">
1214 <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td>
1215 <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>";
1216
1217 $lnum = 0;
1218
1219 while ($line = db_fetch_assoc($result)) {
1220
1221 $class = ($lnum % 2) ? "even" : "odd";
1222
1223 $filter_id = $line["id"];
1224 $edit_filter_id = $_GET["id"];
1225
1226 if ($subop == "edit" && $filter_id != $edit_filter_id) {
1227 $class .= "Grayed";
1228 }
1229
1230 print "<tr class=\"$class\" id=\"FILRR-$filter_id\">";
1231
1232 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
1233 $line["description"] = htmlspecialchars($line["description"]);
1234
1235 if (!$edit_filter_id || $subop != "edit") {
1236
1237 if (!$line["description"]) $line["description"] = "[No description]";
1238
1239 print "<td><input onclick='toggleSelectRow(this);'
1240 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
1241
1242 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1243 $line["reg_exp"] . "</td>";
1244
1245 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1246 $line["description"] . "</td>";
1247
1248 print "<td>".$line["filter_type_descr"]."</td>";
1249
1250 } else if ($filter_id != $edit_filter_id) {
1251
1252 if (!$line["description"]) $line["description"] = "[No description]";
1253
1254 print "<td><input disabled=\"true\" type=\"checkbox\"
1255 id=\"FICHK-".$line["id"]."\"></td>";
1256
1257 print "<td>".$line["reg_exp"]."</td>";
1258 print "<td>".$line["description"]."</td>";
1259 print "<td>".$line["filter_type_descr"]."</td>";
1260
1261 } else {
1262
1263 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1264
1265 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
1266 "\"></td>";
1267
1268 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1269 "\"></td>";
1270
1271 print "<td>";
1272 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
1273 print "</td>";
1274
1275 }
1276
1277
1278 print "</tr>";
1279
1280 ++$lnum;
1281 }
1282
1283 if ($lnum == 0) {
1284 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
1285 }
1286
1287 print "</table>";
1288
1289 print "<p>";
1290
1291 if ($subop == "edit") {
1292 print "Edit feed:
1293 <input type=\"submit\" class=\"button\"
1294 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
1295 <input type=\"submit\" class=\"button\"
1296 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
1297
1298 } else {
1299
1300 print "
1301 Selection:
1302 <input type=\"submit\" class=\"button\"
1303 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
1304 <input type=\"submit\" class=\"button\"
1305 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
1306 }
1307 }
1308
1309 if ($op == "pref-labels") {
1310
1311 $subop = $_GET["subop"];
1312
1313 if ($subop == "editSave") {
1314
1315 $sql_exp = $_GET["s"];
1316 $descr = $_GET["d"];
1317 $label_id = db_escape_string($_GET["id"]);
1318
1319 // print "$sql_exp : $descr : $label_id";
1320
1321 $result = db_query($link, "UPDATE ttrss_labels SET
1322 sql_exp = '$sql_exp',
1323 description = '$descr'
1324 WHERE id = '$label_id'");
1325 }
1326
1327 if ($subop == "remove") {
1328
1329 if (!WEB_DEMO_MODE) {
1330
1331 $ids = split(",", $_GET["ids"]);
1332
1333 foreach ($ids as $id) {
1334 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
1335
1336 }
1337 }
1338 }
1339
1340 if ($subop == "add") {
1341
1342 if (!WEB_DEMO_MODE) {
1343
1344 $exp = $_GET["exp"];
1345
1346 $result = db_query($link,
1347 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
1348 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
1349 }
1350 }
1351
1352 print "<table class=\"prefAddFeed\"><tr>
1353 <td><input id=\"ladd_expr\"></td>";
1354
1355 print"<td colspan=\"4\" align=\"right\">
1356 <a class=\"button\" href=\"javascript:addLabel()\">Add label</a></td></tr>
1357 </table>";
1358
1359 $result = db_query($link, "SELECT
1360 id,sql_exp,description
1361 FROM
1362 ttrss_labels
1363 WHERE
1364 owner_uid = ".$_SESSION["uid"]."
1365 ORDER by description");
1366
1367 print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">";
1368
1369 print "<tr class=\"title\">
1370 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
1371 <a class=\"helpLink\" href=\"javascript:popupHelp(1)\">(?)</a>
1372 </td>
1373 <td width=\"40%\">Caption</td></tr>";
1374
1375 $lnum = 0;
1376
1377 while ($line = db_fetch_assoc($result)) {
1378
1379 $class = ($lnum % 2) ? "even" : "odd";
1380
1381 $label_id = $line["id"];
1382 $edit_label_id = $_GET["id"];
1383
1384 if ($subop == "edit" && $label_id != $edit_label_id) {
1385 $class .= "Grayed";
1386 }
1387
1388 print "<tr class=\"$class\" id=\"LILRR-$label_id\">";
1389
1390 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
1391 $line["description"] = htmlspecialchars($line["description"]);
1392
1393 if (!$edit_label_id || $subop != "edit") {
1394
1395 if (!$line["description"]) $line["description"] = "[No caption]";
1396
1397 print "<td><input onclick='toggleSelectRow(this);'
1398 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
1399
1400 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1401 $line["sql_exp"] . "</td>";
1402
1403 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1404 $line["description"] . "</td>";
1405
1406 } else if ($label_id != $edit_label_id) {
1407
1408 if (!$line["description"]) $line["description"] = "[No description]";
1409
1410 print "<td><input disabled=\"true\" type=\"checkbox\"
1411 id=\"LICHK-".$line["id"]."\"></td>";
1412
1413 print "<td>".$line["sql_exp"]."</td>";
1414 print "<td>".$line["description"]."</td>";
1415
1416 } else {
1417
1418 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1419
1420 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
1421 "\"></td>";
1422
1423 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1424 "\"></td>";
1425
1426 }
1427
1428
1429 print "</tr>";
1430
1431 ++$lnum;
1432 }
1433
1434 if ($lnum == 0) {
1435 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
1436 }
1437
1438 print "</table>";
1439
1440 print "<p>";
1441
1442 if ($subop == "edit") {
1443 print "Edit label:
1444 <input type=\"submit\" class=\"button\"
1445 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
1446 <input type=\"submit\" class=\"button\"
1447 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
1448
1449 } else {
1450
1451 print "
1452 Selection:
1453 <input type=\"submit\" class=\"button\"
1454 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
1455 <input type=\"submit\" class=\"button\"
1456 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
1457 }
1458 }
1459
1460 if ($op == "error") {
1461 print "<div width=\"100%\" align='center'>";
1462 $msg = $_GET["msg"];
1463 print $msg;
1464 print "</div>";
1465 }
1466
1467 if ($op == "help") {
1468 print "<html><head>
1469 <title>Tiny Tiny RSS : Help</title>
1470 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
1471 <script type=\"text/javascript\" src=\"functions.js\"></script>
1472 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1473 </head><body>";
1474
1475 $tid = sprintf("%d", $_GET["tid"]);
1476
1477 /* FIXME this badly needs real implementation */
1478
1479 print "<div class='helpResponse'>";
1480
1481 ?>
1482
1483 <h1>Help for SQL expressions</h1>
1484
1485 <h2>Description</h2>
1486
1487 <p>The &laquo;SQL expression&raquo; is added to WHERE clause of
1488 view feed query. You can match on ttrss_entries table fields
1489 and even use subselect to query additional information. This
1490 functionality is considered to be advanced and requires basic
1491 understanding of SQL.</p>
1492
1493 <h2>Examples</h2>
1494
1495 <pre>unread = true</pre>
1496
1497 Matches all unread articles
1498
1499 <pre>title like '%Linux%'</pre>
1500
1501 Matches all articles which mention Linux in the title. You get the idea.
1502
1503 <p>See the database schema included in the distribution package for gruesome
1504 details.</p>
1505
1506 <?
1507
1508 print "<div align='center'>
1509 <a class=\"helpLink\"
1510 href=\"javascript:window.close()\">(Close this window)</a></div>";
1511
1512 print "</div>";
1513
1514 print "</body></html>";
1515
1516 }
1517
1518 if ($op == "dlg") {
1519 $id = $_GET["id"];
1520 $param = $_GET["param"];
1521
1522 if ($id == "quickAddFeed") {
1523 print "Feed URL: <input
1524 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1525 id=\"qafInput\">
1526 <input class=\"button\"
1527 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
1528 <input class=\"button\"
1529 type=\"submit\" onclick=\"javascript:closeDlg()\"
1530 value=\"Cancel\">";
1531 }
1532
1533 if ($id == "quickDelFeed") {
1534
1535 $param = db_escape_string($param);
1536
1537 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
1538
1539 if ($result) {
1540
1541 $f_title = db_fetch_result($result, 0, "title");
1542
1543 print "Remove current feed ($f_title)?&nbsp;
1544 <input class=\"button\"
1545 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
1546 <input class=\"button\"
1547 type=\"submit\" onclick=\"javascript:closeDlg()\"
1548 value=\"Cancel\">";
1549 } else {
1550 print "Error: Feed $param not found.&nbsp;
1551 <input class=\"button\"
1552 type=\"submit\" onclick=\"javascript:closeDlg()\"
1553 value=\"Cancel\">";
1554 }
1555 }
1556
1557 if ($id == "search") {
1558
1559 print "<input id=\"searchbox\" class=\"extSearch\"
1560 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1561 onchange=\"javascript:search()\">
1562 <select id=\"searchmodebox\">
1563 <option selected>All feeds</option>
1564 <option>This feed</option>
1565 </select>
1566 <input type=\"submit\"
1567 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
1568 <input class=\"button\"
1569 type=\"submit\" onclick=\"javascript:closeDlg()\"
1570 value=\"Close\">";
1571
1572 }
1573
1574 }
1575
1576 if ($op == "updateAllFeeds") {
1577 update_all_feeds($link, true);
1578
1579 print "<rpc-reply>";
1580 getLabelCounters($link);
1581 getFeedCounters($link);
1582 getTagCounters($link);
1583 getGlobalCounters($link);
1584 print "</rpc-reply>";
1585
1586 }
1587
1588 if ($op == "pref-prefs") {
1589
1590 $subop = $_REQUEST["subop"];
1591
1592 if ($subop == "Save configuration") {
1593
1594 if (WEB_DEMO_MODE) return;
1595
1596 foreach (array_keys($_POST) as $pref_name) {
1597
1598 $pref_name = db_escape_string($pref_name);
1599 $value = db_escape_string($_POST[$pref_name]);
1600
1601 $result = db_query($link, "SELECT type_name
1602 FROM ttrss_prefs,ttrss_prefs_types
1603 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
1604
1605 if (db_num_rows($result) > 0) {
1606
1607 $type_name = db_fetch_result($result, 0, "type_name");
1608
1609 // print "$pref_name : $type_name : $value<br>";
1610
1611 if ($type_name == "bool") {
1612 if ($value == "1") {
1613 $value = "true";
1614 } else {
1615 $value = "false";
1616 }
1617 } else if ($type_name == "integer") {
1618 $value = sprintf("%d", $value);
1619 }
1620
1621 // print "$pref_name : $type_name : $value<br>";
1622
1623 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
1624 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
1625
1626 }
1627
1628 header("Location: prefs.php");
1629
1630 }
1631
1632 } else if ($subop == "getHelp") {
1633
1634 $pref_name = db_escape_string($_GET["pn"]);
1635
1636 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
1637 WHERE pref_name = '$pref_name'");
1638
1639 if (db_num_rows($result) > 0) {
1640 $help_text = db_fetch_result($result, 0, "help_text");
1641 print $help_text;
1642 } else {
1643 print "Unknown option: $pref_name";
1644 }
1645
1646 } else if ($subop == "Change password") {
1647
1648 if (WEB_DEMO_MODE) return;
1649
1650 $old_pw = $_POST["OLD_PASSWORD"];
1651 $new_pw = $_POST["OLD_PASSWORD"];
1652
1653 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
1654 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
1655
1656 $active_uid = $_SESSION["uid"];
1657
1658 if ($old_pw && $new_pw) {
1659
1660 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
1661
1662 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
1663 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
1664 pwd_hash = '$old_pw_hash')");
1665
1666 if (db_num_rows($result) == 1) {
1667 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
1668 WHERE id = '$active_uid'");
1669 }
1670 }
1671
1672 header("Location: prefs.php");
1673
1674 } else if ($subop == "Reset to defaults") {
1675
1676 if (WEB_DEMO_MODE) return;
1677
1678 if (DB_TYPE == "pgsql") {
1679 db_query($link,"UPDATE ttrss_user_prefs
1680 SET value = ttrss_prefs.def_value
1681 WHERE owner_uid = '".$_SESSION["uid"]."' AND
1682 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
1683 } else {
1684 db_query($link, "DELETE FROM ttrss_user_prefs
1685 WHERE owner_uid = ".$_SESSION["uid"]);
1686 initialize_user_prefs($link, $_SESSION["uid"]);
1687 }
1688
1689 header("Location: prefs.php");
1690
1691 } else {
1692
1693 if (!SINGLE_USER_MODE) {
1694
1695 print "<form action=\"backend.php\" method=\"POST\">";
1696
1697 print "<table width=\"100%\" class=\"prefPrefsList\">";
1698 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
1699
1700 print "<tr><td width=\"40%\">Old password</td>";
1701 print "<td><input class=\"editbox\" type=\"password\"
1702 name=\"OLD_PASSWORD\"></td></tr>";
1703
1704 print "<tr><td width=\"40%\">New password</td>";
1705
1706 print "<td><input class=\"editbox\" type=\"password\"
1707 name=\"NEW_PASSWORD\"></td></tr>";
1708
1709 print "</table>";
1710
1711 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
1712
1713 print "<p><input class=\"button\" type=\"submit\"
1714 value=\"Change password\" name=\"subop\">";
1715
1716 print "</form>";
1717
1718 }
1719
1720 $result = db_query($link, "SELECT
1721 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
1722 section_name,def_value
1723 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
1724 WHERE type_id = ttrss_prefs_types.id AND
1725 section_id = ttrss_prefs_sections.id AND
1726 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
1727 owner_uid = ".$_SESSION["uid"]."
1728 ORDER BY section_id,short_desc");
1729
1730 print "<form action=\"backend.php\" method=\"POST\">";
1731
1732 $lnum = 0;
1733
1734 $active_section = "";
1735
1736 while ($line = db_fetch_assoc($result)) {
1737
1738 if ($active_section != $line["section_name"]) {
1739
1740 if ($active_section != "") {
1741 print "</table>";
1742 }
1743
1744 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
1745
1746 $active_section = $line["section_name"];
1747
1748 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
1749 // print "<tr class=\"title\">
1750 // <td width=\"25%\">Option</td><td>Value</td></tr>";
1751
1752 $lnum = 0;
1753 }
1754
1755 // $class = ($lnum % 2) ? "even" : "odd";
1756
1757 print "<tr>";
1758
1759 $type_name = $line["type_name"];
1760 $pref_name = $line["pref_name"];
1761 $value = $line["value"];
1762 $def_value = $line["def_value"];
1763 $help_text = $line["help_text"];
1764
1765 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
1766
1767 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
1768
1769 print "</td>";
1770
1771 print "<td>";
1772
1773 if ($type_name == "bool") {
1774 // print_select($pref_name, $value, array("true", "false"));
1775
1776 if ($value == "true") {
1777 $value = "Yes";
1778 } else {
1779 $value = "No";
1780 }
1781
1782 print_radio($pref_name, $value, array("Yes", "No"));
1783
1784 } else {
1785 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
1786 }
1787
1788 print "</td>";
1789
1790 print "</tr>";
1791
1792 $lnum++;
1793 }
1794
1795 print "</table>";
1796
1797 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
1798
1799 print "<p><input class=\"button\" type=\"submit\"
1800 name=\"subop\" value=\"Save configuration\">";
1801
1802 print "&nbsp;<input class=\"button\" type=\"submit\"
1803 name=\"subop\" value=\"Reset to defaults\"></p>";
1804
1805 print "</form>";
1806
1807 }
1808
1809 }
1810
1811 if ($op == "pref-users") {
1812
1813 $subop = $_GET["subop"];
1814
1815 if ($subop == "editSave") {
1816
1817 if (!WEB_DEMO_MODE) {
1818
1819 $login = db_escape_string($_GET["l"]);
1820 $uid = db_escape_string($_GET["id"]);
1821 $access_level = sprintf("%d", $_GET["al"]);
1822
1823 db_query($link, "UPDATE ttrss_users SET login = '$login', access_level = '$access_level' WHERE id = '$uid'");
1824
1825 }
1826 } else if ($subop == "remove") {
1827
1828 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
1829
1830 $ids = split(",", $_GET["ids"]);
1831
1832 foreach ($ids as $id) {
1833 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
1834
1835 }
1836 }
1837 } else if ($subop == "add") {
1838
1839 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
1840
1841 $login = db_escape_string($_GET["login"]);
1842 $tmp_user_pwd = make_password(8);
1843 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
1844
1845 db_query($link, "INSERT INTO ttrss_users (login,pwd_hash,access_level)
1846 VALUES ('$login', '$pwd_hash', 0)");
1847
1848
1849 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
1850 login = '$login' AND pwd_hash = '$pwd_hash'");
1851
1852 if (db_num_rows($result) == 1) {
1853
1854 $new_uid = db_fetch_result($result, 0, "id");
1855
1856 print "<div class=\"notice\">Added user <b>".$_GET["login"].
1857 "</b> with password <b>$tmp_user_pwd</b>.</div>";
1858
1859 initialize_user($link, $new_uid);
1860
1861 } else {
1862
1863 print "<div class=\"warning\">Error while adding user <b>".
1864 $_GET["login"].".</b></div>";
1865
1866 }
1867 }
1868 } else if ($subop == "resetPass") {
1869
1870 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
1871
1872 $uid = db_escape_string($_GET["id"]);
1873
1874 $result = db_query($link, "SELECT login FROM ttrss_users WHERE id = '$uid'");
1875
1876 $login = db_fetch_result($result, 0, "login");
1877 $tmp_user_pwd = make_password(8);
1878 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
1879
1880 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
1881 WHERE id = '$uid'");
1882
1883 print "<div class=\"notice\">Changed password of
1884 user <b>$login</b> to <b>$tmp_user_pwd</b>.</div>";
1885
1886 }
1887 }
1888
1889 print "<table class=\"prefAddFeed\"><tr>
1890 <td><input id=\"uadd_box\"></td>";
1891
1892 print"<td colspan=\"4\" align=\"right\">
1893 <a class=\"button\" href=\"javascript:addUser()\">Add user</a></td></tr>
1894 </table>";
1895
1896 $result = db_query($link, "SELECT
1897 id,login,access_level,last_login
1898 FROM
1899 ttrss_users
1900 ORDER by login");
1901
1902 print "<div id=\"prefUserDetails\">PLACEHOLDER</div>";
1903
1904 print "<p><table width=\"100%\" class=\"prefUserList\" id=\"prefUserList\">";
1905
1906 print "<tr class=\"title\">
1907 <td width=\"5%\">Select</td>
1908 <td width='30%'>Username</td>
1909 <td width='30%'>Access Level</td>
1910 <td width='30%'>Last login</td></tr>";
1911
1912 $lnum = 0;
1913
1914 while ($line = db_fetch_assoc($result)) {
1915
1916 $class = ($lnum % 2) ? "even" : "odd";
1917
1918 $uid = $line["id"];
1919 $edit_uid = $_GET["id"];
1920
1921 if ($uid == $_SESSION["uid"] || ($subop == "edit" && $uid != $edit_uid)) {
1922 $class .= "Grayed";
1923 }
1924
1925 print "<tr class=\"$class\" id=\"UMRR-$uid\">";
1926
1927 $line["login"] = htmlspecialchars($line["login"]);
1928
1929 if ($uid == $_SESSION["uid"]) {
1930
1931 print "<td><input disabled=\"true\" type=\"checkbox\"
1932 id=\"UMCHK-".$line["id"]."\"></td>";
1933
1934 print "<td>".$line["login"]."</td>";
1935 print "<td>".$line["access_level"]."</td>";
1936
1937 } else if (!$edit_uid || $subop != "edit") {
1938
1939 print "<td><input onclick='toggleSelectRow(this);'
1940 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
1941
1942 print "<td><a href=\"javascript:editUser($uid);\">" .
1943 $line["login"] . "</td>";
1944
1945 print "<td><a href=\"javascript:editUser($uid);\">" .
1946 $line["access_level"] . "</td>";
1947
1948 } else if ($uid != $edit_uid) {
1949
1950 print "<td><input disabled=\"true\" type=\"checkbox\"
1951 id=\"UMCHK-".$line["id"]."\"></td>";
1952
1953 print "<td>".$line["login"]."</td>";
1954 print "<td>".$line["access_level"]."</td>";
1955
1956 } else {
1957
1958 print "<td><input disabled=\"true\" type=\"checkbox\" checked></td>";
1959
1960 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
1961 "\"></td>";
1962
1963 print "<td><input id=\"iedit_ulevel\" value=\"".$line["access_level"].
1964 "\"></td>";
1965
1966 }
1967
1968 print "<td>".$line["last_login"]."</td>";
1969
1970 print "</tr>";
1971
1972 ++$lnum;
1973 }
1974
1975 print "</table>";
1976
1977 print "<p>";
1978
1979 if ($subop == "edit") {
1980 print "Edit label:
1981 <input type=\"submit\" class=\"button\"
1982 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">
1983 <input type=\"submit\" class=\"button\"
1984 onclick=\"javascript:userEditSave()\" value=\"Save\">";
1985
1986 } else {
1987
1988 print "
1989 Selection:
1990 <input type=\"submit\" class=\"button\"
1991 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
1992 <input type=\"submit\" class=\"button\"
1993 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
1994 <input type=\"submit\" class=\"button\"
1995 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
1996 <input type=\"submit\" class=\"button\"
1997 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
1998
1999 }
2000 }
2001
2002 if ($op == "user-details") {
2003
2004 if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
2005 return;
2006 }
2007
2008 /* print "<html><head>
2009 <title>Tiny Tiny RSS : User Details</title>
2010 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
2011 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2012 </head><body>"; */
2013
2014 $uid = sprintf("%d", $_GET["id"]);
2015
2016 print "<div class='userDetails'>";
2017
2018 $result = db_query($link, "SELECT login,last_login,access_level
2019 FROM ttrss_users
2020 WHERE id = '$uid'");
2021
2022 if (db_num_rows($result) == 0) {
2023 print "<h1>User not found</h1>";
2024 return;
2025 }
2026
2027 print "<h1>User Details</h1>";
2028
2029 print "<table width='100%'>";
2030
2031 $login = db_fetch_result($result, 0, "login");
2032 $last_login = db_fetch_result($result, 0, "last_login");
2033 $access_level = db_fetch_result($result, 0, "access_level");
2034
2035 print "<tr><td>Username</td><td>$login</td></tr>";
2036 print "<tr><td>Access level</td><td>$access_level</td></tr>";
2037 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
2038
2039 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
2040 WHERE owner_uid = '$uid'");
2041
2042 $num_feeds = db_fetch_result($result, 0, "num_feeds");
2043
2044 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
2045
2046 /* $result = db_query($link, "SELECT
2047 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
2048 FROM ttrss_entries WHERE owner_uid = '$uid'");
2049
2050 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
2051
2052 print "<tr><td>Approx. DB size</td><td>$db_size KBytes</td></tr>"; */
2053
2054 print "</table>";
2055
2056 print "<h1>Subscribed feeds</h1>";
2057
2058 $result = db_query($link, "SELECT id,title,feed_url FROM ttrss_feeds
2059 WHERE owner_uid = '$uid' ORDER BY title");
2060
2061 print "<ul class=\"nomarks\">";
2062
2063 while ($line = db_fetch_assoc($result)) {
2064
2065 $icon_file = ICONS_URL."/".$line["id"].".ico";
2066
2067 if (file_exists($icon_file) && filesize($icon_file) > 0) {
2068 $feed_icon = "<img class=\"feedIcon\" src=\"$icon_file\">";
2069 } else {
2070 $feed_icon = "<img class=\"feedIcon\" src=\"images/blank_icon.gif\">";
2071 }
2072
2073 print "<li>$feed_icon&nbsp;<a href=\"".$line["feed_url"]."\">".$line["title"]."</a></li>";
2074 }
2075
2076 print "</ul>";
2077
2078 print "</div>";
2079
2080 print "<div align='center'>
2081 <input type='submit' class='button'
2082 onclick=\"closeUserDetails()\" value=\"Close this window\"></div>";
2083
2084 // print "</body></html>";
2085
2086 }
2087
2088 db_close($link);
2089 ?>
2090
2091 <!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
2092