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