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