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