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