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