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