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