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