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