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