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