]>
Commit | Line | Data |
---|---|---|
1cd17194 AD |
1 | <? |
2 | header("Content-Type: application/xml"); | |
3 | ||
82baad4a AD |
4 | require_once "config.php"; |
5 | require_once "functions.php"; | |
6 | require_once "magpierss/rss_fetch.inc"; | |
1cd17194 | 7 | |
d76a3b03 AD |
8 | |
9 | $link = pg_connect(DB_CONN); | |
10 | ||
11 | pg_query("set client_encoding = 'utf-8'"); | |
12 | ||
6f428bc5 | 13 | $op = $_GET["op"]; |
331900c6 | 14 | $fetch = $_GET["fetch"]; |
175847de AD |
15 | |
16 | if ($op == "rpc") { | |
17 | ||
18 | $subop = $_GET["subop"]; | |
82baad4a | 19 | |
175847de AD |
20 | if ($subop == "catchupPage") { |
21 | ||
22 | $ids = split(",", $_GET["ids"]); | |
23 | ||
24 | foreach ($ids as $id) { | |
25 | ||
26 | pg_query("UPDATE ttrss_entries SET unread=false,last_read = NOW() | |
27 | WHERE id = '$id'"); | |
28 | ||
29 | } | |
30 | ||
31 | print "Marked active page as read."; | |
32 | } | |
33 | ||
34 | } | |
35 | ||
1cd17194 AD |
36 | if ($op == "feeds") { |
37 | ||
476cac42 AD |
38 | $subop = $_GET["subop"]; |
39 | ||
40 | if ($subop == "catchupAll") { | |
41 | pg_query("UPDATE ttrss_entries SET last_read = NOW(),unread = false"); | |
42 | } | |
43 | ||
9d9c9dd6 | 44 | update_all_feeds($link, $fetch); |
476cac42 | 45 | |
d76a3b03 AD |
46 | $result = pg_query("SELECT *, |
47 | (SELECT count(id) FROM ttrss_entries | |
48 | WHERE feed_id = ttrss_feeds.id) AS total, | |
49 | (SELECT count(id) FROM ttrss_entries | |
50 | WHERE feed_id = ttrss_feeds.id AND unread = true) as unread | |
51 | FROM ttrss_feeds ORDER BY title"); | |
1cd17194 | 52 | |
82baad4a | 53 | print "<table width=\"100%\" class=\"feeds\">"; |
1cd17194 AD |
54 | |
55 | $lnum = 0; | |
56 | ||
76798ff3 AD |
57 | $total_unread = 0; |
58 | ||
6f428bc5 | 59 | while ($line = pg_fetch_assoc($result)) { |
a1a8a2be | 60 | |
6f428bc5 | 61 | $feed = $line["title"]; |
2c1dd701 AD |
62 | $feed_id = $line["id"]; |
63 | ||
d76a3b03 AD |
64 | $total = $line["total"]; |
65 | $unread = $line["unread"]; | |
66 | ||
1cd17194 | 67 | $class = ($lnum % 2) ? "even" : "odd"; |
a1a8a2be AD |
68 | |
69 | if ($unread > 0) $class .= "Unread"; | |
70 | ||
76798ff3 AD |
71 | $total_unread += $unread; |
72 | ||
a1a8a2be AD |
73 | print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">"; |
74 | ||
75 | $feed = "<a href=\"javascript:viewfeed($feed_id, 0);\">$feed</a>"; | |
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 | |
476cac42 AD |
94 | print "<p align=\"center\">All feeds: |
95 | <a class=\"button\" | |
96 | href=\"javascript:updateFeedList(false,true)\">Update</a>"; | |
97 | ||
98 | print " <a class=\"button\" | |
99 | href=\"javascript:catchupAllFeeds()\">Mark as read</a></p>"; | |
100 | ||
76798ff3 AD |
101 | print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>"; |
102 | ||
1cd17194 AD |
103 | } |
104 | ||
105 | if ($op == "view") { | |
106 | ||
d76a3b03 AD |
107 | $id = $_GET["id"]; |
108 | ||
b197f117 | 109 | $result = pg_query("UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'"); |
a1a8a2be | 110 | |
d76a3b03 AD |
111 | $result = pg_query("SELECT title,link,content FROM ttrss_entries |
112 | WHERE id = '$id'"); | |
1cd17194 | 113 | |
d76a3b03 | 114 | if ($result) { |
1cd17194 | 115 | |
d76a3b03 | 116 | $line = pg_fetch_assoc($result); |
1cd17194 | 117 | |
d76a3b03 AD |
118 | print "<table class=\"feedOverview\">"; |
119 | print "<tr><td><b>Title:</b></td><td>".$line["title"]."</td></tr>"; | |
120 | print "<tr><td><b>Link:</b></td><td><a href=\"".$line["link"]."\">".$line["link"]."</a></td></tr>"; | |
121 | ||
122 | print "</table>"; | |
123 | ||
124 | print $line["content"]; | |
125 | ||
126 | ||
127 | } | |
1cd17194 AD |
128 | } |
129 | ||
130 | if ($op == "viewfeed") { | |
131 | ||
132 | $feed = $_GET["feed"]; | |
d76a3b03 | 133 | $skip = $_GET["skip"]; |
476cac42 | 134 | $subop = $_GET["subop"]; |
a1a8a2be | 135 | |
ac53063a AD |
136 | if (!$skip) $skip = 0; |
137 | ||
476cac42 | 138 | if ($subop == "undefined") $subop = ""; |
1cd17194 | 139 | |
ac53063a AD |
140 | // FIXME: check for null value here |
141 | ||
82baad4a AD |
142 | $result = pg_query("SELECT *, |
143 | EXTRACT(EPOCH FROM NOW()) - EXTRACT(EPOCH FROM last_updated) as update_timeout | |
144 | FROM ttrss_feeds WHERE id = '$feed'"); | |
1cd17194 | 145 | |
d76a3b03 | 146 | if ($result) { |
1cd17194 | 147 | |
d76a3b03 | 148 | $line = pg_fetch_assoc($result); |
1cd17194 | 149 | |
476cac42 AD |
150 | if ($subop == "ForceUpdate" || |
151 | (!$subop && $line["update_timeout"] > MIN_UPDATE_TIME)) { | |
82baad4a AD |
152 | |
153 | update_rss_feed($link, $line["feed_url"], $feed); | |
d76a3b03 | 154 | |
a1a8a2be | 155 | } else { |
d76a3b03 | 156 | |
476cac42 | 157 | if ($subop == "MarkAllRead") { |
d76a3b03 | 158 | |
b197f117 | 159 | pg_query("UPDATE ttrss_entries SET unread = false,last_read = NOW() |
a1a8a2be AD |
160 | WHERE feed_id = '$feed'"); |
161 | } | |
83fe4d6d | 162 | |
476cac42 | 163 | if ($subop == "MarkPageRead") { |
83fe4d6d AD |
164 | |
165 | // pg_query("UPDATE ttrss_entries SET unread = false | |
166 | // WHERE feed_id = '$feed' ORDER BY updated OFFSET $skip LIMIT 1"); | |
167 | } | |
168 | ||
a1a8a2be AD |
169 | } |
170 | } | |
d76a3b03 | 171 | |
175847de | 172 | print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">"; |
ac53063a | 173 | |
1c37c607 | 174 | print "<tr><td class=\"search\" colspan=\"3\"> |
83fe4d6d | 175 | Search: <input onchange=\"javascript:search($feed,this);\"></td></tr>"; |
b197f117 | 176 | print "<tr><td colspan=\"3\" class=\"title\">" . $line["title"] . "</td></tr>"; |
d76a3b03 | 177 | |
ac53063a AD |
178 | if ($ext == "SEARCH") { |
179 | $search = $_GET["search"]; | |
180 | $search_query_part = "(upper(title) LIKE upper('%$search%') | |
181 | OR content LIKE '%$search%') AND"; | |
182 | } | |
183 | ||
e6d1c0a0 AD |
184 | $result = pg_query("SELECT count(id) AS total_entries |
185 | FROM ttrss_entries WHERE feed_id = '$feed'"); | |
186 | ||
187 | $total_entries = pg_fetch_result($result, 0, "total_entries"); | |
188 | ||
b197f117 AD |
189 | $result = pg_query("SELECT |
190 | id,title,updated,unread,feed_id, | |
191 | EXTRACT(EPOCH FROM last_read) AS last_read_ts, | |
192 | EXTRACT(EPOCH FROM updated) AS updated_ts | |
193 | FROM | |
194 | ttrss_entries | |
195 | WHERE | |
ac53063a AD |
196 | $search_query_part |
197 | feed_id = '$feed' ORDER BY updated DESC LIMIT ".HEADLINES_PER_PAGE." OFFSET $skip"); | |
d76a3b03 | 198 | |
a1a8a2be | 199 | $lnum = 0; |
d76a3b03 | 200 | |
a1a8a2be | 201 | while ($line = pg_fetch_assoc($result)) { |
d76a3b03 | 202 | |
a1a8a2be | 203 | $class = ($lnum % 2) ? "even" : "odd"; |
d76a3b03 | 204 | |
b197f117 AD |
205 | if ($line["last_read_ts"] < $line["updated_ts"] && $line["unread"] == "f") { |
206 | $update_pic = "<img src=\"updated.png\" alt=\"Updated\">"; | |
207 | } else { | |
208 | $update_pic = " "; | |
209 | } | |
210 | ||
a1a8a2be AD |
211 | if ($line["unread"] == "t") |
212 | $class .= "Unread"; | |
d76a3b03 | 213 | |
b197f117 AD |
214 | $id = $line["id"]; |
215 | $feed_id = $line["feed_id"]; | |
216 | ||
217 | $content_link = "<a href=\"javascript:view($id,$feed_id);\">" . | |
218 | $line["title"] . "</a>"; | |
219 | ||
220 | print "<tr class='$class' id='RROW-$id'>"; | |
221 | ||
222 | print "<td id='FUPDPIC-$id' valign='center' class='headlineUpdateMark'>$update_pic</td>"; | |
223 | ||
a1a8a2be AD |
224 | print "<td class='headlineUpdated'>".$line["updated"]."</td>"; |
225 | print "<td class='headlineTitle'>$content_link</td>"; | |
d76a3b03 | 226 | |
a1a8a2be | 227 | print "</tr>"; |
d76a3b03 | 228 | |
a1a8a2be AD |
229 | ++$lnum; |
230 | } | |
d76a3b03 | 231 | |
ac53063a AD |
232 | if ($lnum == 0) { |
233 | print "<tr><td align='center'>No entries found.</td></tr>"; | |
234 | ||
235 | } | |
236 | ||
b197f117 | 237 | print "<tr><td colspan=\"3\" class=\"headlineToolbar\">"; |
d76a3b03 | 238 | |
a1a8a2be AD |
239 | $next_skip = $skip + HEADLINES_PER_PAGE; |
240 | $prev_skip = $skip - HEADLINES_PER_PAGE; | |
83fe4d6d AD |
241 | |
242 | print "Navigate: "; | |
e6d1c0a0 AD |
243 | |
244 | if ($prev_skip >= 0) { | |
245 | print "<a class=\"button\" | |
246 | href=\"javascript:viewfeed($feed, $prev_skip);\">Previous Page</a>"; | |
247 | } else { | |
248 | print "<a class=\"disabledButton\">Previous Page</a>"; | |
249 | } | |
a1a8a2be | 250 | print " "; |
e6d1c0a0 AD |
251 | |
252 | if ($next_skip < $total_entries) { | |
253 | print "<a class=\"button\" | |
254 | href=\"javascript:viewfeed($feed, $next_skip);\">Next Page</a>"; | |
255 | } else { | |
256 | print "<a class=\"disabledButton\">Next Page</a>"; | |
257 | } | |
2127761f AD |
258 | print " Feed: "; |
259 | // print "<a class=\"button\" | |
260 | // href=\"javascript:viewfeed($feed, $skip, '');\">Refresh Page</a>"; | |
261 | // print " "; | |
262 | ||
ac53063a | 263 | print "<a class=\"button\" |
2127761f | 264 | href=\"javascript:viewfeed($feed, 0, 'ForceUpdate');\">Update</a>"; |
175847de | 265 | |
83fe4d6d | 266 | print " Mark as read: "; |
175847de | 267 | |
83fe4d6d | 268 | print "<a class=\"button\" |
175847de | 269 | href=\"javascript:catchupPage($feed);\">This Page</a>"; |
83fe4d6d | 270 | print " "; |
a1a8a2be | 271 | print "<a class=\"button\" |
83fe4d6d | 272 | href=\"javascript:viewfeed($feed, $skip, 'MarkAllRead');\">All Posts</a>"; |
d76a3b03 | 273 | |
a1a8a2be AD |
274 | print "</td></tr>"; |
275 | print "</table>"; | |
d76a3b03 | 276 | |
a1a8a2be AD |
277 | $result = pg_query("SELECT id, (SELECT count(id) FROM ttrss_entries |
278 | WHERE feed_id = ttrss_feeds.id) AS total, | |
279 | (SELECT count(id) FROM ttrss_entries | |
280 | WHERE feed_id = ttrss_feeds.id AND unread = true) as unread | |
281 | FROM ttrss_feeds WHERE id = '$feed'"); | |
d76a3b03 | 282 | |
a1a8a2be AD |
283 | $total = pg_fetch_result($result, 0, "total"); |
284 | $unread = pg_fetch_result($result, 0, "unread"); | |
d76a3b03 | 285 | |
a1a8a2be AD |
286 | print "<div class=\"invisible\" id=\"FACTIVE\">$feed</div>"; |
287 | print "<div class=\"invisible\" id=\"FTOTAL\">$total</div>"; | |
288 | print "<div class=\"invisible\" id=\"FUNREAD\">$unread</div>"; | |
d76a3b03 | 289 | |
1cd17194 AD |
290 | } |
291 | ||
0e091d38 | 292 | if ($op == "pref-rpc") { |
331900c6 | 293 | |
0e091d38 | 294 | $subop = $_GET["subop"]; |
331900c6 | 295 | |
83fe4d6d AD |
296 | if ($subop == "unread") { |
297 | $ids = split(",", $_GET["ids"]); | |
298 | foreach ($ids as $id) { | |
299 | pg_query("UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'"); | |
300 | } | |
0e091d38 AD |
301 | |
302 | print "Marked selected feeds as read."; | |
83fe4d6d AD |
303 | } |
304 | ||
305 | if ($subop == "read") { | |
306 | $ids = split(",", $_GET["ids"]); | |
307 | foreach ($ids as $id) { | |
b197f117 AD |
308 | pg_query("UPDATE ttrss_entries |
309 | SET unread = false,last_read = NOW() WHERE feed_id = '$id'"); | |
83fe4d6d | 310 | } |
0e091d38 AD |
311 | |
312 | print "Marked selected feeds as unread."; | |
313 | ||
314 | } | |
315 | ||
316 | } | |
317 | ||
318 | if ($op == "pref-feeds") { | |
319 | ||
320 | $subop = $_GET["subop"]; | |
321 | ||
322 | if ($subop == "edit") { | |
323 | print "<p>[Edit feed placeholder]</p>"; | |
83fe4d6d AD |
324 | } |
325 | ||
331900c6 AD |
326 | if ($subop == "remove") { |
327 | $ids = split(",", $_GET["ids"]); | |
328 | ||
329 | foreach ($ids as $id) { | |
330 | pg_query("BEGIN"); | |
331 | pg_query("DELETE FROM ttrss_entries WHERE feed_id = '$id'"); | |
332 | pg_query("DELETE FROM ttrss_feeds WHERE id = '$id'"); | |
333 | pg_query("COMMIT"); | |
334 | ||
335 | } | |
336 | } | |
337 | ||
338 | if ($subop == "add") { | |
339 | $feed_link = pg_escape_string($_GET["link"]); | |
340 | ||
341 | $result = pg_query( | |
342 | "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')"); | |
343 | ||
344 | $result = pg_query("SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'"); | |
345 | ||
346 | $feed_id = pg_fetch_result($result, 0, "id"); | |
347 | ||
348 | if ($feed_id) { | |
349 | update_rss_feed($link, $feed_link, $feed_id); | |
350 | } | |
351 | ||
352 | } | |
353 | ||
007bda35 | 354 | $result = pg_query("SELECT * FROM ttrss_feeds ORDER by title"); |
1cd17194 | 355 | |
331900c6 | 356 | print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">"; |
007bda35 AD |
357 | print "<tr class=\"title\"> |
358 | <td>Select</td><td>Title</td><td>Link</td><td>Last Updated</td></tr>"; | |
359 | ||
360 | $lnum = 0; | |
361 | ||
362 | while ($line = pg_fetch_assoc($result)) { | |
363 | ||
364 | $class = ($lnum % 2) ? "even" : "odd"; | |
331900c6 AD |
365 | |
366 | $feed_id = $line["id"]; | |
367 | ||
368 | print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">"; | |
007bda35 AD |
369 | |
370 | print "<td><input onclick='toggleSelectRow(this);' | |
331900c6 AD |
371 | type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>"; |
372 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
373 | $line["title"] . "</td>"; | |
374 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
375 | $line["feed_url"] . "</td>"; | |
376 | ||
007bda35 AD |
377 | print "<td>" . $line["last_updated"] . "</td>"; |
378 | print "</tr>"; | |
379 | ||
380 | ++$lnum; | |
381 | } | |
382 | ||
383 | print "</table>"; | |
384 | ||
385 | } | |
386 | ||
387 | pg_close($link); | |
1cd17194 | 388 | ?> |