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