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