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