]> git.wh0rd.org - tt-rss.git/blame - backend.php
update NEWS
[tt-rss.git] / backend.php
CommitLineData
1cd17194 1<?
295f9b42 2 define(SCHEMA_VERSION, 2);
7ec2a838 3
090e250b
AD
4 $op = $_GET["op"];
5
6 if ($op == "rpc") {
7 header("Content-Type: application/xml");
8 }
1cd17194 9
82baad4a 10 require_once "config.php";
648472a7 11 require_once "db.php";
82baad4a
AD
12 require_once "functions.php";
13 require_once "magpierss/rss_fetch.inc";
1cd17194 14
406d9489
AD
15 $script_started = getmicrotime();
16
648472a7 17 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
d76a3b03 18
5136011e
AD
19 if (!$link) {
20 if (DB_TYPE == "mysql") {
21 print mysql_error();
22 }
23 // PG seems to display its own errors just fine by default.
24 return;
25 }
26
648472a7
AD
27 if (DB_TYPE == "pgsql") {
28 pg_query("set client_encoding = 'utf-8'");
29 }
7ec2a838 30
295f9b42 31/*
7ec2a838
AD
32 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
33
34 $schema_version = db_fetch_result($result, 0, "schema_version");
35
36 if ($schema_version != SCHEMA_VERSION) {
37 print "Error: database schema is invalid
38 (got version $schema_version; expected ".SCHEMA_VERSION.")";
39 return;
40 }
295f9b42
AD
41*/
42
331900c6 43 $fetch = $_GET["fetch"];
175847de 44
8143ae1f
AD
45 /* FIXME this needs reworking */
46
fc69e641
AD
47 function getGlobalCounters($link) {
48 $result = db_query($link, "SELECT count(id) as c_id FROM ttrss_entries
49 WHERE unread = true");
50 $c_id = db_fetch_result($result, 0, "c_id");
51 print "<counter id='global-unread' counter='$c_id'/>";
52 }
53
8143ae1f
AD
54 function getTagCounters($link) {
55 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
56 FROM ttrss_tags,ttrss_entries WHERE
57 post_id = ttrss_entries.id AND unread = true GROUP BY tag_name
58 UNION
59 select tag_name,0 as count FROM ttrss_tags");
60
61 $tags = array();
62
63 while ($line = db_fetch_assoc($result)) {
64 $tags[$line["tag_name"]] += $line["count"];
65 }
66
67 foreach (array_keys($tags) as $tag) {
68 $unread = $tags[$tag];
69
70 $tag = htmlspecialchars($tag);
71 print "<tag id=\"$tag\" counter=\"$unread\"/>";
72 }
73 }
74
090e250b
AD
75 function getLabelCounters($link) {
76
77 $result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
8073cce7 78 WHERE marked = true AND unread = true");
090e250b 79
d61fd764 80 $count = db_fetch_result($result, 0, "count");
090e250b
AD
81
82 print "<label id=\"-1\" counter=\"$count\"/>";
83
84 $result = db_query($link, "SELECT id,sql_exp,description FROM
85 ttrss_labels ORDER by description");
86
87 while ($line = db_fetch_assoc($result)) {
88
89 $id = -$line["id"] - 11;
90
91 error_reporting (0);
d61fd764
AD
92
93 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
392d4563 94 WHERE (" . $line["sql_exp"] . ") AND unread = true");
090e250b 95
d61fd764 96 $count = db_fetch_result($tmp_result, 0, "count");
090e250b 97
ab3f3f72 98 print "<label id=\"$id\" counter=\"$count\"/>";
090e250b
AD
99
100 error_reporting (E_ERROR | E_WARNING | E_PARSE);
101
102 }
103 }
104
8073cce7
AD
105 function getFeedCounter($link, $id) {
106
107 $result = db_query($link, "SELECT
108 count(id) as count FROM ttrss_entries
109 WHERE feed_id = '$id' AND unread = true");
110
111 $count = db_fetch_result($result, 0, "count");
112
113 print "<feed id=\"$id\" counter=\"$count\"/>";
114 }
090e250b 115
8073cce7
AD
116 function getFeedCounters($link) {
117
090e250b
AD
118 $result = db_query($link, "SELECT id,
119 (SELECT count(id) FROM ttrss_entries WHERE feed_id = ttrss_feeds.id
120 AND unread = true) as count
121 FROM ttrss_feeds");
122
123 while ($line = db_fetch_assoc($result)) {
124
125 $id = $line["id"];
126 $count = $line["count"];
127
128 print "<feed id=\"$id\" counter=\"$count\"/>";
129 }
130 }
131
8143ae1f 132 function outputFeedList($link, $tags = false) {
175847de 133
1a66d16e
AD
134 print "<html><head>
135 <title>Tiny Tiny RSS : Feedlist</title>
430bf183
AD
136 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
137
138 if (USE_COMPACT_STYLESHEET) {
139 print "<link rel=\"stylesheet\" type=\"text/css\"
140 href=\"tt-rss_compact.css\"/>";
141 } else {
142 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
143 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
144 }
145
146 print "<script type=\"text/javascript\" src=\"functions.js\"></script>
1a66d16e
AD
147 <script type=\"text/javascript\" src=\"feedlist.js\"></script>
148 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
3745788e 149 </head><body onload=\"init()\">";
254e0e4b
AD
150
151 print "<ul class=\"feedList\" id=\"feedList\">";
152
8143ae1f 153 if (!$tags) {
254e0e4b 154
8143ae1f 155 /* virtual feeds */
254e0e4b 156
8143ae1f
AD
157 $result = db_query($link, "SELECT count(id) as num_starred
158 FROM ttrss_entries WHERE marked = true AND unread = true");
159 $num_starred = db_fetch_result($result, 0, "num_starred");
254e0e4b 160
3745788e 161 $class = "virt";
8add756a
AD
162
163 if ($num_starred > 0) $class .= "Unread";
164
165 printFeedEntry(-1, $class, "Starred articles", $num_starred,
8143ae1f 166 "images/mark_set.png");
48f0adb0 167
8143ae1f
AD
168 if (ENABLE_LABELS) {
169
170 $result = db_query($link, "SELECT id,sql_exp,description FROM
171 ttrss_labels ORDER by description");
172
173 if (db_num_rows($result) > 0) {
174 print "<li><hr></li>";
175 }
176
177 while ($line = db_fetch_assoc($result)) {
48f0adb0 178
8143ae1f
AD
179 error_reporting (0);
180
181 $tmp_result = db_query($link, "SELECT count(id) as count FROM ttrss_entries
182 WHERE (" . $line["sql_exp"] . ") AND unread = true");
183
184 $count = db_fetch_result($tmp_result, 0, "count");
185
3745788e 186 $class = "label";
8143ae1f
AD
187
188 if ($count > 0) {
189 $class .= "Unread";
190 }
191
192 error_reporting (E_ERROR | E_WARNING | E_PARSE);
193
194 printFeedEntry(-$line["id"]-11,
195 $class, $line["description"], $count, "images/label.png");
196
197 }
48f0adb0
AD
198 }
199
8143ae1f
AD
200 print "<li><hr></li>";
201
202 $result = db_query($link, "SELECT *,
203 (SELECT count(id) FROM ttrss_entries
204 WHERE feed_id = ttrss_feeds.id) AS total,
205 (SELECT count(id) FROM ttrss_entries
206 WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
207 FROM ttrss_feeds ORDER BY title");
208
209 $actid = $_GET["actid"];
210
211 /* real feeds */
212
213 $lnum = 0;
214
215 $total_unread = 0;
216
48f0adb0 217 while ($line = db_fetch_assoc($result)) {
8143ae1f
AD
218
219 $feed = $line["title"];
220 $feed_id = $line["id"];
221
222 $subop = $_GET["subop"];
223
224 $total = $line["total"];
225 $unread = $line["unread"];
226
227 // $class = ($lnum % 2) ? "even" : "odd";
48f0adb0 228
3745788e 229 $class = "feed";
8143ae1f
AD
230
231 if ($unread > 0) $class .= "Unread";
232
233 if ($actid == $feed_id) {
234 $class .= "Selected";
392d4563 235 }
48f0adb0 236
8143ae1f
AD
237 $total_unread += $unread;
238
239 printFeedEntry($feed_id, $class, $feed, $unread, "icons/$feed_id.ico");
240
241 ++$lnum;
48f0adb0 242 }
8143ae1f 243 } else {
a1a8a2be 244
8143ae1f 245 // tags
a1a8a2be 246
8143ae1f
AD
247 $result = db_query($link, "SELECT tag_name,count(ttrss_entries.id) AS count
248 FROM ttrss_tags,ttrss_entries WHERE
249 post_id = ttrss_entries.id AND unread = true GROUP BY tag_name
250 UNION
251 select tag_name,0 as count FROM ttrss_tags");
252
253 $tags = array();
254
255 while ($line = db_fetch_assoc($result)) {
256 $tags[$line["tag_name"]] += $line["count"];
1a66d16e 257 }
8143ae1f
AD
258
259 foreach (array_keys($tags) as $tag) {
260
261 $unread = $tags[$tag];
262
263 $class = "odd";
264
265 if ($unread > 0) {
266 $class .= "Unread";
267 }
268
269 printFeedEntry($tag, $class, $tag, $unread, "images/tag.png");
270
271 }
1a66d16e 272
e828e31e 273 }
82baad4a 274
dc33ec95
AD
275 if (db_num_rows($result) == 0) {
276 print "<li>No tags to display.</li>";
277 }
278
8143ae1f 279 print "</ul>";
1cd17194 280
caa4e57f
AD
281 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
282
c3b81db0
AD
283 }
284
285
286 if ($op == "rpc") {
287
288 $subop = $_GET["subop"];
289
090e250b 290 if ($subop == "getLabelCounters") {
8073cce7 291 $aid = $_GET["aid"];
090e250b
AD
292 print "<rpc-reply>";
293 getLabelCounters($link);
8073cce7
AD
294 if ($aid) {
295 getFeedCounter($link, $aid);
296 }
090e250b
AD
297 print "</rpc-reply>";
298 }
299
300 if ($subop == "getFeedCounters") {
301 print "<rpc-reply>";
302 getFeedCounters($link);
303 print "</rpc-reply>";
304 }
305
306 if ($subop == "getAllCounters") {
307 print "<rpc-reply>";
308 getLabelCounters($link);
309 getFeedCounters($link);
8143ae1f 310 getTagCounters($link);
fc69e641 311 getGlobalCounters($link);
090e250b 312 print "</rpc-reply>";
090e250b
AD
313 }
314
f4c10d44
AD
315 if ($subop == "mark") {
316 $mark = $_GET["mark"];
648472a7 317 $id = db_escape_string($_GET["id"]);
f4c10d44
AD
318
319 if ($mark == "1") {
320 $mark = "true";
321 } else {
322 $mark = "false";
323 }
324
648472a7 325 $result = db_query($link, "UPDATE ttrss_entries SET marked = $mark
f4c10d44
AD
326 WHERE id = '$id'");
327 }
328
caa4e57f 329 if ($subop == "updateFeed") {
648472a7 330 $feed_id = db_escape_string($_GET["feed"]);
9cfc649a 331
648472a7 332 $result = db_query($link,
caa4e57f 333 "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'");
9cfc649a 334
648472a7
AD
335 if (db_num_rows($result) > 0) {
336 $feed_url = db_fetch_result($result, 0, "feed_url");
caa4e57f
AD
337// update_rss_feed($link, $feed_url, $feed_id);
338 }
9cfc649a 339
caa4e57f 340 print "DONE-$feed_id";
9cfc649a 341
caa4e57f 342 return;
9cfc649a
AD
343 }
344
090e250b 345 if ($subop == "forceUpdateAllFeeds" || $subop == "updateAllFeeds") {
c5142cca 346
c3b81db0 347 update_all_feeds($link, true);
c3b81db0 348
ab3f3f72
AD
349 $omode = $_GET["omode"];
350
351 if (!$omode) $omode = "tfl";
352
090e250b 353 print "<rpc-reply>";
ab3f3f72
AD
354 if (strchr($omode, "l")) getLabelCounters($link);
355 if (strchr($omode, "f")) getFeedCounters($link);
356 if (strchr($omode, "t")) getTagCounters($link);
fc69e641 357 getGlobalCounters($link);
090e250b 358 print "</rpc-reply>";
c3b81db0
AD
359 }
360
361 if ($subop == "catchupPage") {
362
363 $ids = split(",", $_GET["ids"]);
364
365 foreach ($ids as $id) {
366
648472a7 367 db_query($link, "UPDATE ttrss_entries SET unread=false,last_read = NOW()
c3b81db0
AD
368 WHERE id = '$id'");
369
370 }
371
372 print "Marked active page as read.";
373 }
295f9b42
AD
374
375 if ($subop == "sanityCheck") {
376
377 $error_code = 0;
378
379 $result = db_query($link, "SELECT schema_version FROM ttrss_version");
380
381 $schema_version = db_fetch_result($result, 0, "schema_version");
382
383 if ($schema_version != SCHEMA_VERSION) {
384 $error_code = 5;
385 }
386
387 print "<error code='$error_code'/>";
388 }
c3b81db0
AD
389 }
390
391 if ($op == "feeds") {
392
8143ae1f
AD
393 $tags = $_GET["tags"];
394
c3b81db0
AD
395 $subop = $_GET["subop"];
396
397 if ($subop == "catchupAll") {
648472a7 398 db_query($link, "UPDATE ttrss_entries SET last_read = NOW(),unread = false");
c3b81db0
AD
399 }
400
8143ae1f 401 outputFeedList($link, $tags);
c3b81db0 402
1cd17194
AD
403 }
404
405 if ($op == "view") {
406
d76a3b03 407 $id = $_GET["id"];
8073cce7 408 $feed_id = $_GET["feed"];
d76a3b03 409
648472a7 410 $result = db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'");
a1a8a2be 411
70830c87
AD
412 $addheader = $_GET["addheader"];
413
648472a7 414 $result = db_query($link, "SELECT title,link,content,feed_id,comments,
b7f4bda2
AD
415 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
416 FROM ttrss_entries
d76a3b03 417 WHERE id = '$id'");
1cd17194 418
70830c87 419 if ($addheader) {
f0601b87 420 print "<html><head>
70830c87
AD
421 <title>Tiny Tiny RSS : Article $id</title>
422 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
c05608c2 423 <script type=\"text/javascript\" src=\"functions.js\"></script>
70830c87 424 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
f0601b87 425 </head><body>";
70830c87
AD
426 }
427
d76a3b03 428 if ($result) {
1cd17194 429
648472a7 430 $line = db_fetch_assoc($result);
1cd17194 431
b7f4bda2
AD
432 if ($line["icon_url"]) {
433 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
434 } else {
435 $feed_icon = "&nbsp;";
436 }
d76a3b03 437
f7181e9b
AD
438 if ($line["comments"] && $line["link"] != $line["comments"]) {
439 $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)";
440 } else {
441 $entry_comments = "";
442 }
443
e828e31e
AD
444 print "<div class=\"postReply\">";
445
446 print "<div class=\"postHeader\"><table>";
447
448 print "<tr><td><b>Title:</b></td>
449 <td width='100%'>" . $line["title"] . "</td></tr>";
f7181e9b 450
e828e31e 451 print "<tr><td><b>Link:</b></td>
f7181e9b
AD
452 <td width='100%'>
453 <a href=\"" . $line["link"] . "\">".$line["link"]."</a>
454 $entry_comments</td></tr>";
e828e31e
AD
455
456 print "</table></div>";
457
458 print "<div class=\"postIcon\">" . $feed_icon . "</div>";
459 print "<div class=\"postContent\">" . $line["content"] . "</div>";
460
461 print "</div>";
462
090e250b 463 print "<script type=\"text/javascript\">
8143ae1f 464 update_label_counters('$feed_id');
090e250b 465 </script>";
d76a3b03 466 }
70830c87
AD
467
468 if ($addheader) {
469 print "</body></html>";
470 }
1cd17194
AD
471 }
472
473 if ($op == "viewfeed") {
474
475 $feed = $_GET["feed"];
d76a3b03 476 $skip = $_GET["skip"];
476cac42 477 $subop = $_GET["subop"];
f175937c 478 $view_mode = $_GET["view"];
f0601b87 479 $addheader = $_GET["addheader"];
cb1083a1 480 $limit = $_GET["limit"];
a1a8a2be 481
8d7008c7
AD
482 if (!$feed) {
483 print "Error: no feed to display.";
484 return;
485 }
486
ac53063a
AD
487 if (!$skip) $skip = 0;
488
476cac42 489 if ($subop == "undefined") $subop = "";
1cd17194 490
f0601b87
AD
491 if ($addheader) {
492 print "<html><head>
ac43eba1 493 <title>Tiny Tiny RSS : Feed $feed</title>
430bf183
AD
494 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">";
495
496 if (USE_COMPACT_STYLESHEET) {
497 print "<link rel=\"stylesheet\"
498 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
499
500 } else {
501 print "<link title=\"Compact Stylesheet\" rel=\"alternate stylesheet\"
502 type=\"text/css\" href=\"tt-rss_compact.css\"/>";
503 }
504 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
f0601b87
AD
505 <script type=\"text/javascript\" src=\"functions.js\"></script>
506 <script type=\"text/javascript\" src=\"viewfeed.js\"></script>
b623b3ed 507 </head><body onload='init()'>";
f0601b87
AD
508 }
509
dcee8f61
AD
510 if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
511
512 $tmp_result = db_query($link, "SELECT feed_url FROM ttrss_feeds
513 WHERE id = '$feed'");
514
515 $feed_url = db_fetch_result($tmp_result, 0, "feed_url");
516
517 update_rss_feed($link, $feed_url, $feed);
518
519 }
520
0e32076b 521 if ($subop == "MarkAllRead") {
d76a3b03 522
0e32076b
AD
523 if (sprintf("%d", $feed) != 0) {
524
525 if ($feed > 0) {
526 db_query($link, "UPDATE ttrss_entries
527 SET unread = false,last_read = NOW()
254e0e4b 528 WHERE feed_id = '$feed'");
0e32076b
AD
529
530 } else if ($feed < 0 && $feed > -10) { // special, like starred
531
532 if ($feed == -1) {
533 db_query($link, "UPDATE ttrss_entries
534 SET unread = false,last_read = NOW()
535 WHERE marked = true");
536 }
537
538 } else if ($feed < -10) { // label
539
7db95187 540 $label_id = -$feed - 11;
0e32076b 541
7db95187
AD
542 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
543 WHERE id = '$label_id'");
544
545 if ($tmp_result) {
546 $sql_exp = db_fetch_result($tmp_result, 0, "sql_exp");
547
548 db_query($link, "UPDATE ttrss_entries
549 SET unread = false,last_read = NOW()
550 WHERE $sql_exp");
551 }
254e0e4b 552 }
0e32076b
AD
553 } else { // tag
554 // FIXME, implement catchup for tags
a1a8a2be 555 }
0e32076b 556
a1a8a2be 557 }
d76a3b03 558
175847de 559 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
ac53063a 560
c374a3fe
AD
561 $search = $_GET["search"];
562
52b51244
AD
563 $search_mode = $_GET["smode"];
564
f175937c 565 if ($search) {
ac53063a
AD
566 $search_query_part = "(upper(title) LIKE upper('%$search%')
567 OR content LIKE '%$search%') AND";
f175937c
AD
568 } else {
569 $search_query_part = "";
570 }
571
572 $view_query_part = "";
573
574 if ($view_mode == "Starred") {
575 $view_query_part = " marked = true AND ";
ac53063a
AD
576 }
577
ac43eba1
AD
578 if ($view_mode == "Unread") {
579 $view_query_part = " unread = true AND ";
580 }
581
b5aa95e7
AD
582 if ($view_mode == "Unread or Starred") {
583 $view_query_part = " (unread = true OR marked = true) AND ";
584 }
585
bdd01d3f
AD
586 if ($view_mode == "Unread or Updated") {
587 $view_query_part = " (unread = true OR last_read is NULL) AND ";
588 }
589
254e0e4b 590/* $result = db_query($link, "SELECT count(id) AS total_entries
36bf7496
AD
591 FROM ttrss_entries WHERE
592 $search_query_part
593 feed_id = '$feed'");
e6d1c0a0 594
254e0e4b 595 $total_entries = db_fetch_result($result, 0, "total_entries"); */
e6d1c0a0 596
648472a7 597/* $result = db_query("SELECT count(id) AS unread_entries
ac43eba1
AD
598 FROM ttrss_entries WHERE
599 $search_query_part
600 unread = true AND
601 feed_id = '$feed'");
602
648472a7 603 $unread_entries = db_fetch_result($result, 0, "unread_entries"); */
ac43eba1 604
8d7008c7 605 if ($limit && $limit != "All") {
82c9223c 606 $limit_query_part = "LIMIT " . $limit;
ad3cb710 607 }
f0601b87 608
254e0e4b
AD
609 $vfeed_query_part = "";
610
52b51244
AD
611 // override query strategy and enable feed display when searching globally
612 if ($search_mode == "All feeds") {
613 $query_strategy_part = "id > 0";
614 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
615 id = feed_id) as feed_title,";
616 } else if (sprintf("%d", $feed) == 0) {
8143ae1f
AD
617 $query_strategy_part = "ttrss_entries.id > 0";
618 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
619 id = feed_id) as feed_title,";
620 } else if ($feed >= 0) {
254e0e4b 621 $query_strategy_part = "feed_id = '$feed'";
48f0adb0 622 } else if ($feed == -1) { // starred virtual feed
254e0e4b 623 $query_strategy_part = "marked = true";
48f0adb0
AD
624 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
625 id = feed_id) as feed_title,";
626 } else if ($feed <= -10) { // labels
627 $label_id = -$feed - 11;
628
629 $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels
630 WHERE id = '$label_id'");
631
632 $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp");
633
254e0e4b
AD
634 $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE
635 id = feed_id) as feed_title,";
636 } else {
48f0adb0 637 $query_strategy_part = "id > 0"; // dumb
254e0e4b
AD
638 }
639
52b51244 640
f99321a3
AD
641 $order_by = "updated DESC";
642
643// if ($feed < -10) {
644// $order_by = "feed_id,updated DESC";
645// }
646
48f0adb0
AD
647 if ($feed < -10) error_reporting (0);
648
8143ae1f
AD
649 if (sprintf("%d", $feed) != 0) {
650
651 $result = db_query($link, "SELECT
652 id,title,updated,unread,feed_id,marked,link,last_read,
653 SUBSTRING(last_read,1,19) as last_read_noms,
654 $vfeed_query_part
655 SUBSTRING(updated,1,19) as updated_noms
656 FROM
657 ttrss_entries
658 WHERE
659 $search_query_part
660 $view_query_part
661 $query_strategy_part ORDER BY $order_by
662 $limit_query_part");
663
664 } else {
665 // browsing by tag
666
667 $result = db_query($link, "SELECT
668 ttrss_entries.id as id,title,updated,unread,feed_id,
669 marked,link,last_read,
c05a19f3 670 SUBSTRING(last_read,1,19) as last_read_noms,
254e0e4b 671 $vfeed_query_part
c05a19f3 672 SUBSTRING(updated,1,19) as updated_noms
8143ae1f
AD
673 FROM
674 ttrss_entries,ttrss_tags
675 WHERE
676 post_id = ttrss_entries.id AND tag_name = '$feed' AND
677 $view_query_part
678 $search_query_part
679 $query_strategy_part ORDER BY $order_by
680 $limit_query_part");
681 }
d76a3b03 682
48f0adb0
AD
683 if (!$result) {
684 print "<tr><td colspan='4' align='center'>
685 Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>";
686 return;
687 }
688
a1a8a2be 689 $lnum = 0;
48f0adb0
AD
690
691 error_reporting (E_ERROR | E_WARNING | E_PARSE);
692
e1123aee 693 $num_unread = 0;
d76a3b03 694
648472a7 695 while ($line = db_fetch_assoc($result)) {
d76a3b03 696
a1a8a2be 697 $class = ($lnum % 2) ? "even" : "odd";
d76a3b03 698
ad99045e
AD
699 $id = $line["id"];
700 $feed_id = $line["feed_id"];
701
c43f77f5 702// printf("L %d (%s) &gt; U %d (%s) = %d<br>",
c05a19f3 703// strtotime($line["last_read_noms"]), $line["last_read_noms"],
c43f77f5
AD
704// strtotime($line["updated"]), $line["updated"],
705// strtotime($line["last_read"]) >= strtotime($line["updated"]));
706
ecb14114 707/* if ($line["last_read"] != "" && $line["updated"] != "" &&
c05a19f3 708 strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) {
c43f77f5
AD
709
710 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
711 alt=\"Updated\">";
712
713 } else {
714
5bfef089 715 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
c43f77f5
AD
716 alt=\"Updated\">";
717
ecb14114
AD
718 } */
719
4cc6ea5e
AD
720 if ($line["last_read"] == "" &&
721 ($line["unread"] != "t" && $line["unread"] != "1")) {
722
ecb14114
AD
723 $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\"
724 alt=\"Updated\">";
725 } else {
726 $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\"
727 alt=\"Updated\">";
c43f77f5 728 }
b197f117 729
8158c57a 730 if ($line["unread"] == "t" || $line["unread"] == "1") {
a1a8a2be 731 $class .= "Unread";
e1123aee
AD
732 ++$num_unread;
733 }
d76a3b03 734
8158c57a 735 if ($line["marked"] == "t" || $line["marked"] == "1") {
f4c10d44
AD
736 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\"
737 alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>";
738 } else {
739 $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\"
740 alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>";
741 }
742
ac43eba1 743 $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" .
b197f117
AD
744 $line["title"] . "</a>";
745
d5224f0d 746 print "<tr class='$class' id='RROW-$id'>";
5f89f780 747 // onclick=\"javascript:view($id,$feed_id)\">
b197f117 748
8d7008c7
AD
749 print "<td valign='center' align='center'>$update_pic</td>";
750 print "<td valign='center' align='center'>$marked_pic</td>";
b197f117 751
8d7008c7 752 print "<td width='25%'>
a3ee2a38 753 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
254e0e4b
AD
754
755 if ($line["feed_title"]) {
756 print "<td width='50%'>$content_link</td>";
2db4190c
AD
757 print "<td width='20%'>
758 <a href='javascript:viewfeed($feed_id)'>".$line["feed_title"]."</a></td>";
254e0e4b
AD
759 } else {
760 print "<td width='70%'>$content_link</td>";
761 }
d76a3b03 762
a1a8a2be 763 print "</tr>";
d76a3b03 764
a1a8a2be
AD
765 ++$lnum;
766 }
d76a3b03 767
ac53063a 768 if ($lnum == 0) {
a82065a1 769 print "<tr><td align='center'>No articles found.</td></tr>";
047bae73 770 }
a2015351 771
a1a8a2be 772 print "</table>";
6113ef7d
AD
773
774 print "<script type=\"text/javascript\">
bb7cface 775 document.onkeydown = hotkey_handler;
8143ae1f 776 update_label_counters('$feed');
6113ef7d 777 </script>";
d76a3b03 778
f0601b87
AD
779 if ($addheader) {
780 print "</body></html>";
781 }
782
1cd17194
AD
783 }
784
0e091d38 785 if ($op == "pref-rpc") {
331900c6 786
0e091d38 787 $subop = $_GET["subop"];
331900c6 788
83fe4d6d
AD
789 if ($subop == "unread") {
790 $ids = split(",", $_GET["ids"]);
791 foreach ($ids as $id) {
648472a7 792 db_query($link, "UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'");
83fe4d6d 793 }
0e091d38
AD
794
795 print "Marked selected feeds as read.";
83fe4d6d
AD
796 }
797
798 if ($subop == "read") {
799 $ids = split(",", $_GET["ids"]);
800 foreach ($ids as $id) {
648472a7 801 db_query($link, "UPDATE ttrss_entries
b197f117 802 SET unread = false,last_read = NOW() WHERE feed_id = '$id'");
83fe4d6d 803 }
0e091d38
AD
804
805 print "Marked selected feeds as unread.";
806
807 }
808
809 }
810
811 if ($op == "pref-feeds") {
812
813 $subop = $_GET["subop"];
814
508a81e1 815 if ($subop == "editSave") {
648472a7
AD
816 $feed_title = db_escape_string($_GET["t"]);
817 $feed_link = db_escape_string($_GET["l"]);
d148926e 818 $upd_intl = db_escape_string($_GET["ui"]);
5d73494a 819 $purge_intl = db_escape_string($_GET["pi"]);
508a81e1
AD
820 $feed_id = $_GET["id"];
821
d148926e
AD
822 if (strtoupper($upd_intl) == "DEFAULT")
823 $upd_intl = 0;
824
5d73494a
AD
825 if (strtoupper($purge_intl) == "DEFAULT")
826 $purge_intl = 0;
827
648472a7 828 $result = db_query($link, "UPDATE ttrss_feeds SET
d148926e 829 title = '$feed_title', feed_url = '$feed_link',
5d73494a
AD
830 update_interval = '$upd_intl',
831 purge_interval = '$purge_intl'
832 WHERE id = '$feed_id'");
508a81e1 833
83fe4d6d
AD
834 }
835
331900c6 836 if ($subop == "remove") {
331900c6 837
b0b4abcf 838 if (!WEB_DEMO_MODE) {
331900c6 839
b0b4abcf
AD
840 $ids = split(",", $_GET["ids"]);
841
842 foreach ($ids as $id) {
648472a7 843 db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'");
d5caaae5
AD
844
845 if (file_exists(ICONS_DIR . "/$id.ico")) {
846 unlink(ICONS_DIR . "/$id.ico");
847 }
b0b4abcf 848 }
331900c6
AD
849 }
850 }
851
852 if ($subop == "add") {
b0b4abcf
AD
853
854 if (!WEB_DEMO_MODE) {
331900c6 855
648472a7 856 $feed_link = db_escape_string($_GET["link"]);
b0b4abcf 857
648472a7 858 $result = db_query($link,
b0b4abcf 859 "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')");
331900c6 860
648472a7 861 $result = db_query($link,
e9c54861 862 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'");
331900c6 863
648472a7 864 $feed_id = db_fetch_result($result, 0, "id");
331900c6 865
b0b4abcf
AD
866 if ($feed_id) {
867 update_rss_feed($link, $feed_link, $feed_id);
868 }
869 }
331900c6 870 }
a0d53889 871
ab3d0b99
AD
872 $result = db_query($link, "SELECT id,title,feed_url,last_error
873 FROM ttrss_feeds WHERE last_error != ''");
874
875 if (db_num_rows($result) > 0) {
876
877 print "<div class=\"warning\">";
878
879 print "<b>Feeds with update errors:</b>";
880
881 print "<ul class=\"nomarks\">";
882
883 while ($line = db_fetch_assoc($result)) {
884 print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " .
885 $line["last_error"];
886 }
887
888 print "</ul>";
889 print "</div>";
890
891 }
892
a0d53889
AD
893 print "<table class=\"prefAddFeed\"><tr>
894 <td><input id=\"fadd_link\"></td>
895 <td colspan=\"4\" align=\"right\">
896 <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr>
897 </table>";
898
648472a7 899 $result = db_query($link, "SELECT
d148926e 900 id,title,feed_url,substring(last_updated,1,16) as last_updated,
5d73494a 901 update_interval,purge_interval
c0e5a40e
AD
902 FROM
903 ttrss_feeds ORDER by title");
1cd17194 904
331900c6 905 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
007bda35 906 print "<tr class=\"title\">
5d73494a
AD
907 <td>&nbsp;</td><td>Select</td><td width=\"30%\">Title</td>
908 <td width=\"30%\">Link</td>
909 <td width=\"10%\">Update Interval</td>
910 <td width=\"10%\">Purge Days</td>
d148926e 911 <td>Last updated</td></tr>";
007bda35
AD
912
913 $lnum = 0;
914
648472a7 915 while ($line = db_fetch_assoc($result)) {
007bda35
AD
916
917 $class = ($lnum % 2) ? "even" : "odd";
9b307248 918
331900c6 919 $feed_id = $line["id"];
603c27f8
AD
920
921 $edit_feed_id = $_GET["id"];
922
9b307248
AD
923 if ($subop == "edit" && $feed_id != $edit_feed_id) {
924 $class .= "Grayed";
925 }
926
331900c6 927 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
007bda35 928
c0e5a40e
AD
929 $icon_file = ICONS_DIR . "/$feed_id.ico";
930
931 if (file_exists($icon_file) && filesize($icon_file) > 0) {
932 $feed_icon = "<img width=\"16\" height=\"16\"
933 src=\"" . ICONS_URL . "/$feed_id.ico\">";
934 } else {
935 $feed_icon = "&nbsp;";
936 }
937 print "<td align='center'>$feed_icon</td>";
938
6e0584e9
AD
939 $edit_title = htmlspecialchars(db_unescape_string($line["title"]));
940 $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"]));
941
9b307248 942 if (!$edit_feed_id || $subop != "edit") {
603c27f8
AD
943
944 print "<td><input onclick='toggleSelectRow(this);'
331900c6 945 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
603c27f8
AD
946
947 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
5d73494a 948 $edit_title . "</a></td>";
603c27f8 949 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
5d73494a 950 $edit_link . "</a></td>";
d148926e
AD
951
952 if ($line["update_interval"] == "0")
953 $line["update_interval"] = "Default";
954
5d73494a
AD
955 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
956 $line["update_interval"] . "</a></td>";
d148926e 957
5d73494a
AD
958 if ($line["purge_interval"] == "0")
959 $line["purge_interval"] = "Default";
960
961 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
962 $line["purge_interval"] . "</a></td>";
9b307248
AD
963
964 } else if ($feed_id != $edit_feed_id) {
965
e9c54861
AD
966 print "<td><input disabled=\"true\" type=\"checkbox\"
967 id=\"FRCHK-".$line["id"]."\"></td>";
9b307248 968
6e0584e9
AD
969 print "<td>$edit_title</td>";
970 print "<td>$edit_link</td>";
9b307248 971
d148926e
AD
972 if ($line["update_interval"] == "0")
973 $line["update_interval"] = "Default";
974
975 print "<td>" . $line["update_interval"] . "</td>";
976
5d73494a
AD
977 if ($line["purge_interval"] == "0")
978 $line["purge_interval"] = "Default";
979
980 print "<td>" . $line["purge_interval"] . "</td>";
981
603c27f8
AD
982 } else {
983
e9c54861 984 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
603c27f8 985
6e0584e9
AD
986 print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>";
987 print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>";
d148926e 988 print "<td><input id=\"iedit_updintl\" value=\"".$line["update_interval"]."\"></td>";
5d73494a 989 print "<td><input id=\"iedit_purgintl\" value=\"".$line["purge_interval"]."\"></td>";
d148926e 990
603c27f8 991 }
0afbd851
AD
992
993 if (!$line["last_updated"]) $line["last_updated"] = "Never";
994
007bda35 995 print "<td>" . $line["last_updated"] . "</td>";
603c27f8 996
007bda35
AD
997 print "</tr>";
998
999 ++$lnum;
1000 }
1001
0afbd851
AD
1002 if ($lnum == 0) {
1003 print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>";
1004 }
1005
007bda35
AD
1006 print "</table>";
1007
603c27f8
AD
1008 print "<p>";
1009
1010 if ($subop == "edit") {
1011 print "Edit feed:&nbsp;
e828e31e
AD
1012 <input type=\"submit\" class=\"button\"
1013 onclick=\"javascript:feedEditCancel()\" value=\"Cancel\">
1014 <input type=\"submit\" class=\"button\"
8158c57a 1015 onclick=\"javascript:feedEditSave()\" value=\"Save\">";
603c27f8
AD
1016 } else {
1017
603c27f8
AD
1018 print "
1019 Selection:&nbsp;
e828e31e
AD
1020 <input type=\"submit\" class=\"button\"
1021 onclick=\"javascript:editSelectedFeed()\" value=\"Edit\">
1022 <input type=\"submit\" class=\"button\"
1023 onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">";
1024
f92db4f5
AD
1025 if (ENABLE_PREFS_CATCHUP_UNCATCHUP) {
1026 print "
e828e31e
AD
1027 <input type=\"submit\" class=\"button\"
1028 onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\">
1029 <input type=\"submit\" class=\"button\"
1030 onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\">&nbsp;";
f92db4f5
AD
1031 }
1032 print "
e828e31e
AD
1033 All feeds:
1034 <input type=\"submit\"
8158c57a 1035 class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">";
10c5820d 1036
603c27f8
AD
1037 }
1038
f5a50b25
AD
1039 print "<h3>OPML Import</h3>
1040 <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\">
1041 File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\">&nbsp;
1042 <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\"
1043 type=\"submit\" value=\"Import\">
1044 </form>";
1045
007bda35
AD
1046 }
1047
a0d53889
AD
1048 if ($op == "pref-filters") {
1049
1050 $subop = $_GET["subop"];
1051
1052 if ($subop == "editSave") {
a0d53889 1053
648472a7
AD
1054 $regexp = db_escape_string($_GET["r"]);
1055 $descr = db_escape_string($_GET["d"]);
1056 $match = db_escape_string($_GET["m"]);
1057 $filter_id = db_escape_string($_GET["id"]);
0afbd851 1058
648472a7 1059 $result = db_query($link, "UPDATE ttrss_filters SET
4b3dff6e 1060 reg_exp = '$regexp',
0afbd851
AD
1061 description = '$descr',
1062 filter_type = (SELECT id FROM ttrss_filter_types WHERE
1063 description = '$match')
1064 WHERE id = '$filter_id'");
a0d53889
AD
1065 }
1066
1067 if ($subop == "remove") {
1068
1069 if (!WEB_DEMO_MODE) {
1070
1071 $ids = split(",", $_GET["ids"]);
1072
1073 foreach ($ids as $id) {
648472a7 1074 db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'");
a0d53889
AD
1075
1076 }
1077 }
1078 }
1079
1080 if ($subop == "add") {
1081
de435974 1082 if (!WEB_DEMO_MODE) {
a0d53889 1083
8158c57a 1084 $regexp = db_escape_string($_GET["regexp"]);
648472a7 1085 $match = db_escape_string($_GET["match"]);
a0d53889 1086
648472a7 1087 $result = db_query($link,
4b3dff6e 1088 "INSERT INTO ttrss_filters (reg_exp,filter_type) VALUES
de435974
AD
1089 ('$regexp', (SELECT id FROM ttrss_filter_types WHERE
1090 description = '$match'))");
1091 }
a0d53889
AD
1092 }
1093
648472a7 1094 $result = db_query($link, "SELECT description
a0d53889
AD
1095 FROM ttrss_filter_types ORDER BY description");
1096
1097 $filter_types = array();
1098
648472a7 1099 while ($line = db_fetch_assoc($result)) {
a0d53889
AD
1100 array_push($filter_types, $line["description"]);
1101 }
1102
1103 print "<table class=\"prefAddFeed\"><tr>
ea6774cf 1104 <td><input id=\"fadd_regexp\"></td>
a0d53889 1105 <td>";
bdc00fe0 1106 print_select("fadd_match", "Title", $filter_types);
a0d53889
AD
1107
1108 print"</td><td colspan=\"4\" align=\"right\">
1109 <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr>
1110 </table>";
1111
648472a7 1112 $result = db_query($link, "SELECT
4b3dff6e 1113 id,reg_exp,description,
a0d53889
AD
1114 (SELECT name FROM ttrss_filter_types WHERE
1115 id = filter_type) as filter_type_name,
1116 (SELECT description FROM ttrss_filter_types
1117 WHERE id = filter_type) as filter_type_descr
1118 FROM
4b3dff6e 1119 ttrss_filters ORDER by reg_exp");
a0d53889
AD
1120
1121 print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">";
1122
1123 print "<tr class=\"title\">
0afbd851
AD
1124 <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td>
1125 <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>";
a0d53889
AD
1126
1127 $lnum = 0;
1128
648472a7 1129 while ($line = db_fetch_assoc($result)) {
a0d53889
AD
1130
1131 $class = ($lnum % 2) ? "even" : "odd";
1132
1133 $filter_id = $line["id"];
1134 $edit_filter_id = $_GET["id"];
1135
1136 if ($subop == "edit" && $filter_id != $edit_filter_id) {
1137 $class .= "Grayed";
1138 }
1139
1140 print "<tr class=\"$class\" id=\"FILRR-$filter_id\">";
1141
4b3dff6e 1142 $line["regexp"] = htmlspecialchars($line["reg_exp"]);
ea6774cf
AD
1143 $line["description"] = htmlspecialchars($line["description"]);
1144
a0d53889
AD
1145 if (!$edit_filter_id || $subop != "edit") {
1146
0afbd851
AD
1147 if (!$line["description"]) $line["description"] = "[No description]";
1148
a0d53889
AD
1149 print "<td><input onclick='toggleSelectRow(this);'
1150 type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>";
1151
1152 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
4b3dff6e 1153 $line["reg_exp"] . "</td>";
a0d53889
AD
1154
1155 print "<td><a href=\"javascript:editFilter($filter_id);\">" .
1156 $line["description"] . "</td>";
1157
1158 print "<td>".$line["filter_type_descr"]."</td>";
1159
1160 } else if ($filter_id != $edit_filter_id) {
1161
0afbd851
AD
1162 if (!$line["description"]) $line["description"] = "[No description]";
1163
a0d53889
AD
1164 print "<td><input disabled=\"true\" type=\"checkbox\"
1165 id=\"FICHK-".$line["id"]."\"></td>";
1166
4b3dff6e 1167 print "<td>".$line["reg_exp"]."</td>";
a0d53889
AD
1168 print "<td>".$line["description"]."</td>";
1169 print "<td>".$line["filter_type_descr"]."</td>";
1170
1171 } else {
1172
1173 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
1174
4b3dff6e 1175 print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"].
a0d53889
AD
1176 "\"></td>";
1177
1178 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1179 "\"></td>";
1180
1181 print "<td>";
1182 print_select("iedit_match", $line["filter_type_descr"], $filter_types);
1183 print "</td>";
1184
1185 }
1186
1187
1188 print "</tr>";
1189
1190 ++$lnum;
1191 }
1192
0afbd851
AD
1193 if ($lnum == 0) {
1194 print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>";
1195 }
1196
a0d53889
AD
1197 print "</table>";
1198
1199 print "<p>";
1200
1201 if ($subop == "edit") {
e828e31e
AD
1202 print "Edit feed:
1203 <input type=\"submit\" class=\"button\"
1204 onclick=\"javascript:filterEditCancel()\" value=\"Cancel\">
1205 <input type=\"submit\" class=\"button\"
1206 onclick=\"javascript:filterEditSave()\" value=\"Save\">";
a0d53889
AD
1207
1208 } else {
1209
1210 print "
e828e31e
AD
1211 Selection:
1212 <input type=\"submit\" class=\"button\"
1213 onclick=\"javascript:editSelectedFilter()\" value=\"Edit\">
1214 <input type=\"submit\" class=\"button\"
1215 onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">";
a0d53889
AD
1216 }
1217 }
1218
48f0adb0
AD
1219 if ($op == "pref-labels") {
1220
1221 $subop = $_GET["subop"];
1222
1223 if ($subop == "editSave") {
1224
1225 $sql_exp = $_GET["s"];
1226 $descr = $_GET["d"];
1227 $label_id = db_escape_string($_GET["id"]);
1228
1229// print "$sql_exp : $descr : $label_id";
1230
1231 $result = db_query($link, "UPDATE ttrss_labels SET
1232 sql_exp = '$sql_exp',
1233 description = '$descr'
1234 WHERE id = '$label_id'");
1235 }
1236
1237 if ($subop == "remove") {
1238
1239 if (!WEB_DEMO_MODE) {
1240
1241 $ids = split(",", $_GET["ids"]);
1242
1243 foreach ($ids as $id) {
1244 db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'");
1245
1246 }
1247 }
1248 }
1249
1250 if ($subop == "add") {
1251
1252 if (!WEB_DEMO_MODE) {
1253
1254 $exp = $_GET["exp"];
1255
1256 $result = db_query($link,
1257 "INSERT INTO ttrss_labels (sql_exp,description)
1258 VALUES ('$exp', '$exp')");
1259 }
1260 }
1261
1262 print "<table class=\"prefAddFeed\"><tr>
1263 <td><input id=\"ladd_expr\"></td>";
1264
1265 print"<td colspan=\"4\" align=\"right\">
1266 <a class=\"button\" href=\"javascript:addLabel()\">Add label</a></td></tr>
1267 </table>";
1268
1269 $result = db_query($link, "SELECT
1270 id,sql_exp,description
1271 FROM
1272 ttrss_labels ORDER by description");
1273
1274 print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">";
1275
1276 print "<tr class=\"title\">
7dc66a61
AD
1277 <td width=\"5%\">Select</td><td width=\"40%\">SQL expression
1278 <a class=\"helpLink\" href=\"javascript:popupHelp(1)\">(?)</a>
1279 </td>
48f0adb0
AD
1280 <td width=\"40%\">Caption</td></tr>";
1281
1282 $lnum = 0;
1283
1284 while ($line = db_fetch_assoc($result)) {
1285
1286 $class = ($lnum % 2) ? "even" : "odd";
1287
1288 $label_id = $line["id"];
1289 $edit_label_id = $_GET["id"];
1290
1291 if ($subop == "edit" && $label_id != $edit_label_id) {
1292 $class .= "Grayed";
1293 }
1294
1295 print "<tr class=\"$class\" id=\"LILRR-$label_id\">";
1296
1297 $line["sql_exp"] = htmlspecialchars($line["sql_exp"]);
1298 $line["description"] = htmlspecialchars($line["description"]);
1299
1300 if (!$edit_label_id || $subop != "edit") {
1301
1302 if (!$line["description"]) $line["description"] = "[No caption]";
1303
1304 print "<td><input onclick='toggleSelectRow(this);'
1305 type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>";
1306
1307 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1308 $line["sql_exp"] . "</td>";
1309
1310 print "<td><a href=\"javascript:editLabel($label_id);\">" .
1311 $line["description"] . "</td>";
1312
1313 } else if ($label_id != $edit_label_id) {
1314
1315 if (!$line["description"]) $line["description"] = "[No description]";
1316
1317 print "<td><input disabled=\"true\" type=\"checkbox\"
1318 id=\"LICHK-".$line["id"]."\"></td>";
1319
1320 print "<td>".$line["sql_exp"]."</td>";
1321 print "<td>".$line["description"]."</td>";
1322
1323 } else {
1324
1325 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
1326
1327 print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"].
1328 "\"></td>";
1329
1330 print "<td><input id=\"iedit_descr\" value=\"".$line["description"].
1331 "\"></td>";
1332
1333 }
1334
1335
1336 print "</tr>";
1337
1338 ++$lnum;
1339 }
1340
1341 if ($lnum == 0) {
1342 print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>";
1343 }
1344
1345 print "</table>";
1346
1347 print "<p>";
1348
1349 if ($subop == "edit") {
1350 print "Edit label:
1351 <input type=\"submit\" class=\"button\"
1352 onclick=\"javascript:labelEditCancel()\" value=\"Cancel\">
1353 <input type=\"submit\" class=\"button\"
1354 onclick=\"javascript:labelEditSave()\" value=\"Save\">";
1355
1356 } else {
1357
1358 print "
1359 Selection:
1360 <input type=\"submit\" class=\"button\"
1361 onclick=\"javascript:editSelectedLabel()\" value=\"Edit\">
1362 <input type=\"submit\" class=\"button\"
1363 onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">";
1364 }
1365 }
1366
e828e31e
AD
1367 if ($op == "error") {
1368 print "<div width=\"100%\" align='center'>";
1369 $msg = $_GET["msg"];
1370 print $msg;
1371 print "</div>";
1372 }
1373
7dc66a61
AD
1374 if ($op == "help") {
1375 print "<html><head>
1376 <title>Tiny Tiny RSS : Help</title>
1377 <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\">
1378 <script type=\"text/javascript\" src=\"functions.js\"></script>
7dc66a61
AD
1379 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
1380 </head><body>";
1381
1382 $tid = sprintf("%d", $_GET["tid"]);
1383
1384 /* FIXME this badly needs real implementation */
1385
1386 print "<div class='helpResponse'>";
1387
1388 ?>
1389
1390 <h1>Help for SQL expressions</h1>
1391
1392 <h2>Description</h2>
1393
1394 <p>The &laquo;SQL expression&raquo; is added to WHERE clause of
d1f948d1 1395 view feed query. You can match on ttrss_entries table fields
7dc66a61
AD
1396 and even use subselect to query additional information. This
1397 functionality is considered to be advanced and requires basic
1398 understanding of SQL.</p>
1399
1400 <h2>Examples</h2>
1401
1402 <pre>unread = true</pre>
1403
1404 Matches all unread articles
1405
1406 <pre>title like '%Linux%'</pre>
1407
1408 Matches all articles which mention Linux in the title. You get the idea.
1409
1410 <p>See the database schema included in the distribution package for gruesome
1411 details.</p>
1412
1413 <?
1414
1415 print "<div align='center'>
1416 <a class=\"helpLink\"
1417 href=\"javascript:window.close()\">(Close this window)</a></div>";
1418
1419 print "</div>";
1420
1421 print "</body></html>";
1422
1423 }
1424
f84a97a3
AD
1425 if ($op == "dlg") {
1426 $id = $_GET["id"];
6de5d056 1427 $param = $_GET["param"];
f84a97a3
AD
1428
1429 if ($id == "quickAddFeed") {
033e47e0
AD
1430 print "Feed URL: <input
1431 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1432 id=\"qafInput\">
f84a97a3
AD
1433 <input class=\"button\"
1434 type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\">
1435 <input class=\"button\"
1436 type=\"submit\" onclick=\"javascript:closeDlg()\"
1437 value=\"Cancel\">";
1438 }
6de5d056
AD
1439
1440 if ($id == "quickDelFeed") {
1441
1442 $param = db_escape_string($param);
1443
1444 $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'");
1445
1446 if ($result) {
1447
1448 $f_title = db_fetch_result($result, 0, "title");
1449
1450 print "Remove current feed ($f_title)?&nbsp;
1451 <input class=\"button\"
1452 type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\">
1453 <input class=\"button\"
1454 type=\"submit\" onclick=\"javascript:closeDlg()\"
1455 value=\"Cancel\">";
1456 } else {
1457 print "Error: Feed $param not found.&nbsp;
1458 <input class=\"button\"
1459 type=\"submit\" onclick=\"javascript:closeDlg()\"
1460 value=\"Cancel\">";
1461 }
1462 }
1463
033e47e0
AD
1464 if ($id == "search") {
1465
1466 print "<input id=\"searchbox\" class=\"extSearch\"
1467 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
1468 onchange=\"javascript:search()\">
1469 <select id=\"searchmodebox\">
1470 <option selected>All feeds</option>
1471 <option>This feed</option>
1472 </select>
1473 <input type=\"submit\"
1474 class=\"button\" onclick=\"javascript:search()\" value=\"Search\">
1475 <input class=\"button\"
1476 type=\"submit\" onclick=\"javascript:closeDlg()\"
1477 value=\"Close\">";
1478
1479 }
1480
f84a97a3
AD
1481 }
1482
4b3dff6e 1483 db_close($link);
1cd17194 1484?>
406d9489
AD
1485
1486<!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> -->
1487