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