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