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