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