]>
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 | |
82baad4a AD |
114 | if (!$ext && $line["update_timeout"] > MIN_UPDATE_TIME) { |
115 | ||
116 | update_rss_feed($link, $line["feed_url"], $feed); | |
d76a3b03 | 117 | |
a1a8a2be | 118 | } else { |
d76a3b03 | 119 | |
a1a8a2be | 120 | if ($ext == "MarkAllRead") { |
d76a3b03 | 121 | |
a1a8a2be AD |
122 | pg_query("UPDATE ttrss_entries SET unread = false |
123 | WHERE feed_id = '$feed'"); | |
124 | } | |
83fe4d6d AD |
125 | |
126 | if ($ext == "MarkPageRead") { | |
127 | ||
128 | // pg_query("UPDATE ttrss_entries SET unread = false | |
129 | // WHERE feed_id = '$feed' ORDER BY updated OFFSET $skip LIMIT 1"); | |
130 | } | |
131 | ||
a1a8a2be AD |
132 | } |
133 | } | |
d76a3b03 | 134 | |
a1a8a2be | 135 | print "<table class=\"headlines\" width=\"100%\">"; |
ac53063a AD |
136 | |
137 | print "<tr><td class=\"search\" colspan=\"2\"> | |
83fe4d6d AD |
138 | Search: <input onchange=\"javascript:search($feed,this);\"></td></tr>"; |
139 | print "<tr><td colspan=\"2\" class=\"title\">" . $line["title"] . "</td></tr>"; | |
d76a3b03 | 140 | |
ac53063a AD |
141 | if ($ext == "SEARCH") { |
142 | $search = $_GET["search"]; | |
143 | $search_query_part = "(upper(title) LIKE upper('%$search%') | |
144 | OR content LIKE '%$search%') AND"; | |
145 | } | |
146 | ||
a1a8a2be AD |
147 | $result = pg_query("SELECT id,title,updated,unread,feed_id FROM |
148 | ttrss_entries WHERE | |
ac53063a AD |
149 | $search_query_part |
150 | feed_id = '$feed' ORDER BY updated DESC LIMIT ".HEADLINES_PER_PAGE." OFFSET $skip"); | |
d76a3b03 | 151 | |
a1a8a2be | 152 | $lnum = 0; |
d76a3b03 | 153 | |
a1a8a2be | 154 | while ($line = pg_fetch_assoc($result)) { |
d76a3b03 | 155 | |
a1a8a2be | 156 | $class = ($lnum % 2) ? "even" : "odd"; |
d76a3b03 | 157 | |
a1a8a2be AD |
158 | if ($line["unread"] == "t") |
159 | $class .= "Unread"; | |
d76a3b03 | 160 | |
a1a8a2be | 161 | $content_link = "<a href=\"javascript:view(".$line["id"].",".$line["feed_id"].");\">".$line["title"]."</a>"; |
1cd17194 | 162 | |
a1a8a2be AD |
163 | print "<tr class='$class' id='RROW-".$line["id"]."'>"; |
164 | print "<td class='headlineUpdated'>".$line["updated"]."</td>"; | |
165 | print "<td class='headlineTitle'>$content_link</td>"; | |
d76a3b03 | 166 | |
a1a8a2be | 167 | print "</tr>"; |
d76a3b03 | 168 | |
a1a8a2be AD |
169 | ++$lnum; |
170 | } | |
d76a3b03 | 171 | |
ac53063a AD |
172 | if ($lnum == 0) { |
173 | print "<tr><td align='center'>No entries found.</td></tr>"; | |
174 | ||
175 | } | |
176 | ||
a1a8a2be | 177 | print "<tr><td colspan=\"2\" class=\"headlineToolbar\">"; |
d76a3b03 | 178 | |
a1a8a2be AD |
179 | $next_skip = $skip + HEADLINES_PER_PAGE; |
180 | $prev_skip = $skip - HEADLINES_PER_PAGE; | |
83fe4d6d AD |
181 | |
182 | print "Navigate: "; | |
a1a8a2be AD |
183 | print "<a class=\"button\" |
184 | href=\"javascript:viewfeed($feed, $prev_skip);\">Previous Page</a>"; | |
185 | print " "; | |
186 | print "<a class=\"button\" | |
187 | href=\"javascript:viewfeed($feed, $next_skip);\">Next Page</a>"; | |
83fe4d6d | 188 | print " "; |
ac53063a | 189 | print "<a class=\"button\" |
83fe4d6d AD |
190 | href=\"javascript:viewfeed($feed, $skip, '');\">Refresh</a>"; |
191 | print " Mark as read: "; | |
192 | print "<a class=\"button\" | |
193 | href=\"javascript:viewfeed($feed, $skip, 'MarkPageRead');\">This Page</a>"; | |
194 | print " "; | |
a1a8a2be | 195 | print "<a class=\"button\" |
83fe4d6d | 196 | href=\"javascript:viewfeed($feed, $skip, 'MarkAllRead');\">All Posts</a>"; |
d76a3b03 | 197 | |
a1a8a2be AD |
198 | print "</td></tr>"; |
199 | print "</table>"; | |
d76a3b03 | 200 | |
a1a8a2be AD |
201 | $result = pg_query("SELECT id, (SELECT count(id) FROM ttrss_entries |
202 | WHERE feed_id = ttrss_feeds.id) AS total, | |
203 | (SELECT count(id) FROM ttrss_entries | |
204 | WHERE feed_id = ttrss_feeds.id AND unread = true) as unread | |
205 | FROM ttrss_feeds WHERE id = '$feed'"); | |
d76a3b03 | 206 | |
a1a8a2be AD |
207 | $total = pg_fetch_result($result, 0, "total"); |
208 | $unread = pg_fetch_result($result, 0, "unread"); | |
d76a3b03 | 209 | |
a1a8a2be AD |
210 | print "<div class=\"invisible\" id=\"FACTIVE\">$feed</div>"; |
211 | print "<div class=\"invisible\" id=\"FTOTAL\">$total</div>"; | |
212 | print "<div class=\"invisible\" id=\"FUNREAD\">$unread</div>"; | |
d76a3b03 | 213 | |
1cd17194 AD |
214 | } |
215 | ||
0e091d38 | 216 | if ($op == "pref-rpc") { |
331900c6 | 217 | |
0e091d38 | 218 | $subop = $_GET["subop"]; |
331900c6 | 219 | |
83fe4d6d AD |
220 | if ($subop == "unread") { |
221 | $ids = split(",", $_GET["ids"]); | |
222 | foreach ($ids as $id) { | |
223 | pg_query("UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'"); | |
224 | } | |
0e091d38 AD |
225 | |
226 | print "Marked selected feeds as read."; | |
83fe4d6d AD |
227 | } |
228 | ||
229 | if ($subop == "read") { | |
230 | $ids = split(",", $_GET["ids"]); | |
231 | foreach ($ids as $id) { | |
232 | pg_query("UPDATE ttrss_entries SET unread = false WHERE feed_id = '$id'"); | |
233 | } | |
0e091d38 AD |
234 | |
235 | print "Marked selected feeds as unread."; | |
236 | ||
237 | } | |
238 | ||
239 | } | |
240 | ||
241 | if ($op == "pref-feeds") { | |
242 | ||
243 | $subop = $_GET["subop"]; | |
244 | ||
245 | if ($subop == "edit") { | |
246 | print "<p>[Edit feed placeholder]</p>"; | |
83fe4d6d AD |
247 | } |
248 | ||
331900c6 AD |
249 | if ($subop == "remove") { |
250 | $ids = split(",", $_GET["ids"]); | |
251 | ||
252 | foreach ($ids as $id) { | |
253 | pg_query("BEGIN"); | |
254 | pg_query("DELETE FROM ttrss_entries WHERE feed_id = '$id'"); | |
255 | pg_query("DELETE FROM ttrss_feeds WHERE id = '$id'"); | |
256 | pg_query("COMMIT"); | |
257 | ||
258 | } | |
259 | } | |
260 | ||
261 | if ($subop == "add") { | |
262 | $feed_link = pg_escape_string($_GET["link"]); | |
263 | ||
264 | $result = pg_query( | |
265 | "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')"); | |
266 | ||
267 | $result = pg_query("SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'"); | |
268 | ||
269 | $feed_id = pg_fetch_result($result, 0, "id"); | |
270 | ||
271 | if ($feed_id) { | |
272 | update_rss_feed($link, $feed_link, $feed_id); | |
273 | } | |
274 | ||
275 | } | |
276 | ||
007bda35 | 277 | $result = pg_query("SELECT * FROM ttrss_feeds ORDER by title"); |
1cd17194 | 278 | |
331900c6 | 279 | print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">"; |
007bda35 AD |
280 | print "<tr class=\"title\"> |
281 | <td>Select</td><td>Title</td><td>Link</td><td>Last Updated</td></tr>"; | |
282 | ||
283 | $lnum = 0; | |
284 | ||
285 | while ($line = pg_fetch_assoc($result)) { | |
286 | ||
287 | $class = ($lnum % 2) ? "even" : "odd"; | |
331900c6 AD |
288 | |
289 | $feed_id = $line["id"]; | |
290 | ||
291 | print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">"; | |
007bda35 AD |
292 | |
293 | print "<td><input onclick='toggleSelectRow(this);' | |
331900c6 AD |
294 | type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>"; |
295 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
296 | $line["title"] . "</td>"; | |
297 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
298 | $line["feed_url"] . "</td>"; | |
299 | ||
007bda35 AD |
300 | print "<td>" . $line["last_updated"] . "</td>"; |
301 | print "</tr>"; | |
302 | ||
303 | ++$lnum; | |
304 | } | |
305 | ||
306 | print "</table>"; | |
307 | ||
308 | } | |
309 | ||
310 | pg_close($link); | |
1cd17194 | 311 | ?> |