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