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