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