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