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