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