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