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