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