]>
Commit | Line | Data |
---|---|---|
1 | <? | |
2 | // header("Content-Type: application/xml"); | |
3 | ||
4 | require_once "config.php"; | |
5 | require_once "functions.php"; | |
6 | require_once "magpierss/rss_fetch.inc"; | |
7 | ||
8 | error_reporting(0); | |
9 | ||
10 | $link = pg_connect(DB_CONN); | |
11 | ||
12 | error_reporting (E_ERROR | E_WARNING | E_PARSE); | |
13 | ||
14 | if (!$link) { | |
15 | print "Could not connect to database. Please check local configuration."; | |
16 | return; | |
17 | } | |
18 | ||
19 | pg_query("set client_encoding = 'utf-8'"); | |
20 | ||
21 | $op = $_GET["op"]; | |
22 | $fetch = $_GET["fetch"]; | |
23 | ||
24 | function outputFeedList($link) { | |
25 | ||
26 | $result = pg_query($link, "SELECT *, | |
27 | (SELECT count(id) FROM ttrss_entries | |
28 | WHERE feed_id = ttrss_feeds.id) AS total, | |
29 | (SELECT count(id) FROM ttrss_entries | |
30 | WHERE feed_id = ttrss_feeds.id AND unread = true) as unread | |
31 | FROM ttrss_feeds ORDER BY title"); | |
32 | ||
33 | print "<table width=\"100%\" class=\"feeds\" id=\"feedsList\">"; | |
34 | ||
35 | $lnum = 0; | |
36 | ||
37 | $total_unread = 0; | |
38 | ||
39 | while ($line = pg_fetch_assoc($result)) { | |
40 | ||
41 | $feed = $line["title"]; | |
42 | $feed_id = $line["id"]; | |
43 | ||
44 | $subop = $_GET["subop"]; | |
45 | ||
46 | $total = $line["total"]; | |
47 | $unread = $line["unread"]; | |
48 | ||
49 | $class = ($lnum % 2) ? "even" : "odd"; | |
50 | ||
51 | if ($unread > 0) $class .= "Unread"; | |
52 | ||
53 | $total_unread += $unread; | |
54 | ||
55 | print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">"; | |
56 | ||
57 | $icon_file = ICONS_DIR . "/$feed_id.ico"; | |
58 | ||
59 | if ($subop != "piggie") { | |
60 | ||
61 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
62 | $feed_icon = "<img width=\"16\" height=\"16\" | |
63 | src=\"" . ICONS_URL . "/$feed_id.ico\">"; | |
64 | } else { | |
65 | $feed_icon = " "; | |
66 | } | |
67 | } else { | |
68 | $feed_icon = "<img width=\"16\" height=\"16\" | |
69 | src=\"http://madoka.spb.ru/stuff/fox/tiny_piggie.png\">"; | |
70 | } | |
71 | ||
72 | $feed = "<a href=\"javascript:viewfeed($feed_id, 0);\">$feed</a>"; | |
73 | if (ENABLE_FEED_ICONS) { | |
74 | print "<td>$feed_icon</td>"; | |
75 | } | |
76 | print "<td id=\"FEEDN-$feed_id\">$feed</td>"; | |
77 | print "<td>"; | |
78 | print "<span id=\"FEEDU-$feed_id\">$unread</span> / "; | |
79 | print "<span id=\"FEEDT-$feed_id\">$total</span>"; | |
80 | print "</td>"; | |
81 | ||
82 | print "</tr>"; | |
83 | ++$lnum; | |
84 | } | |
85 | ||
86 | // print "<tr><td class=\"footer\" colspan=\"3\"> | |
87 | // <a href=\"javascript:update_feed_list(false,true)\">Update all feeds</a></td></tr>"; | |
88 | ||
89 | // print "<tr><td class=\"footer\" colspan=\"2\"> "; | |
90 | // print "</td></tr>"; | |
91 | ||
92 | print "</table>"; | |
93 | ||
94 | print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>"; | |
95 | ||
96 | /* | |
97 | print "<p align=\"center\">All feeds: | |
98 | <a class=\"button\" | |
99 | href=\"javascript:scheduleFeedUpdate(true)\">Update</a>"; | |
100 | ||
101 | print " <a class=\"button\" | |
102 | href=\"javascript:catchupAllFeeds()\">Mark as read</a></p>"; | |
103 | ||
104 | print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>"; | |
105 | */ | |
106 | ||
107 | ||
108 | } | |
109 | ||
110 | ||
111 | if ($op == "rpc") { | |
112 | ||
113 | $subop = $_GET["subop"]; | |
114 | ||
115 | if ($subop == "updateFeed") { | |
116 | $feed_id = $_GET["feed"]; | |
117 | ||
118 | $result = pg_query($link, | |
119 | "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'"); | |
120 | ||
121 | if (pg_num_rows($result) > 0) { | |
122 | $feed_url = pg_fetch_result($result, 0, "feed_url"); | |
123 | // update_rss_feed($link, $feed_url, $feed_id); | |
124 | } | |
125 | ||
126 | print "DONE-$feed_id"; | |
127 | ||
128 | return; | |
129 | } | |
130 | ||
131 | if ($subop == "forceUpdateAllFeeds") { | |
132 | update_all_feeds($link, true); | |
133 | outputFeedList($link); | |
134 | } | |
135 | ||
136 | if ($subop == "updateAllFeeds") { | |
137 | update_all_feeds($link, false); | |
138 | outputFeedList($link); | |
139 | } | |
140 | ||
141 | if ($subop == "catchupPage") { | |
142 | ||
143 | $ids = split(",", $_GET["ids"]); | |
144 | ||
145 | foreach ($ids as $id) { | |
146 | ||
147 | pg_query("UPDATE ttrss_entries SET unread=false,last_read = NOW() | |
148 | WHERE id = '$id'"); | |
149 | ||
150 | } | |
151 | ||
152 | print "Marked active page as read."; | |
153 | } | |
154 | ||
155 | } | |
156 | ||
157 | if ($op == "feeds") { | |
158 | ||
159 | $subop = $_GET["subop"]; | |
160 | ||
161 | if ($subop == "catchupAll") { | |
162 | pg_query("UPDATE ttrss_entries SET last_read = NOW(),unread = false"); | |
163 | } | |
164 | ||
165 | outputFeedList($link); | |
166 | ||
167 | } | |
168 | ||
169 | if ($op == "view") { | |
170 | ||
171 | $id = $_GET["id"]; | |
172 | ||
173 | $result = pg_query("UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'"); | |
174 | ||
175 | $result = pg_query("SELECT title,link,content,feed_id,comments, | |
176 | (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url | |
177 | FROM ttrss_entries | |
178 | WHERE id = '$id'"); | |
179 | ||
180 | if ($result) { | |
181 | ||
182 | $line = pg_fetch_assoc($result); | |
183 | ||
184 | if ($line["icon_url"]) { | |
185 | $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">"; | |
186 | } else { | |
187 | $feed_icon = " "; | |
188 | } | |
189 | ||
190 | print "<table class=\"postTable\" width=\"100%\" cellspacing=\"0\" | |
191 | cellpadding=\"0\">"; | |
192 | ||
193 | print "<tr class=\"titleTop\"><td align=\"right\"><b>Title:</b></td> | |
194 | <td width=\"100%\">".$line["title"]."</td> | |
195 | <td> </td></tr>"; | |
196 | ||
197 | if ($line["comments"] && $line["comments"] != $line["link"]) { | |
198 | // print "<tr class=\"titleInner\"><td align=\"right\"><b>Comments:</b></td> | |
199 | // <td><a href=\"".$line["comments"]."\">".$line["comments"]."</a></td> | |
200 | // <td> </td> </tr>"; | |
201 | ||
202 | $comments_prompt = "(<a href=\"".$line["comments"]."\">Comments</a>)"; | |
203 | } | |
204 | ||
205 | print "<tr class=\"titleBottom\"><td align=\"right\"><b>Link:</b></td> | |
206 | <td><a href=\"".$line["link"]."\">".$line["link"]."</a> $comments_prompt</td> | |
207 | <td> </td></tr>"; | |
208 | print "<tr><td valign=\"top\" class=\"post\" | |
209 | colspan=\"2\">" . $line["content"] . "</td> | |
210 | <td valign=\"top\">$feed_icon</td> | |
211 | </tr>"; | |
212 | print "</table>"; | |
213 | ||
214 | } | |
215 | } | |
216 | ||
217 | if ($op == "viewfeed") { | |
218 | ||
219 | $feed = $_GET["feed"]; | |
220 | $skip = $_GET["skip"]; | |
221 | $subop = $_GET["subop"]; | |
222 | ||
223 | if (!$skip) $skip = 0; | |
224 | ||
225 | if ($subop == "undefined") $subop = ""; | |
226 | ||
227 | // FIXME: check for null value here | |
228 | ||
229 | $result = pg_query("SELECT *,SUBSTRING(last_updated,1,16) as last_updated, | |
230 | EXTRACT(EPOCH FROM NOW()) - EXTRACT(EPOCH FROM last_updated) as update_timeout | |
231 | FROM ttrss_feeds WHERE id = '$feed'"); | |
232 | ||
233 | if ($result) { | |
234 | ||
235 | $line = pg_fetch_assoc($result); | |
236 | ||
237 | if ($subop == "ForceUpdate" || | |
238 | (!$subop && $line["update_timeout"] > MIN_UPDATE_TIME)) { | |
239 | ||
240 | update_rss_feed($link, $line["feed_url"], $feed); | |
241 | ||
242 | } else { | |
243 | ||
244 | if ($subop == "MarkAllRead") { | |
245 | ||
246 | pg_query("UPDATE ttrss_entries SET unread = false,last_read = NOW() | |
247 | WHERE feed_id = '$feed'"); | |
248 | } | |
249 | } | |
250 | } | |
251 | ||
252 | print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">"; | |
253 | ||
254 | $feed_last_updated = "Updated: " . $line["last_updated"]; | |
255 | ||
256 | print "<tr><td class=\"search\" colspan=\"3\"> | |
257 | Search: <input id=\"searchbox\" | |
258 | onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\" | |
259 | onchange=\"javascript:search($feed);\"> | |
260 | <a class=\"button\" href=\"javascript:resetSearch()\">Reset</a> | |
261 | </td></tr>"; | |
262 | print "<tr> | |
263 | <td colspan=\"3\" class=\"title\">" . $line["title"] . "</td></tr>"; | |
264 | ||
265 | $search = $_GET["search"]; | |
266 | ||
267 | if (search) { | |
268 | $search_query_part = "(upper(title) LIKE upper('%$search%') | |
269 | OR content LIKE '%$search%') AND"; | |
270 | } | |
271 | ||
272 | $result = pg_query("SELECT count(id) AS total_entries | |
273 | FROM ttrss_entries WHERE | |
274 | $search_query_part | |
275 | feed_id = '$feed'"); | |
276 | ||
277 | $total_entries = pg_fetch_result($result, 0, "total_entries"); | |
278 | ||
279 | $result = pg_query("SELECT | |
280 | id,title,updated,unread,feed_id, | |
281 | EXTRACT(EPOCH FROM last_read) AS last_read_ts, | |
282 | EXTRACT(EPOCH FROM updated) AS updated_ts | |
283 | FROM | |
284 | ttrss_entries | |
285 | WHERE | |
286 | $search_query_part | |
287 | feed_id = '$feed' ORDER BY updated DESC LIMIT ".HEADLINES_PER_PAGE." OFFSET $skip"); | |
288 | ||
289 | $lnum = 0; | |
290 | ||
291 | $num_unread = 0; | |
292 | ||
293 | while ($line = pg_fetch_assoc($result)) { | |
294 | ||
295 | $class = ($lnum % 2) ? "even" : "odd"; | |
296 | ||
297 | if ($line["last_read_ts"] < $line["updated_ts"] && $line["unread"] == "f") { | |
298 | $update_pic = "<img src=\"images/updated.png\" alt=\"Updated\">"; | |
299 | ++$num_unread; | |
300 | } else { | |
301 | $update_pic = " "; | |
302 | } | |
303 | ||
304 | if ($line["unread"] == "t") { | |
305 | $class .= "Unread"; | |
306 | ++$num_unread; | |
307 | } | |
308 | ||
309 | $id = $line["id"]; | |
310 | $feed_id = $line["feed_id"]; | |
311 | ||
312 | $content_link = "<a href=\"javascript:view($id,$feed_id);\">" . | |
313 | $line["title"] . "</a>"; | |
314 | ||
315 | print "<tr class='$class' id='RROW-$id'>"; | |
316 | ||
317 | print "<td id='FUPDPIC-$id' valign='center' class='headlineUpdateMark'>$update_pic</td>"; | |
318 | ||
319 | print "<td class='headlineUpdated'> | |
320 | <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>"; | |
321 | print "<td class='headlineTitle'>$content_link</td>"; | |
322 | ||
323 | print "</tr>"; | |
324 | ||
325 | ++$lnum; | |
326 | } | |
327 | ||
328 | if ($lnum == 0) { | |
329 | print "<tr><td align='center'>No entries found.</td></tr>"; | |
330 | } | |
331 | ||
332 | while ($lnum < HEADLINES_PER_PAGE) { | |
333 | ++$lnum; | |
334 | print "<tr><td> </td></tr>"; | |
335 | } | |
336 | ||
337 | // start unholy navbar block | |
338 | ||
339 | print "<tr><td colspan=\"3\" class=\"headlineToolbar\">"; | |
340 | ||
341 | $next_skip = $skip + HEADLINES_PER_PAGE; | |
342 | $prev_skip = $skip - HEADLINES_PER_PAGE; | |
343 | ||
344 | print "Navigate: "; | |
345 | ||
346 | if ($prev_skip >= 0) { | |
347 | print "<a class=\"button\" | |
348 | href=\"javascript:viewfeed($feed, $prev_skip);\">Previous Page</a>"; | |
349 | } else { | |
350 | print "<a class=\"disabledButton\">Previous Page</a>"; | |
351 | } | |
352 | print " "; | |
353 | ||
354 | if ($next_skip < $total_entries) { | |
355 | print "<a class=\"button\" | |
356 | href=\"javascript:viewfeed($feed, $next_skip);\">Next Page</a>"; | |
357 | } else { | |
358 | print "<a class=\"disabledButton\">Next Page</a>"; | |
359 | } | |
360 | print " Feed: "; | |
361 | ||
362 | print "<a class=\"button\" | |
363 | href=\"javascript:viewfeed($feed, 0, 'ForceUpdate');\">Update</a>"; | |
364 | ||
365 | print " Mark as read: "; | |
366 | ||
367 | if ($num_unread > 0) { | |
368 | print "<a class=\"button\" id=\"btnCatchupPage\" | |
369 | href=\"javascript:catchupPage($feed);\">This Page</a>"; | |
370 | print " "; | |
371 | } else { | |
372 | print "<a class=\"disabledButton\">This Page</a>"; | |
373 | print " "; | |
374 | } | |
375 | ||
376 | print "<a class=\"button\" | |
377 | href=\"javascript:viewfeed($feed, $skip, 'MarkAllRead');\">All Posts</a>"; | |
378 | ||
379 | print "</td></tr>"; | |
380 | ||
381 | // end unholy navbar block | |
382 | ||
383 | print "</table>"; | |
384 | ||
385 | $result = pg_query("SELECT id, (SELECT count(id) FROM ttrss_entries | |
386 | WHERE feed_id = ttrss_feeds.id) AS total, | |
387 | (SELECT count(id) FROM ttrss_entries | |
388 | WHERE feed_id = ttrss_feeds.id AND unread = true) as unread | |
389 | FROM ttrss_feeds WHERE id = '$feed'"); | |
390 | ||
391 | $total = pg_fetch_result($result, 0, "total"); | |
392 | $unread = pg_fetch_result($result, 0, "unread"); | |
393 | ||
394 | print "<div class=\"invisible\" id=\"FACTIVE\">$feed</div>"; | |
395 | print "<div class=\"invisible\" id=\"FTOTAL\">$total</div>"; | |
396 | print "<div class=\"invisible\" id=\"FUNREAD\">$unread</div>"; | |
397 | ||
398 | } | |
399 | ||
400 | if ($op == "pref-rpc") { | |
401 | ||
402 | $subop = $_GET["subop"]; | |
403 | ||
404 | if ($subop == "unread") { | |
405 | $ids = split(",", $_GET["ids"]); | |
406 | foreach ($ids as $id) { | |
407 | pg_query("UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'"); | |
408 | } | |
409 | ||
410 | print "Marked selected feeds as read."; | |
411 | } | |
412 | ||
413 | if ($subop == "read") { | |
414 | $ids = split(",", $_GET["ids"]); | |
415 | foreach ($ids as $id) { | |
416 | pg_query("UPDATE ttrss_entries | |
417 | SET unread = false,last_read = NOW() WHERE feed_id = '$id'"); | |
418 | } | |
419 | ||
420 | print "Marked selected feeds as unread."; | |
421 | ||
422 | } | |
423 | ||
424 | } | |
425 | ||
426 | if ($op == "pref-feeds") { | |
427 | ||
428 | $subop = $_GET["subop"]; | |
429 | ||
430 | if ($subop == "editSave") { | |
431 | $feed_title = pg_escape_string($_GET["t"]); | |
432 | $feed_link = pg_escape_string($_GET["l"]); | |
433 | $feed_id = $_GET["id"]; | |
434 | ||
435 | $result = pg_query("UPDATE ttrss_feeds SET | |
436 | title = '$feed_title', feed_url = '$feed_link' WHERE id = '$feed_id'"); | |
437 | ||
438 | } | |
439 | ||
440 | if ($subop == "remove") { | |
441 | ||
442 | if (!WEB_DEMO_MODE) { | |
443 | ||
444 | $ids = split(",", $_GET["ids"]); | |
445 | ||
446 | foreach ($ids as $id) { | |
447 | pg_query("BEGIN"); | |
448 | pg_query("DELETE FROM ttrss_entries WHERE feed_id = '$id'"); | |
449 | pg_query("DELETE FROM ttrss_feeds WHERE id = '$id'"); | |
450 | pg_query("COMMIT"); | |
451 | ||
452 | if (file_exists(ICONS_DIR . "/$id.ico")) { | |
453 | unlink(ICONS_DIR . "/$id.ico"); | |
454 | } | |
455 | } | |
456 | } | |
457 | } | |
458 | ||
459 | if ($subop == "add") { | |
460 | ||
461 | if (!WEB_DEMO_MODE) { | |
462 | ||
463 | $feed_link = pg_escape_string($_GET["link"]); | |
464 | ||
465 | $result = pg_query( | |
466 | "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')"); | |
467 | ||
468 | $result = pg_query( | |
469 | "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'"); | |
470 | ||
471 | $feed_id = pg_fetch_result($result, 0, "id"); | |
472 | ||
473 | if ($feed_id) { | |
474 | update_rss_feed($link, $feed_link, $feed_id); | |
475 | } | |
476 | } | |
477 | } | |
478 | ||
479 | print "<table class=\"prefAddFeed\"><tr> | |
480 | <td><input id=\"fadd_link\"></td> | |
481 | <td colspan=\"4\" align=\"right\"> | |
482 | <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr> | |
483 | </table>"; | |
484 | ||
485 | $result = pg_query("SELECT | |
486 | id,title,feed_url,substring(last_updated,1,16) as last_updated | |
487 | FROM | |
488 | ttrss_feeds ORDER by title"); | |
489 | ||
490 | print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">"; | |
491 | print "<tr class=\"title\"> | |
492 | <td> </td><td>Select</td><td width=\"40%\">Title</td> | |
493 | <td width=\"40%\">Link</td><td>Last Updated</td></tr>"; | |
494 | ||
495 | $lnum = 0; | |
496 | ||
497 | while ($line = pg_fetch_assoc($result)) { | |
498 | ||
499 | $class = ($lnum % 2) ? "even" : "odd"; | |
500 | ||
501 | $feed_id = $line["id"]; | |
502 | ||
503 | $edit_feed_id = $_GET["id"]; | |
504 | ||
505 | if ($subop == "edit" && $feed_id != $edit_feed_id) { | |
506 | $class .= "Grayed"; | |
507 | } | |
508 | ||
509 | print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">"; | |
510 | ||
511 | $icon_file = ICONS_DIR . "/$feed_id.ico"; | |
512 | ||
513 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
514 | $feed_icon = "<img width=\"16\" height=\"16\" | |
515 | src=\"" . ICONS_URL . "/$feed_id.ico\">"; | |
516 | } else { | |
517 | $feed_icon = " "; | |
518 | } | |
519 | print "<td align='center'>$feed_icon</td>"; | |
520 | ||
521 | if (!$edit_feed_id || $subop != "edit") { | |
522 | ||
523 | print "<td><input onclick='toggleSelectRow(this);' | |
524 | type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>"; | |
525 | ||
526 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
527 | $line["title"] . "</td>"; | |
528 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
529 | $line["feed_url"] . "</td>"; | |
530 | ||
531 | ||
532 | } else if ($feed_id != $edit_feed_id) { | |
533 | ||
534 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
535 | id=\"FRCHK-".$line["id"]."\"></td>"; | |
536 | ||
537 | print "<td>".$line["title"]."</td>"; | |
538 | print "<td>".$line["feed_url"]."</td>"; | |
539 | ||
540 | } else { | |
541 | ||
542 | print "<td><input disabled=\"true\" type=\"checkbox\"></td>"; | |
543 | ||
544 | print "<td><input id=\"iedit_title\" value=\"".$line["title"]."\"></td>"; | |
545 | print "<td><input id=\"iedit_link\" value=\"".$line["feed_url"]."\"></td>"; | |
546 | ||
547 | } | |
548 | ||
549 | print "<td>" . $line["last_updated"] . "</td>"; | |
550 | ||
551 | print "</tr>"; | |
552 | ||
553 | ++$lnum; | |
554 | } | |
555 | ||
556 | print "</table>"; | |
557 | ||
558 | print "<p>"; | |
559 | ||
560 | if ($subop == "edit") { | |
561 | print "Edit feed: | |
562 | <a class=\"button\" href=\"javascript:feedEditCancel()\">Cancel</a> | |
563 | <a class=\"button\" href=\"javascript:feedEditSave()\">Save</a>"; | |
564 | } else { | |
565 | ||
566 | print " | |
567 | Selection: | |
568 | <a class=\"button\" | |
569 | href=\"javascript:editSelectedFeed()\">Edit</a> | |
570 | <a class=\"buttonWarn\" | |
571 | href=\"javascript:removeSelectedFeeds()\">Remove</a> "; | |
572 | if (ENABLE_PREFS_CATCHUP_UNCATCHUP) { | |
573 | print " | |
574 | <a class=\"button\" | |
575 | href=\"javascript:readSelectedFeeds()\">Mark as read</a> | |
576 | <a class=\"button\" | |
577 | href=\"javascript:unreadSelectedFeeds()\">Mark as unread</a> "; | |
578 | } | |
579 | print " | |
580 | All feeds: | |
581 | <a class=\"button\" href=\"opml.php?op=Export\">Export OPML</a>"; | |
582 | ||
583 | } | |
584 | ||
585 | } | |
586 | ||
587 | if ($op == "pref-filters") { | |
588 | ||
589 | $subop = $_GET["subop"]; | |
590 | ||
591 | if ($subop == "editSave") { | |
592 | /* $feed_title = pg_escape_string($_GET["t"]); | |
593 | $feed_link = pg_escape_string($_GET["l"]); | |
594 | $feed_id = $_GET["id"]; | |
595 | ||
596 | $result = pg_query("UPDATE ttrss_feeds SET | |
597 | title = '$feed_title', feed_url = '$feed_link' WHERE id = '$feed_id'"); */ | |
598 | ||
599 | } | |
600 | ||
601 | if ($subop == "remove") { | |
602 | ||
603 | if (!WEB_DEMO_MODE) { | |
604 | ||
605 | $ids = split(",", $_GET["ids"]); | |
606 | ||
607 | foreach ($ids as $id) { | |
608 | pg_query("DELETE FROM ttrss_filters WHERE id = '$id'"); | |
609 | ||
610 | } | |
611 | } | |
612 | } | |
613 | ||
614 | if ($subop == "add") { | |
615 | ||
616 | /* if (!WEB_DEMO_MODE) { | |
617 | ||
618 | $feed_link = pg_escape_string($_GET["link"]); | |
619 | ||
620 | $result = pg_query( | |
621 | "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')"); | |
622 | ||
623 | $result = pg_query( | |
624 | "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'"); | |
625 | ||
626 | $feed_id = pg_fetch_result($result, 0, "id"); | |
627 | ||
628 | if ($feed_id) { | |
629 | update_rss_feed($link, $feed_link, $feed_id); | |
630 | } | |
631 | } */ | |
632 | } | |
633 | ||
634 | $result = pg_query("SELECT description | |
635 | FROM ttrss_filter_types ORDER BY description"); | |
636 | ||
637 | $filter_types = array(); | |
638 | ||
639 | while ($line = pg_fetch_assoc($result)) { | |
640 | array_push($filter_types, $line["description"]); | |
641 | } | |
642 | ||
643 | print "<table class=\"prefAddFeed\"><tr> | |
644 | <td>Expr: <input id=\"fadd_regexp\"></td> | |
645 | <td>"; | |
646 | print_select("fadd_match", "", $filter_types); | |
647 | ||
648 | print"</td><td colspan=\"4\" align=\"right\"> | |
649 | <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr> | |
650 | </table>"; | |
651 | ||
652 | $result = pg_query("SELECT | |
653 | id,regexp,description, | |
654 | (SELECT name FROM ttrss_filter_types WHERE | |
655 | id = filter_type) as filter_type_name, | |
656 | (SELECT description FROM ttrss_filter_types | |
657 | WHERE id = filter_type) as filter_type_descr | |
658 | FROM | |
659 | ttrss_filters ORDER by id"); | |
660 | ||
661 | print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">"; | |
662 | ||
663 | print "<tr class=\"title\"> | |
664 | <td>Select</td><td width=\"40%\">Filter Expression</td> | |
665 | <td width=\"40%\">Description</td><td>Match</td></tr>"; | |
666 | ||
667 | $lnum = 0; | |
668 | ||
669 | while ($line = pg_fetch_assoc($result)) { | |
670 | ||
671 | $class = ($lnum % 2) ? "even" : "odd"; | |
672 | ||
673 | $filter_id = $line["id"]; | |
674 | $edit_filter_id = $_GET["id"]; | |
675 | ||
676 | if ($subop == "edit" && $filter_id != $edit_filter_id) { | |
677 | $class .= "Grayed"; | |
678 | } | |
679 | ||
680 | print "<tr class=\"$class\" id=\"FILRR-$filter_id\">"; | |
681 | ||
682 | if (!$edit_filter_id || $subop != "edit") { | |
683 | ||
684 | print "<td><input onclick='toggleSelectRow(this);' | |
685 | type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>"; | |
686 | ||
687 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
688 | $line["regexp"] . "</td>"; | |
689 | ||
690 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
691 | $line["description"] . "</td>"; | |
692 | ||
693 | print "<td>".$line["filter_type_descr"]."</td>"; | |
694 | ||
695 | } else if ($filter_id != $edit_filter_id) { | |
696 | ||
697 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
698 | id=\"FICHK-".$line["id"]."\"></td>"; | |
699 | ||
700 | print "<td>".$line["regexp"]."</td>"; | |
701 | print "<td>".$line["description"]."</td>"; | |
702 | print "<td>".$line["filter_type_descr"]."</td>"; | |
703 | ||
704 | } else { | |
705 | ||
706 | print "<td><input disabled=\"true\" type=\"checkbox\"></td>"; | |
707 | ||
708 | print "<td><input id=\"iedit_regexp\" value=\"".$line["regexp"]. | |
709 | "\"></td>"; | |
710 | ||
711 | print "<td><input id=\"iedit_descr\" value=\"".$line["description"]. | |
712 | "\"></td>"; | |
713 | ||
714 | print "<td>"; | |
715 | print_select("iedit_match", $line["filter_type_descr"], $filter_types); | |
716 | print "</td>"; | |
717 | ||
718 | } | |
719 | ||
720 | ||
721 | print "</tr>"; | |
722 | ||
723 | ++$lnum; | |
724 | } | |
725 | ||
726 | print "</table>"; | |
727 | ||
728 | print "<p>"; | |
729 | ||
730 | if ($subop == "edit") { | |
731 | print "Edit feed: | |
732 | <a class=\"button\" href=\"javascript:filterEditCancel()\">Cancel</a> | |
733 | <a class=\"button\" href=\"javascript:filterEditSave()\">Save</a>"; | |
734 | ||
735 | } else { | |
736 | ||
737 | print " | |
738 | Selection: | |
739 | <a class=\"button\" | |
740 | href=\"javascript:editSelectedFilter()\">Edit</a> | |
741 | <a class=\"buttonWarn\" | |
742 | href=\"javascript:removeSelectedFilters()\">Remove</a> "; | |
743 | } | |
744 | } | |
745 | ||
746 | pg_close($link); | |
747 | ?> |