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