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