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