]>
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 | |
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 | ||
a2015351 | 159 | $result = pg_query("SELECT *,SUBSTRING(last_updated,1,16) as last_updated, |
82baad4a AD |
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 | |
a2015351 AD |
184 | $feed_last_updated = "Updated: " . $line["last_updated"]; |
185 | ||
1c37c607 | 186 | print "<tr><td class=\"search\" colspan=\"3\"> |
83fe4d6d | 187 | Search: <input onchange=\"javascript:search($feed,this);\"></td></tr>"; |
a2015351 AD |
188 | print "<tr> |
189 | <td colspan=\"3\" class=\"title\">" . $line["title"] . "</td></tr>"; | |
d76a3b03 | 190 | |
ac53063a AD |
191 | if ($ext == "SEARCH") { |
192 | $search = $_GET["search"]; | |
193 | $search_query_part = "(upper(title) LIKE upper('%$search%') | |
194 | OR content LIKE '%$search%') AND"; | |
195 | } | |
196 | ||
e6d1c0a0 AD |
197 | $result = pg_query("SELECT count(id) AS total_entries |
198 | FROM ttrss_entries WHERE feed_id = '$feed'"); | |
199 | ||
200 | $total_entries = pg_fetch_result($result, 0, "total_entries"); | |
201 | ||
b197f117 AD |
202 | $result = pg_query("SELECT |
203 | id,title,updated,unread,feed_id, | |
204 | EXTRACT(EPOCH FROM last_read) AS last_read_ts, | |
205 | EXTRACT(EPOCH FROM updated) AS updated_ts | |
206 | FROM | |
207 | ttrss_entries | |
208 | WHERE | |
ac53063a AD |
209 | $search_query_part |
210 | feed_id = '$feed' ORDER BY updated DESC LIMIT ".HEADLINES_PER_PAGE." OFFSET $skip"); | |
d76a3b03 | 211 | |
a1a8a2be | 212 | $lnum = 0; |
d76a3b03 | 213 | |
a1a8a2be | 214 | while ($line = pg_fetch_assoc($result)) { |
d76a3b03 | 215 | |
a1a8a2be | 216 | $class = ($lnum % 2) ? "even" : "odd"; |
d76a3b03 | 217 | |
b197f117 AD |
218 | if ($line["last_read_ts"] < $line["updated_ts"] && $line["unread"] == "f") { |
219 | $update_pic = "<img src=\"updated.png\" alt=\"Updated\">"; | |
220 | } else { | |
221 | $update_pic = " "; | |
222 | } | |
223 | ||
a1a8a2be AD |
224 | if ($line["unread"] == "t") |
225 | $class .= "Unread"; | |
d76a3b03 | 226 | |
b197f117 AD |
227 | $id = $line["id"]; |
228 | $feed_id = $line["feed_id"]; | |
229 | ||
230 | $content_link = "<a href=\"javascript:view($id,$feed_id);\">" . | |
231 | $line["title"] . "</a>"; | |
232 | ||
233 | print "<tr class='$class' id='RROW-$id'>"; | |
234 | ||
235 | print "<td id='FUPDPIC-$id' valign='center' class='headlineUpdateMark'>$update_pic</td>"; | |
236 | ||
a1a8a2be AD |
237 | print "<td class='headlineUpdated'>".$line["updated"]."</td>"; |
238 | print "<td class='headlineTitle'>$content_link</td>"; | |
d76a3b03 | 239 | |
a1a8a2be | 240 | print "</tr>"; |
d76a3b03 | 241 | |
a1a8a2be AD |
242 | ++$lnum; |
243 | } | |
d76a3b03 | 244 | |
ac53063a AD |
245 | if ($lnum == 0) { |
246 | print "<tr><td align='center'>No entries found.</td></tr>"; | |
247 | ||
248 | } | |
249 | ||
b197f117 | 250 | print "<tr><td colspan=\"3\" class=\"headlineToolbar\">"; |
d76a3b03 | 251 | |
a1a8a2be AD |
252 | $next_skip = $skip + HEADLINES_PER_PAGE; |
253 | $prev_skip = $skip - HEADLINES_PER_PAGE; | |
83fe4d6d AD |
254 | |
255 | print "Navigate: "; | |
e6d1c0a0 AD |
256 | |
257 | if ($prev_skip >= 0) { | |
258 | print "<a class=\"button\" | |
259 | href=\"javascript:viewfeed($feed, $prev_skip);\">Previous Page</a>"; | |
260 | } else { | |
261 | print "<a class=\"disabledButton\">Previous Page</a>"; | |
262 | } | |
a1a8a2be | 263 | print " "; |
e6d1c0a0 | 264 | |
a2015351 AD |
265 | // start unholy navbar block |
266 | ||
267 | ||
e6d1c0a0 AD |
268 | if ($next_skip < $total_entries) { |
269 | print "<a class=\"button\" | |
270 | href=\"javascript:viewfeed($feed, $next_skip);\">Next Page</a>"; | |
271 | } else { | |
272 | print "<a class=\"disabledButton\">Next Page</a>"; | |
273 | } | |
2127761f | 274 | print " Feed: "; |
2127761f | 275 | |
ac53063a | 276 | print "<a class=\"button\" |
2127761f | 277 | href=\"javascript:viewfeed($feed, 0, 'ForceUpdate');\">Update</a>"; |
175847de | 278 | |
83fe4d6d | 279 | print " Mark as read: "; |
175847de | 280 | |
83fe4d6d | 281 | print "<a class=\"button\" |
175847de | 282 | href=\"javascript:catchupPage($feed);\">This Page</a>"; |
83fe4d6d | 283 | print " "; |
a1a8a2be | 284 | print "<a class=\"button\" |
83fe4d6d | 285 | href=\"javascript:viewfeed($feed, $skip, 'MarkAllRead');\">All Posts</a>"; |
d76a3b03 | 286 | |
a1a8a2be | 287 | print "</td></tr>"; |
a2015351 AD |
288 | |
289 | // end unholy navbar block | |
290 | ||
a1a8a2be | 291 | print "</table>"; |
d76a3b03 | 292 | |
a1a8a2be AD |
293 | $result = pg_query("SELECT id, (SELECT count(id) FROM ttrss_entries |
294 | WHERE feed_id = ttrss_feeds.id) AS total, | |
295 | (SELECT count(id) FROM ttrss_entries | |
296 | WHERE feed_id = ttrss_feeds.id AND unread = true) as unread | |
297 | FROM ttrss_feeds WHERE id = '$feed'"); | |
d76a3b03 | 298 | |
a1a8a2be AD |
299 | $total = pg_fetch_result($result, 0, "total"); |
300 | $unread = pg_fetch_result($result, 0, "unread"); | |
d76a3b03 | 301 | |
a1a8a2be AD |
302 | print "<div class=\"invisible\" id=\"FACTIVE\">$feed</div>"; |
303 | print "<div class=\"invisible\" id=\"FTOTAL\">$total</div>"; | |
304 | print "<div class=\"invisible\" id=\"FUNREAD\">$unread</div>"; | |
d76a3b03 | 305 | |
1cd17194 AD |
306 | } |
307 | ||
0e091d38 | 308 | if ($op == "pref-rpc") { |
331900c6 | 309 | |
0e091d38 | 310 | $subop = $_GET["subop"]; |
331900c6 | 311 | |
83fe4d6d AD |
312 | if ($subop == "unread") { |
313 | $ids = split(",", $_GET["ids"]); | |
314 | foreach ($ids as $id) { | |
315 | pg_query("UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'"); | |
316 | } | |
0e091d38 AD |
317 | |
318 | print "Marked selected feeds as read."; | |
83fe4d6d AD |
319 | } |
320 | ||
321 | if ($subop == "read") { | |
322 | $ids = split(",", $_GET["ids"]); | |
323 | foreach ($ids as $id) { | |
b197f117 AD |
324 | pg_query("UPDATE ttrss_entries |
325 | SET unread = false,last_read = NOW() WHERE feed_id = '$id'"); | |
83fe4d6d | 326 | } |
0e091d38 AD |
327 | |
328 | print "Marked selected feeds as unread."; | |
329 | ||
330 | } | |
331 | ||
332 | } | |
333 | ||
334 | if ($op == "pref-feeds") { | |
335 | ||
336 | $subop = $_GET["subop"]; | |
337 | ||
338 | if ($subop == "edit") { | |
339 | print "<p>[Edit feed placeholder]</p>"; | |
83fe4d6d AD |
340 | } |
341 | ||
331900c6 AD |
342 | if ($subop == "remove") { |
343 | $ids = split(",", $_GET["ids"]); | |
344 | ||
345 | foreach ($ids as $id) { | |
346 | pg_query("BEGIN"); | |
347 | pg_query("DELETE FROM ttrss_entries WHERE feed_id = '$id'"); | |
348 | pg_query("DELETE FROM ttrss_feeds WHERE id = '$id'"); | |
349 | pg_query("COMMIT"); | |
350 | ||
351 | } | |
352 | } | |
353 | ||
354 | if ($subop == "add") { | |
355 | $feed_link = pg_escape_string($_GET["link"]); | |
356 | ||
357 | $result = pg_query( | |
358 | "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')"); | |
359 | ||
360 | $result = pg_query("SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'"); | |
361 | ||
362 | $feed_id = pg_fetch_result($result, 0, "id"); | |
363 | ||
364 | if ($feed_id) { | |
365 | update_rss_feed($link, $feed_link, $feed_id); | |
366 | } | |
367 | ||
368 | } | |
369 | ||
007bda35 | 370 | $result = pg_query("SELECT * FROM ttrss_feeds ORDER by title"); |
1cd17194 | 371 | |
331900c6 | 372 | print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">"; |
007bda35 AD |
373 | print "<tr class=\"title\"> |
374 | <td>Select</td><td>Title</td><td>Link</td><td>Last Updated</td></tr>"; | |
375 | ||
376 | $lnum = 0; | |
377 | ||
378 | while ($line = pg_fetch_assoc($result)) { | |
379 | ||
380 | $class = ($lnum % 2) ? "even" : "odd"; | |
331900c6 AD |
381 | |
382 | $feed_id = $line["id"]; | |
383 | ||
384 | print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">"; | |
007bda35 AD |
385 | |
386 | print "<td><input onclick='toggleSelectRow(this);' | |
331900c6 AD |
387 | type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>"; |
388 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
389 | $line["title"] . "</td>"; | |
390 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
391 | $line["feed_url"] . "</td>"; | |
392 | ||
007bda35 AD |
393 | print "<td>" . $line["last_updated"] . "</td>"; |
394 | print "</tr>"; | |
395 | ||
396 | ++$lnum; | |
397 | } | |
398 | ||
399 | print "</table>"; | |
400 | ||
401 | } | |
402 | ||
403 | pg_close($link); | |
1cd17194 | 404 | ?> |