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