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