]> git.wh0rd.org - tt-rss.git/blame - backend.php
fix: feed editor was broken if categories were disabled, bump version to p1
[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) {
8bde41c3
AD
1433 $category_qpart = "cat_id = '$cat_id',";
1434 $category_qpart_nocomma = "cat_id = '$cat_id'";
a2db6a4a 1435 } else {
8bde41c3
AD
1436 $category_qpart = 'cat_id = NULL,';
1437 $category_qpart_nocomma = 'cat_id = NULL';
a2db6a4a 1438 }
91ff844a 1439 } else {
a2db6a4a 1440 $category_qpart = "";
8bde41c3 1441 $category_qpart_nocomma = "";
91ff844a
AD
1442 }
1443
14f69488 1444 if ($parent_feed && $parent_feed != 0) {
a283b8d1 1445 $parent_qpart = "parent_feed = '$parent_feed'";
1da7e457 1446 } else {
a283b8d1 1447 $parent_qpart = 'parent_feed = NULL';
1da7e457
AD
1448 }
1449
648472a7 1450 $result = db_query($link, "UPDATE ttrss_feeds SET
8bde41c3 1451 $category_qpart $parent_qpart,
d148926e 1452 title = '$feed_title', feed_url = '$feed_link',
5d73494a 1453 update_interval = '$upd_intl',
47c6c988
AD
1454 purge_interval = '$purge_intl',
1455 auth_login = '$auth_login',
e3c99f3b 1456 auth_pass = '$auth_pass',
ac92cb46 1457 private = $private,
0da49bad 1458 rtl_content = $rtl_content,
3dd9183c
AD
1459 hidden = $hidden,
1460 include_in_digest = $include_in_digest
ac92cb46 1461 WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]);
a283b8d1 1462
8bde41c3
AD
1463 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1464 # update linked feed categories
1465 $result = db_query($link, "UPDATE ttrss_feeds SET
1466 $category_qpart_nocomma WHERE parent_feed = '$feed_id' AND
1467 owner_uid = " . $_SESSION["uid"]);
1468 }
5ddadb4c
AD
1469 }
1470
1471 if ($subop == "saveCat") {
605f7d46 1472 $cat_title = db_escape_string(trim($_GET["title"]));
5ddadb4c
AD
1473 $cat_id = db_escape_string($_GET["id"]);
1474
1475 $result = db_query($link, "UPDATE ttrss_feed_categories SET
1476 title = '$cat_title' WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]);
508a81e1 1477
83fe4d6d
AD
1478 }
1479
331900c6 1480 if ($subop == "remove") {
331900c6 1481
b0b4abcf 1482 if (!WEB_DEMO_MODE) {
331900c6 1483
f932bc9f 1484 $ids = split(",", db_escape_string($_GET["ids"]));
b0b4abcf
AD
1485
1486 foreach ($ids as $id) {
4769ddaf 1487
88040f57
AD
1488 if ($id > 0) {
1489
1490 db_query($link, "DELETE FROM ttrss_feeds
1491 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1492
1493 $icons_dir = ICONS_DIR;
d5caaae5 1494
88040f57
AD
1495 if (file_exists($icons_dir . "/$id.ico")) {
1496 unlink($icons_dir . "/$id.ico");
1497 }
1498 } else if ($id < -10) {
1499
1500 $label_id = -$id - 11;
1501
1502 db_query($link, "DELETE FROM ttrss_labels
1503 WHERE id = '$label_id' AND owner_uid = " . $_SESSION["uid"]);
d5caaae5 1504 }
b0b4abcf 1505 }
331900c6
AD
1506 }
1507 }
1508
1509 if ($subop == "add") {
b0b4abcf
AD
1510
1511 if (!WEB_DEMO_MODE) {
331900c6 1512
07eb9178
AD
1513 $feed_url = db_escape_string(trim($_GET["feed_url"]));
1514 $cat_id = db_escape_string($_GET["cat_id"]);
15da5cc1 1515
07eb9178 1516 if (subscribe_to_feed($link, $feed_url, $cat_id)) {
956c7629 1517 print "Added feed.";
15da5cc1 1518 } else {
7e9a3986 1519 print "<div class=\"warning\">
07eb9178 1520 Feed <b>$feed_url</b> already exists in the database.
7e9a3986 1521 </div>";
b0b4abcf
AD
1522 }
1523 }
331900c6 1524 }
a0d53889 1525
91ff844a
AD
1526 if ($subop == "addCat") {
1527
1528 if (!WEB_DEMO_MODE) {
1529
1530 $feed_cat = db_escape_string(trim($_GET["cat"]));
1531
1532 $result = db_query($link,
1533 "SELECT id FROM ttrss_feed_categories
1534 WHERE title = '$feed_cat' AND owner_uid = ".$_SESSION["uid"]);
1535
1536 if (db_num_rows($result) == 0) {
1537
1538 $result = db_query($link,
1539 "INSERT INTO ttrss_feed_categories (owner_uid,title)
1540 VALUES ('".$_SESSION["uid"]."', '$feed_cat')");
1541
1542 } else {
1543
1544 print "<div class=\"warning\">
1545 Category <b>$feed_cat</b> already exists in the database.
1546 </div>";
1547 }
1548
1549
1550 }
1551 }
1552
1553 if ($subop == "removeCats") {
1554
1555 if (!WEB_DEMO_MODE) {
1556
f932bc9f 1557 $ids = split(",", db_escape_string($_GET["ids"]));
91ff844a
AD
1558
1559 foreach ($ids as $id) {
1560
1561 db_query($link, "BEGIN");
1562
1563 $result = db_query($link,
1564 "SELECT count(id) as num_feeds FROM ttrss_feeds
1565 WHERE cat_id = '$id'");
1566
1567 $num_feeds = db_fetch_result($result, 0, "num_feeds");
1568
1569 if ($num_feeds == 0) {
1570 db_query($link, "DELETE FROM ttrss_feed_categories
1571 WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]);
1572 } else {
1573
1574 print "<div class=\"warning\">
1575 Unable to delete non empty feed categories.</div>";
1576
1577 }
1578
1579 db_query($link, "COMMIT");
1580 }
1581 }
1582 }
1583
f932bc9f
AD
1584 if ($subop == "categorize") {
1585
1586 if (!WEB_DEMO_MODE) {
1587
1588 $ids = split(",", db_escape_string($_GET["ids"]));
1589
1590 $cat_id = db_escape_string($_GET["cat_id"]);
1591
1592 if ($cat_id == 0) {
1593 $cat_id_qpart = 'NULL';
1594 } else {
1595 $cat_id_qpart = "'$cat_id'";
1596 }
1597
1598 db_query($link, "BEGIN");
1599
1600 foreach ($ids as $id) {
1601
1602 db_query($link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart
a283b8d1
AD
1603 WHERE id = '$id' AND parent_feed IS NULL
1604 AND owner_uid = " . $_SESSION["uid"]);
1605
1606 # update linked feed categories
1607 db_query($link, "UPDATE ttrss_feeds SET
1608 cat_id = $cat_id_qpart WHERE parent_feed = '$id' AND
1609 owner_uid = " . $_SESSION["uid"]);
1610
f932bc9f
AD
1611 }
1612
1613 db_query($link, "COMMIT");
1614 }
1615
1616 }
1617
a24f525c
AD
1618 if ($quiet) return;
1619
c64d5b03 1620// print "<h3>Edit Feeds</h3>";
91ff844a 1621
0da49bad 1622 $result = db_query($link, "SELECT id,title,feed_url,last_error
4904f845
AD
1623 FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]);
1624
1625 if (db_num_rows($result) > 0) {
1626
1627 print "<div class=\"warning\">";
a9b0bfd5
AD
1628
1629// print"<img class=\"closeButton\"
1630// onclick=\"javascript:hideParentElement(this);\" src=\"images/close.png\">";
1631
36aab70f 1632 print "<a href=\"javascript:showBlockElement('feedUpdateErrors')\">
0ceded7a 1633 <b>Some feeds have update errors (click for details)</b></a>";
4904f845 1634
36aab70f 1635 print "<ul id=\"feedUpdateErrors\" class=\"nomarks\">";
4904f845
AD
1636
1637 while ($line = db_fetch_assoc($result)) {
1638 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
1639 $line["last_error"];
1640 }
1641
1642 print "</ul>";
1643 print "</div>";
1644
1645 }
1646
f932bc9f
AD
1647 $feed_search = db_escape_string($_GET["search"]);
1648
1649 if (array_key_exists("search", $_GET)) {
1650 $_SESSION["prefs_feed_search"] = $feed_search;
1651 } else {
1652 $feed_search = $_SESSION["prefs_feed_search"];
1653 }
1654
1655 print "<table width='100%' class=\"prefGenericAddBox\"
1656 cellspacing='0' cellpadding='0'><tr>
1657 <td>
1658 <input id=\"fadd_link\"
2371c520
AD
1659 onkeyup=\"toggleSubmitNotEmpty(this, 'fadd_submit_btn')\"
1660 size=\"40\">
f932bc9f 1661 <input type=\"submit\" class=\"button\"
2371c520
AD
1662 disabled=\"true\" id=\"fadd_submit_btn\"
1663 onclick=\"addFeed()\" value=\"Subscribe\">";
e2f728be 1664
0b68215c 1665 if (ENABLE_FEED_BROWSER && !SINGLE_USER_MODE) {
e5d758e3 1666 print " <input type=\"submit\" class=\"button\"
6311acbe 1667 onclick=\"javascript:browseFeeds()\" value=\"Top 25\">";
e2f728be
AD
1668 }
1669
1670 print "</td><td align='right'>
f932bc9f 1671 <input id=\"feed_search\" size=\"20\"
2371c520 1672 onchange=\"javascript:updateFeedList()\" value=\"$feed_search\">
f932bc9f
AD
1673 <input type=\"submit\" class=\"button\"
1674 onclick=\"javascript:updateFeedList()\" value=\"Search\">
1675 </td>
1676 </tr></table>";
a0d53889 1677
b83c7545
AD
1678 $feeds_sort = db_escape_string($_GET["sort"]);
1679
1680 if (!$feeds_sort || $feeds_sort == "undefined") {
1681 $feeds_sort = $_SESSION["pref_sort_feeds"];
1682 if (!$feeds_sort) $feeds_sort = "title";
1683 }
1684
1685 $_SESSION["pref_sort_feeds"] = $feeds_sort;
1686
f932bc9f 1687 if ($feed_search) {
11de82c3
AD
1688 $search_qpart = "(UPPER(F1.title) LIKE UPPER('%$feed_search%') OR
1689 UPPER(F1.feed_url) LIKE UPPER('%$feed_search%')) AND";
f932bc9f
AD
1690 } else {
1691 $search_qpart = "";
1692 }
1693
a2db6a4a
AD
1694 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1695 $order_by_qpart = "category,$feeds_sort,title";
1696 } else {
1697 $order_by_qpart = "$feeds_sort,title";
1698 }
1699
648472a7 1700 $result = db_query($link, "SELECT
db42b934
AD
1701 F1.id,
1702 F1.title,
1703 F1.feed_url,
1704 substring(F1.last_updated,1,16) AS last_updated,
1705 F1.parent_feed,
1706 F1.update_interval,
1707 F1.purge_interval,
1708 F1.cat_id,
1709 F2.title AS parent_title,
0da49bad 1710 C1.title AS category,
dab4e89e
AD
1711 F1.hidden,
1712 F1.include_in_digest
c0e5a40e 1713 FROM
db42b934
AD
1714 ttrss_feeds AS F1
1715 LEFT JOIN ttrss_feeds AS F2
1716 ON (F1.parent_feed = F2.id)
1717 LEFT JOIN ttrss_feed_categories AS C1
1718 ON (F1.cat_id = C1.id)
f932bc9f 1719 WHERE
db42b934 1720 $search_qpart F1.owner_uid = '".$_SESSION["uid"]."'
a2db6a4a 1721 ORDER by $order_by_qpart");
1cd17194 1722
3b0feb9b 1723 if (db_num_rows($result) != 0) {
91ff844a 1724
59a543f0 1725// print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
35f3c923 1726
f4fe2cde
AD
1727 print "<p><table width=\"100%\" cellspacing=\"0\"
1728 class=\"prefFeedList\" id=\"prefFeedList\">";
35f3c923
AD
1729 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1730 Select:
ce3bf408
AD
1731 <a href=\"javascript:selectPrefRows('feed', true)\">All</a>,
1732 <a href=\"javascript:selectPrefRows('feed', false)\">None</a>
35f3c923
AD
1733 </td</tr>";
1734
0ea4fb50
AD
1735 if (!get_pref($link, 'ENABLE_FEED_CATS')) {
1736 print "<tr class=\"title\">
6e69e9c2
AD
1737 <td width='5%' align='center'>&nbsp;</td>";
1738
1739 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1740 print "<td width='3%'>&nbsp;</td>";
1741 }
1742
1743 print "
01b3e191
AD
1744 <td width='40%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
1745 <td width='45%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
1746 <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
603c27f8 1747 }
603c27f8 1748
c64d5b03 1749 $lnum = 0;
0ea4fb50
AD
1750
1751 $cur_cat_id = -1;
c64d5b03
AD
1752
1753 while ($line = db_fetch_assoc($result)) {
1754
3b0feb9b 1755 $feed_id = $line["id"];
0ea4fb50
AD
1756 $cat_id = $line["cat_id"];
1757
1758 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1759 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
1760 $edit_cat = htmlspecialchars(db_unescape_string($line["category"]));
0ea4fb50 1761
0da49bad
AD
1762 $hidden = sql_bool_to_bool($line["hidden"]);
1763
0ea4fb50
AD
1764 if (!$edit_cat) $edit_cat = "Uncategorized";
1765
01b3e191
AD
1766 $last_updated = $line["last_updated"];
1767
1768 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
1769 $last_updated = smart_date_time(strtotime($last_updated));
1770 } else {
1771 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
1772 $last_updated = date($short_date, strtotime($last_updated));
1773 }
1774
0ea4fb50 1775 if (get_pref($link, 'ENABLE_FEED_CATS') && $cur_cat_id != $cat_id) {
cb58d0df
AD
1776 $lnum = 0;
1777
0ea4fb50
AD
1778 print "<tr><td colspan=\"6\" class=\"feedEditCat\">$edit_cat</td></tr>";
1779
1780 print "<tr class=\"title\">
2eb15f6f 1781 <td width='5%'>&nbsp;</td>";
d1793994
AD
1782
1783 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
2eb15f6f 1784 print "<td width='3%'>&nbsp;</td>";
d1793994
AD
1785 }
1786
1787 print "<td width='40%'><a href=\"javascript:updateFeedList('title')\">Title</a></td>
01b3e191
AD
1788 <td width='45%'><a href=\"javascript:updateFeedList('feed_url')\">Feed</a></td>
1789 <td width='15%' align='right'><a href=\"javascript:updateFeedList('last_updated')\">Updated</a></td>";
0ea4fb50
AD
1790
1791 $cur_cat_id = $cat_id;
c64d5b03 1792 }
0ea4fb50 1793
cb58d0df 1794 $class = ($lnum % 2) ? "even" : "odd";
0ea4fb50
AD
1795 $this_row_id = "id=\"FEEDR-$feed_id\"";
1796
53226edc 1797 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
1798
1799 $icon_file = ICONS_DIR . "/$feed_id.ico";
1800
1801 if (file_exists($icon_file) && filesize($icon_file) > 0) {
327a3bbe 1802 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL . "/$feed_id.ico\">";
3b0feb9b 1803 } else {
327a3bbe 1804 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3b0feb9b 1805 }
d1793994 1806
ce3bf408 1807 print "<td class='feedSelect'><input onclick='toggleSelectPrefRow(this, \"feed\");'
0ea4fb50 1808 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
3547842a 1809
d1793994
AD
1810 if (get_pref($link, 'ENABLE_FEED_ICONS')) {
1811 print "<td class='feedIcon'>$feed_icon</td>";
1812 }
1813
0ea4fb50
AD
1814 $edit_title = truncate_string($edit_title, 40);
1815 $edit_link = truncate_string($edit_link, 60);
a88c1f36 1816
0da49bad
AD
1817 if ($hidden) {
1818 $edit_title = "<span class=\"insensitive\">$edit_title (Hidden)</span>";
1819 $edit_link = "<span class=\"insensitive\">$edit_link</span>";
1820 $last_updated = "<span class=\"insensitive\">$last_updated</span>";
1821 }
1822
1da7e457
AD
1823 $parent_title = $line["parent_title"];
1824 if ($parent_title) {
1825 $parent_title = "<span class='groupPrompt'>(linked to
1826 $parent_title)</span>";
1827 }
1828
0ea4fb50 1829 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
d1793994 1830 "$edit_title $parent_title" . "</a></td>";
0ea4fb50
AD
1831
1832 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
1833 $edit_link . "</a></td>";
3547842a 1834
01b3e191
AD
1835 print "<td align='right'><a href=\"javascript:editFeed($feed_id);\">" .
1836 "$last_updated</a></td>";
1837
c64d5b03
AD
1838 print "</tr>";
1839
1840 ++$lnum;
1841 }
1842
c64d5b03 1843 print "</table>";
3b0feb9b 1844
ce3bf408 1845 print "<p><span id=\"feedOpToolbar\">";
c64d5b03 1846
3b0feb9b
AD
1847 if ($subop == "edit") {
1848 print "Edit feed:&nbsp;
c64d5b03 1849 <input type=\"submit\" class=\"button\"
3b0feb9b 1850 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
c64d5b03 1851 <input type=\"submit\" class=\"button\"
3b0feb9b
AD
1852 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
1853 } else {
c64d5b03
AD
1854
1855 print "
1856 Selection:&nbsp;
ce3bf408 1857 <input type=\"submit\" class=\"button\" disabled=\"true\"
3b0feb9b 1858 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
ce3bf408 1859 <input type=\"submit\" class=\"button\" disabled=\"true\"
e5d758e3 1860 onclick=\"javascript:removeSelectedFeeds()\" value=\"Unsubscribe\">";
f932bc9f
AD
1861
1862 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1863
e5d758e3 1864 print "&nbsp;|&nbsp;";
f932bc9f 1865
673d54ca 1866 print_feed_cat_select($link, "sfeed_set_fcat", "", "disabled");
f932bc9f 1867
ce3bf408 1868 print " <input type=\"submit\" class=\"button\" disabled=\"true\"
6d1e02a2 1869 onclick=\"javascript:categorizeSelectedFeeds()\" value=\"Recategorize\">";
f932bc9f
AD
1870
1871 }
3b0feb9b 1872
ce3bf408 1873 print "</span>
f932bc9f 1874 &nbsp;All feeds: <input type=\"submit\"
3b0feb9b
AD
1875 class=\"button\" onclick=\"gotoExportOpml()\"
1876 value=\"Export OPML\">";
1877 }
1878 } else {
1879
1880 print "<p>No feeds defined.</p>";
1881
1882 }
1883
1884 if (get_pref($link, 'ENABLE_FEED_CATS')) {
1885
1886 print "<h3>Edit Categories</h3>";
1887
3b0feb9b 1888 print "<div class=\"prefGenericAddBox\">
f932bc9f 1889 <input id=\"fadd_cat\"
ce3bf408 1890 onkeyup=\"toggleSubmitNotEmpty(this, 'catadd_submit_btn')\"
f932bc9f
AD
1891 size=\"40\">&nbsp;
1892 <input
ce3bf408 1893 type=\"submit\" class=\"button\" disabled=\"true\" id=\"catadd_submit_btn\"
e5d758e3 1894 onclick=\"javascript:addFeedCat()\" value=\"Create category\"></div>";
3b0feb9b
AD
1895
1896 $result = db_query($link, "SELECT title,id FROM ttrss_feed_categories
1897 WHERE owner_uid = ".$_SESSION["uid"]."
1898 ORDER BY title");
1899
1900 if (db_num_rows($result) != 0) {
1901
0666e120
AD
1902 print "<form id=\"feed_cat_edit_form\">";
1903
35f3c923 1904 print "<p><table width=\"100%\" class=\"prefFeedCatList\"
f4fe2cde 1905 cellspacing=\"0\" id=\"prefFeedCatList\">";
35f3c923
AD
1906
1907 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
1908 Select:
ce3bf408
AD
1909 <a href=\"javascript:selectPrefRows('fcat', true)\">All</a>,
1910 <a href=\"javascript:selectPrefRows('fcat', false)\">None</a>
35f3c923
AD
1911 </td</tr>";
1912
3b0feb9b 1913 print "<tr class=\"title\">
0b68215c 1914 <td width=\"5%\">&nbsp;</td><td width=\"80%\">Title</td>
3b0feb9b
AD
1915 </tr>";
1916
1917 $lnum = 0;
1918
1919 while ($line = db_fetch_assoc($result)) {
1920
1921 $class = ($lnum % 2) ? "even" : "odd";
1922
1923 $cat_id = $line["id"];
1924
1925 $edit_cat_id = $_GET["id"];
1926
3c5783b7 1927 if ($subop == "editCat" && $cat_id != $edit_cat_id) {
0666e120
AD
1928 $class .= "Grayed";
1929 $this_row_id = "";
53226edc
AD
1930 } else {
1931 $this_row_id = "id=\"FCATR-$cat_id\"";
3b0feb9b
AD
1932 }
1933
53226edc 1934 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b
AD
1935
1936 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
1937
1938 if (!$edit_cat_id || $subop != "editCat") {
1939
ce3bf408
AD
1940 print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"fcat\");'
1941 type=\"checkbox\" id=\"FCCHK-".$line["id"]."\"></td>";
3b0feb9b
AD
1942
1943 print "<td><a href=\"javascript:editFeedCat($cat_id);\">" .
1944 $edit_title . "</a></td>";
1945
1946 } else if ($cat_id != $edit_cat_id) {
1947
0666e120 1948 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
3b0feb9b
AD
1949 id=\"FRCHK-".$line["id"]."\"></td>";
1950
1951 print "<td>$edit_title</td>";
1952
1953 } else {
1954
0666e120
AD
1955 print "<td align='center'><input disabled=\"true\" type=\"checkbox\" checked>";
1956
1957 print "<input type=\"hidden\" name=\"id\" value=\"$cat_id\">";
1958 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
1959 print "<input type=\"hidden\" name=\"subop\" value=\"saveCat\">";
1960
1961 print "</td>";
3b0feb9b 1962
ac2cc246
AD
1963 print "<td><input onkeypress=\"return filterCR(event)\"
1964 name=\"title\" class=\"iedit\" value=\"$edit_title\"></td>";
3b0feb9b
AD
1965
1966 }
1967
1968 print "</tr>";
1969
1970 ++$lnum;
1971 }
1972
1973 print "</table>";
0666e120
AD
1974
1975 print "</form>";
3b0feb9b 1976
ce3bf408 1977 print "<p id=\"catOpToolbar\">";
3b0feb9b
AD
1978
1979 if ($subop == "editCat") {
1980 print "Edit category:&nbsp;
ce3bf408 1981 <input type=\"submit\" class=\"button\"
90ac84df 1982 onclick=\"return feedCatEditSave()\" value=\"Save\">
ce3bf408 1983 <input type=\"submit\" class=\"button\"
90ac84df 1984 onclick=\"return feedCatEditCancel()\" value=\"Cancel\">";
3b0feb9b
AD
1985 } else {
1986
1987 print "
1988 Selection:&nbsp;
ce3bf408 1989 <input type=\"submit\" class=\"button\" disabled=\"true\"
90ac84df 1990 onclick=\"return editSelectedFeedCat()\" value=\"Edit\">
ce3bf408 1991 <input type=\"submit\" class=\"button\" disabled=\"true\"
90ac84df 1992 onclick=\"return removeSelectedFeedCats()\" value=\"Remove\">";
3b0feb9b
AD
1993
1994 }
1995
1996 } else {
1997 print "<p>No feed categories defined.</p>";
1998 }
c64d5b03
AD
1999 }
2000
2001 print "<h3>Import OPML</h3>
f5a50b25
AD
2002 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
2003 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
2004 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
2005 type=\"submit\" value=\"Import\">
2006 </form>";
2007
007bda35
AD
2008 }
2009
a0d53889
AD
2010 if ($op == "pref-filters") {
2011
2012 $subop = $_GET["subop"];
a24f525c 2013 $quiet = $_GET["quiet"];
a0d53889 2014
07164479
AD
2015 if ($subop == "edit") {
2016
2017 $filter_id = db_escape_string($_GET["id"]);
2018
2019 $result = db_query($link,
9cd30721 2020 "SELECT * FROM ttrss_filters WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
07164479
AD
2021
2022 $reg_exp = htmlspecialchars(db_unescape_string(db_fetch_result($result, 0, "reg_exp")));
2023 $filter_type = db_fetch_result($result, 0, "filter_type");
2024 $feed_id = db_fetch_result($result, 0, "feed_id");
2025 $action_id = db_fetch_result($result, 0, "action_id");
e8b79d16
AD
2026
2027 $enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled"));
2028
07164479
AD
2029 print "<div id=\"infoBoxTitle\">Filter editor</div>";
2030 print "<div class=\"infoBoxContents\">";
2031
2032 print "<form id=\"filter_edit_form\">";
2033
2034 print "<input type=\"hidden\" name=\"op\" value=\"pref-filters\">";
2035 print "<input type=\"hidden\" name=\"id\" value=\"$filter_id\">";
2036 print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
2037
2038// print "<div class=\"notice\"><b>Note:</b> filter will only apply to new articles.</div>";
2039
2040 $result = db_query($link, "SELECT id,description
2041 FROM ttrss_filter_types ORDER BY description");
2042
2043 $filter_types = array();
2044
2045 while ($line = db_fetch_assoc($result)) {
2046 //array_push($filter_types, $line["description"]);
2047 $filter_types[$line["id"]] = $line["description"];
2048 }
2049
2050 print "<table width='100%'>";
2051
2052 print "<tr><td>Match:</td>
2053 <td><input onkeypress=\"return filterCR(event)\"
2054 onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
4220b0bd 2055 name=\"reg_exp\" class=\"iedit\" value=\"$reg_exp\">";
07164479 2056
4220b0bd
AD
2057 print "</td><td>";
2058
2059 print_select_hash("filter_type", $filter_type, $filter_types, "class=\"iedit\"");
07164479
AD
2060
2061 print "</td></tr>";
4220b0bd 2062 print "<tr><td>Feed:</td><td colspan='2'>";
07164479
AD
2063
2064 print_feed_select($link, "feed_id", $feed_id);
2065
2066 print "</td></tr>";
2067
2068 print "<tr><td>Action:</td>";
2069
4220b0bd 2070 print "<td colspan='2'><select name=\"action_id\">";
07164479
AD
2071
2072 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2073 ORDER BY name");
2074
2075 while ($line = db_fetch_assoc($result)) {
2076 $is_sel = ($line["id"] == $action_id) ? "selected" : "";
2077 printf("<option value='%d' $is_sel>%s</option>", $line["id"], $line["description"]);
2078 }
2079
2080 print "</select>";
2081
e8b79d16
AD
2082 print "</td></tr>";
2083
2084 if ($enabled) {
2085 $checked = "checked";
2086 } else {
2087 $checked = "";
2088 }
2089
2090 print "<tr><td>Options:</td><td>
2091 <input type=\"checkbox\" name=\"enabled\" id=\"enabled\" $checked>
2092 <label for=\"enabled\">Enabled</label>";
2093
07164479
AD
2094 print "</td></tr></table>";
2095
2096 print "</form>";
2097
2098 print "<div align='right'>";
2099
2100 print "<input type=\"submit\"
2101 id=\"infobox_submit\"
90ac84df 2102 class=\"button\" onclick=\"return filterEditSave()\"
07164479
AD
2103 value=\"Save\"> ";
2104
2105 print "<input class=\"button\"
90ac84df 2106 type=\"submit\" onclick=\"return filterEditCancel()\"
07164479
AD
2107 value=\"Cancel\">";
2108
2109 print "</div>";
2110
2111 return;
2112 }
2113
2114
a0d53889 2115 if ($subop == "editSave") {
a0d53889 2116
7e939457
AD
2117 $reg_exp = db_escape_string(trim($_GET["reg_exp"]));
2118 $filter_type = db_escape_string(trim($_GET["filter_type"]));
648472a7 2119 $filter_id = db_escape_string($_GET["id"]);
7e939457
AD
2120 $feed_id = db_escape_string($_GET["feed_id"]);
2121 $action_id = db_escape_string($_GET["action_id"]);
e8b79d16 2122 $enabled = checkbox_to_sql_bool(db_escape_string($_GET["enabled"]));
ead60402
AD
2123
2124 if (!$feed_id) {
2125 $feed_id = 'NULL';
2126 } else {
2127 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2128 }
0afbd851 2129
648472a7 2130 $result = db_query($link, "UPDATE ttrss_filters SET
7e939457
AD
2131 reg_exp = '$reg_exp',
2132 feed_id = $feed_id,
2133 action_id = '$action_id',
e8b79d16
AD
2134 filter_type = '$filter_type',
2135 enabled = $enabled
9cd30721 2136 WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
a0d53889
AD
2137 }
2138
2139 if ($subop == "remove") {
2140
2141 if (!WEB_DEMO_MODE) {
2142
f932bc9f 2143 $ids = split(",", db_escape_string($_GET["ids"]));
a0d53889
AD
2144
2145 foreach ($ids as $id) {
9cd30721 2146 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
a0d53889
AD
2147
2148 }
2149 }
2150 }
2151
2152 if ($subop == "add") {
2153
de435974 2154 if (!WEB_DEMO_MODE) {
a0d53889 2155
79f3553b 2156 $regexp = db_escape_string(trim($_GET["reg_exp"]));
07164479 2157 $filter_type = db_escape_string(trim($_GET["filter_type"]));
79f3553b
AD
2158 $feed_id = db_escape_string($_GET["feed_id"]);
2159 $action_id = db_escape_string($_GET["action_id"]);
ead60402
AD
2160
2161 if (!$feed_id) {
2162 $feed_id = 'NULL';
2163 } else {
2164 $feed_id = sprintf("'%s'", db_escape_string($feed_id));
2165 }
4401bf04 2166
648472a7 2167 $result = db_query($link,
19c9cb11
AD
2168 "INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
2169 action_id)
2170 VALUES
07164479 2171 ('$regexp', '$filter_type','".$_SESSION["uid"]."',
19c9cb11 2172 $feed_id, '$action_id')");
de435974 2173 }
a0d53889
AD
2174 }
2175
a24f525c
AD
2176 if ($quiet) return;
2177
0e317f9d
AD
2178 $sort = db_escape_string($_GET["sort"]);
2179
2180 if (!$sort || $sort == "undefined") {
2181 $sort = "reg_exp";
2182 }
2183
59a543f0 2184// print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
7b5c6012 2185
7e939457 2186 $result = db_query($link, "SELECT id,description
a0d53889
AD
2187 FROM ttrss_filter_types ORDER BY description");
2188
2189 $filter_types = array();
2190
648472a7 2191 while ($line = db_fetch_assoc($result)) {
7e939457
AD
2192 //array_push($filter_types, $line["description"]);
2193 $filter_types[$line["id"]] = $line["description"];
a0d53889
AD
2194 }
2195
7b5c6012
AD
2196 print "<input type=\"submit\"
2197 class=\"button\"
90ac84df 2198 onclick=\"return displayDlg('quickAddFilter', false)\"
4220b0bd 2199 id=\"create_filter_btn\"
7b5c6012
AD
2200 value=\"Create filter\">";
2201
648472a7 2202 $result = db_query($link, "SELECT
ead60402 2203 ttrss_filters.id AS id,reg_exp,
ead60402
AD
2204 ttrss_filter_types.name AS filter_type_name,
2205 ttrss_filter_types.description AS filter_type_descr,
e8b79d16 2206 enabled,
ead60402 2207 feed_id,
19c9cb11 2208 ttrss_filter_actions.description AS action_description,
11de82c3 2209 ttrss_feeds.title AS feed_title
a0d53889 2210 FROM
5890c3f4
AD
2211 ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN
2212 ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id)
4356293a 2213 WHERE
ead60402 2214 filter_type = ttrss_filter_types.id AND
19c9cb11 2215 ttrss_filter_actions.id = action_id AND
ead60402 2216 ttrss_filters.owner_uid = ".$_SESSION["uid"]."
0e317f9d 2217 ORDER by $sort");
a0d53889 2218
3b0feb9b 2219 if (db_num_rows($result) != 0) {
a0d53889 2220
7e939457
AD
2221 print "<form id=\"filter_edit_form\">";
2222
f4fe2cde
AD
2223 print "<p><table width=\"100%\" cellspacing=\"0\" class=\"prefFilterList\"
2224 id=\"prefFilterList\">";
35f3c923
AD
2225
2226 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2227 Select:
ce3bf408
AD
2228 <a href=\"javascript:selectPrefRows('filter', true)\">All</a>,
2229 <a href=\"javascript:selectPrefRows('filter', false)\">None</a>
35f3c923
AD
2230 </td</tr>";
2231
3b0feb9b 2232 print "<tr class=\"title\">
e325c6e7 2233 <td align='center' width=\"5%\">&nbsp;</td>
0e317f9d
AD
2234 <td width=\"20%\"><a href=\"javascript:updateFilterList('reg_exp')\">Filter expression</a></td>
2235 <td width=\"20%\"><a href=\"javascript:updateFilterList('feed_title')\">Feed</a></td>
2236 <td width=\"15%\"><a href=\"javascript:updateFilterList('filter_type')\">Match</a></td>
2237 <td width=\"15%\"><a href=\"javascript:updateFilterList('action_description')\">Action</a></td>";
01b3e191 2238
3b0feb9b
AD
2239 $lnum = 0;
2240
2241 while ($line = db_fetch_assoc($result)) {
2242
2243 $class = ($lnum % 2) ? "even" : "odd";
2244
2245 $filter_id = $line["id"];
2246 $edit_filter_id = $_GET["id"];
e8b79d16
AD
2247
2248 $enabled = sql_bool_to_bool($line["enabled"]);
3b0feb9b
AD
2249
2250 if ($subop == "edit" && $filter_id != $edit_filter_id) {
2251 $class .= "Grayed";
53226edc
AD
2252 $this_row_id = "";
2253 } else {
2254 $this_row_id = "id=\"FILRR-$filter_id\"";
ead60402 2255 }
3b0feb9b 2256
53226edc 2257 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b 2258
07164479 2259 $line["reg_exp"] = htmlspecialchars(db_unescape_string($line["reg_exp"]));
3b0feb9b
AD
2260
2261 if (!$line["feed_title"]) $line["feed_title"] = "All feeds";
7e939457 2262
07164479
AD
2263 $line["feed_title"] = htmlspecialchars(db_unescape_string($line["feed_title"]));
2264
2265 print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"filter\");'
3b0feb9b 2266 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
e8b79d16
AD
2267
2268 if (!$enabled) {
2269 $line["reg_exp"] = "<span class=\"insensitive\">" .
2270 $line["reg_exp"] . " (Disabled)</span>";
2271 $line["feed_title"] = "<span class=\"insensitive\">" .
2272 $line["feed_title"] . "</span>";
2273 $line["filter_type_descr"] = "<span class=\"insensitive\">" .
2274 $line["filter_type_descr"] . "</span>";
2275 $line["action_description"] = "<span class=\"insensitive\">" .
2276 $line["action_description"] . "</span>";
2277 }
3b0feb9b 2278
07164479
AD
2279 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2280 $line["reg_exp"] . "</td>";
3b0feb9b 2281
07164479
AD
2282 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2283 $line["feed_title"] . "</td>";
3b0feb9b 2284
07164479
AD
2285 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2286 $line["filter_type_descr"] . "</td>";
19c9cb11 2287
07164479
AD
2288 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
2289 $line["action_description"] . "</td>";
3b0feb9b
AD
2290
2291 print "</tr>";
2292
2293 ++$lnum;
a0d53889 2294 }
3b0feb9b
AD
2295
2296 if ($lnum == 0) {
2297 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
2298 }
2299
2300 print "</table>";
7e939457
AD
2301
2302 print "</form>";
3b0feb9b 2303
ce3bf408 2304 print "<p id=\"filterOpToolbar\">";
3b0feb9b 2305
4220b0bd 2306 print "
3b0feb9b 2307 Selection:
ce3bf408 2308 <input type=\"submit\" class=\"button\" disabled=\"true\"
90ac84df 2309 onclick=\"return editSelectedFilter()\" value=\"Edit\">
ce3bf408 2310 <input type=\"submit\" class=\"button\" disabled=\"true\"
90ac84df 2311 onclick=\"return removeSelectedFilters()\" value=\"Remove\">";
4220b0bd
AD
2312
2313 print "</p>";
3b0feb9b 2314
a0d53889
AD
2315 } else {
2316
3b0feb9b
AD
2317 print "<p>No filters defined.</p>";
2318
a0d53889
AD
2319 }
2320 }
2321
80dce858
AD
2322 // We need to accept raw SQL data in label queries, so not everything is escaped
2323 // here, this is by design. If you don't like the whole idea, disable labels
2324 // altogether with GLOBAL_ENABLE_LABELS = false
2325
48f0adb0
AD
2326 if ($op == "pref-labels") {
2327
cfaba6df 2328 if (!GLOBAL_ENABLE_LABELS) {
9e7bb204
AD
2329
2330 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
2331 return;
2332 }
2333
48f0adb0
AD
2334 $subop = $_GET["subop"];
2335
a4dbc524
AD
2336 if ($subop == "edit") {
2337
2338 $label_id = db_escape_string($_GET["id"]);
2339
2340 $result = db_query($link, "SELECT sql_exp,description FROM ttrss_labels WHERE
2341 owner_uid = ".$_SESSION["uid"]." AND id = '$label_id' ORDER by description");
2342
2343 $line = db_fetch_assoc($result);
2344
2345 $sql_exp = htmlspecialchars(db_unescape_string($line["sql_exp"]));
2346 $description = htmlspecialchars(db_unescape_string($line["description"]));
2347
2348 print "<div id=\"infoBoxTitle\">Label editor</div>";
2349 print "<div class=\"infoBoxContents\">";
2350
2351 print "<form id=\"label_edit_form\">";
2352
2353 print "<input type=\"hidden\" name=\"op\" value=\"pref-labels\">";
2354 print "<input type=\"hidden\" name=\"id\" value=\"$label_id\">";
2355 print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
2356
2357 print "<table width='100%'>";
2358
2359 print "<tr><td>Caption:</td>
2360 <td><input onkeypress=\"return filterCR(event)\"
2361 onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
2362 name=\"description\" class=\"iedit\" value=\"$description\">";
2363
2364 print "</td></tr>";
2365
2366 print "<tr><td colspan=\"2\">
2367 <p>SQL Expression:</p>";
2368
2369 print "<textarea onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
2370 rows=\"4\" name=\"sql_exp\" class=\"iedit\">$sql_exp</textarea>";
2371
2372 print "</td></tr></table>";
2373
2374 print "</form>";
2375
2376 print "<div style=\"display : none\" id=\"label_test_result\"></div>";
2377
2378 print "<div align='right'>";
2379
7c620da8
AD
2380 $is_disabled = (strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== FALSE) ? "disabled" : "";
2381
2382 print "<input $is_disabled type=\"submit\" onclick=\"return labelTest()\" value=\"Test\">
a4dbc524
AD
2383 ";
2384
2385 print "<input type=\"submit\"
2386 id=\"infobox_submit\"
2387 class=\"button\" onclick=\"return labelEditSave()\"
2388 value=\"Save\"> ";
2389
2390 print "<input class=\"button\"
2391 type=\"submit\" onclick=\"return labelEditCancel()\"
2392 value=\"Cancel\">";
2393
2394 print "</div>";
2395
2396 return;
2397 }
2398
d9dde1d6
AD
2399 if ($subop == "test") {
2400
d11bc4de
AD
2401 $expr = db_unescape_string(trim($_GET["expr"]));
2402 $descr = db_unescape_string(trim($_GET["descr"]));
d9dde1d6 2403
a4dbc524 2404 print "<div>";
e5d758e3 2405
a4dbc524 2406 error_reporting(0);
d9dde1d6 2407
d9dde1d6
AD
2408
2409 $result = db_query($link,
88040f57
AD
2410 "SELECT count(ttrss_entries.id) AS num_matches
2411 FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
d9dde1d6
AD
2412 WHERE ($expr) AND
2413 ttrss_user_entries.ref_id = ttrss_entries.id AND
88040f57 2414 ttrss_user_entries.feed_id = ttrss_feeds.id AND
a4dbc524
AD
2415 ttrss_user_entries.owner_uid = " . $_SESSION["uid"], false);
2416
2417 error_reporting (DEFAULT_ERROR_LEVEL);
2418
2419 if (!$result) {
2420 print "<p>" . db_last_error($link) . "</p>";
2421 print "</div>";
2422 return;
2423 }
d9dde1d6
AD
2424
2425 $num_matches = db_fetch_result($result, 0, "num_matches");;
2426
2427 if ($num_matches > 0) {
2428
f531499b
AD
2429 if ($num_matches > 10) {
2430 $showing_msg = ", showing first 10";
2431 }
2432
2433 print "<p>Query returned <b>$num_matches</b> matches$showing_msg:</p>";
d9dde1d6
AD
2434
2435 $result = db_query($link,
88040f57 2436 "SELECT ttrss_entries.title,
d9dde1d6 2437 (SELECT title FROM ttrss_feeds WHERE id = feed_id) AS feed_title
88040f57 2438 FROM ttrss_entries,ttrss_user_entries,ttrss_feeds
d9dde1d6
AD
2439 WHERE ($expr) AND
2440 ttrss_user_entries.ref_id = ttrss_entries.id
88040f57
AD
2441 AND ttrss_user_entries.feed_id = ttrss_feeds.id
2442 AND ttrss_user_entries.owner_uid = " . $_SESSION["uid"] . "
a4dbc524 2443 ORDER BY date_entered DESC LIMIT 10", false);
d9dde1d6 2444
a4dbc524 2445 print "<ul class=\"labelTestResults\">";
673d54ca
AD
2446
2447 $row_class = "even";
2448
d9dde1d6 2449 while ($line = db_fetch_assoc($result)) {
673d54ca
AD
2450 $row_class = toggleEvenOdd($row_class);
2451
2452 print "<li class=\"$row_class\">".$line["title"].
d9dde1d6
AD
2453 " <span class=\"insensitive\">(".$line["feed_title"].")</span></li>";
2454 }
2455 print "</ul>";
2456
2457 } else {
2458 print "<p>Query didn't return any matches.</p>";
2459 }
2460
2461 print "</div>";
2462
d9dde1d6
AD
2463 return;
2464 }
2465
48f0adb0
AD
2466 if ($subop == "editSave") {
2467
f3120e5a
AD
2468 $sql_exp = trim($_GET["sql_exp"]);
2469 $descr = db_escape_string(trim($_GET["description"]));
48f0adb0
AD
2470 $label_id = db_escape_string($_GET["id"]);
2471
48f0adb0
AD
2472 $result = db_query($link, "UPDATE ttrss_labels SET
2473 sql_exp = '$sql_exp',
2474 description = '$descr'
2475 WHERE id = '$label_id'");
2476 }
2477
2478 if ($subop == "remove") {
2479
2480 if (!WEB_DEMO_MODE) {
2481
f932bc9f 2482 $ids = split(",", db_escape_string($_GET["ids"]));
48f0adb0
AD
2483
2484 foreach ($ids as $id) {
2485 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
2486
2487 }
2488 }
2489 }
2490
2491 if ($subop == "add") {
2492
2493 if (!WEB_DEMO_MODE) {
2494
4401bf04 2495 // no escaping is done here on purpose
f156fd00
AD
2496 $sql_exp = trim($_GET["sql_exp"]);
2497 $description = db_escape_string($_GET["description"]);
48f0adb0
AD
2498
2499 $result = db_query($link,
4356293a 2500 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
f156fd00 2501 VALUES ('$sql_exp', '$description', '".$_SESSION["uid"]."')");
48f0adb0
AD
2502 }
2503 }
2504
e161a2cc
AD
2505 $sort = db_escape_string($_GET["sort"]);
2506
2507 if (!$sort || $sort == "undefined") {
2508 $sort = "description";
2509 }
2510
f156fd00
AD
2511 print "<div class=\"prefGenericAddBox\">";
2512
2c7070b5 2513 print"<input type=\"submit\" class=\"button\"
f156fd00
AD
2514 id=\"label_create_btn\"
2515 onclick=\"return displayDlg('quickAddLabel', false)\"
2516 value=\"Create label\"></div>";
48f0adb0
AD
2517
2518 $result = db_query($link, "SELECT
2519 id,sql_exp,description
2520 FROM
4356293a
AD
2521 ttrss_labels
2522 WHERE
2523 owner_uid = ".$_SESSION["uid"]."
e161a2cc 2524 ORDER BY $sort");
48f0adb0 2525
59a543f0 2526// print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
d9dde1d6 2527
3b0feb9b 2528 if (db_num_rows($result) != 0) {
48f0adb0 2529
f3120e5a
AD
2530 print "<form id=\"label_edit_form\">";
2531
f4fe2cde
AD
2532 print "<p><table width=\"100%\" cellspacing=\"0\"
2533 class=\"prefLabelList\" id=\"prefLabelList\">";
35f3c923
AD
2534
2535 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
2536 Select:
ce3bf408
AD
2537 <a href=\"javascript:selectPrefRows('label', true)\">All</a>,
2538 <a href=\"javascript:selectPrefRows('label', false)\">None</a>
35f3c923
AD
2539 </td</tr>";
2540
3b0feb9b 2541 print "<tr class=\"title\">
673d54ca 2542 <td width=\"5%\">&nbsp;</td>
e161a2cc
AD
2543 <td width=\"30%\"><a href=\"javascript:updateLabelList('description')\">Caption</a></td>
2544 <td width=\"50%\"><a href=\"javascript:updateLabelList('sql_exp')\">SQL Expression</a>
01c9c74a 2545 <a class=\"helpLink\" href=\"javascript:displayHelpInfobox(1)\">(?)</a>
3b0feb9b 2546 </td>
f531499b 2547 </tr>";
3b0feb9b
AD
2548
2549 $lnum = 0;
2550
2551 while ($line = db_fetch_assoc($result)) {
2552
2553 $class = ($lnum % 2) ? "even" : "odd";
2554
2555 $label_id = $line["id"];
2556 $edit_label_id = $_GET["id"];
2557
2558 if ($subop == "edit" && $label_id != $edit_label_id) {
2559 $class .= "Grayed";
53226edc
AD
2560 $this_row_id = "";
2561 } else {
2562 $this_row_id = "id=\"LILRR-$label_id\"";
3b0feb9b
AD
2563 }
2564
53226edc 2565 print "<tr class=\"$class\" $this_row_id>";
3b0feb9b 2566
5f212f40
AD
2567 $line["sql_exp"] = htmlspecialchars(db_unescape_string($line["sql_exp"]));
2568 $line["description"] = htmlspecialchars(
2569 db_unescape_string($line["description"]));
3b0feb9b 2570
a4dbc524 2571 if (!$line["description"]) $line["description"] = "[No caption]";
3b0feb9b 2572
a4dbc524 2573 print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"label\");'
3b0feb9b
AD
2574 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
2575
a4dbc524
AD
2576 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2577 $line["description"] . "</td>";
f531499b
AD
2578
2579 print "<td><a href=\"javascript:editLabel($label_id);\">" .
2580 $line["sql_exp"] . "</td>";
2581
3b0feb9b
AD
2582 print "</tr>";
2583
2584 ++$lnum;
2585 }
2586
2587 if ($lnum == 0) {
2588 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
2589 }
2590
2591 print "</table>";
f3120e5a
AD
2592
2593 print "</form>";
3b0feb9b 2594
ce3bf408 2595 print "<p id=\"labelOpToolbar\">";
3b0feb9b 2596
f531499b 2597 print "
3b0feb9b 2598 Selection:
ce3bf408 2599 <input type=\"submit\" class=\"button\" disabled=\"true\"
3b0feb9b 2600 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
ce3bf408 2601 <input type=\"submit\" class=\"button\" disabled=\"true\"
f531499b
AD
2602 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
2603
48f0adb0 2604 } else {
3b0feb9b 2605 print "<p>No labels defined.</p>";
48f0adb0
AD
2606 }
2607 }
2608
e828e31e
AD
2609 if ($op == "error") {
2610 print "<div width=\"100%\" align='center'>";
2611 $msg = $_GET["msg"];
2612 print $msg;
2613 print "</div>";
2614 }
2615
7dc66a61 2616 if ($op == "help") {
01c9c74a
AD
2617 if (!$_GET["noheaders"]) {
2618 print "<html><head>
2619 <title>Tiny Tiny RSS : Help</title>
2620 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
86b682ce 2621 <script type=\"text/javascript\" src=\"prototype.js\"></script>
53515ff1 2622 <script type=\"text/javascript\" src=\"functions.js?$script_dt_add\"></script>
01c9c74a
AD
2623 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
2624 </head><body>";
2625 }
7dc66a61
AD
2626
2627 $tid = sprintf("%d", $_GET["tid"]);
2628
e5d758e3
AD
2629 print "<div id=\"infoBoxTitle\">Help</div>";
2630
01c9c74a 2631 print "<div class='infoBoxContents'>";
7dc66a61 2632
01c9c74a
AD
2633 if (file_exists("help/$tid.php")) {
2634 include("help/$tid.php");
2635 } else {
2636 print "<p>Help topic not found.</p>";
2637 }
7dc66a61 2638
01c9c74a 2639 print "</div>";
7dc66a61
AD
2640
2641 print "<div align='center'>
01c9c74a
AD
2642 <input type='submit' class='button'
2643 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
7dc66a61 2644
01c9c74a
AD
2645 if (!$_GET["noheaders"]) {
2646 print "</body></html>";
2647 }
7dc66a61
AD
2648
2649 }
2650
f84a97a3
AD
2651 if ($op == "dlg") {
2652 $id = $_GET["id"];
6de5d056 2653 $param = $_GET["param"];
f84a97a3
AD
2654
2655 if ($id == "quickAddFeed") {
e5d758e3
AD
2656
2657 print "<div id=\"infoBoxTitle\">Subscribe to feed</div>";
2658 print "<div class=\"infoBoxContents\">";
2659
07eb9178
AD
2660 print "<form id='feed_add_form'>";
2661
2662 print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
2663 print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
2664 print "<input type=\"hidden\" name=\"subop\" value=\"add\">";
2665
e5d758e3
AD
2666 print "<table width='100%'>
2667 <tr><td>Feed URL:</td><td>
07eb9178 2668 <input class=\"iedit\" onblur=\"javascript:enableHotkeys()\"
ac2cc246 2669 onkeypress=\"return filterCR(event)\"
2371c520 2670 onkeyup=\"toggleSubmitNotEmpty(this, 'fadd_submit_btn')\"
07eb9178 2671 onfocus=\"javascript:disableHotkeys()\" name=\"feed_url\"></td></tr>";
15da5cc1
AD
2672
2673 if (get_pref($link, 'ENABLE_FEED_CATS')) {
e5d758e3 2674 print "<tr><td>Category:</td><td>";
07eb9178 2675 print_feed_cat_select($link, "cat_id");
e5d758e3 2676 print "</td></tr>";
15da5cc1 2677 }
07eb9178
AD
2678
2679 print "</table>";
2680 print "</form>";
2681
2682 print "<div align='right'>
2371c520
AD
2683 <input class=\"button\"
2684 id=\"fadd_submit_btn\" disabled=\"true\"
2685 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Subscribe\">
2686 <input class=\"button\"
07eb9178
AD
2687 type=\"submit\" onclick=\"javascript:closeInfoBox()\"
2688 value=\"Cancel\"></div>";
c14b5566 2689
f84a97a3 2690 }
6de5d056 2691
033e47e0
AD
2692 if ($id == "search") {
2693
e5d758e3
AD
2694 print "<div id=\"infoBoxTitle\">Search</div>";
2695 print "<div class=\"infoBoxContents\">";
2696
86b682ce
AD
2697 print "<form id='search_form'>";
2698
0a6c4846
AD
2699 #$active_feed_id = db_escape_string($_GET["param"]);
2700
2701 $params = split(":", db_escape_string($_GET["param"]));
2702
b788b632 2703 $active_feed_id = sprintf("%d", $params[0]);
0a6c4846 2704 $is_cat = $params[1] == "true";
49b7cbd3 2705
e5d758e3 2706 print "<table width='100%'><tr><td>Search:</td><td>";
86b682ce
AD
2707
2708 print "<input name=\"query\" class=\"iedit\"
2709 onkeypress=\"return filterCR(event)\"
2371c520 2710 onkeyup=\"toggleSubmitNotEmpty(this, 'search_submit_btn')\"
86b682ce
AD
2711 value=\"\">
2712 </td></tr>";
2713
2714 print "<tr><td>Where:</td><td>";
2715
2716 print "<select name=\"search_mode\">
2717 <option value=\"all_feeds\">All feeds</option>";
2718
2719 $feed_title = getFeedTitle($link, $active_feed_id);
0a6c4846
AD
2720
2721 if (!$is_cat) {
2722 $feed_cat_title = getFeedCatTitle($link, $active_feed_id);
2723 } else {
2724 $feed_cat_title = getCategoryTitle($link, $active_feed_id);
2725 }
86b682ce 2726
0a6c4846 2727 if ($active_feed_id && !$is_cat) {
86b682ce 2728 print "<option selected value=\"this_feed\">This feed ($feed_title)</option>";
49b7cbd3
AD
2729 } else {
2730 print "<option disabled>This feed</option>";
2731 }
b0005823 2732
0a6c4846
AD
2733 if ($is_cat) {
2734 $cat_preselected = "selected";
2735 }
2736
b788b632 2737 if (get_pref($link, 'ENABLE_FEED_CATS') && ($active_feed_id > 0 || $is_cat)) {
0a6c4846 2738 print "<option $cat_preselected value=\"this_cat\">This category ($feed_cat_title)</option>";
86b682ce
AD
2739 } else {
2740 print "<option disabled>This category</option>";
b0005823
AD
2741 }
2742
86b682ce
AD
2743 print "</select></td></tr>";
2744
2745 print "<tr><td>Match on:</td><td>";
2746
2747 $search_fields = array(
2748 "title" => "Title",
2749 "content" => "Content",
2750 "both" => "Title or content");
e5d758e3 2751
86b682ce
AD
2752 print_select_hash("match_on", 3, $search_fields);
2753
2754 print "</td></tr></table>";
2755
2756 print "</form>";
2757
2758 print "<div align=\"right\">
033e47e0 2759 <input type=\"submit\"
2371c520
AD
2760 class=\"button\" onclick=\"javascript:search()\"
2761 id=\"search_submit_btn\" disabled=\"true\"
2762 value=\"Search\">
033e47e0 2763 <input class=\"button\"
86b682ce
AD
2764 type=\"submit\" onclick=\"javascript:searchCancel()\"
2765 value=\"Cancel\"></div>";
2766
2767 print "</div>";
033e47e0
AD
2768
2769 }
2770
f156fd00
AD
2771 if ($id == "quickAddLabel") {
2772 print "<div id=\"infoBoxTitle\">Create label</div>";
2773 print "<div class=\"infoBoxContents\">";
2774
2775 print "<form id=\"label_edit_form\">";
2776
2777 print "<input type=\"hidden\" name=\"op\" value=\"pref-labels\">";
2778 print "<input type=\"hidden\" name=\"subop\" value=\"add\">";
2779
2780 print "<table width='100%'>";
2781
2782 print "<tr><td>Caption:</td>
2783 <td><input onkeypress=\"return filterCR(event)\"
2784 onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
2785 name=\"description\" class=\"iedit\">";
2786
2787 print "</td></tr>";
2788
2789 print "<tr><td colspan=\"2\">
2790 <p>SQL Expression:</p>";
2791
2792 print "<textarea onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
2793 rows=\"4\" name=\"sql_exp\" class=\"iedit\"></textarea>";
2794
2795 print "</td></tr></table>";
2796
2797 print "</form>";
2798
2799 print "<div style=\"display : none\" id=\"label_test_result\"></div>";
2800
2801 print "<div align='right'>";
2802
2803 print "<input type=\"submit\" onclick=\"labelTest()\" value=\"Test\">
2804 ";
2805
2806 print "<input type=\"submit\"
2807 id=\"infobox_submit\"
2808 disabled=\"true\"
2809 class=\"button\" onclick=\"return addLabel()\"
2810 value=\"Create\"> ";
2811
2812 print "<input class=\"button\"
2813 type=\"submit\" onclick=\"return labelEditCancel()\"
2814 value=\"Cancel\">";
2815 }
2816
a24f525c
AD
2817 if ($id == "quickAddFilter") {
2818
757e8a2d
AD
2819 $active_feed_id = db_escape_string($_GET["param"]);
2820
e5d758e3
AD
2821 print "<div id=\"infoBoxTitle\">Create filter</div>";
2822 print "<div class=\"infoBoxContents\">";
2823
79f3553b
AD
2824 print "<form id=\"filter_add_form\">";
2825
2826 print "<input type=\"hidden\" name=\"op\" value=\"pref-filters\">";
2827 print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
c14b5566 2828 print "<input type=\"hidden\" name=\"subop\" value=\"add\">";
79f3553b 2829
c6932f8d 2830// print "<div class=\"notice\"><b>Note:</b> filter will only apply to new articles.</div>";
757e8a2d 2831
79f3553b 2832 $result = db_query($link, "SELECT id,description
a24f525c
AD
2833 FROM ttrss_filter_types ORDER BY description");
2834
2835 $filter_types = array();
2836
2837 while ($line = db_fetch_assoc($result)) {
79f3553b
AD
2838 //array_push($filter_types, $line["description"]);
2839 $filter_types[$line["id"]] = $line["description"];
a24f525c
AD
2840 }
2841
e5d758e3 2842 print "<table width='100%'>";
a24f525c 2843
2371c520 2844 print "<tr><td>Match:</td>
86b682ce
AD
2845 <td><input onkeypress=\"return filterCR(event)\"
2846 onkeyup=\"toggleSubmitNotEmpty(this, 'infobox_submit')\"
4220b0bd
AD
2847 name=\"reg_exp\" class=\"iedit\">";
2848 print "</td><td>";
2849
2850 print_select_hash("filter_type", 1, $filter_types, "class=\"iedit\"");
a24f525c
AD
2851
2852 print "</td></tr>";
4220b0bd 2853 print "<tr><td>Feed:</td><td colspan='2'>";
673d54ca 2854
757e8a2d 2855 print_feed_select($link, "feed_id", $active_feed_id);
673d54ca
AD
2856
2857 print "</td></tr>";
a24f525c
AD
2858
2859 print "<tr><td>Action:</td>";
2860
4220b0bd 2861 print "<td colspan='2'><select name=\"action_id\">";
a24f525c
AD
2862
2863 $result = db_query($link, "SELECT id,description FROM ttrss_filter_actions
2864 ORDER BY name");
2865
2866 while ($line = db_fetch_assoc($result)) {
79f3553b 2867 printf("<option value='%d'>%s</option>", $line["id"], $line["description"]);
a24f525c
AD
2868 }
2869
2870 print "</select>";
c14b5566
AD
2871
2872 print "</td></tr></table>";
2873
2874 print "</form>";
2875
2876 print "<div align='right'>";
2877
a24f525c 2878 print "<input type=\"submit\"
2371c520 2879 id=\"infobox_submit\"
90ac84df 2880 class=\"button\" onclick=\"return qaddFilter()\"
2371c520 2881 disabled=\"true\" value=\"Create\"> ";
a24f525c
AD
2882
2883 print "<input class=\"button\"
90ac84df 2884 type=\"submit\" onclick=\"return closeInfoBox()\"
e5d758e3 2885 value=\"Cancel\">";
a24f525c 2886
c14b5566 2887 print "</div>";
e5d758e3 2888
c14b5566 2889// print "</td></tr></table>";
79f3553b 2890
a24f525c 2891 }
7b5c6012
AD
2892
2893 print "</div>";
2894
f84a97a3
AD
2895 }
2896
a2770077
AD
2897 // update feeds of all users, may be used anonymously
2898 if ($op == "globalUpdateFeeds") {
2899
2900 $result = db_query($link, "SELECT id FROM ttrss_users");
2901
2902 while ($line = db_fetch_assoc($result)) {
2903 $user_id = $line["id"];
2904// print "<!-- updating feeds of uid $user_id -->";
2905 update_all_feeds($link, false, $user_id);
2906 }
e65af9c1 2907
a2770077
AD
2908 print "<rpc-reply>
2909 <message msg=\"All feeds updated\"/>
2910 </rpc-reply>";
e65af9c1
AD
2911
2912 }
2913
77e96719
AD
2914 if ($op == "pref-prefs") {
2915
b1895692 2916 $subop = $_REQUEST["subop"];
77e96719
AD
2917
2918 if ($subop == "Save configuration") {
2919
d2892032
AD
2920 if (WEB_DEMO_MODE) {
2921 header("Location: prefs.php");
2922 return;
2923 }
01d68cf9 2924
93cb4442
AD
2925 $_SESSION["prefs_op_result"] = "save-config";
2926
11de82c3
AD
2927 $_SESSION["prefs_cache"] = false;
2928
77e96719
AD
2929 foreach (array_keys($_POST) as $pref_name) {
2930
2931 $pref_name = db_escape_string($pref_name);
2932 $value = db_escape_string($_POST[$pref_name]);
2933
2934 $result = db_query($link, "SELECT type_name
2935 FROM ttrss_prefs,ttrss_prefs_types
2936 WHERE pref_name = '$pref_name' AND type_id = ttrss_prefs_types.id");
2937
2938 if (db_num_rows($result) > 0) {
2939
2940 $type_name = db_fetch_result($result, 0, "type_name");
2941
5da169d9
AD
2942// print "$pref_name : $type_name : $value<br>";
2943
77e96719 2944 if ($type_name == "bool") {
5da169d9 2945 if ($value == "1") {
77e96719
AD
2946 $value = "true";
2947 } else {
2948 $value = "false";
2949 }
2950 } else if ($type_name == "integer") {
2951 $value = sprintf("%d", $value);
2952 }
2953
2954// print "$pref_name : $type_name : $value<br>";
2955
ff485f1d
AD
2956 db_query($link, "UPDATE ttrss_user_prefs SET value = '$value'
2957 WHERE pref_name = '$pref_name' AND owner_uid = ".$_SESSION["uid"]);
77e96719
AD
2958
2959 }
2960
2961 header("Location: prefs.php");
2962
2963 }
2964
b1895692
AD
2965 } else if ($subop == "getHelp") {
2966
2967 $pref_name = db_escape_string($_GET["pn"]);
2968
2969 $result = db_query($link, "SELECT help_text FROM ttrss_prefs
2970 WHERE pref_name = '$pref_name'");
2971
2972 if (db_num_rows($result) > 0) {
2973 $help_text = db_fetch_result($result, 0, "help_text");
2974 print $help_text;
2975 } else {
2976 print "Unknown option: $pref_name";
2977 }
2978
cbb01696
AD
2979 } else if ($subop == "Change e-mail") {
2980
2981 if (WEB_DEMO_MODE) {
2982 header("Location: prefs.php");
2983 return;
2984 }
2985
2986 $email = db_escape_string($_GET["email"]);
2987 $active_uid = $_SESSION["uid"];
2988
2989 if ($email) {
2990 db_query($link, "UPDATE ttrss_users SET email = '$email'
2991 WHERE id = '$active_uid'");
2992 }
2993
2994 header("Location: prefs.php");
2995
1c7f75ed
AD
2996 } else if ($subop == "Change password") {
2997
d2892032
AD
2998 if (WEB_DEMO_MODE) {
2999 header("Location: prefs.php");
3000 return;
3001 }
1c7f75ed
AD
3002
3003 $old_pw = $_POST["OLD_PASSWORD"];
3004 $new_pw = $_POST["OLD_PASSWORD"];
3005
3006 $old_pw_hash = 'SHA1:' . sha1($_POST["OLD_PASSWORD"]);
3007 $new_pw_hash = 'SHA1:' . sha1($_POST["NEW_PASSWORD"]);
3008
3009 $active_uid = $_SESSION["uid"];
3010
3011 if ($old_pw && $new_pw) {
3012
3013 $login = db_escape_string($_SERVER['PHP_AUTH_USER']);
3014
3015 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3016 id = '$active_uid' AND (pwd_hash = '$old_pw' OR
3017 pwd_hash = '$old_pw_hash')");
3018
3019 if (db_num_rows($result) == 1) {
3020 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash'
3021 WHERE id = '$active_uid'");
b791095d
AD
3022
3023 $_SESSION["pwd_change_result"] = "ok";
3024 } else {
3025 $_SESSION["pwd_change_result"] = "failed";
1c7f75ed
AD
3026 }
3027 }
3028
3029 header("Location: prefs.php");
b791095d 3030
77e96719
AD
3031 } else if ($subop == "Reset to defaults") {
3032
d2892032
AD
3033 if (WEB_DEMO_MODE) {
3034 header("Location: prefs.php");
3035 return;
3036 }
01d68cf9 3037
93cb4442
AD
3038 $_SESSION["prefs_op_result"] = "reset-to-defaults";
3039
e1aa0559
AD
3040 if (DB_TYPE == "pgsql") {
3041 db_query($link,"UPDATE ttrss_user_prefs
3042 SET value = ttrss_prefs.def_value
3043 WHERE owner_uid = '".$_SESSION["uid"]."' AND
3044 ttrss_prefs.pref_name = ttrss_user_prefs.pref_name");
3045 } else {
3046 db_query($link, "DELETE FROM ttrss_user_prefs
3047 WHERE owner_uid = ".$_SESSION["uid"]);
3048 initialize_user_prefs($link, $_SESSION["uid"]);
3049 }
5da169d9 3050
77e96719
AD
3051 header("Location: prefs.php");
3052
58f8ad54
AD
3053 } else if ($subop == "Change theme") {
3054
3055 $theme = db_escape_string($_POST["theme"]);
3056
3057 if ($theme == "Default") {
3058 $theme_qpart = 'NULL';
3059 } else {
3060 $theme_qpart = "'$theme'";
3061 }
3062
6752e330
AD
3063 $result = db_query($link, "SELECT id,theme_path FROM ttrss_themes
3064 WHERE theme_name = '$theme'");
3065
3066 if (db_num_rows($result) == 1) {
3067 $theme_id = db_fetch_result($result, 0, "id");
3068 $theme_path = db_fetch_result($result, 0, "theme_path");
3069 } else {
3070 $theme_id = "NULL";
3071 $theme_path = "";
3072 }
3073
58f8ad54 3074 db_query($link, "UPDATE ttrss_users SET
6752e330 3075 theme_id = $theme_id WHERE id = " . $_SESSION["uid"]);
58f8ad54 3076
6752e330 3077 $_SESSION["theme"] = $theme_path;
503eb349 3078
58f8ad54
AD
3079 header("Location: prefs.php");
3080
77e96719
AD
3081 } else {
3082
b72c3ef8
AD
3083 print check_for_update($link);
3084
7d4c898a 3085 if (!SINGLE_USER_MODE) {
1c7f75ed 3086
cbb01696 3087 $result = db_query($link, "SELECT id,email FROM ttrss_users
a029d530
AD
3088 WHERE id = ".$_SESSION["uid"]." AND (pwd_hash = 'password' OR
3089 pwd_hash = 'SHA1:".sha1("password")."')");
3090
3091 if (db_num_rows($result) != 0) {
b791095d 3092 print "<div class=\"warning\">
a029d530
AD
3093 Your password is at default value, please change it.
3094 </div>";
3095 }
3096
b791095d
AD
3097 if ($_SESSION["pwd_change_result"] == "failed") {
3098 print "<div class=\"warning\">
3099 There was an error while changing your password.
3100 </div>";
3101 }
3102
3103 if ($_SESSION["pwd_change_result"] == "ok") {
3104 print "<div class=\"notice\">
3105 Password changed successfully.
3106 </div>";
3107 }
3108
3109 $_SESSION["pwd_change_result"] = "";
3110
93cb4442
AD
3111 if ($_SESSION["prefs_op_result"] == "reset-to-defaults") {
3112 print "<div class=\"notice\">
3113 Your configuration was reset to defaults.
3114 </div>";
3115 }
3116
3117 if ($_SESSION["prefs_op_result"] == "save-config") {
3118 print "<div class=\"notice\">
3119 Your configuration was saved successfully.
3120 </div>";
3121 }
3122
3123 $_SESSION["prefs_op_result"] = "";
3124
cbb01696
AD
3125 print "<form action=\"backend.php\" method=\"GET\">";
3126
3127 print "<table width=\"100%\" class=\"prefPrefsList\">";
3128 print "<tr><td colspan='3'><h3>Personal data</h3></tr></td>";
3129
3130 $result = db_query($link, "SELECT email FROM ttrss_users
3131 WHERE id = ".$_SESSION["uid"]);
3132
3133 $email = db_fetch_result($result, 0, "email");
3134
3135 print "<tr><td width=\"40%\">E-mail</td>";
3136 print "<td><input class=\"editbox\" name=\"email\"
3137 value=\"$email\"></td></tr>";
3138
3139 print "</table>";
3140
3141 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3142
3143 print "<p><input class=\"button\" type=\"submit\"
3144 value=\"Change e-mail\" name=\"subop\">";
3145
a132b8b1
AD
3146 print "</form>";
3147
64dc5976 3148 print "<form action=\"backend.php\" method=\"POST\" name=\"changePassForm\">";
7d4c898a
AD
3149
3150 print "<table width=\"100%\" class=\"prefPrefsList\">";
3151 print "<tr><td colspan='3'><h3>Authentication</h3></tr></td>";
3152
3153 print "<tr><td width=\"40%\">Old password</td>";
3154 print "<td><input class=\"editbox\" type=\"password\"
3155 name=\"OLD_PASSWORD\"></td></tr>";
3156
3157 print "<tr><td width=\"40%\">New password</td>";
3158
3159 print "<td><input class=\"editbox\" type=\"password\"
3160 name=\"NEW_PASSWORD\"></td></tr>";
3161
3162 print "</table>";
3163
3164 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3165
3166 print "<p><input class=\"button\" type=\"submit\"
64dc5976 3167 onclick=\"return validateNewPassword(this.form)\"
7d4c898a
AD
3168 value=\"Change password\" name=\"subop\">";
3169
3170 print "</form>";
1c7f75ed 3171
7d4c898a 3172 }
1c7f75ed 3173
58f8ad54
AD
3174 $result = db_query($link, "SELECT
3175 theme_id FROM ttrss_users WHERE id = " . $_SESSION["uid"]);
3176
3177 $user_theme_id = db_fetch_result($result, 0, "theme_id");
3178
3179 $result = db_query($link, "SELECT
3180 id,theme_name FROM ttrss_themes ORDER BY theme_name");
3181
3182 if (db_num_rows($result) > 0) {
6752e330
AD
3183
3184 print "<form action=\"backend.php\" method=\"POST\">";
3185 print "<table width=\"100%\" class=\"prefPrefsList\">";
3186 print "<tr><td colspan='3'><h3>Themes</h3></tr></td>";
3187 print "<tr><td width=\"40%\">Select theme</td>";
3188 print "<td><select name=\"theme\">";
3189 print "<option>Default</option>";
58f8ad54 3190 print "<option disabled>--------</option>";
6752e330 3191
58f8ad54
AD
3192 while ($line = db_fetch_assoc($result)) {
3193 if ($line["id"] == $user_theme_id) {
3194 $selected = "selected";
3195 } else {
3196 $selected = "";
3197 }
3198 print "<option $selected>" . $line["theme_name"] . "</option>";
3199 }
6752e330
AD
3200 print "</select></td></tr>";
3201 print "</table>";
3202 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3203 print "<p><input class=\"button\" type=\"submit\"
3204 value=\"Change theme\" name=\"subop\">";
3205 print "</form>";
58f8ad54
AD
3206 }
3207
144a5ef8
AD
3208 initialize_user_prefs($link, $_SESSION["uid"]);
3209
77e96719 3210 $result = db_query($link, "SELECT
ff485f1d 3211 ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name,
77e96719 3212 section_name,def_value
ff485f1d 3213 FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs
77e96719 3214 WHERE type_id = ttrss_prefs_types.id AND
ff485f1d 3215 section_id = ttrss_prefs_sections.id AND
a2411bd9
AD
3216 ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND
3217 owner_uid = ".$_SESSION["uid"]."
650bc435 3218 ORDER BY section_id,short_desc");
77e96719
AD
3219
3220 print "<form action=\"backend.php\" method=\"POST\">";
3221
77e96719
AD
3222 $lnum = 0;
3223
3224 $active_section = "";
3225
3226 while ($line = db_fetch_assoc($result)) {
3227
3228 if ($active_section != $line["section_name"]) {
59a654ba
AD
3229
3230 if ($active_section != "") {
1c7f75ed 3231 print "</table>";
59a654ba 3232 }
1c7f75ed
AD
3233
3234 print "<p><table width=\"100%\" class=\"prefPrefsList\">";
59a654ba
AD
3235
3236 $active_section = $line["section_name"];
3237
77e96719 3238 print "<tr><td colspan=\"3\"><h3>$active_section</h3></td></tr>";
59a654ba
AD
3239// print "<tr class=\"title\">
3240// <td width=\"25%\">Option</td><td>Value</td></tr>";
7268adf7
AD
3241
3242 $lnum = 0;
77e96719
AD
3243 }
3244
650bc435 3245// $class = ($lnum % 2) ? "even" : "odd";
77e96719 3246
650bc435 3247 print "<tr>";
77e96719 3248
77e96719
AD
3249 $type_name = $line["type_name"];
3250 $pref_name = $line["pref_name"];
3251 $value = $line["value"];
3252 $def_value = $line["def_value"];
b1895692
AD
3253 $help_text = $line["help_text"];
3254
3255 print "<td width=\"40%\" id=\"$pref_name\">" . $line["short_desc"];
3256
3257 if ($help_text) print "<div class=\"prefHelp\">$help_text</div>";
3258
3259 print "</td>";
77e96719
AD
3260
3261 print "<td>";
3262
3263 if ($type_name == "bool") {
3264// print_select($pref_name, $value, array("true", "false"));
3265
3266 if ($value == "true") {
3267 $value = "Yes";
3268 } else {
3269 $value = "No";
3270 }
3271
3272 print_radio($pref_name, $value, array("Yes", "No"));
3273
3274 } else {
3275 print "<input class=\"editbox\" name=\"$pref_name\" value=\"$value\">";
3276 }
3277
3278 print "</td>";
3279
3280 print "</tr>";
3281
3282 $lnum++;
3283 }
3284
3285 print "</table>";
3286
3287 print "<input type=\"hidden\" name=\"op\" value=\"pref-prefs\">";
3288
3289 print "<p><input class=\"button\" type=\"submit\"
3290 name=\"subop\" value=\"Save configuration\">";
3291
3292 print "&nbsp;<input class=\"button\" type=\"submit\"
69668465
AD
3293 name=\"subop\" onclick=\"return validatePrefsReset()\"
3294 value=\"Reset to defaults\"></p>";
77e96719
AD
3295
3296 print "</form>";
3297
3298 }
3299
3300 }
3301
e6cb77a0
AD
3302 if ($op == "pref-users") {
3303
3304 $subop = $_GET["subop"];
3305
3c5783b7
AD
3306 if ($subop == "edit") {
3307
3308 $id = db_escape_string($_GET["id"]);
3309
3310 print "<div id=\"infoBoxTitle\">User editor</div>";
3311
3312 print "<div class=\"infoBoxContents\">";
3313
3314 print "<form id=\"user_edit_form\">";
3315
3316 print "<input type=\"hidden\" name=\"id\" value=\"$id\">";
3317 print "<input type=\"hidden\" name=\"op\" value=\"pref-users\">";
3318 print "<input type=\"hidden\" name=\"subop\" value=\"editSave\">";
3319
3320 $result = db_query($link, "SELECT * FROM ttrss_users WHERE id = '$id'");
3321
3322 $login = db_fetch_result($result, 0, "login");
3323 $access_level = db_fetch_result($result, 0, "access_level");
3324 $email = db_fetch_result($result, 0, "email");
3325
3326 print "<table width='100%'>";
3327 print "<tr><td>Login:</td><td>
ac2cc246
AD
3328 <input class=\"iedit\" onkeypress=\"return filterCR(event)\"
3329 name=\"login\" value=\"$login\"></td></tr>";
3c5783b7
AD
3330
3331 print "<tr><td>Change password:</td><td>
ac2cc246
AD
3332 <input class=\"iedit\" onkeypress=\"return filterCR(event)\"
3333 name=\"password\"></td></tr>";
3c5783b7
AD
3334
3335 print "<tr><td>E-mail:</td><td>
ac2cc246
AD
3336 <input class=\"iedit\" name=\"email\" onkeypress=\"return filterCR(event)\"
3337 value=\"$email\"></td></tr>";
3c5783b7
AD
3338
3339 $sel_disabled = ($id == $_SESSION["uid"]) ? "disabled" : "";
3340
3341 print "<tr><td>Access level:</td><td>";
3342 print_select_hash("access_level", $access_level, $access_level_names,
3343 $sel_disabled);
3344 print "</td></tr>";
3345
3346 print "</table>";
3347
3348 print "</form>";
3349
3350 print "<div align='right'>
3351 <input class=\"button\"
90ac84df
AD
3352 type=\"submit\" onclick=\"return userEditSave()\"
3353 value=\"Save\">
3c5783b7 3354 <input class=\"button\"
90ac84df 3355 type=\"submit\" onclick=\"return userEditCancel()\"
3c5783b7
AD
3356 value=\"Cancel\"></div>";
3357
3358 print "</div>";
3359
3360 return;
3361 }
3362
e6cb77a0
AD
3363 if ($subop == "editSave") {
3364
3c5783b7 3365 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
e6cb77a0 3366
3c5783b7 3367 $login = db_escape_string(trim($_GET["login"]));
e6cb77a0 3368 $uid = db_escape_string($_GET["id"]);
3c5783b7
AD
3369 $access_level = sprintf("%d", $_GET["access_level"]);
3370 $email = db_escape_string(trim($_GET["email"]));
3371 $password = db_escape_string(trim($_GET["password"]));
3372
3373 if ($password) {
3374 $pwd_hash = 'SHA1:' . sha1($password);
3375 $pass_query_part = "pwd_hash = '$pwd_hash', ";
3376 print "<div class='notice'>Changed password for user <b>$login</b>.</div>";
3377 } else {
3378 $pass_query_part = "";
3379 }
e6cb77a0 3380
3c5783b7 3381 db_query($link, "UPDATE ttrss_users SET $pass_query_part login = '$login',
72932a75 3382 access_level = '$access_level', email = '$email' WHERE id = '$uid'");
e6cb77a0
AD
3383
3384 }
3385 } else if ($subop == "remove") {
3386
3387 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3388
f932bc9f 3389 $ids = split(",", db_escape_string($_GET["ids"]));
e6cb77a0
AD
3390
3391 foreach ($ids as $id) {
3392 db_query($link, "DELETE FROM ttrss_users WHERE id = '$id' AND id != " . $_SESSION["uid"]);
3393
3394 }
3395 }
3396 } else if ($subop == "add") {
3397
3398 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3399
b6b535ca 3400 $login = db_escape_string(trim($_GET["login"]));
e6cb77a0
AD
3401 $tmp_user_pwd = make_password(8);
3402 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3403
e6cb77a0 3404 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
ce3bf408 3405 login = '$login'");
e6cb77a0 3406
ce3bf408 3407 if (db_num_rows($result) == 0) {
e6cb77a0 3408
ce3bf408
AD
3409 db_query($link, "INSERT INTO ttrss_users
3410 (login,pwd_hash,access_level,last_login)
3411 VALUES ('$login', '$pwd_hash', 0, NOW())");
3412
3413
3414 $result = db_query($link, "SELECT id FROM ttrss_users WHERE
3415 login = '$login' AND pwd_hash = '$pwd_hash'");
3416
3417 if (db_num_rows($result) == 1) {
3418
3419 $new_uid = db_fetch_result($result, 0, "id");
3420
3421 print "<div class=\"notice\">Added user <b>".$_GET["login"].
3422 "</b> with password <b>$tmp_user_pwd</b>.</div>";
3423
3424 initialize_user($link, $new_uid);
3425
3426 } else {
3427
3428 print "<div class=\"warning\">Could not create user <b>".
3429 $_GET["login"]."</b></div>";
3430
3431 }
e6cb77a0 3432 } else {
ce3bf408
AD
3433 print "<div class=\"warning\">User <b>".
3434 $_GET["login"]."</b> already exists.</div>";
e6cb77a0
AD
3435 }
3436 }
3437 } else if ($subop == "resetPass") {
3438
3439 if (!WEB_DEMO_MODE && $_SESSION["access_level"] >= 10) {
3440
3441 $uid = db_escape_string($_GET["id"]);
3442
72932a75
AD
3443 $result = db_query($link, "SELECT login,email
3444 FROM ttrss_users WHERE id = '$uid'");
e6cb77a0
AD
3445
3446 $login = db_fetch_result($result, 0, "login");
72932a75 3447 $email = db_fetch_result($result, 0, "email");
e6cb77a0
AD
3448 $tmp_user_pwd = make_password(8);
3449 $pwd_hash = 'SHA1:' . sha1($tmp_user_pwd);
3450
3451 db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash'
3452 WHERE id = '$uid'");
3453
3454 print "<div class=\"notice\">Changed password of
72932a75
AD
3455 user <b>$login</b> to <b>$tmp_user_pwd</b>.";
3456
3457 if (MAIL_RESET_PASS && $email) {
3458 print " Notifying <b>$email</b>.";
3459
3460 mail("$login <$email>", "Password reset notification",
3461 "Hi, $login.\n".
3462 "\n".
3463 "Your password for this TT-RSS installation was reset by".
3464 " an administrator.\n".
3465 "\n".
3466 "Your new password is $tmp_user_pwd, please remember".
3467 " it for later reference.\n".
3468 "\n".
3469 "Sincerely, TT-RSS Mail Daemon.", "From: " . MAIL_FROM);
3470 }
3471
3472 print "</div>";
e6cb77a0
AD
3473
3474 }
3475 }
3476
79ec0f2f
AD
3477 $sort = db_escape_string($_GET["sort"]);
3478
3479 if (!$sort || $sort == "undefined") {
3480 $sort = "login";
3481 }
3482
2c7070b5 3483 print "<div class=\"prefGenericAddBox\">
2371c520
AD
3484 <input id=\"uadd_box\"
3485 onkeyup=\"toggleSubmitNotEmpty(this, 'user_add_btn')\"
292a8a12 3486 size=\"40\">&nbsp;";
e6cb77a0 3487
2c7070b5 3488 print"<input type=\"submit\" class=\"button\"
2371c520
AD
3489 id=\"user_add_btn\" disabled=\"true\"
3490 onclick=\"javascript:addUser()\" value=\"Create user\"></div>";
e6cb77a0
AD
3491
3492 $result = db_query($link, "SELECT
72932a75 3493 id,login,access_level,email,
fe99ab12 3494 SUBSTRING(last_login,1,16) as last_login
e6cb77a0
AD
3495 FROM
3496 ttrss_users
79ec0f2f 3497 ORDER BY $sort");
e6cb77a0 3498
59a543f0 3499// print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
1a7572cb 3500
f4fe2cde
AD
3501 print "<p><table width=\"100%\" cellspacing=\"0\"
3502 class=\"prefUserList\" id=\"prefUserList\">";
e6cb77a0 3503
35f3c923
AD
3504 print "<tr><td class=\"selectPrompt\" colspan=\"8\">
3505 Select:
ce3bf408
AD
3506 <a href=\"javascript:selectPrefRows('user', true)\">All</a>,
3507 <a href=\"javascript:selectPrefRows('user', false)\">None</a>
35f3c923
AD
3508 </td</tr>";
3509
e6cb77a0 3510 print "<tr class=\"title\">
e325c6e7 3511 <td align='center' width=\"5%\">&nbsp;</td>
79ec0f2f
AD
3512 <td width='40%'><a href=\"javascript:updateUsersList('login')\">Login</a></td>
3513 <td width='40%'><a href=\"javascript:updateUsersList('access_level')\">Access Level</a></td>
3514 <td width='30%'><a href=\"javascript:updateUsersList('last_login')\">Last login</a></td></tr>";
e6cb77a0
AD
3515
3516 $lnum = 0;
3517
3518 while ($line = db_fetch_assoc($result)) {
3519
3520 $class = ($lnum % 2) ? "even" : "odd";
3521
3522 $uid = $line["id"];
3523 $edit_uid = $_GET["id"];
3524
4154a415 3525 if ($subop == "edit" && $uid != $edit_uid) {
e6cb77a0 3526 $class .= "Grayed";
53226edc
AD
3527 $this_row_id = "";
3528 } else {
3529 $this_row_id = "id=\"UMRR-$uid\"";
3530 }
3531
3532 print "<tr class=\"$class\" $this_row_id>";
e6cb77a0
AD
3533
3534 $line["login"] = htmlspecialchars($line["login"]);
3535
6be6bc03
AD
3536 $line["last_login"] = date(get_pref($link, 'SHORT_DATE_FORMAT'),
3537 strtotime($line["last_login"]));
3538
5917a8e4
AD
3539 $access_level_names = array(0 => "User", 10 => "Administrator");
3540
3c5783b7 3541// if (!$edit_uid || $subop != "edit") {
e6cb77a0 3542
ce3bf408 3543 print "<td align='center'><input onclick='toggleSelectPrefRow(this, \"user\");'
1a7572cb 3544 type=\"checkbox\" id=\"UMCHK-$uid\"></td>";
e6cb77a0
AD
3545
3546 print "<td><a href=\"javascript:editUser($uid);\">" .
3547 $line["login"] . "</td>";
72932a75 3548
0b68215c
AD
3549 if (!$line["email"]) $line["email"] = "&nbsp;";
3550
e6cb77a0 3551 print "<td><a href=\"javascript:editUser($uid);\">" .
5917a8e4 3552 $access_level_names[$line["access_level"]] . "</td>";
e6cb77a0 3553
3c5783b7 3554/* } else if ($uid != $edit_uid) {
e6cb77a0 3555
0b68215c
AD
3556 if (!$line["email"]) $line["email"] = "&nbsp;";
3557
72932a75 3558 print "<td align='center'><input disabled=\"true\" type=\"checkbox\"
e6cb77a0
AD
3559 id=\"UMCHK-".$line["id"]."\"></td>";
3560
3561 print "<td>".$line["login"]."</td>";
72932a75 3562 print "<td>".$line["email"]."</td>";
5917a8e4 3563 print "<td>".$access_level_names[$line["access_level"]]."</td>";
e6cb77a0
AD
3564
3565 } else {
3566
72932a75
AD
3567 print "<td align='center'>
3568 <input disabled=\"true\" type=\"checkbox\" checked></td>";
e6cb77a0
AD
3569
3570 print "<td><input id=\"iedit_ulogin\" value=\"".$line["login"].
3571 "\"></td>";
3572
72932a75
AD
3573 print "<td><input id=\"iedit_email\" value=\"".$line["email"].
3574 "\"></td>";
3575
5917a8e4
AD
3576 print "<td>";
3577 print "<select id=\"iedit_ulevel\">";
3578 foreach (array_keys($access_level_names) as $al) {
3579 if ($al == $line["access_level"]) {
3580 $selected = "selected";
3581 } else {
3582 $selected = "";
3583 }
3584 print "<option $selected id=\"$al\">" .
3585 $access_level_names[$al] . "</option>";
3586 }
3587 print "</select>";
3588 print "</td>";
3589
3c5783b7 3590 } */
e6cb77a0 3591
f6f32198
AD
3592 print "<td>".$line["last_login"]."</td>";
3593
e6cb77a0
AD
3594 print "</tr>";
3595
3596 ++$lnum;
3597 }
3598
3599 print "</table>";
3600
ce3bf408 3601 print "<p id='userOpToolbar'>";
e6cb77a0 3602
3c5783b7 3603/* if ($subop == "edit") {
d10fabe4 3604 print "Edit user:
e6cb77a0 3605 <input type=\"submit\" class=\"button\"
d10fabe4 3606 onclick=\"javascript:userEditSave()\" value=\"Save\">
e6cb77a0 3607 <input type=\"submit\" class=\"button\"
d10fabe4 3608 onclick=\"javascript:userEditCancel()\" value=\"Cancel\">";
e6cb77a0 3609
3c5783b7 3610 } else { */
e6cb77a0
AD
3611
3612 print "
3613 Selection:
ce3bf408 3614 <input type=\"submit\" class=\"button\" disabled=\"true\"
717f5e64 3615 onclick=\"javascript:selectedUserDetails()\" value=\"User details\">
ce3bf408 3616 <input type=\"submit\" class=\"button\" disabled=\"true\"
e6cb77a0 3617 onclick=\"javascript:editSelectedUser()\" value=\"Edit\">
ce3bf408 3618 <input type=\"submit\" class=\"button\" disabled=\"true\"
717f5e64 3619 onclick=\"javascript:removeSelectedUsers()\" value=\"Remove\">
ce3bf408 3620 <input type=\"submit\" class=\"button\" disabled=\"true\"
717f5e64
AD
3621 onclick=\"javascript:resetSelectedUserPass()\" value=\"Reset password\">";
3622
3c5783b7 3623// }
717f5e64
AD
3624 }
3625
3626 if ($op == "user-details") {
3627
3628 if (WEB_DEMO_MODE || $_SESSION["access_level"] < 10) {
3629 return;
3630 }
3631
1a7572cb 3632/* print "<html><head>
717f5e64
AD
3633 <title>Tiny Tiny RSS : User Details</title>
3634 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
3635 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1a7572cb 3636 </head><body>"; */
717f5e64
AD
3637
3638 $uid = sprintf("%d", $_GET["id"]);
3639
e5d758e3
AD
3640 print "<div id=\"infoBoxTitle\">User details</div>";
3641
c6c3a07f 3642 print "<div class='infoBoxContents'>";
717f5e64 3643
fe99ab12
AD
3644 $result = db_query($link, "SELECT login,
3645 SUBSTRING(last_login,1,16) AS last_login,
3646 access_level,
c6c3a07f
AD
3647 (SELECT COUNT(int_id) FROM ttrss_user_entries
3648 WHERE owner_uid = id) AS stored_articles
717f5e64
AD
3649 FROM ttrss_users
3650 WHERE id = '$uid'");
3651
3652 if (db_num_rows($result) == 0) {
3653 print "<h1>User not found</h1>";
3654 return;
3655 }
3656
adba6b85
AD
3657# print "<h1>User Details</h1>";
3658
3659 $login = db_fetch_result($result, 0, "login");
3660
c0ae0fdb 3661# print "<h1>$login</h1>";
717f5e64
AD
3662
3663 print "<table width='100%'>";
3664
6be6bc03
AD
3665 $last_login = date(get_pref($link, 'LONG_DATE_FORMAT'),
3666 strtotime(db_fetch_result($result, 0, "last_login")));
717f5e64 3667 $access_level = db_fetch_result($result, 0, "access_level");
c6c3a07f 3668 $stored_articles = db_fetch_result($result, 0, "stored_articles");
717f5e64 3669
adba6b85 3670# print "<tr><td>Username</td><td>$login</td></tr>";
c0ae0fdb 3671# print "<tr><td>Access level</td><td>$access_level</td></tr>";
717f5e64 3672 print "<tr><td>Last logged in</td><td>$last_login</td></tr>";
c6c3a07f 3673 print "<tr><td>Stored articles</td><td>$stored_articles</td></tr>";
717f5e64
AD
3674
3675 $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
3676 WHERE owner_uid = '$uid'");
3677
3678 $num_feeds = db_fetch_result($result, 0, "num_feeds");
3679
3680 print "<tr><td>Subscribed feeds count</td><td>$num_feeds</td></tr>";
3681
5d15d3ea 3682/* $result = db_query($link, "SELECT
717f5e64 3683 SUM(LENGTH(content)+LENGTH(title)+LENGTH(link)+LENGTH(guid)) AS db_size
c6c3a07f
AD
3684 FROM ttrss_user_entries,ttrss_entries
3685 WHERE owner_uid = '$uid' AND ref_id = id");
717f5e64 3686
d9f115c3 3687 $db_size = round(db_fetch_result($result, 0, "db_size") / 1024);
717f5e64 3688
c6c3a07f 3689 print "<tr><td>Approx. used DB size</td><td>$db_size KBytes</td></tr>"; */
717f5e64
AD
3690
3691 print "</table>";
3692
3693 print "<h1>Subscribed feeds</h1>";
3694
e94645ca 3695 $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds
9b3e2cc7 3696 WHERE owner_uid = '$uid' ORDER BY title");
717f5e64 3697
9b3e2cc7 3698 print "<ul class=\"userFeedList\">";
717f5e64 3699
adba6b85
AD
3700 $row_class = "odd";
3701
717f5e64
AD
3702 while ($line = db_fetch_assoc($result)) {
3703
3704 $icon_file = ICONS_URL."/".$line["id"].".ico";
3705
3706 if (file_exists($icon_file) && filesize($icon_file) > 0) {
6c56687e 3707 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"$icon_file\">";
717f5e64 3708 } else {
5951ded1 3709 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
717f5e64
AD
3710 }
3711
adba6b85
AD
3712 print "<li class=\"$row_class\">$feed_icon&nbsp;<a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
3713
3714 $row_class = toggleEvenOdd($row_class);
3715
e6cb77a0 3716 }
717f5e64 3717
a88c1f36
AD
3718 if (db_num_rows($result) < $num_feeds) {
3719 // FIXME - add link to show ALL subscribed feeds here somewhere
3720 print "<li><img
3721 class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">&nbsp;...</li>";
3722 }
3723
717f5e64
AD
3724 print "</ul>";
3725
717f5e64
AD
3726 print "</div>";
3727
1a7572cb
AD
3728 print "<div align='center'>
3729 <input type='submit' class='button'
c6c3a07f 3730 onclick=\"closeInfoBox()\" value=\"Close this window\"></div>";
1a7572cb
AD
3731
3732// print "</body></html>";
717f5e64 3733
e6cb77a0
AD
3734 }
3735
c6232e43
AD
3736 if ($op == "pref-feed-browser") {
3737
e2f728be
AD
3738 if (!ENABLE_FEED_BROWSER) {
3739 print "Feed browser is administratively disabled.";
3740 return;
3741 }
3742
c6232e43
AD
3743 $subop = $_REQUEST["subop"];
3744
3745 if ($subop == "details") {
3746 $id = db_escape_string($_GET["id"]);
c2b2aee0 3747
072f1ee2
AD
3748 print "<div class=\"browserFeedInfo\">";
3749 print "<b>Feed information:</b>";
3750 print "<div class=\"detailsPart\">";
3751
3752 $result = db_query($link, "SELECT
3753 feed_url,site_url,
3754 SUBSTRING(last_updated,1,19) AS last_updated
3755 FROM ttrss_feeds WHERE id = '$id'");
3756
3757 $feed_url = db_fetch_result($result, 0, "feed_url");
3758 $site_url = db_fetch_result($result, 0, "site_url");
3759 $last_updated = db_fetch_result($result, 0, "last_updated");
3760
3761 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
3762 $last_updated = smart_date_time(strtotime($last_updated));
3763 } else {
3764 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
3765 $last_updated = date($short_date, strtotime($last_updated));
3766 }
3767
7a4dd799
AD
3768 print "Site: <a target=\"_new\" href='$site_url'>$site_url</a> ".
3769 "(<a target=\"_new\" href='$feed_url'>feed</a>), ".
072f1ee2
AD
3770 "Last updated: $last_updated";
3771
3772 print "</div>";
3773
3774 $result = db_query($link, "SELECT
3775 ttrss_entries.title,
7a4dd799 3776 content,link,
c2b2aee0
AD
3777 substring(date_entered,1,19) as date_entered,
3778 substring(updated,1,19) as updated
072f1ee2
AD
3779 FROM ttrss_entries,ttrss_user_entries
3780 WHERE ttrss_entries.id = ref_id AND feed_id = '$id'
c2b2aee0
AD
3781 ORDER BY updated DESC LIMIT 5");
3782
3783 if (db_num_rows($result) > 0) {
c2b2aee0
AD
3784
3785 print "<b>Last headlines:</b><br>";
3786
3787 print "<div class=\"detailsPart\">";
3788 print "<ul class=\"compact\">";
3789 while ($line = db_fetch_assoc($result)) {
3790
3791 if (get_pref($link, 'HEADLINES_SMART_DATE')) {
3792 $entry_dt = smart_date_time(strtotime($line["updated"]));
3793 } else {
3794 $short_date = get_pref($link, 'SHORT_DATE_FORMAT');
3795 $entry_dt = date($short_date, strtotime($line["updated"]));
3796 }
3797
7a4dd799 3798 print "<li><a target=\"_new\" href=\"" . $line["link"] . "\">" . $line["title"] . "</a>" .
c2b2aee0
AD
3799 "&nbsp;<span class=\"insensitive\">($entry_dt)</span></li>";
3800 }
3801 print "</ul></div>";
3802 }
072f1ee2
AD
3803
3804 print "</div>";
c2b2aee0 3805
c6232e43
AD
3806 return;
3807 }
65f28a40 3808
beccbed5
AD
3809 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>";
3810
6311acbe
AD
3811 $limit = db_escape_string($_GET["limit"]);
3812
3813 if (!$limit) $limit = 25;
3814
0af33e87
AD
3815 $owner_uid = $_SESSION["uid"];
3816
3817 $result = db_query($link, "SELECT feed_url,COUNT(id) AS subscribers
3818 FROM ttrss_feeds WHERE (SELECT COUNT(id) = 0 FROM ttrss_feeds AS tf
3819 WHERE tf.feed_url = ttrss_feeds.feed_url
3820 AND owner_uid = '$owner_uid') GROUP BY feed_url
3821 ORDER BY subscribers DESC LIMIT $limit");
6311acbe 3822
0af33e87 3823
6311acbe
AD
3824 print "<div style=\"float : right\">
3825 Top <select id=\"feedBrowserLimit\">";
3826
3827 foreach (array(25, 50, 100) as $l) {
3828 $issel = ($l == $limit) ? "selected" : "";
3829 print "<option $issel>$l</option>";
3830 }
3831
3832 print "</select>
3833 <input type=\"submit\" class=\"button\"
3834 onclick=\"updateBigFeedBrowser()\" value=\"Show\">
3835 </div>";
0b68215c 3836
c0ae0fdb 3837 print "<p id=\"fbrOpToolbar\">Selection:
0b68215c 3838 <input type='submit' class='button' onclick=\"feedBrowserSubscribe()\"
c0ae0fdb 3839 disabled=\"true\" value=\"Subscribe\">";
0b68215c 3840
0fefdacc 3841 print "<ul class='nomarks' id='browseBigFeedList'>";
c6232e43
AD
3842
3843 $feedctr = 0;
3844
3845 while ($line = db_fetch_assoc($result)) {
3846 $feed_url = $line["feed_url"];
3847 $subscribers = $line["subscribers"];
c6232e43
AD
3848
3849 $det_result = db_query($link, "SELECT site_url,title,id
3850 FROM ttrss_feeds WHERE feed_url = '$feed_url' LIMIT 1");
3851
3852 $details = db_fetch_assoc($det_result);
3853
3854 $icon_file = ICONS_DIR . "/" . $details["id"] . ".ico";
3855
3856 if (file_exists($icon_file) && filesize($icon_file) > 0) {
3857 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"" . ICONS_URL .
3858 "/".$details["id"].".ico\">";
3859 } else {
3860 $feed_icon = "<img class=\"tinyFeedIcon\" src=\"images/blank_icon.gif\">";
3861 }
3862
c0ae0fdb 3863 $check_box = "<input onclick='toggleSelectFBListRow(this)' class='feedBrowseCB'
c6232e43
AD
3864 type=\"checkbox\" id=\"FBCHK-" . $details["id"] . "\">";
3865
3866 $class = ($feedctr % 2) ? "even" : "odd";
3867
3868 print "<li class='$class' id=\"FBROW-".$details["id"]."\">$check_box".
3869 "$feed_icon ";
3870
c2b2aee0 3871 print "<a href=\"javascript:browserToggleExpand('".$details["id"]."')\">" .
c6232e43
AD
3872 $details["title"] ."</a>&nbsp;" .
3873 "<span class='subscribers'>($subscribers)</span>";
3874
3875 print "<div class=\"browserDetails\" id=\"BRDET-" . $details["id"] . "\">";
3876 print "</div>";
3877
3878 print "</li>";
3879
3880 ++$feedctr;
3881 }
3882
3883 if ($feedctr == 0) {
3884 print "<li>No feeds found to subscribe.</li>";
3885 }
3886
3887 print "</ul>";
3888
c6232e43
AD
3889 print "</div>";
3890
3891 }
3892
18664970
AD
3893 if ($op == "rss") {
3894 $feed = db_escape_string($_GET["id"]);
3895 $user = db_escape_string($_GET["user"]);
3896 $pass = db_escape_string($_GET["pass"]);
3897 $is_cat = $_GET["is_cat"] != false;
3898
e1eb2147
AD
3899 $search = db_escape_string($_GET["q"]);
3900 $match_on = db_escape_string($_GET["m"]);
3901 $search_mode = db_escape_string($_GET["smode"]);
3902
18664970
AD
3903 if (!$_SESSION["uid"] && $user && $pass) {
3904 authenticate_user($link, $user, $pass);
3905 }
3906
3907 if ($_SESSION["uid"] ||
3908 http_authenticate_user($link)) {
3909
e1eb2147
AD
3910 generate_syndicated_feed($link, $feed, $is_cat,
3911 $search, $search_mode, $match_on);
18664970
AD
3912 }
3913 }
3914
657770a0
AD
3915 function check_configuration_variables() {
3916 if (!defined('SESSION_EXPIRE_TIME')) {
adf702d6 3917 return "config: SESSION_EXPIRE_TIME is undefined";
657770a0
AD
3918 }
3919
3920 if (SESSION_EXPIRE_TIME < 60) {
adf702d6
AD
3921 return "config: SESSION_EXPIRE_TIME is too low (less than 60)";
3922 }
3923
3924 if (SESSION_EXPIRE_TIME < SESSION_COOKIE_LIFETIME_REMEMBER) {
3925 return "config: SESSION_EXPIRE_TIME should be greater or equal to" .
3926 "SESSION_COOKIE_LIFETIME_REMEMBER";
3927 }
3928
9a3bb96a 3929 if (defined('DISABLE_SESSIONS')) {
adf702d6 3930 return "config: you have enabled DISABLE_SESSIONS. Please disable this option.";
657770a0
AD
3931 }
3932
8a414837
AD
3933 if (DATABASE_BACKED_SESSIONS && SINGLE_USER_MODE) {
3934 return "config: DATABASE_BACKED_SESSIONS is incompatible with SINGLE_USER_MODE";
3935 }
3936
657770a0
AD
3937 return false;
3938 }
3939
88040f57
AD
3940 if ($op == "labelFromSearch") {
3941 $search = db_escape_string($_GET["search"]);
3942 $search_mode = db_escape_string($_GET["smode"]);
3943 $match_on = db_escape_string($_GET["match"]);
3944 $is_cat = db_escape_string($_GET["is_cat"]);
3945 $title = db_escape_string($_GET["title"]);
3946 $feed = sprintf("%d", $_GET["feed"]);
3947
3948 $label_qparts = array();
3949
3950 $search_expr = getSearchSql($search, $match_on);
3951
3952 if ($is_cat) {
3953 if ($feed != 0) {
3954 $search_expr .= " AND ttrss_feeds.cat_id = $feed ";
3955 } else {
3956 $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
3957 }
3958 } else {
3959 if ($search_mode == "all_feeds") {
3960 // NOOP
3961 } else if ($search_mode == "this_cat") {
3962
3963 $tmp_result = db_query($link, "SELECT cat_id
3964 FROM ttrss_feeds WHERE id = '$feed'");
3965
3966 $cat_id = db_fetch_result($tmp_result, 0, "cat_id");
3967
3968 if ($cat_id > 0) {
3969 $search_expr .= " AND ttrss_feeds.cat_id = $cat_id ";
3970 } else {
3971 $search_expr .= " AND ttrss_feeds.cat_id IS NULL ";
3972 }
3973 } else {
3974 $search_expr .= " AND ttrss_feeds.id = $feed ";
3975 }
3976
3977 }
3978
3979 $search_expr = db_escape_string($search_expr);
3980
3981 print $search_expr;
3982
3983 if ($title) {
3984 $result = db_query($link,
3985 "INSERT INTO ttrss_labels (sql_exp,description,owner_uid)
3986 VALUES ('$search_expr', '$title', '".$_SESSION["uid"]."')");
3987 }
3988 }
3989
f3acc32e
AD
3990 if ($op == "getUnread") {
3991 $login = db_escape_string($_GET["login"]);
3992
7e3634d9 3993 header("Content-Type: text/plain; charset=utf-8");
f3acc32e
AD
3994
3995 $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$login'");
3996
3997 if (db_num_rows($result) == 1) {
3998 $uid = db_fetch_result($result, 0, "id");
3999 print getGlobalUnread($link, $uid);
4000 } else {
0599d09e 4001 print "-1;User not found";
f3acc32e 4002 }
7e3634d9
AD
4003
4004 $print_exec_time = false;
4005 }
4006
4007 if ($op == "digestTest") {
4008 header("Content-Type: text/plain");
9cd7c995
AD
4009 print_r(prepare_headlines_digest($link, $_SESSION["uid"]));
4010 $print_exec_time = false;
4011
4012 }
448b0abd 4013
9cd7c995
AD
4014 if ($op == "digestSend") {
4015 header("Content-Type: text/plain");
4016 send_headlines_digests($link);
7e3634d9
AD
4017 $print_exec_time = false;
4018
f3acc32e
AD
4019 }
4020
4b3dff6e 4021 db_close($link);
1cd17194 4022?>
406d9489 4023
7e3634d9 4024<?php if ($print_exec_time) { ?>
1d3a17c7 4025<!-- <?php echo sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
f3acc32e 4026<?php } ?>