]> git.wh0rd.org - tt-rss.git/blame - backend.php
rework label editor from inline to infobox
[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
0ea4fb50
AD
1386 print "</div>";
1387
1388 print "<div align='center'>
0ea4fb50 1389 <input type=\"submit\" class=\"button\"
c14b5566 1390 onclick=\"return feedEditSave()\" value=\"Save\">
d10fabe4 1391 <input type='submit' class='button'
c14b5566 1392 onclick=\"return feedEditCancel()\" value=\"Cancel\"></div>";
0ea4fb50
AD
1393 return;
1394 }
1395
508a81e1 1396 if ($subop == "editSave") {
a88c1f36 1397
14f69488
AD
1398 $feed_title = db_escape_string(trim($_POST["title"]));
1399 $feed_link = db_escape_string(trim($_POST["feed_url"]));
1400 $upd_intl = db_escape_string($_POST["update_interval"]);
1401 $purge_intl = db_escape_string($_POST["purge_interval"]);
1402 $feed_id = db_escape_string($_POST["id"]);
1403 $cat_id = db_escape_string($_POST["cat_id"]);
1404 $auth_login = db_escape_string(trim($_POST["auth_login"]));
1405 $auth_pass = db_escape_string(trim($_POST["auth_pass"]));
1406 $parent_feed = db_escape_string($_POST["parent_feed"]);
1407 $private = checkbox_to_sql_bool(db_escape_string($_POST["private"]));
1408 $rtl_content = checkbox_to_sql_bool(db_escape_string($_POST["rtl_content"]));
0da49bad 1409 $hidden = checkbox_to_sql_bool(db_escape_string($_POST["hidden"]));
14f69488 1410
a2db6a4a
AD
1411 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1412 if ($cat_id && $cat_id != 0) {
1413 $category_qpart = "cat_id = '$cat_id',";
1414 } else {
1415 $category_qpart = 'cat_id = NULL,';
1416 }
91ff844a 1417 } else {
a2db6a4a 1418 $category_qpart = "";
91ff844a
AD
1419 }
1420
14f69488 1421 if ($parent_feed && $parent_feed != 0) {
a2db6a4a 1422 $parent_qpart = "parent_feed = '$parent_feed',";
1da7e457 1423 } else {
a2db6a4a 1424 $parent_qpart = 'parent_feed = NULL,';
1da7e457
AD
1425 }
1426
648472a7 1427 $result = db_query($link, "UPDATE ttrss_feeds SET
a2db6a4a
AD
1428 $category_qpart
1429 $parent_qpart
d148926e 1430 title = '$feed_title', feed_url = '$feed_link',
5d73494a 1431 update_interval = '$upd_intl',
47c6c988
AD
1432 purge_interval = '$purge_intl',
1433 auth_login = '$auth_login',
e3c99f3b 1434 auth_pass = '$auth_pass',
ac92cb46 1435 private = $private,
0da49bad
AD
1436 rtl_content = $rtl_content,
1437 hidden = $hidden
ac92cb46 1438 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
5ddadb4c
AD
1439 }
1440
1441 if ($subop == "saveCat") {
605f7d46 1442 $cat_title = db_escape_string(trim($_GET["title"]));
5ddadb4c
AD
1443 $cat_id = db_escape_string($_GET["id"]);
1444
1445 $result = db_query($link, "UPDATE ttrss_feed_categories SET
1446 title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
508a81e1 1447
83fe4d6d
AD
1448 }
1449
331900c6 1450 if ($subop == "remove") {
331900c6 1451
b0b4abcf 1452 if (!WEB_DEMO_MODE) {
331900c6 1453
f932bc9f 1454 $ids = split(",", db_escape_string($_GET["ids"]));
b0b4abcf
AD
1455
1456 foreach ($ids as $id) {
4769ddaf 1457
88040f57
AD
1458 if ($id > 0) {
1459
1460 db_query($link, "DELETE FROM ttrss_feeds
1461 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1462
1463 $icons_dir = ICONS_DIR;
d5caaae5 1464
88040f57
AD
1465 if (file_exists($icons_dir . "/$id.ico")) {
1466 unlink($icons_dir . "/$id.ico");
1467 }
1468 } else if ($id < -10) {
1469
1470 $label_id = -$id - 11;
1471
1472 db_query($link, "DELETE FROM ttrss_labels
1473 WHERE id = '$label_id' AND owner_uid = " . $_SESSION["uid"]);
d5caaae5 1474 }
b0b4abcf 1475 }
331900c6
AD
1476 }
1477 }
1478
1479 if ($subop == "add") {
b0b4abcf
AD
1480
1481 if (!WEB_DEMO_MODE) {
331900c6 1482
07eb9178
AD
1483 $feed_url = db_escape_string(trim($_GET["feed_url"]));
1484 $cat_id = db_escape_string($_GET["cat_id"]);
15da5cc1 1485
07eb9178 1486 if (subscribe_to_feed($link, $feed_url, $cat_id)) {
956c7629 1487 print "Added feed.";
15da5cc1 1488 } else {
7e9a3986 1489 print "<div class=\"warning\">
07eb9178 1490 Feed <b>$feed_url</b> already exists in the database.
7e9a3986 1491 </div>";
b0b4abcf
AD
1492 }
1493 }
331900c6 1494 }
a0d53889 1495
91ff844a
AD
1496 if ($subop == "addCat") {
1497
1498 if (!WEB_DEMO_MODE) {
1499
1500 $feed_cat = db_escape_string(trim($_GET["cat"]));
1501
1502 $result = db_query($link,
1503 "SELECT id FROM ttrss_feed_categories
1504 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
1505
1506 if (db_num_rows($result) == 0) {
1507
1508 $result = db_query($link,
1509 "INSERT INTO ttrss_feed_categories (owner_uid,title)
1510 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
1511
1512 } else {
1513
1514 print "<div class=\"warning\">
1515 Category <b>$feed_cat</b> already exists in the database.
1516 </div>";
1517 }
1518
1519
1520 }
1521 }
1522
1523 if ($subop == "removeCats") {
1524
1525 if (!WEB_DEMO_MODE) {
1526
f932bc9f 1527 $ids = split(",", db_escape_string($_GET["ids"]));
91ff844a
AD
1528
1529 foreach ($ids as $id) {
1530
1531 db_query($link, "BEGIN");
1532
1533 $result = db_query($link,
1534 "SELECT count(id) as num_feeds FROM ttrss_feeds
1535 WHERE cat_id = '$id'");
1536
1537 $num_feeds = db_fetch_result($result, 0, "num_feeds");
1538
1539 if ($num_feeds == 0) {
1540 db_query($link, "DELETE FROM ttrss_feed_categories
1541 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1542 } else {
1543
1544 print "<div class=\"warning\">
1545 Unable to delete non empty feed categories.</div>";
1546
1547 }
1548
1549 db_query($link, "COMMIT");
1550 }
1551 }
1552 }
1553
f932bc9f
AD
1554 if ($subop == "categorize") {
1555
1556 if (!WEB_DEMO_MODE) {
1557
1558 $ids = split(",", db_escape_string($_GET["ids"]));
1559
1560 $cat_id = db_escape_string($_GET["cat_id"]);
1561
1562 if ($cat_id == 0) {
1563 $cat_id_qpart = 'NULL';
1564 } else {
1565 $cat_id_qpart = "'$cat_id'";
1566 }
1567
1568 db_query($link, "BEGIN");
1569
1570 foreach ($ids as $id) {
1571
1572 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
1573 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1574 }
1575
1576 db_query($link, "COMMIT");
1577 }
1578
1579 }
1580
a24f525c
AD
1581 if ($quiet) return;
1582
c64d5b03 1583// print "<h3>Edit Feeds</h3>";
91ff844a 1584
0da49bad 1585 $result = db_query($link, "SELECT id,title,feed_url,last_error
4904f845
AD
1586 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1587
1588 if (db_num_rows($result) > 0) {
1589
1590 print "<div class=\"warning\">";
a9b0bfd5
AD
1591
1592// print"<img class=\"closeButton\"
1593// onclick=\"javascript:hideParentElement(this);\" src=\"images/close.png\">";
1594
36aab70f 1595 print "<a href=\"javascript:showBlockElement('feedUpdateErrors')\">
0ceded7a 1596 <b>Some feeds have update errors (click for details)</b></a>";
4904f845 1597
36aab70f 1598 print "<ul id=\"feedUpdateErrors\" class=\"nomarks\">";
4904f845
AD
1599
1600 while ($line = db_fetch_assoc($result)) {
1601 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
1602 $line["last_error"];
1603 }
1604
1605 print "</ul>";
1606 print "</div>";
1607
1608 }
1609
f932bc9f
AD
1610 $feed_search = db_escape_string($_GET["search"]);
1611
1612 if (array_key_exists("search", $_GET)) {
1613 $_SESSION["prefs_feed_search"] = $feed_search;
1614 } else {
1615 $feed_search = $_SESSION["prefs_feed_search"];
1616 }
1617
1618 print "<table width='100%' class=\"prefGenericAddBox\"
1619 cellspacing='0' cellpadding='0'><tr>
1620 <td>
1621 <input id=\"fadd_link\"
2371c520
AD
1622 onkeyup=\"toggleSubmitNotEmpty(this, 'fadd_submit_btn')\"
1623 size=\"40\">
f932bc9f 1624 <input type=\"submit\" class=\"button\"
2371c520
AD
1625 disabled=\"true\" id=\"fadd_submit_btn\"
1626 onclick=\"addFeed()\" value=\"Subscribe\">";
e2f728be 1627
0b68215c 1628 if (ENABLE_FEED_BROWSER && !SINGLE_USER_MODE) {
e5d758e3 1629 print " <input type=\"submit\" class=\"button\"
6311acbe 1630 onclick=\"javascript:browseFeeds()\" value=\"Top 25\">";
e2f728be
AD
1631 }
1632
1633 print "</td><td align='right'>
f932bc9f 1634 <input id=\"feed_search\" size=\"20\"
2371c520 1635 onchange=\"javascript:updateFeedList()\" value=\"$feed_search\">
f932bc9f
AD
1636 <input type=\"submit\" class=\"button\"
1637 onclick=\"javascript:updateFeedList()\" value=\"Search\">
1638 </td>
1639 </tr></table>";
a0d53889 1640
b83c7545
AD
1641 $feeds_sort = db_escape_string($_GET["sort"]);
1642
1643 if (!$feeds_sort || $feeds_sort == "undefined") {
1644 $feeds_sort = $_SESSION["pref_sort_feeds"];
1645 if (!$feeds_sort) $feeds_sort = "title";
1646 }
1647
1648 $_SESSION["pref_sort_feeds"] = $feeds_sort;
1649
f932bc9f 1650 if ($feed_search) {
11de82c3
AD
1651 $search_qpart = "(UPPER(F1.title) LIKE UPPER('%$feed_search%') OR
1652 UPPER(F1.feed_url) LIKE UPPER('%$feed_search%')) AND";
f932bc9f
AD
1653 } else {
1654 $search_qpart = "";
1655 }
1656
a2db6a4a
AD
1657 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1658 $order_by_qpart = "category,$feeds_sort,title";
1659 } else {
1660 $order_by_qpart = "$feeds_sort,title";
1661 }
1662
648472a7 1663 $result = db_query($link, "SELECT
db42b934
AD
1664 F1.id,
1665 F1.title,
1666 F1.feed_url,
1667 substring(F1.last_updated,1,16) AS last_updated,
1668 F1.parent_feed,
1669 F1.update_interval,
1670 F1.purge_interval,
1671 F1.cat_id,
1672 F2.title AS parent_title,
0da49bad
AD
1673 C1.title AS category,
1674 F1.hidden
c0e5a40e 1675 FROM
db42b934
AD
1676 ttrss_feeds AS F1
1677 LEFT JOIN ttrss_feeds AS F2
1678 ON (F1.parent_feed = F2.id)
1679 LEFT JOIN ttrss_feed_categories AS C1
1680 ON (F1.cat_id = C1.id)
f932bc9f 1681 WHERE
db42b934 1682 $search_qpart F1.owner_uid = '".$_SESSION["uid"]."'
a2db6a4a 1683 ORDER by $order_by_qpart");
1cd17194 1684
3b0feb9b 1685 if (db_num_rows($result) != 0) {
91ff844a 1686
59a543f0 1687// print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
35f3c923 1688
f4fe2cde
AD
1689 print "<p><table width=\"100%\" cellspacing=\"0\"
1690 class=\"prefFeedList\" id=\"prefFeedList\">";
35f3c923
AD
1691 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1692 Select:
ce3bf408
AD
1693 <a href=\"javascript:selectPrefRows('feed', true)\">All</a>,
1694 <a href=\"javascript:selectPrefRows('feed', false)\">None</a>
35f3c923
AD
1695 </td</tr>";
1696
0ea4fb50
AD
1697 if (!get_pref($link, 'ENABLE_FEED_CATS')) {
1698 print "<tr class=\"title\">
6e69e9c2
AD
1699 <td width='5%' align='center'>&nbsp;</td>";
1700
1701 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1702 print "<td width='3%'>&nbsp;</td>";
1703 }
1704
1705 print "
01b3e191
AD
1706 <td width='40%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
1707 <td width='45%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
1708 <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
603c27f8 1709 }
603c27f8 1710
c64d5b03 1711 $lnum = 0;
0ea4fb50
AD
1712
1713 $cur_cat_id = -1;
c64d5b03
AD
1714
1715 while ($line = db_fetch_assoc($result)) {
1716
3b0feb9b 1717 $feed_id = $line["id"];
0ea4fb50
AD
1718 $cat_id = $line["cat_id"];
1719
1720 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1721 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
1722 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
0ea4fb50 1723
0da49bad
AD
1724 $hidden = sql_bool_to_bool($line["hidden"]);
1725
0ea4fb50
AD
1726 if (!$edit_cat) $edit_cat = "Uncategorized";
1727
01b3e191
AD
1728 $last_updated = $line["last_updated"];
1729
1730 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1731 $last_updated = smart_date_time(strtotime($last_updated));
1732 } else {
1733 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1734 $last_updated = date($short_date, strtotime($last_updated));
1735 }
1736
0ea4fb50 1737 if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
cb58d0df
AD
1738 $lnum = 0;
1739
0ea4fb50
AD
1740 print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>";
1741
1742 print "<tr class=\"title\">
2eb15f6f 1743 <td width='5%'>&nbsp;</td>";
d1793994
AD
1744
1745 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
2eb15f6f 1746 print "<td width='3%'>&nbsp;</td>";
d1793994
AD
1747 }
1748
1749 print "<td width='40%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
01b3e191
AD
1750 <td width='45%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
1751 <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
0ea4fb50
AD
1752
1753 $cur_cat_id = $cat_id;
c64d5b03 1754 }
0ea4fb50 1755
cb58d0df 1756 $class = ($lnum % 2) ? "even" : "odd";
0ea4fb50
AD
1757 $this_row_id = "id=\"FEEDR-$feed_id\"";
1758
53226edc 1759 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
1760
1761 $icon_file = ICONS_DIR . "/$feed_id.ico";
1762
1763 if (file_exists($icon_file) && filesize($icon_file) > 0) {
327a3bbe 1764 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/$feed_id.ico\">";
3b0feb9b 1765 } else {
327a3bbe 1766 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3b0feb9b 1767 }
d1793994 1768
ce3bf408 1769 print "<td class='feedSelect'><input onclick='toggleSelectPrefRow(this, \"feed\");'
0ea4fb50 1770 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
3547842a 1771
d1793994
AD
1772 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1773 print "<td class='feedIcon'>$feed_icon</td>";
1774 }
1775
0ea4fb50
AD
1776 $edit_title = truncate_string($edit_title, 40);
1777 $edit_link = truncate_string($edit_link, 60);
a88c1f36 1778
0da49bad
AD
1779 if ($hidden) {
1780 $edit_title = "<span class=\"insensitive\">$edit_title (Hidden)</span>";
1781 $edit_link = "<span class=\"insensitive\">$edit_link</span>";
1782 $last_updated = "<span class=\"insensitive\">$last_updated</span>";
1783 }
1784
1da7e457
AD
1785 $parent_title = $line["parent_title"];
1786 if ($parent_title) {
1787 $parent_title = "<span class='groupPrompt'>(linked to
1788 $parent_title)</span>";
1789 }
1790
0ea4fb50 1791 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
d1793994 1792 "$edit_title $parent_title" . "</a></td>";
0ea4fb50
AD
1793
1794 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1795 $edit_link . "</a></td>";
3547842a 1796
01b3e191
AD
1797 print "<td align='right'><a href=\"javascript:editFeed($feed_id);\">" .
1798 "$last_updated</a></td>";
1799
c64d5b03
AD
1800 print "</tr>";
1801
1802 ++$lnum;
1803 }
1804
c64d5b03 1805 print "</table>";
3b0feb9b 1806
ce3bf408 1807 print "<p><span id=\"feedOpToolbar\">";
c64d5b03 1808
3b0feb9b
AD
1809 if ($subop == "edit") {
1810 print "Edit feed:&nbsp;
c64d5b03 1811 <input type=\"submit\" class=\"button\"
3b0feb9b 1812 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
c64d5b03 1813 <input type=\"submit\" class=\"button\"
3b0feb9b
AD
1814 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1815 } else {
c64d5b03
AD
1816
1817 print "
1818 Selection:&nbsp;
ce3bf408 1819 <input type=\"submit\" class=\"button\" disabled=\"true\"
3b0feb9b 1820 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
ce3bf408 1821 <input type=\"submit\" class=\"button\" disabled=\"true\"
e5d758e3 1822 onclick=\"javascript:removeSelectedFeeds()\" value=\"Unsubscribe\">";
f932bc9f
AD
1823
1824 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1825
e5d758e3 1826 print "&nbsp;|&nbsp;";
f932bc9f 1827
673d54ca 1828 print_feed_cat_select($link, "sfeed_set_fcat", "", "disabled");
f932bc9f 1829
ce3bf408 1830 print " <input type=\"submit\" class=\"button\" disabled=\"true\"
6d1e02a2 1831 onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Recategorize\">";
f932bc9f
AD
1832
1833 }
3b0feb9b 1834
ce3bf408 1835 print "</span>
f932bc9f 1836 &nbsp;All feeds: <input type=\"submit\"
3b0feb9b
AD
1837 class=\"button\" onclick=\"gotoExportOpml()\"
1838 value=\"Export OPML\">";
1839 }
1840 } else {
1841
1842 print "<p>No feeds defined.</p>";
1843
1844 }
1845
1846 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1847
1848 print "<h3>Edit Categories</h3>";
1849
3b0feb9b 1850 print "<div class=\"prefGenericAddBox\">
f932bc9f 1851 <input id=\"fadd_cat\"
ce3bf408 1852 onkeyup=\"toggleSubmitNotEmpty(this, 'catadd_submit_btn')\"
f932bc9f
AD
1853 size=\"40\">&nbsp;
1854 <input
ce3bf408 1855 type=\"submit\" class=\"button\" disabled=\"true\" id=\"catadd_submit_btn\"
e5d758e3 1856 onclick=\"javascript:addFeedCat()\" value=\"Create category\"></div>";
3b0feb9b
AD
1857
1858 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1859 WHERE owner_uid = ".$_SESSION["uid"]."
1860 ORDER BY title");
1861
1862 if (db_num_rows($result) != 0) {
1863
0666e120
AD
1864 print "<form id=\"feed_cat_edit_form\">";
1865
35f3c923 1866 print "<p><table width=\"100%\" class=\"prefFeedCatList\"
f4fe2cde 1867 cellspacing=\"0\" id=\"prefFeedCatList\">";
35f3c923
AD
1868
1869 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1870 Select:
ce3bf408
AD
1871 <a href=\"javascript:selectPrefRows('fcat', true)\">All</a>,
1872 <a href=\"javascript:selectPrefRows('fcat', false)\">None</a>
35f3c923
AD
1873 </td</tr>";
1874
3b0feb9b 1875 print "<tr class=\"title\">
0b68215c 1876 <td width=\"5%\">&nbsp;</td><td width=\"80%\">Title</td>
3b0feb9b
AD
1877 </tr>";
1878
1879 $lnum = 0;
1880
1881 while ($line = db_fetch_assoc($result)) {
1882
1883 $class = ($lnum % 2) ? "even" : "odd";
1884
1885 $cat_id = $line["id"];
1886
1887 $edit_cat_id = $_GET["id"];
1888
3c5783b7 1889 if ($subop == "editCat" && $cat_id != $edit_cat_id) {
0666e120
AD
1890 $class .= "Grayed";
1891 $this_row_id = "";
53226edc
AD
1892 } else {
1893 $this_row_id = "id=\"FCATR-$cat_id\"";
3b0feb9b
AD
1894 }
1895
53226edc 1896 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
1897
1898 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1899
1900 if (!$edit_cat_id || $subop != "editCat") {
1901
ce3bf408
AD
1902 print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"fcat\");'
1903 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
3b0feb9b
AD
1904
1905 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
1906 $edit_title . "</a></td>";
1907
1908 } else if ($cat_id != $edit_cat_id) {
1909
0666e120 1910 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
3b0feb9b
AD
1911 id=\"FRCHK-".$line["id"]."\"></td>";
1912
1913 print "<td>$edit_title</td>";
1914
1915 } else {
1916
0666e120
AD
1917 print "<td align='center'><input disabled=\"true\" type=\"checkbox\" checked>";
1918
1919 print "<input type=\"hidden\" name=\"id\" value=\"$cat_id\">";
1920 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
1921 print "<input type=\"hidden\" name=\"subop\" value=\"saveCat\">";
1922
1923 print "</td>";
3b0feb9b 1924
ac2cc246
AD
1925 print "<td><input onkeypress=\"return filterCR(event)\"
1926 name=\"title\" class=\"iedit\" value=\"$edit_title\"></td>";
3b0feb9b
AD
1927
1928 }
1929
1930 print "</tr>";
1931
1932 ++$lnum;
1933 }
1934
1935 print "</table>";
0666e120
AD
1936
1937 print "</form>";
3b0feb9b 1938
ce3bf408 1939 print "<p id=\"catOpToolbar\">";
3b0feb9b
AD
1940
1941 if ($subop == "editCat") {
1942 print "Edit category:&nbsp;
ce3bf408 1943 <input type=\"submit\" class=\"button\"
90ac84df 1944 onclick=\"return feedCatEditSave()\" value=\"Save\">
ce3bf408 1945 <input type=\"submit\" class=\"button\"
90ac84df 1946 onclick=\"return feedCatEditCancel()\" value=\"Cancel\">";
3b0feb9b
AD
1947 } else {
1948
1949 print "
1950 Selection:&nbsp;
ce3bf408 1951 <input type=\"submit\" class=\"button\" disabled=\"true\"
90ac84df 1952 onclick=\"return editSelectedFeedCat()\" value=\"Edit\">
ce3bf408 1953 <input type=\"submit\" class=\"button\" disabled=\"true\"
90ac84df 1954 onclick=\"return removeSelectedFeedCats()\" value=\"Remove\">";
3b0feb9b
AD
1955
1956 }
1957
1958 } else {
1959 print "<p>No feed categories defined.</p>";
1960 }
c64d5b03
AD
1961 }
1962
1963 print "<h3>Import OPML</h3>
f5a50b25
AD
1964 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1965 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1966 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
1967 type=\"submit\" value=\"Import\">
1968 </form>";
1969
007bda35
AD
1970 }
1971
a0d53889
AD
1972 if ($op == "pref-filters") {
1973
1974 $subop = $_GET["subop"];
a24f525c 1975 $quiet = $_GET["quiet"];
a0d53889 1976
07164479
AD
1977 if ($subop == "edit") {
1978
1979 $filter_id = db_escape_string($_GET["id"]);
1980
1981 $result = db_query($link,
9cd30721 1982 "SELECT * FROM ttrss_filters WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
07164479
AD
1983
1984 $reg_exp = htmlspecialchars(db_unescape_string(db_fetch_result($result, 0, "reg_exp")));
1985 $filter_type = db_fetch_result($result, 0, "filter_type");
1986 $feed_id = db_fetch_result($result, 0, "feed_id");
1987 $action_id = db_fetch_result($result, 0, "action_id");
1988
1989 print "<div id=\"infoBoxTitle\">Filter editor</div>";
1990 print "<div class=\"infoBoxContents\">";
1991
1992 print "<form id=\"filter_edit_form\">";
1993
1994 print "<input type=\"hidden\" name=\"op\" value=\"pref-filters\">";
1995 print "<input type=\"hidden\" name=\"id\" value=\"$filter_id\">";
1996 print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
1997
1998// print "<div class=\"notice\"><b>Note:</b> filter will only apply to new articles.</div>";
1999
2000 $result = db_query($link, "SELECT id,description
2001 FROM ttrss_filter_types ORDER BY description");
2002
2003 $filter_types = array();
2004
2005 while ($line = db_fetch_assoc($result)) {
2006 //array_push($filter_types, $line["description"]);
2007 $filter_types[$line["id"]] = $line["description"];
2008 }
2009
2010 print "<table width='100%'>";
2011
2012 print "<tr><td>Match:</td>
2013 <td><input onkeypress=\"return filterCR(event)\"
2014 onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
4220b0bd 2015 name=\"reg_exp\" class=\"iedit\" value=\"$reg_exp\">";
07164479 2016
4220b0bd
AD
2017 print "</td><td>";
2018
2019 print_select_hash("filter_type", $filter_type, $filter_types, "class=\"iedit\"");
07164479
AD
2020
2021 print "</td></tr>";
4220b0bd 2022 print "<tr><td>Feed:</td><td colspan='2'>";
07164479
AD
2023
2024 print_feed_select($link, "feed_id", $feed_id);
2025
2026 print "</td></tr>";
2027
2028 print "<tr><td>Action:</td>";
2029
4220b0bd 2030 print "<td colspan='2'><select name=\"action_id\">";
07164479
AD
2031
2032 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2033 ORDER BY name");
2034
2035 while ($line = db_fetch_assoc($result)) {
2036 $is_sel = ($line["id"] == $action_id) ? "selected" : "";
2037 printf("<option value='%d' $is_sel>%s</option>", $line["id"], $line["description"]);
2038 }
2039
2040 print "</select>";
2041
2042 print "</td></tr></table>";
2043
2044 print "</form>";
2045
2046 print "<div align='right'>";
2047
2048 print "<input type=\"submit\"
2049 id=\"infobox_submit\"
90ac84df 2050 class=\"button\" onclick=\"return filterEditSave()\"
07164479
AD
2051 value=\"Save\"> ";
2052
2053 print "<input class=\"button\"
90ac84df 2054 type=\"submit\" onclick=\"return filterEditCancel()\"
07164479
AD
2055 value=\"Cancel\">";
2056
2057 print "</div>";
2058
2059 return;
2060 }
2061
2062
a0d53889 2063 if ($subop == "editSave") {
a0d53889 2064
7e939457
AD
2065 $reg_exp = db_escape_string(trim($_GET["reg_exp"]));
2066 $filter_type = db_escape_string(trim($_GET["filter_type"]));
648472a7 2067 $filter_id = db_escape_string($_GET["id"]);
7e939457
AD
2068 $feed_id = db_escape_string($_GET["feed_id"]);
2069 $action_id = db_escape_string($_GET["action_id"]);
ead60402
AD
2070
2071 if (!$feed_id) {
2072 $feed_id = 'NULL';
2073 } else {
2074 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2075 }
0afbd851 2076
648472a7 2077 $result = db_query($link, "UPDATE ttrss_filters SET
7e939457
AD
2078 reg_exp = '$reg_exp',
2079 feed_id = $feed_id,
2080 action_id = '$action_id',
2081 filter_type = '$filter_type'
9cd30721 2082 WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
a0d53889
AD
2083 }
2084
2085 if ($subop == "remove") {
2086
2087 if (!WEB_DEMO_MODE) {
2088
f932bc9f 2089 $ids = split(",", db_escape_string($_GET["ids"]));
a0d53889
AD
2090
2091 foreach ($ids as $id) {
9cd30721 2092 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
a0d53889
AD
2093
2094 }
2095 }
2096 }
2097
2098 if ($subop == "add") {
2099
de435974 2100 if (!WEB_DEMO_MODE) {
a0d53889 2101
79f3553b 2102 $regexp = db_escape_string(trim($_GET["reg_exp"]));
07164479 2103 $filter_type = db_escape_string(trim($_GET["filter_type"]));
79f3553b
AD
2104 $feed_id = db_escape_string($_GET["feed_id"]);
2105 $action_id = db_escape_string($_GET["action_id"]);
ead60402
AD
2106
2107 if (!$feed_id) {
2108 $feed_id = 'NULL';
2109 } else {
2110 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2111 }
4401bf04 2112
648472a7 2113 $result = db_query($link,
19c9cb11
AD
2114 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
2115 action_id)
2116 VALUES
07164479 2117 ('$regexp', '$filter_type','".$_SESSION["uid"]."',
19c9cb11 2118 $feed_id, '$action_id')");
de435974 2119 }
a0d53889
AD
2120 }
2121
a24f525c
AD
2122 if ($quiet) return;
2123
59a543f0 2124// print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
7b5c6012 2125
7e939457 2126 $result = db_query($link, "SELECT id,description
a0d53889
AD
2127 FROM ttrss_filter_types ORDER BY description");
2128
2129 $filter_types = array();
2130
648472a7 2131 while ($line = db_fetch_assoc($result)) {
7e939457
AD
2132 //array_push($filter_types, $line["description"]);
2133 $filter_types[$line["id"]] = $line["description"];
a0d53889
AD
2134 }
2135
7b5c6012
AD
2136 print "<input type=\"submit\"
2137 class=\"button\"
90ac84df 2138 onclick=\"return displayDlg('quickAddFilter', false)\"
4220b0bd 2139 id=\"create_filter_btn\"
7b5c6012
AD
2140 value=\"Create filter\">";
2141
648472a7 2142 $result = db_query($link, "SELECT
ead60402 2143 ttrss_filters.id AS id,reg_exp,
ead60402
AD
2144 ttrss_filter_types.name AS filter_type_name,
2145 ttrss_filter_types.description AS filter_type_descr,
2146 feed_id,
19c9cb11 2147 ttrss_filter_actions.description AS action_description,
11de82c3 2148 ttrss_feeds.title AS feed_title
a0d53889 2149 FROM
5890c3f4
AD
2150 ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN
2151 ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id)
4356293a 2152 WHERE
ead60402 2153 filter_type = ttrss_filter_types.id AND
19c9cb11 2154 ttrss_filter_actions.id = action_id AND
ead60402 2155 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
4356293a 2156 ORDER by reg_exp");
a0d53889 2157
3b0feb9b 2158 if (db_num_rows($result) != 0) {
a0d53889 2159
7e939457
AD
2160 print "<form id=\"filter_edit_form\">";
2161
f4fe2cde
AD
2162 print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\"
2163 id=\"prefFilterList\">";
35f3c923
AD
2164
2165 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2166 Select:
ce3bf408
AD
2167 <a href=\"javascript:selectPrefRows('filter', true)\">All</a>,
2168 <a href=\"javascript:selectPrefRows('filter', false)\">None</a>
35f3c923
AD
2169 </td</tr>";
2170
3b0feb9b 2171 print "<tr class=\"title\">
e325c6e7 2172 <td align='center' width=\"5%\">&nbsp;</td>
19c9cb11
AD
2173 <td width=\"20%\">Filter expression</td>
2174 <td width=\"20%\">Feed</td>
2175 <td width=\"15%\">Match</td>
01b3e191
AD
2176 <td width=\"15%\">Action</td>";
2177
3b0feb9b
AD
2178 $lnum = 0;
2179
2180 while ($line = db_fetch_assoc($result)) {
2181
2182 $class = ($lnum % 2) ? "even" : "odd";
2183
2184 $filter_id = $line["id"];
2185 $edit_filter_id = $_GET["id"];
2186
2187 if ($subop == "edit" && $filter_id != $edit_filter_id) {
2188 $class .= "Grayed";
53226edc
AD
2189 $this_row_id = "";
2190 } else {
2191 $this_row_id = "id=\"FILRR-$filter_id\"";
ead60402 2192 }
3b0feb9b 2193
53226edc 2194 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b 2195
07164479 2196 $line["reg_exp"] = htmlspecialchars(db_unescape_string($line["reg_exp"]));
3b0feb9b
AD
2197
2198 if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
7e939457 2199
07164479
AD
2200 $line["feed_title"] = htmlspecialchars(db_unescape_string($line["feed_title"]));
2201
2202 print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"filter\");'
3b0feb9b
AD
2203 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
2204
07164479
AD
2205 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2206 $line["reg_exp"] . "</td>";
3b0feb9b 2207
07164479
AD
2208 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2209 $line["feed_title"] . "</td>";
3b0feb9b 2210
07164479
AD
2211 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2212 $line["filter_type_descr"] . "</td>";
19c9cb11 2213
07164479
AD
2214 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2215 $line["action_description"] . "</td>";
3b0feb9b
AD
2216
2217 print "</tr>";
2218
2219 ++$lnum;
a0d53889 2220 }
3b0feb9b
AD
2221
2222 if ($lnum == 0) {
2223 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
2224 }
2225
2226 print "</table>";
7e939457
AD
2227
2228 print "</form>";
3b0feb9b 2229
ce3bf408 2230 print "<p id=\"filterOpToolbar\">";
3b0feb9b 2231
4220b0bd 2232 print "
3b0feb9b 2233 Selection:
ce3bf408 2234 <input type=\"submit\" class=\"button\" disabled=\"true\"
90ac84df 2235 onclick=\"return editSelectedFilter()\" value=\"Edit\">
ce3bf408 2236 <input type=\"submit\" class=\"button\" disabled=\"true\"
90ac84df 2237 onclick=\"return removeSelectedFilters()\" value=\"Remove\">";
4220b0bd
AD
2238
2239 print "</p>";
3b0feb9b 2240
a0d53889
AD
2241 } else {
2242
3b0feb9b
AD
2243 print "<p>No filters defined.</p>";
2244
a0d53889
AD
2245 }
2246 }
2247
80dce858
AD
2248 // We need to accept raw SQL data in label queries, so not everything is escaped
2249 // here, this is by design. If you don't like the whole idea, disable labels
2250 // altogether with GLOBAL_ENABLE_LABELS = false
2251
48f0adb0
AD
2252 if ($op == "pref-labels") {
2253
cfaba6df
AD
2254 if (!GLOBAL_ENABLE_LABELS) {
2255 return;
2256 }
2257
48f0adb0
AD
2258 $subop = $_GET["subop"];
2259
a4dbc524
AD
2260 if ($subop == "edit") {
2261
2262 $label_id = db_escape_string($_GET["id"]);
2263
2264 $result = db_query($link, "SELECT sql_exp,description FROM ttrss_labels WHERE
2265 owner_uid = ".$_SESSION["uid"]." AND id = '$label_id' ORDER by description");
2266
2267 $line = db_fetch_assoc($result);
2268
2269 $sql_exp = htmlspecialchars(db_unescape_string($line["sql_exp"]));
2270 $description = htmlspecialchars(db_unescape_string($line["description"]));
2271
2272 print "<div id=\"infoBoxTitle\">Label editor</div>";
2273 print "<div class=\"infoBoxContents\">";
2274
2275 print "<form id=\"label_edit_form\">";
2276
2277 print "<input type=\"hidden\" name=\"op\" value=\"pref-labels\">";
2278 print "<input type=\"hidden\" name=\"id\" value=\"$label_id\">";
2279 print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
2280
2281 print "<table width='100%'>";
2282
2283 print "<tr><td>Caption:</td>
2284 <td><input onkeypress=\"return filterCR(event)\"
2285 onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
2286 name=\"description\" class=\"iedit\" value=\"$description\">";
2287
2288 print "</td></tr>";
2289
2290 print "<tr><td colspan=\"2\">
2291 <p>SQL Expression:</p>";
2292
2293 print "<textarea onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
2294 rows=\"4\" name=\"sql_exp\" class=\"iedit\">$sql_exp</textarea>";
2295
2296 print "</td></tr></table>";
2297
2298 print "</form>";
2299
2300 print "<div style=\"display : none\" id=\"label_test_result\"></div>";
2301
2302 print "<div align='right'>";
2303
2304 print "<input type=\"submit\" onclick=\"labelTest()\" value=\"Test\">
2305 ";
2306
2307 print "<input type=\"submit\"
2308 id=\"infobox_submit\"
2309 class=\"button\" onclick=\"return labelEditSave()\"
2310 value=\"Save\"> ";
2311
2312 print "<input class=\"button\"
2313 type=\"submit\" onclick=\"return labelEditCancel()\"
2314 value=\"Cancel\">";
2315
2316 print "</div>";
2317
2318 return;
2319 }
2320
d9dde1d6
AD
2321 if ($subop == "test") {
2322
d11bc4de
AD
2323 $expr = db_unescape_string(trim($_GET["expr"]));
2324 $descr = db_unescape_string(trim($_GET["descr"]));
d9dde1d6 2325
a4dbc524 2326 print "<div>";
e5d758e3 2327
a4dbc524 2328 error_reporting(0);
d9dde1d6 2329
d9dde1d6
AD
2330
2331 $result = db_query($link,
88040f57
AD
2332 "SELECT count(ttrss_entries.id) AS num_matches
2333 FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
d9dde1d6
AD
2334 WHERE ($expr) AND
2335 ttrss_user_entries.ref_id = ttrss_entries.id AND
88040f57 2336 ttrss_user_entries.feed_id = ttrss_feeds.id AND
a4dbc524
AD
2337 ttrss_user_entries.owner_uid = " . $_SESSION["uid"], false);
2338
2339 error_reporting (DEFAULT_ERROR_LEVEL);
2340
2341 if (!$result) {
2342 print "<p>" . db_last_error($link) . "</p>";
2343 print "</div>";
2344 return;
2345 }
d9dde1d6
AD
2346
2347 $num_matches = db_fetch_result($result, 0, "num_matches");;
2348
2349 if ($num_matches > 0) {
2350
a4dbc524 2351 print "<p>Query returned <b>$num_matches</b> matches, showing up to first 10:</p>";
d9dde1d6
AD
2352
2353 $result = db_query($link,
88040f57 2354 "SELECT ttrss_entries.title,
d9dde1d6 2355 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
88040f57 2356 FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
d9dde1d6
AD
2357 WHERE ($expr) AND
2358 ttrss_user_entries.ref_id = ttrss_entries.id
88040f57
AD
2359 AND ttrss_user_entries.feed_id = ttrss_feeds.id
2360 AND ttrss_user_entries.owner_uid = " . $_SESSION["uid"] . "
a4dbc524 2361 ORDER BY date_entered DESC LIMIT 10", false);
d9dde1d6 2362
a4dbc524 2363 print "<ul class=\"labelTestResults\">";
673d54ca
AD
2364
2365 $row_class = "even";
2366
d9dde1d6 2367 while ($line = db_fetch_assoc($result)) {
673d54ca
AD
2368 $row_class = toggleEvenOdd($row_class);
2369
2370 print "<li class=\"$row_class\">".$line["title"].
d9dde1d6
AD
2371 " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
2372 }
2373 print "</ul>";
2374
2375 } else {
2376 print "<p>Query didn't return any matches.</p>";
2377 }
2378
2379 print "</div>";
2380
d9dde1d6
AD
2381 return;
2382 }
2383
48f0adb0
AD
2384 if ($subop == "editSave") {
2385
f3120e5a
AD
2386 $sql_exp = trim($_GET["sql_exp"]);
2387 $descr = db_escape_string(trim($_GET["description"]));
48f0adb0
AD
2388 $label_id = db_escape_string($_GET["id"]);
2389
48f0adb0
AD
2390 $result = db_query($link, "UPDATE ttrss_labels SET
2391 sql_exp = '$sql_exp',
2392 description = '$descr'
2393 WHERE id = '$label_id'");
2394 }
2395
2396 if ($subop == "remove") {
2397
2398 if (!WEB_DEMO_MODE) {
2399
f932bc9f 2400 $ids = split(",", db_escape_string($_GET["ids"]));
48f0adb0
AD
2401
2402 foreach ($ids as $id) {
2403 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
2404
2405 }
2406 }
2407 }
2408
2409 if ($subop == "add") {
2410
2411 if (!WEB_DEMO_MODE) {
2412
4401bf04
AD
2413 // no escaping is done here on purpose
2414 $exp = trim($_GET["exp"]);
48f0adb0
AD
2415
2416 $result = db_query($link,
4356293a
AD
2417 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
2418 VALUES ('$exp', '$exp', '".$_SESSION["uid"]."')");
48f0adb0
AD
2419 }
2420 }
2421
2c7070b5 2422 print "<div class=\"prefGenericAddBox\">
2371c520
AD
2423 <input size=\"40\"
2424 onkeyup=\"toggleSubmitNotEmpty(this, 'label_create_btn')\"
2425 id=\"ladd_expr\">&nbsp;";
48f0adb0 2426
2c7070b5 2427 print"<input type=\"submit\" class=\"button\"
2371c520
AD
2428 disabled=\"true\" id=\"label_create_btn\"
2429 onclick=\"javascript:addLabel()\" value=\"Create label\"></div>";
48f0adb0
AD
2430
2431 $result = db_query($link, "SELECT
2432 id,sql_exp,description
2433 FROM
4356293a
AD
2434 ttrss_labels
2435 WHERE
2436 owner_uid = ".$_SESSION["uid"]."
2437 ORDER by description");
48f0adb0 2438
59a543f0 2439// print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
d9dde1d6 2440
3b0feb9b 2441 if (db_num_rows($result) != 0) {
48f0adb0 2442
f3120e5a
AD
2443 print "<form id=\"label_edit_form\">";
2444
f4fe2cde
AD
2445 print "<p><table width=\"100%\" cellspacing=\"0\"
2446 class=\"prefLabelList\" id=\"prefLabelList\">";
35f3c923
AD
2447
2448 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2449 Select:
ce3bf408
AD
2450 <a href=\"javascript:selectPrefRows('label', true)\">All</a>,
2451 <a href=\"javascript:selectPrefRows('label', false)\">None</a>
35f3c923
AD
2452 </td</tr>";
2453
3b0feb9b 2454 print "<tr class=\"title\">
673d54ca 2455 <td width=\"5%\">&nbsp;</td>
e325c6e7 2456 <td width=\"40%\">SQL expression
01c9c74a 2457 <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a>
3b0feb9b
AD
2458 </td>
2459 <td width=\"40%\">Caption</td></tr>";
2460
2461 $lnum = 0;
2462
2463 while ($line = db_fetch_assoc($result)) {
2464
2465 $class = ($lnum % 2) ? "even" : "odd";
2466
2467 $label_id = $line["id"];
2468 $edit_label_id = $_GET["id"];
2469
2470 if ($subop == "edit" && $label_id != $edit_label_id) {
2471 $class .= "Grayed";
53226edc
AD
2472 $this_row_id = "";
2473 } else {
2474 $this_row_id = "id=\"LILRR-$label_id\"";
3b0feb9b
AD
2475 }
2476
53226edc 2477 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b 2478
5f212f40
AD
2479 $line["sql_exp"] = htmlspecialchars(db_unescape_string($line["sql_exp"]));
2480 $line["description"] = htmlspecialchars(
2481 db_unescape_string($line["description"]));
3b0feb9b 2482
a4dbc524 2483 if (!$line["description"]) $line["description"] = "[No caption]";
3b0feb9b 2484
a4dbc524 2485 print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"label\");'
3b0feb9b
AD
2486 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
2487
a4dbc524
AD
2488 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2489 $line["sql_exp"] . "</td>";
48f0adb0 2490
a4dbc524
AD
2491 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2492 $line["description"] . "</td>";
48f0adb0 2493
3b0feb9b
AD
2494 print "</tr>";
2495
2496 ++$lnum;
2497 }
2498
2499 if ($lnum == 0) {
2500 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
2501 }
2502
2503 print "</table>";
f3120e5a
AD
2504
2505 print "</form>";
3b0feb9b 2506
ce3bf408 2507 print "<p id=\"labelOpToolbar\">";
3b0feb9b
AD
2508
2509 if ($subop == "edit") {
2510 print "Edit label:
d9dde1d6
AD
2511 <input type=\"submit\" class=\"button\"
2512 onclick=\"javascript:labelTest()\" value=\"Test\">
3b0feb9b 2513 <input type=\"submit\" class=\"button\"
d10fabe4 2514 onclick=\"javascript:labelEditSave()\" value=\"Save\">
3b0feb9b 2515 <input type=\"submit\" class=\"button\"
d10fabe4 2516 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">";
3b0feb9b 2517
ce3bf408 2518 } else {
3b0feb9b
AD
2519 print "
2520 Selection:
ce3bf408 2521 <input type=\"submit\" class=\"button\" disabled=\"true\"
3b0feb9b 2522 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
ce3bf408 2523 <input type=\"submit\" class=\"button\" disabled=\"true\"
3b0feb9b
AD
2524 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
2525 }
48f0adb0 2526 } else {
3b0feb9b 2527 print "<p>No labels defined.</p>";
48f0adb0
AD
2528 }
2529 }
2530
e828e31e
AD
2531 if ($op == "error") {
2532 print "<div width=\"100%\" align='center'>";
2533 $msg = $_GET["msg"];
2534 print $msg;
2535 print "</div>";
2536 }
2537
7dc66a61 2538 if ($op == "help") {
01c9c74a
AD
2539 if (!$_GET["noheaders"]) {
2540 print "<html><head>
2541 <title>Tiny Tiny RSS : Help</title>
2542 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
86b682ce 2543 <script type=\"text/javascript\" src=\"prototype.js\"></script>
53515ff1 2544 <script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
01c9c74a
AD
2545 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2546 </head><body>";
2547 }
7dc66a61
AD
2548
2549 $tid = sprintf("%d", $_GET["tid"]);
2550
e5d758e3
AD
2551 print "<div id=\"infoBoxTitle\">Help</div>";
2552
01c9c74a 2553 print "<div class='infoBoxContents'>";
7dc66a61 2554
01c9c74a
AD
2555 if (file_exists("help/$tid.php")) {
2556 include("help/$tid.php");
2557 } else {
2558 print "<p>Help topic not found.</p>";
2559 }
7dc66a61 2560
01c9c74a 2561 print "</div>";
7dc66a61
AD
2562
2563 print "<div align='center'>
01c9c74a
AD
2564 <input type='submit' class='button'
2565 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
7dc66a61 2566
01c9c74a
AD
2567 if (!$_GET["noheaders"]) {
2568 print "</body></html>";
2569 }
7dc66a61
AD
2570
2571 }
2572
f84a97a3
AD
2573 if ($op == "dlg") {
2574 $id = $_GET["id"];
6de5d056 2575 $param = $_GET["param"];
f84a97a3
AD
2576
2577 if ($id == "quickAddFeed") {
e5d758e3
AD
2578
2579 print "<div id=\"infoBoxTitle\">Subscribe to feed</div>";
2580 print "<div class=\"infoBoxContents\">";
2581
07eb9178
AD
2582 print "<form id='feed_add_form'>";
2583
2584 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
2585 print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
2586 print "<input type=\"hidden\" name=\"subop\" value=\"add\">";
2587
e5d758e3
AD
2588 print "<table width='100%'>
2589 <tr><td>Feed URL:</td><td>
07eb9178 2590 <input class=\"iedit\" onblur=\"javascript:enableHotkeys()\"
ac2cc246 2591 onkeypress=\"return filterCR(event)\"
2371c520 2592 onkeyup=\"toggleSubmitNotEmpty(this, 'fadd_submit_btn')\"
07eb9178 2593 onfocus=\"javascript:disableHotkeys()\" name=\"feed_url\"></td></tr>";
15da5cc1
AD
2594
2595 if (get_pref($link, 'ENABLE_FEED_CATS')) {
e5d758e3 2596 print "<tr><td>Category:</td><td>";
07eb9178 2597 print_feed_cat_select($link, "cat_id");
e5d758e3 2598 print "</td></tr>";
15da5cc1 2599 }
07eb9178
AD
2600
2601 print "</table>";
2602 print "</form>";
2603
2604 print "<div align='right'>
2371c520
AD
2605 <input class=\"button\"
2606 id=\"fadd_submit_btn\" disabled=\"true\"
2607 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Subscribe\">
2608 <input class=\"button\"
07eb9178
AD
2609 type=\"submit\" onclick=\"javascript:closeInfoBox()\"
2610 value=\"Cancel\"></div>";
c14b5566 2611
f84a97a3 2612 }
6de5d056 2613
033e47e0
AD
2614 if ($id == "search") {
2615
e5d758e3
AD
2616 print "<div id=\"infoBoxTitle\">Search</div>";
2617 print "<div class=\"infoBoxContents\">";
2618
86b682ce
AD
2619 print "<form id='search_form'>";
2620
0a6c4846
AD
2621 #$active_feed_id = db_escape_string($_GET["param"]);
2622
2623 $params = split(":", db_escape_string($_GET["param"]));
2624
b788b632 2625 $active_feed_id = sprintf("%d", $params[0]);
0a6c4846 2626 $is_cat = $params[1] == "true";
49b7cbd3 2627
e5d758e3 2628 print "<table width='100%'><tr><td>Search:</td><td>";
86b682ce
AD
2629
2630 print "<input name=\"query\" class=\"iedit\"
2631 onkeypress=\"return filterCR(event)\"
2371c520 2632 onkeyup=\"toggleSubmitNotEmpty(this, 'search_submit_btn')\"
86b682ce
AD
2633 value=\"\">
2634 </td></tr>";
2635
2636 print "<tr><td>Where:</td><td>";
2637
2638 print "<select name=\"search_mode\">
2639 <option value=\"all_feeds\">All feeds</option>";
2640
2641 $feed_title = getFeedTitle($link, $active_feed_id);
0a6c4846
AD
2642
2643 if (!$is_cat) {
2644 $feed_cat_title = getFeedCatTitle($link, $active_feed_id);
2645 } else {
2646 $feed_cat_title = getCategoryTitle($link, $active_feed_id);
2647 }
86b682ce 2648
0a6c4846 2649 if ($active_feed_id && !$is_cat) {
86b682ce 2650 print "<option selected value=\"this_feed\">This feed ($feed_title)</option>";
49b7cbd3
AD
2651 } else {
2652 print "<option disabled>This feed</option>";
2653 }
b0005823 2654
0a6c4846
AD
2655 if ($is_cat) {
2656 $cat_preselected = "selected";
2657 }
2658
b788b632 2659 if (get_pref($link, 'ENABLE_FEED_CATS') && ($active_feed_id > 0 || $is_cat)) {
0a6c4846 2660 print "<option $cat_preselected value=\"this_cat\">This category ($feed_cat_title)</option>";
86b682ce
AD
2661 } else {
2662 print "<option disabled>This category</option>";
b0005823
AD
2663 }
2664
86b682ce
AD
2665 print "</select></td></tr>";
2666
2667 print "<tr><td>Match on:</td><td>";
2668
2669 $search_fields = array(
2670 "title" => "Title",
2671 "content" => "Content",
2672 "both" => "Title or content");
e5d758e3 2673
86b682ce
AD
2674 print_select_hash("match_on", 3, $search_fields);
2675
2676 print "</td></tr></table>";
2677
2678 print "</form>";
2679
2680 print "<div align=\"right\">
033e47e0 2681 <input type=\"submit\"
2371c520
AD
2682 class=\"button\" onclick=\"javascript:search()\"
2683 id=\"search_submit_btn\" disabled=\"true\"
2684 value=\"Search\">
033e47e0 2685 <input class=\"button\"
86b682ce
AD
2686 type=\"submit\" onclick=\"javascript:searchCancel()\"
2687 value=\"Cancel\"></div>";
2688
2689 print "</div>";
033e47e0
AD
2690
2691 }
2692
a24f525c
AD
2693 if ($id == "quickAddFilter") {
2694
757e8a2d
AD
2695 $active_feed_id = db_escape_string($_GET["param"]);
2696
e5d758e3
AD
2697 print "<div id=\"infoBoxTitle\">Create filter</div>";
2698 print "<div class=\"infoBoxContents\">";
2699
79f3553b
AD
2700 print "<form id=\"filter_add_form\">";
2701
2702 print "<input type=\"hidden\" name=\"op\" value=\"pref-filters\">";
2703 print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
c14b5566 2704 print "<input type=\"hidden\" name=\"subop\" value=\"add\">";
79f3553b 2705
c6932f8d 2706// print "<div class=\"notice\"><b>Note:</b> filter will only apply to new articles.</div>";
757e8a2d 2707
79f3553b 2708 $result = db_query($link, "SELECT id,description
a24f525c
AD
2709 FROM ttrss_filter_types ORDER BY description");
2710
2711 $filter_types = array();
2712
2713 while ($line = db_fetch_assoc($result)) {
79f3553b
AD
2714 //array_push($filter_types, $line["description"]);
2715 $filter_types[$line["id"]] = $line["description"];
a24f525c
AD
2716 }
2717
e5d758e3 2718 print "<table width='100%'>";
a24f525c 2719
2371c520 2720 print "<tr><td>Match:</td>
86b682ce
AD
2721 <td><input onkeypress=\"return filterCR(event)\"
2722 onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
4220b0bd
AD
2723 name=\"reg_exp\" class=\"iedit\">";
2724 print "</td><td>";
2725
2726 print_select_hash("filter_type", 1, $filter_types, "class=\"iedit\"");
a24f525c
AD
2727
2728 print "</td></tr>";
4220b0bd 2729 print "<tr><td>Feed:</td><td colspan='2'>";
673d54ca 2730
757e8a2d 2731 print_feed_select($link, "feed_id", $active_feed_id);
673d54ca
AD
2732
2733 print "</td></tr>";
a24f525c
AD
2734
2735 print "<tr><td>Action:</td>";
2736
4220b0bd 2737 print "<td colspan='2'><select name=\"action_id\">";
a24f525c
AD
2738
2739 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2740 ORDER BY name");
2741
2742 while ($line = db_fetch_assoc($result)) {
79f3553b 2743 printf("<option value='%d'>%s</option>", $line["id"], $line["description"]);
a24f525c
AD
2744 }
2745
2746 print "</select>";
c14b5566
AD
2747
2748 print "</td></tr></table>";
2749
2750 print "</form>";
2751
2752 print "<div align='right'>";
2753
a24f525c 2754 print "<input type=\"submit\"
2371c520 2755 id=\"infobox_submit\"
90ac84df 2756 class=\"button\" onclick=\"return qaddFilter()\"
2371c520 2757 disabled=\"true\" value=\"Create\"> ";
a24f525c
AD
2758
2759 print "<input class=\"button\"
90ac84df 2760 type=\"submit\" onclick=\"return closeInfoBox()\"
e5d758e3 2761 value=\"Cancel\">";
a24f525c 2762
c14b5566 2763 print "</div>";
e5d758e3 2764
c14b5566 2765// print "</td></tr></table>";
79f3553b 2766
a24f525c 2767 }
7b5c6012
AD
2768
2769 print "</div>";
2770
f84a97a3
AD
2771 }
2772
a2770077
AD
2773 // update feeds of all users, may be used anonymously
2774 if ($op == "globalUpdateFeeds") {
2775
2776 $result = db_query($link, "SELECT id FROM ttrss_users");
2777
2778 while ($line = db_fetch_assoc($result)) {
2779 $user_id = $line["id"];
2780// print "<!-- updating feeds of uid $user_id -->";
2781 update_all_feeds($link, false, $user_id);
2782 }
e65af9c1 2783
a2770077
AD
2784 print "<rpc-reply>
2785 <message msg=\"All feeds updated\"/>
2786 </rpc-reply>";
e65af9c1
AD
2787
2788 }
2789
77e96719
AD
2790 if ($op == "pref-prefs") {
2791
b1895692 2792 $subop = $_REQUEST["subop"];
77e96719
AD
2793
2794 if ($subop == "Save configuration") {
2795
d2892032
AD
2796 if (WEB_DEMO_MODE) {
2797 header("Location: prefs.php");
2798 return;
2799 }
01d68cf9 2800
93cb4442
AD
2801 $_SESSION["prefs_op_result"] = "save-config";
2802
11de82c3
AD
2803 $_SESSION["prefs_cache"] = false;
2804
77e96719
AD
2805 foreach (array_keys($_POST) as $pref_name) {
2806
2807 $pref_name = db_escape_string($pref_name);
2808 $value = db_escape_string($_POST[$pref_name]);
2809
2810 $result = db_query($link, "SELECT type_name
2811 FROM ttrss_prefs,ttrss_prefs_types
2812 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
2813
2814 if (db_num_rows($result) > 0) {
2815
2816 $type_name = db_fetch_result($result, 0, "type_name");
2817
5da169d9
AD
2818// print "$pref_name : $type_name : $value<br>";
2819
77e96719 2820 if ($type_name == "bool") {
5da169d9 2821 if ($value == "1") {
77e96719
AD
2822 $value = "true";
2823 } else {
2824 $value = "false";
2825 }
2826 } else if ($type_name == "integer") {
2827 $value = sprintf("%d", $value);
2828 }
2829
2830// print "$pref_name : $type_name : $value<br>";
2831
ff485f1d
AD
2832 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
2833 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
77e96719
AD
2834
2835 }
2836
2837 header("Location: prefs.php");
2838
2839 }
2840
b1895692
AD
2841 } else if ($subop == "getHelp") {
2842
2843 $pref_name = db_escape_string($_GET["pn"]);
2844
2845 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
2846 WHERE pref_name = '$pref_name'");
2847
2848 if (db_num_rows($result) > 0) {
2849 $help_text = db_fetch_result($result, 0, "help_text");
2850 print $help_text;
2851 } else {
2852 print "Unknown option: $pref_name";
2853 }
2854
cbb01696
AD
2855 } else if ($subop == "Change e-mail") {
2856
2857 if (WEB_DEMO_MODE) {
2858 header("Location: prefs.php");
2859 return;
2860 }
2861
2862 $email = db_escape_string($_GET["email"]);
2863 $active_uid = $_SESSION["uid"];
2864
2865 if ($email) {
2866 db_query($link, "UPDATE ttrss_users SET email = '$email'
2867 WHERE id = '$active_uid'");
2868 }
2869
2870 header("Location: prefs.php");
2871
1c7f75ed
AD
2872 } else if ($subop == "Change password") {
2873
d2892032
AD
2874 if (WEB_DEMO_MODE) {
2875 header("Location: prefs.php");
2876 return;
2877 }
1c7f75ed
AD
2878
2879 $old_pw = $_POST["OLD_PASSWORD"];
2880 $new_pw = $_POST["OLD_PASSWORD"];
2881
2882 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
2883 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
2884
2885 $active_uid = $_SESSION["uid"];
2886
2887 if ($old_pw && $new_pw) {
2888
2889 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
2890
2891 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
2892 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
2893 pwd_hash = '$old_pw_hash')");
2894
2895 if (db_num_rows($result) == 1) {
2896 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
2897 WHERE id = '$active_uid'");
b791095d
AD
2898
2899 $_SESSION["pwd_change_result"] = "ok";
2900 } else {
2901 $_SESSION["pwd_change_result"] = "failed";
1c7f75ed
AD
2902 }
2903 }
2904
2905 header("Location: prefs.php");
b791095d 2906
77e96719
AD
2907 } else if ($subop == "Reset to defaults") {
2908
d2892032
AD
2909 if (WEB_DEMO_MODE) {
2910 header("Location: prefs.php");
2911 return;
2912 }
01d68cf9 2913
93cb4442
AD
2914 $_SESSION["prefs_op_result"] = "reset-to-defaults";
2915
e1aa0559
AD
2916 if (DB_TYPE == "pgsql") {
2917 db_query($link,"UPDATE ttrss_user_prefs
2918 SET value = ttrss_prefs.def_value
2919 WHERE owner_uid = '".$_SESSION["uid"]."' AND
2920 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
2921 } else {
2922 db_query($link, "DELETE FROM ttrss_user_prefs
2923 WHERE owner_uid = ".$_SESSION["uid"]);
2924 initialize_user_prefs($link, $_SESSION["uid"]);
2925 }
5da169d9 2926
77e96719
AD
2927 header("Location: prefs.php");
2928
58f8ad54
AD
2929 } else if ($subop == "Change theme") {
2930
2931 $theme = db_escape_string($_POST["theme"]);
2932
2933 if ($theme == "Default") {
2934 $theme_qpart = 'NULL';
2935 } else {
2936 $theme_qpart = "'$theme'";
2937 }
2938
6752e330
AD
2939 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
2940 WHERE theme_name = '$theme'");
2941
2942 if (db_num_rows($result) == 1) {
2943 $theme_id = db_fetch_result($result, 0, "id");
2944 $theme_path = db_fetch_result($result, 0, "theme_path");
2945 } else {
2946 $theme_id = "NULL";
2947 $theme_path = "";
2948 }
2949
58f8ad54 2950 db_query($link, "UPDATE ttrss_users SET
6752e330 2951 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
58f8ad54 2952
6752e330 2953 $_SESSION["theme"] = $theme_path;
503eb349 2954
58f8ad54
AD
2955 header("Location: prefs.php");
2956
77e96719
AD
2957 } else {
2958
7d4c898a 2959 if (!SINGLE_USER_MODE) {
1c7f75ed 2960
cbb01696 2961 $result = db_query($link, "SELECT id,email FROM ttrss_users
a029d530
AD
2962 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
2963 pwd_hash = 'SHA1:".sha1("password")."')");
2964
2965 if (db_num_rows($result) != 0) {
b791095d 2966 print "<div class=\"warning\">
a029d530
AD
2967 Your password is at default value, please change it.
2968 </div>";
2969 }
2970
b791095d
AD
2971 if ($_SESSION["pwd_change_result"] == "failed") {
2972 print "<div class=\"warning\">
2973 There was an error while changing your password.
2974 </div>";
2975 }
2976
2977 if ($_SESSION["pwd_change_result"] == "ok") {
2978 print "<div class=\"notice\">
2979 Password changed successfully.
2980 </div>";
2981 }
2982
2983 $_SESSION["pwd_change_result"] = "";
2984
93cb4442
AD
2985 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
2986 print "<div class=\"notice\">
2987 Your configuration was reset to defaults.
2988 </div>";
2989 }
2990
2991 if ($_SESSION["prefs_op_result"] == "save-config") {
2992 print "<div class=\"notice\">
2993 Your configuration was saved successfully.
2994 </div>";
2995 }
2996
2997 $_SESSION["prefs_op_result"] = "";
2998
cbb01696
AD
2999 print "<form action=\"backend.php\" method=\"GET\">";
3000
3001 print "<table width=\"100%\" class=\"prefPrefsList\">";
3002 print "<tr><td colspan='3'><h3>Personal data</h3></tr></td>";
3003
3004 $result = db_query($link, "SELECT email FROM ttrss_users
3005 WHERE id = ".$_SESSION["uid"]);
3006
3007 $email = db_fetch_result($result, 0, "email");
3008
3009 print "<tr><td width=\"40%\">E-mail</td>";
3010 print "<td><input class=\"editbox\" name=\"email\"
3011 value=\"$email\"></td></tr>";
3012
3013 print "</table>";
3014
3015 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3016
3017 print "<p><input class=\"button\" type=\"submit\"
3018 value=\"Change e-mail\" name=\"subop\">";
3019
a132b8b1
AD
3020 print "</form>";
3021
64dc5976 3022 print "<form action=\"backend.php\" method=\"POST\" name=\"changePassForm\">";
7d4c898a
AD
3023
3024 print "<table width=\"100%\" class=\"prefPrefsList\">";
3025 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
3026
3027 print "<tr><td width=\"40%\">Old password</td>";
3028 print "<td><input class=\"editbox\" type=\"password\"
3029 name=\"OLD_PASSWORD\"></td></tr>";
3030
3031 print "<tr><td width=\"40%\">New password</td>";
3032
3033 print "<td><input class=\"editbox\" type=\"password\"
3034 name=\"NEW_PASSWORD\"></td></tr>";
3035
3036 print "</table>";
3037
3038 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3039
3040 print "<p><input class=\"button\" type=\"submit\"
64dc5976 3041 onclick=\"return validateNewPassword(this.form)\"
7d4c898a
AD
3042 value=\"Change password\" name=\"subop\">";
3043
3044 print "</form>";
1c7f75ed 3045
7d4c898a 3046 }
1c7f75ed 3047
58f8ad54
AD
3048 $result = db_query($link, "SELECT
3049 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
3050
3051 $user_theme_id = db_fetch_result($result, 0, "theme_id");
3052
3053 $result = db_query($link, "SELECT
3054 id,theme_name FROM ttrss_themes ORDER BY theme_name");
3055
3056 if (db_num_rows($result) > 0) {
6752e330
AD
3057
3058 print "<form action=\"backend.php\" method=\"POST\">";
3059 print "<table width=\"100%\" class=\"prefPrefsList\">";
3060 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
3061 print "<tr><td width=\"40%\">Select theme</td>";
3062 print "<td><select name=\"theme\">";
3063 print "<option>Default</option>";
58f8ad54 3064 print "<option disabled>--------</option>";
6752e330 3065
58f8ad54
AD
3066 while ($line = db_fetch_assoc($result)) {
3067 if ($line["id"] == $user_theme_id) {
3068 $selected = "selected";
3069 } else {
3070 $selected = "";
3071 }
3072 print "<option $selected>" . $line["theme_name"] . "</option>";
3073 }
6752e330
AD
3074 print "</select></td></tr>";
3075 print "</table>";
3076 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3077 print "<p><input class=\"button\" type=\"submit\"
3078 value=\"Change theme\" name=\"subop\">";
3079 print "</form>";
58f8ad54
AD
3080 }
3081
77e96719 3082 $result = db_query($link, "SELECT
ff485f1d 3083 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
77e96719 3084 section_name,def_value
ff485f1d 3085 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
77e96719 3086 WHERE type_id = ttrss_prefs_types.id AND
ff485f1d 3087 section_id = ttrss_prefs_sections.id AND
a2411bd9
AD
3088 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
3089 owner_uid = ".$_SESSION["uid"]."
650bc435 3090 ORDER BY section_id,short_desc");
77e96719
AD
3091
3092 print "<form action=\"backend.php\" method=\"POST\">";
3093
77e96719
AD
3094 $lnum = 0;
3095
3096 $active_section = "";
3097
3098 while ($line = db_fetch_assoc($result)) {
3099
3100 if ($active_section != $line["section_name"]) {
59a654ba
AD
3101
3102 if ($active_section != "") {
1c7f75ed 3103 print "</table>";
59a654ba 3104 }
1c7f75ed
AD
3105
3106 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
59a654ba
AD
3107
3108 $active_section = $line["section_name"];
3109
77e96719 3110 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
59a654ba
AD
3111// print "<tr class=\"title\">
3112// <td width=\"25%\">Option</td><td>Value</td></tr>";
7268adf7
AD
3113
3114 $lnum = 0;
77e96719
AD
3115 }
3116
650bc435 3117// $class = ($lnum % 2) ? "even" : "odd";
77e96719 3118
650bc435 3119 print "<tr>";
77e96719 3120
77e96719
AD
3121 $type_name = $line["type_name"];
3122 $pref_name = $line["pref_name"];
3123 $value = $line["value"];
3124 $def_value = $line["def_value"];
b1895692
AD
3125 $help_text = $line["help_text"];
3126
3127 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
3128
3129 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
3130
3131 print "</td>";
77e96719
AD
3132
3133 print "<td>";
3134
3135 if ($type_name == "bool") {
3136// print_select($pref_name, $value, array("true", "false"));
3137
3138 if ($value == "true") {
3139 $value = "Yes";
3140 } else {
3141 $value = "No";
3142 }
3143
3144 print_radio($pref_name, $value, array("Yes", "No"));
3145
3146 } else {
3147 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
3148 }
3149
3150 print "</td>";
3151
3152 print "</tr>";
3153
3154 $lnum++;
3155 }
3156
3157 print "</table>";
3158
3159 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3160
3161 print "<p><input class=\"button\" type=\"submit\"
3162 name=\"subop\" value=\"Save configuration\">";
3163
3164 print "&nbsp;<input class=\"button\" type=\"submit\"
69668465
AD
3165 name=\"subop\" onclick=\"return validatePrefsReset()\"
3166 value=\"Reset to defaults\"></p>";
77e96719
AD
3167
3168 print "</form>";
3169
3170 }
3171
3172 }
3173
e6cb77a0
AD
3174 if ($op == "pref-users") {
3175
3176 $subop = $_GET["subop"];
3177
3c5783b7
AD
3178 if ($subop == "edit") {
3179
3180 $id = db_escape_string($_GET["id"]);
3181
3182 print "<div id=\"infoBoxTitle\">User editor</div>";
3183
3184 print "<div class=\"infoBoxContents\">";
3185
3186 print "<form id=\"user_edit_form\">";
3187
3188 print "<input type=\"hidden\" name=\"id\" value=\"$id\">";
3189 print "<input type=\"hidden\" name=\"op\" value=\"pref-users\">";
3190 print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
3191
3192 $result = db_query($link, "SELECT * FROM ttrss_users WHERE id = '$id'");
3193
3194 $login = db_fetch_result($result, 0, "login");
3195 $access_level = db_fetch_result($result, 0, "access_level");
3196 $email = db_fetch_result($result, 0, "email");
3197
3198 print "<table width='100%'>";
3199 print "<tr><td>Login:</td><td>
ac2cc246
AD
3200 <input class=\"iedit\" onkeypress=\"return filterCR(event)\"
3201 name=\"login\" value=\"$login\"></td></tr>";
3c5783b7
AD
3202
3203 print "<tr><td>Change password:</td><td>
ac2cc246
AD
3204 <input class=\"iedit\" onkeypress=\"return filterCR(event)\"
3205 name=\"password\"></td></tr>";
3c5783b7
AD
3206
3207 print "<tr><td>E-mail:</td><td>
ac2cc246
AD
3208 <input class=\"iedit\" name=\"email\" onkeypress=\"return filterCR(event)\"
3209 value=\"$email\"></td></tr>";
3c5783b7
AD
3210
3211 $sel_disabled = ($id == $_SESSION["uid"]) ? "disabled" : "";
3212
3213 print "<tr><td>Access level:</td><td>";
3214 print_select_hash("access_level", $access_level, $access_level_names,
3215 $sel_disabled);
3216 print "</td></tr>";
3217
3218 print "</table>";
3219
3220 print "</form>";
3221
3222 print "<div align='right'>
3223 <input class=\"button\"
90ac84df
AD
3224 type=\"submit\" onclick=\"return userEditSave()\"
3225 value=\"Save\">
3c5783b7 3226 <input class=\"button\"
90ac84df 3227 type=\"submit\" onclick=\"return userEditCancel()\"
3c5783b7
AD
3228 value=\"Cancel\"></div>";
3229
3230 print "</div>";
3231
3232 return;
3233 }
3234
e6cb77a0
AD
3235 if ($subop == "editSave") {
3236
3c5783b7 3237 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
e6cb77a0 3238
3c5783b7 3239 $login = db_escape_string(trim($_GET["login"]));
e6cb77a0 3240 $uid = db_escape_string($_GET["id"]);
3c5783b7
AD
3241 $access_level = sprintf("%d", $_GET["access_level"]);
3242 $email = db_escape_string(trim($_GET["email"]));
3243 $password = db_escape_string(trim($_GET["password"]));
3244
3245 if ($password) {
3246 $pwd_hash = 'SHA1:' . sha1($password);
3247 $pass_query_part = "pwd_hash = '$pwd_hash', ";
3248 print "<div class='notice'>Changed password for user <b>$login</b>.</div>";
3249 } else {
3250 $pass_query_part = "";
3251 }
e6cb77a0 3252
3c5783b7 3253 db_query($link, "UPDATE ttrss_users SET $pass_query_part login = '$login',
72932a75 3254 access_level = '$access_level', email = '$email' WHERE id = '$uid'");
e6cb77a0
AD
3255
3256 }
3257 } else if ($subop == "remove") {
3258
3259 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3260
f932bc9f 3261 $ids = split(",", db_escape_string($_GET["ids"]));
e6cb77a0
AD
3262
3263 foreach ($ids as $id) {
3264 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
3265
3266 }
3267 }
3268 } else if ($subop == "add") {
3269
3270 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3271
b6b535ca 3272 $login = db_escape_string(trim($_GET["login"]));
e6cb77a0
AD
3273 $tmp_user_pwd = make_password(8);
3274 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3275
e6cb77a0 3276 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
ce3bf408 3277 login = '$login'");
e6cb77a0 3278
ce3bf408 3279 if (db_num_rows($result) == 0) {
e6cb77a0 3280
ce3bf408
AD
3281 db_query($link, "INSERT INTO ttrss_users
3282 (login,pwd_hash,access_level,last_login)
3283 VALUES ('$login', '$pwd_hash', 0, NOW())");
3284
3285
3286 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3287 login = '$login' AND pwd_hash = '$pwd_hash'");
3288
3289 if (db_num_rows($result) == 1) {
3290
3291 $new_uid = db_fetch_result($result, 0, "id");
3292
3293 print "<div class=\"notice\">Added user <b>".$_GET["login"].
3294 "</b> with password <b>$tmp_user_pwd</b>.</div>";
3295
3296 initialize_user($link, $new_uid);
3297
3298 } else {
3299
3300 print "<div class=\"warning\">Could not create user <b>".
3301 $_GET["login"]."</b></div>";
3302
3303 }
e6cb77a0 3304 } else {
ce3bf408
AD
3305 print "<div class=\"warning\">User <b>".
3306 $_GET["login"]."</b> already exists.</div>";
e6cb77a0
AD
3307 }
3308 }
3309 } else if ($subop == "resetPass") {
3310
3311 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3312
3313 $uid = db_escape_string($_GET["id"]);
3314
72932a75
AD
3315 $result = db_query($link, "SELECT login,email
3316 FROM ttrss_users WHERE id = '$uid'");
e6cb77a0
AD
3317
3318 $login = db_fetch_result($result, 0, "login");
72932a75 3319 $email = db_fetch_result($result, 0, "email");
e6cb77a0
AD
3320 $tmp_user_pwd = make_password(8);
3321 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3322
3323 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
3324 WHERE id = '$uid'");
3325
3326 print "<div class=\"notice\">Changed password of
72932a75
AD
3327 user <b>$login</b> to <b>$tmp_user_pwd</b>.";
3328
3329 if (MAIL_RESET_PASS && $email) {
3330 print " Notifying <b>$email</b>.";
3331
3332 mail("$login <$email>", "Password reset notification",
3333 "Hi, $login.\n".
3334 "\n".
3335 "Your password for this TT-RSS installation was reset by".
3336 " an administrator.\n".
3337 "\n".
3338 "Your new password is $tmp_user_pwd, please remember".
3339 " it for later reference.\n".
3340 "\n".
3341 "Sincerely, TT-RSS Mail Daemon.", "From: " . MAIL_FROM);
3342 }
3343
3344 print "</div>";
e6cb77a0
AD
3345
3346 }
3347 }
3348
2c7070b5 3349 print "<div class=\"prefGenericAddBox\">
2371c520
AD
3350 <input id=\"uadd_box\"
3351 onkeyup=\"toggleSubmitNotEmpty(this, 'user_add_btn')\"
292a8a12 3352 size=\"40\">&nbsp;";
e6cb77a0 3353
2c7070b5 3354 print"<input type=\"submit\" class=\"button\"
2371c520
AD
3355 id=\"user_add_btn\" disabled=\"true\"
3356 onclick=\"javascript:addUser()\" value=\"Create user\"></div>";
e6cb77a0
AD
3357
3358 $result = db_query($link, "SELECT
72932a75 3359 id,login,access_level,email,
fe99ab12 3360 SUBSTRING(last_login,1,16) as last_login
e6cb77a0
AD
3361 FROM
3362 ttrss_users
3363 ORDER by login");
3364
59a543f0 3365// print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1a7572cb 3366
f4fe2cde
AD
3367 print "<p><table width=\"100%\" cellspacing=\"0\"
3368 class=\"prefUserList\" id=\"prefUserList\">";
e6cb77a0 3369
35f3c923
AD
3370 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
3371 Select:
ce3bf408
AD
3372 <a href=\"javascript:selectPrefRows('user', true)\">All</a>,
3373 <a href=\"javascript:selectPrefRows('user', false)\">None</a>
35f3c923
AD
3374 </td</tr>";
3375
e6cb77a0 3376 print "<tr class=\"title\">
e325c6e7 3377 <td align='center' width=\"5%\">&nbsp;</td>
3c5783b7
AD
3378 <td width='40%'>Login</td>
3379 <td width='40%'>Access Level</td>
3380 <td width='30%'>Last login</td></tr>";
e6cb77a0
AD
3381
3382 $lnum = 0;
3383
3384 while ($line = db_fetch_assoc($result)) {
3385
3386 $class = ($lnum % 2) ? "even" : "odd";
3387
3388 $uid = $line["id"];
3389 $edit_uid = $_GET["id"];
3390
4154a415 3391 if ($subop == "edit" && $uid != $edit_uid) {
e6cb77a0 3392 $class .= "Grayed";
53226edc
AD
3393 $this_row_id = "";
3394 } else {
3395 $this_row_id = "id=\"UMRR-$uid\"";
3396 }
3397
3398 print "<tr class=\"$class\" $this_row_id>";
e6cb77a0
AD
3399
3400 $line["login"] = htmlspecialchars($line["login"]);
3401
6be6bc03
AD
3402 $line["last_login"] = date(get_pref($link, 'SHORT_DATE_FORMAT'),
3403 strtotime($line["last_login"]));
3404
5917a8e4
AD
3405 $access_level_names = array(0 => "User", 10 => "Administrator");
3406
3c5783b7 3407// if (!$edit_uid || $subop != "edit") {
e6cb77a0 3408
ce3bf408 3409 print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"user\");'
1a7572cb 3410 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
e6cb77a0
AD
3411
3412 print "<td><a href=\"javascript:editUser($uid);\">" .
3413 $line["login"] . "</td>";
72932a75 3414
0b68215c
AD
3415 if (!$line["email"]) $line["email"] = "&nbsp;";
3416
e6cb77a0 3417 print "<td><a href=\"javascript:editUser($uid);\">" .
5917a8e4 3418 $access_level_names[$line["access_level"]] . "</td>";
e6cb77a0 3419
3c5783b7 3420/* } else if ($uid != $edit_uid) {
e6cb77a0 3421
0b68215c
AD
3422 if (!$line["email"]) $line["email"] = "&nbsp;";
3423
72932a75 3424 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
e6cb77a0
AD
3425 id=\"UMCHK-".$line["id"]."\"></td>";
3426
3427 print "<td>".$line["login"]."</td>";
72932a75 3428 print "<td>".$line["email"]."</td>";
5917a8e4 3429 print "<td>".$access_level_names[$line["access_level"]]."</td>";
e6cb77a0
AD
3430
3431 } else {
3432
72932a75
AD
3433 print "<td align='center'>
3434 <input disabled=\"true\" type=\"checkbox\" checked></td>";
e6cb77a0
AD
3435
3436 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
3437 "\"></td>";
3438
72932a75
AD
3439 print "<td><input id=\"iedit_email\" value=\"".$line["email"].
3440 "\"></td>";
3441
5917a8e4
AD
3442 print "<td>";
3443 print "<select id=\"iedit_ulevel\">";
3444 foreach (array_keys($access_level_names) as $al) {
3445 if ($al == $line["access_level"]) {
3446 $selected = "selected";
3447 } else {
3448 $selected = "";
3449 }
3450 print "<option $selected id=\"$al\">" .
3451 $access_level_names[$al] . "</option>";
3452 }
3453 print "</select>";
3454 print "</td>";
3455
3c5783b7 3456 } */
e6cb77a0 3457
f6f32198
AD
3458 print "<td>".$line["last_login"]."</td>";
3459
e6cb77a0
AD
3460 print "</tr>";
3461
3462 ++$lnum;
3463 }
3464
3465 print "</table>";
3466
ce3bf408 3467 print "<p id='userOpToolbar'>";
e6cb77a0 3468
3c5783b7 3469/* if ($subop == "edit") {
d10fabe4 3470 print "Edit user:
e6cb77a0 3471 <input type=\"submit\" class=\"button\"
d10fabe4 3472 onclick=\"javascript:userEditSave()\" value=\"Save\">
e6cb77a0 3473 <input type=\"submit\" class=\"button\"
d10fabe4 3474 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">";
e6cb77a0 3475
3c5783b7 3476 } else { */
e6cb77a0
AD
3477
3478 print "
3479 Selection:
ce3bf408 3480 <input type=\"submit\" class=\"button\" disabled=\"true\"
717f5e64 3481 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
ce3bf408 3482 <input type=\"submit\" class=\"button\" disabled=\"true\"
e6cb77a0 3483 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
ce3bf408 3484 <input type=\"submit\" class=\"button\" disabled=\"true\"
717f5e64 3485 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
ce3bf408 3486 <input type=\"submit\" class=\"button\" disabled=\"true\"
717f5e64
AD
3487 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
3488
3c5783b7 3489// }
717f5e64
AD
3490 }
3491
3492 if ($op == "user-details") {
3493
3494 if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
3495 return;
3496 }
3497
1a7572cb 3498/* print "<html><head>
717f5e64
AD
3499 <title>Tiny Tiny RSS : User Details</title>
3500 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
3501 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1a7572cb 3502 </head><body>"; */
717f5e64
AD
3503
3504 $uid = sprintf("%d", $_GET["id"]);
3505
e5d758e3
AD
3506 print "<div id=\"infoBoxTitle\">User details</div>";
3507
c6c3a07f 3508 print "<div class='infoBoxContents'>";
717f5e64 3509
fe99ab12
AD
3510 $result = db_query($link, "SELECT login,
3511 SUBSTRING(last_login,1,16) AS last_login,
3512 access_level,
c6c3a07f
AD
3513 (SELECT COUNT(int_id) FROM ttrss_user_entries
3514 WHERE owner_uid = id) AS stored_articles
717f5e64
AD
3515 FROM ttrss_users
3516 WHERE id = '$uid'");
3517
3518 if (db_num_rows($result) == 0) {
3519 print "<h1>User not found</h1>";
3520 return;
3521 }
3522
adba6b85
AD
3523# print "<h1>User Details</h1>";
3524
3525 $login = db_fetch_result($result, 0, "login");
3526
c0ae0fdb 3527# print "<h1>$login</h1>";
717f5e64
AD
3528
3529 print "<table width='100%'>";
3530
6be6bc03
AD
3531 $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'),
3532 strtotime(db_fetch_result($result, 0, "last_login")));
717f5e64 3533 $access_level = db_fetch_result($result, 0, "access_level");
c6c3a07f 3534 $stored_articles = db_fetch_result($result, 0, "stored_articles");
717f5e64 3535
adba6b85 3536# print "<tr><td>Username</td><td>$login</td></tr>";
c0ae0fdb 3537# print "<tr><td>Access level</td><td>$access_level</td></tr>";
717f5e64 3538 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
c6c3a07f 3539 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
717f5e64
AD
3540
3541 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
3542 WHERE owner_uid = '$uid'");
3543
3544 $num_feeds = db_fetch_result($result, 0, "num_feeds");
3545
3546 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
3547
5d15d3ea 3548/* $result = db_query($link, "SELECT
717f5e64 3549 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
c6c3a07f
AD
3550 FROM ttrss_user_entries,ttrss_entries
3551 WHERE owner_uid = '$uid' AND ref_id = id");
717f5e64 3552
d9f115c3 3553 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
717f5e64 3554
c6c3a07f 3555 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
717f5e64
AD
3556
3557 print "</table>";
3558
3559 print "<h1>Subscribed feeds</h1>";
3560
e94645ca 3561 $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
9b3e2cc7 3562 WHERE owner_uid = '$uid' ORDER BY title");
717f5e64 3563
9b3e2cc7 3564 print "<ul class=\"userFeedList\">";
717f5e64 3565
adba6b85
AD
3566 $row_class = "odd";
3567
717f5e64
AD
3568 while ($line = db_fetch_assoc($result)) {
3569
3570 $icon_file = ICONS_URL."/".$line["id"].".ico";
3571
3572 if (file_exists($icon_file) && filesize($icon_file) > 0) {
6c56687e 3573 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
717f5e64 3574 } else {
5951ded1 3575 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
717f5e64
AD
3576 }
3577
adba6b85
AD
3578 print "<li class=\"$row_class\">$feed_icon&nbsp;<a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
3579
3580 $row_class = toggleEvenOdd($row_class);
3581
e6cb77a0 3582 }
717f5e64 3583
a88c1f36
AD
3584 if (db_num_rows($result) < $num_feeds) {
3585 // FIXME - add link to show ALL subscribed feeds here somewhere
3586 print "<li><img
3587 class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">&nbsp;...</li>";
3588 }
3589
717f5e64
AD
3590 print "</ul>";
3591
717f5e64
AD
3592 print "</div>";
3593
1a7572cb
AD
3594 print "<div align='center'>
3595 <input type='submit' class='button'
c6c3a07f 3596 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
1a7572cb
AD
3597
3598// print "</body></html>";
717f5e64 3599
e6cb77a0
AD
3600 }
3601
c6232e43
AD
3602 if ($op == "pref-feed-browser") {
3603
e2f728be
AD
3604 if (!ENABLE_FEED_BROWSER) {
3605 print "Feed browser is administratively disabled.";
3606 return;
3607 }
3608
c6232e43
AD
3609 $subop = $_REQUEST["subop"];
3610
3611 if ($subop == "details") {
3612 $id = db_escape_string($_GET["id"]);
c2b2aee0 3613
072f1ee2
AD
3614 print "<div class=\"browserFeedInfo\">";
3615 print "<b>Feed information:</b>";
3616 print "<div class=\"detailsPart\">";
3617
3618 $result = db_query($link, "SELECT
3619 feed_url,site_url,
3620 SUBSTRING(last_updated,1,19) AS last_updated
3621 FROM ttrss_feeds WHERE id = '$id'");
3622
3623 $feed_url = db_fetch_result($result, 0, "feed_url");
3624 $site_url = db_fetch_result($result, 0, "site_url");
3625 $last_updated = db_fetch_result($result, 0, "last_updated");
3626
3627 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
3628 $last_updated = smart_date_time(strtotime($last_updated));
3629 } else {
3630 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
3631 $last_updated = date($short_date, strtotime($last_updated));
3632 }
3633
3634 print "Site: <a href='$site_url'>$site_url</a> ".
3635 "(<a href='$feed_url'>feed</a>), ".
3636 "Last updated: $last_updated";
3637
3638 print "</div>";
3639
3640 $result = db_query($link, "SELECT
3641 ttrss_entries.title,
3642 content,
c2b2aee0
AD
3643 substring(date_entered,1,19) as date_entered,
3644 substring(updated,1,19) as updated
072f1ee2
AD
3645 FROM ttrss_entries,ttrss_user_entries
3646 WHERE ttrss_entries.id = ref_id AND feed_id = '$id'
c2b2aee0
AD
3647 ORDER BY updated DESC LIMIT 5");
3648
3649 if (db_num_rows($result) > 0) {
c2b2aee0
AD
3650
3651 print "<b>Last headlines:</b><br>";
3652
3653 print "<div class=\"detailsPart\">";
3654 print "<ul class=\"compact\">";
3655 while ($line = db_fetch_assoc($result)) {
3656
3657 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
3658 $entry_dt = smart_date_time(strtotime($line["updated"]));
3659 } else {
3660 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
3661 $entry_dt = date($short_date, strtotime($line["updated"]));
3662 }
3663
3664 print "<li>" . $line["title"] .
3665 "&nbsp;<span class=\"insensitive\">($entry_dt)</span></li>";
3666 }
3667 print "</ul></div>";
3668 }
072f1ee2
AD
3669
3670 print "</div>";
c2b2aee0 3671
c6232e43
AD
3672 return;
3673 }
65f28a40 3674
beccbed5
AD
3675 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>";
3676
6311acbe
AD
3677 $limit = db_escape_string($_GET["limit"]);
3678
3679 if (!$limit) $limit = 25;
3680
0af33e87
AD
3681 $owner_uid = $_SESSION["uid"];
3682
3683 $result = db_query($link, "SELECT feed_url,COUNT(id) AS subscribers
3684 FROM ttrss_feeds WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
3685 WHERE tf.feed_url = ttrss_feeds.feed_url
3686 AND owner_uid = '$owner_uid') GROUP BY feed_url
3687 ORDER BY subscribers DESC LIMIT $limit");
6311acbe 3688
0af33e87 3689
6311acbe
AD
3690 print "<div style=\"float : right\">
3691 Top <select id=\"feedBrowserLimit\">";
3692
3693 foreach (array(25, 50, 100) as $l) {
3694 $issel = ($l == $limit) ? "selected" : "";
3695 print "<option $issel>$l</option>";
3696 }
3697
3698 print "</select>
3699 <input type=\"submit\" class=\"button\"
3700 onclick=\"updateBigFeedBrowser()\" value=\"Show\">
3701 </div>";
0b68215c 3702
c0ae0fdb 3703 print "<p id=\"fbrOpToolbar\">Selection:
0b68215c 3704 <input type='submit' class='button' onclick=\"feedBrowserSubscribe()\"
c0ae0fdb 3705 disabled=\"true\" value=\"Subscribe\">";
0b68215c 3706
0fefdacc 3707 print "<ul class='nomarks' id='browseBigFeedList'>";
c6232e43
AD
3708
3709 $feedctr = 0;
3710
3711 while ($line = db_fetch_assoc($result)) {
3712 $feed_url = $line["feed_url"];
3713 $subscribers = $line["subscribers"];
c6232e43
AD
3714
3715 $det_result = db_query($link, "SELECT site_url,title,id
3716 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
3717
3718 $details = db_fetch_assoc($det_result);
3719
3720 $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
3721
3722 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3723 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
3724 "/".$details["id"].".ico\">";
3725 } else {
3726 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3727 }
3728
c0ae0fdb 3729 $check_box = "<input onclick='toggleSelectFBListRow(this)' class='feedBrowseCB'
c6232e43
AD
3730 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
3731
3732 $class = ($feedctr % 2) ? "even" : "odd";
3733
3734 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
3735 "$feed_icon ";
3736
c2b2aee0 3737 print "<a href=\"javascript:browserToggleExpand('".$details["id"]."')\">" .
c6232e43
AD
3738 $details["title"] ."</a>&nbsp;" .
3739 "<span class='subscribers'>($subscribers)</span>";
3740
3741 print "<div class=\"browserDetails\" id=\"BRDET-" . $details["id"] . "\">";
3742 print "</div>";
3743
3744 print "</li>";
3745
3746 ++$feedctr;
3747 }
3748
3749 if ($feedctr == 0) {
3750 print "<li>No feeds found to subscribe.</li>";
3751 }
3752
3753 print "</ul>";
3754
c6232e43
AD
3755 print "</div>";
3756
3757 }
3758
18664970
AD
3759 if ($op == "rss") {
3760 $feed = db_escape_string($_GET["id"]);
3761 $user = db_escape_string($_GET["user"]);
3762 $pass = db_escape_string($_GET["pass"]);
3763 $is_cat = $_GET["is_cat"] != false;
3764
e1eb2147
AD
3765 $search = db_escape_string($_GET["q"]);
3766 $match_on = db_escape_string($_GET["m"]);
3767 $search_mode = db_escape_string($_GET["smode"]);
3768
18664970
AD
3769 if (!$_SESSION["uid"] && $user && $pass) {
3770 authenticate_user($link, $user, $pass);
3771 }
3772
3773 if ($_SESSION["uid"] ||
3774 http_authenticate_user($link)) {
3775
e1eb2147
AD
3776 generate_syndicated_feed($link, $feed, $is_cat,
3777 $search, $search_mode, $match_on);
18664970
AD
3778 }
3779 }
3780
657770a0
AD
3781 function check_configuration_variables() {
3782 if (!defined('SESSION_EXPIRE_TIME')) {
adf702d6 3783 return "config: SESSION_EXPIRE_TIME is undefined";
657770a0
AD
3784 }
3785
3786 if (SESSION_EXPIRE_TIME < 60) {
adf702d6
AD
3787 return "config: SESSION_EXPIRE_TIME is too low (less than 60)";
3788 }
3789
3790 if (SESSION_EXPIRE_TIME < SESSION_COOKIE_LIFETIME_REMEMBER) {
3791 return "config: SESSION_EXPIRE_TIME should be greater or equal to" .
3792 "SESSION_COOKIE_LIFETIME_REMEMBER";
3793 }
3794
9a3bb96a 3795 if (defined('DISABLE_SESSIONS')) {
adf702d6 3796 return "config: you have enabled DISABLE_SESSIONS. Please disable this option.";
657770a0
AD
3797 }
3798
8a414837
AD
3799 if (DATABASE_BACKED_SESSIONS && SINGLE_USER_MODE) {
3800 return "config: DATABASE_BACKED_SESSIONS is incompatible with SINGLE_USER_MODE";
3801 }
3802
657770a0
AD
3803 return false;
3804 }
3805
88040f57
AD
3806 if ($op == "labelFromSearch") {
3807 $search = db_escape_string($_GET["search"]);
3808 $search_mode = db_escape_string($_GET["smode"]);
3809 $match_on = db_escape_string($_GET["match"]);
3810 $is_cat = db_escape_string($_GET["is_cat"]);
3811 $title = db_escape_string($_GET["title"]);
3812 $feed = sprintf("%d", $_GET["feed"]);
3813
3814 $label_qparts = array();
3815
3816 $search_expr = getSearchSql($search, $match_on);
3817
3818 if ($is_cat) {
3819 if ($feed != 0) {
3820 $search_expr .= " AND ttrss_feeds.cat_id = $feed ";
3821 } else {
3822 $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
3823 }
3824 } else {
3825 if ($search_mode == "all_feeds") {
3826 // NOOP
3827 } else if ($search_mode == "this_cat") {
3828
3829 $tmp_result = db_query($link, "SELECT cat_id
3830 FROM ttrss_feeds WHERE id = '$feed'");
3831
3832 $cat_id = db_fetch_result($tmp_result, 0, "cat_id");
3833
3834 if ($cat_id > 0) {
3835 $search_expr .= " AND ttrss_feeds.cat_id = $cat_id ";
3836 } else {
3837 $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
3838 }
3839 } else {
3840 $search_expr .= " AND ttrss_feeds.id = $feed ";
3841 }
3842
3843 }
3844
3845 $search_expr = db_escape_string($search_expr);
3846
3847 print $search_expr;
3848
3849 if ($title) {
3850 $result = db_query($link,
3851 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
3852 VALUES ('$search_expr', '$title', '".$_SESSION["uid"]."')");
3853 }
3854 }
3855
4b3dff6e 3856 db_close($link);
1cd17194 3857?>
406d9489
AD
3858
3859<!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
3860