]>
Commit | Line | Data |
---|---|---|
1cd17194 | 1 | <? |
a2015351 | 2 | // header("Content-Type: application/xml"); |
1cd17194 | 3 | |
82baad4a | 4 | require_once "config.php"; |
648472a7 | 5 | require_once "db.php"; |
82baad4a AD |
6 | require_once "functions.php"; |
7 | require_once "magpierss/rss_fetch.inc"; | |
1cd17194 | 8 | |
f07c0eb4 AD |
9 | error_reporting(0); |
10 | ||
648472a7 | 11 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); |
d76a3b03 | 12 | |
f07c0eb4 AD |
13 | error_reporting (E_ERROR | E_WARNING | E_PARSE); |
14 | ||
15 | if (!$link) { | |
16 | print "Could not connect to database. Please check local configuration."; | |
17 | return; | |
18 | } | |
19 | ||
648472a7 AD |
20 | if (DB_TYPE == "pgsql") { |
21 | pg_query("set client_encoding = 'utf-8'"); | |
22 | } | |
d76a3b03 | 23 | |
6f428bc5 | 24 | $op = $_GET["op"]; |
331900c6 | 25 | $fetch = $_GET["fetch"]; |
175847de | 26 | |
c3b81db0 | 27 | function outputFeedList($link) { |
175847de | 28 | |
1a66d16e AD |
29 | print "<html><head> |
30 | <title>Tiny Tiny RSS : Feedlist</title> | |
31 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
32 | <script type=\"text/javascript\" src=\"functions.js\"></script> | |
33 | <script type=\"text/javascript\" src=\"feedlist.js\"></script> | |
34 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
35 | </head><body>"; | |
36 | ||
648472a7 | 37 | $result = db_query($link, "SELECT *, |
d76a3b03 AD |
38 | (SELECT count(id) FROM ttrss_entries |
39 | WHERE feed_id = ttrss_feeds.id) AS total, | |
40 | (SELECT count(id) FROM ttrss_entries | |
41 | WHERE feed_id = ttrss_feeds.id AND unread = true) as unread | |
42 | FROM ttrss_feeds ORDER BY title"); | |
1cd17194 | 43 | |
1a66d16e AD |
44 | $actid = $_GET["actid"]; |
45 | ||
e828e31e AD |
46 | // print "<table width=\"100%\" class=\"feedsList\" id=\"feedsList\">"; |
47 | ||
48 | print "<ul class=\"feedList\" id=\"feedList\">"; | |
1cd17194 AD |
49 | |
50 | $lnum = 0; | |
51 | ||
76798ff3 AD |
52 | $total_unread = 0; |
53 | ||
648472a7 | 54 | while ($line = db_fetch_assoc($result)) { |
a1a8a2be | 55 | |
6f428bc5 | 56 | $feed = $line["title"]; |
2c1dd701 | 57 | $feed_id = $line["id"]; |
13ad9102 AD |
58 | |
59 | $subop = $_GET["subop"]; | |
2c1dd701 | 60 | |
d76a3b03 AD |
61 | $total = $line["total"]; |
62 | $unread = $line["unread"]; | |
63 | ||
e828e31e AD |
64 | // $class = ($lnum % 2) ? "even" : "odd"; |
65 | ||
66 | $class = "odd"; | |
a1a8a2be AD |
67 | |
68 | if ($unread > 0) $class .= "Unread"; | |
69 | ||
1a66d16e AD |
70 | if ($actid == $feed_id) { |
71 | $class .= "Selected"; | |
72 | } | |
73 | ||
76798ff3 AD |
74 | $total_unread += $unread; |
75 | ||
e828e31e | 76 | // print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">"; |
a1a8a2be | 77 | |
78800912 | 78 | $icon_file = ICONS_DIR . "/$feed_id.ico"; |
13ad9102 AD |
79 | |
80 | if ($subop != "piggie") { | |
81 | ||
82 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
e828e31e | 83 | $feed_icon = "<img src=\"" . ICONS_URL . "/$feed_id.ico\">"; |
13ad9102 | 84 | } else { |
e828e31e | 85 | $feed_icon = "<img src=\"images/blank_icon.png\">"; |
13ad9102 | 86 | } |
78800912 | 87 | } else { |
13ad9102 AD |
88 | $feed_icon = "<img width=\"16\" height=\"16\" |
89 | src=\"http://madoka.spb.ru/stuff/fox/tiny_piggie.png\">"; | |
78800912 | 90 | } |
13ad9102 | 91 | |
a1a8a2be | 92 | $feed = "<a href=\"javascript:viewfeed($feed_id, 0);\">$feed</a>"; |
e828e31e AD |
93 | |
94 | /* if (ENABLE_FEED_ICONS) { | |
78800912 AD |
95 | print "<td>$feed_icon</td>"; |
96 | } | |
e828e31e | 97 | |
a1a8a2be | 98 | print "<td id=\"FEEDN-$feed_id\">$feed</td>"; |
c442fb6e AD |
99 | print "<td>"; |
100 | print "<span id=\"FEEDU-$feed_id\">$unread</span> / "; | |
101 | print "<span id=\"FEEDT-$feed_id\">$total</span>"; | |
102 | print "</td>"; | |
a1a8a2be | 103 | |
e828e31e AD |
104 | print "</tr>"; */ |
105 | ||
106 | print "<li id=\"FEEDR-$feed_id\" class=\"$class\">"; | |
107 | if (ENABLE_FEED_ICONS) { | |
108 | print "$feed_icon"; | |
109 | } | |
110 | print "<span id=\"FEEDN-$feed_id\">$feed</span>"; | |
1cd17194 | 111 | |
0c674406 AD |
112 | if ($unread != 0) { |
113 | $fctr_class = ""; | |
114 | } else { | |
115 | $fctr_class = "class=\"invisible\""; | |
e828e31e | 116 | } |
0c674406 AD |
117 | |
118 | print "<span $fctr_class id=\"FEEDCTR-$feed_id\"> | |
119 | (<span id=\"FEEDU-$feed_id\">$unread</span>)</span>"; | |
e828e31e AD |
120 | |
121 | print "</li>"; | |
476cac42 | 122 | |
e828e31e AD |
123 | ++$lnum; |
124 | } | |
82baad4a | 125 | |
a1a8a2be | 126 | print "</table>"; |
1cd17194 | 127 | |
caa4e57f | 128 | print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>"; |
1a66d16e | 129 | print "<div class=\"invisible\" id=\"ACTFEEDID\">$actid</div>"; |
caa4e57f | 130 | |
c3b81db0 AD |
131 | } |
132 | ||
133 | ||
134 | if ($op == "rpc") { | |
135 | ||
136 | $subop = $_GET["subop"]; | |
137 | ||
f4c10d44 AD |
138 | if ($subop == "mark") { |
139 | $mark = $_GET["mark"]; | |
648472a7 | 140 | $id = db_escape_string($_GET["id"]); |
f4c10d44 AD |
141 | |
142 | if ($mark == "1") { | |
143 | $mark = "true"; | |
144 | } else { | |
145 | $mark = "false"; | |
146 | } | |
147 | ||
648472a7 | 148 | $result = db_query($link, "UPDATE ttrss_entries SET marked = $mark |
f4c10d44 AD |
149 | WHERE id = '$id'"); |
150 | } | |
151 | ||
caa4e57f | 152 | if ($subop == "updateFeed") { |
648472a7 | 153 | $feed_id = db_escape_string($_GET["feed"]); |
9cfc649a | 154 | |
648472a7 | 155 | $result = db_query($link, |
caa4e57f | 156 | "SELECT feed_url FROM ttrss_feeds WHERE id = '$feed_id'"); |
9cfc649a | 157 | |
648472a7 AD |
158 | if (db_num_rows($result) > 0) { |
159 | $feed_url = db_fetch_result($result, 0, "feed_url"); | |
caa4e57f AD |
160 | // update_rss_feed($link, $feed_url, $feed_id); |
161 | } | |
9cfc649a | 162 | |
caa4e57f | 163 | print "DONE-$feed_id"; |
9cfc649a | 164 | |
caa4e57f | 165 | return; |
9cfc649a AD |
166 | } |
167 | ||
c3b81db0 AD |
168 | if ($subop == "forceUpdateAllFeeds") { |
169 | update_all_feeds($link, true); | |
c3b81db0 AD |
170 | } |
171 | ||
172 | if ($subop == "updateAllFeeds") { | |
173 | update_all_feeds($link, false); | |
c3b81db0 AD |
174 | } |
175 | ||
176 | if ($subop == "catchupPage") { | |
177 | ||
178 | $ids = split(",", $_GET["ids"]); | |
179 | ||
180 | foreach ($ids as $id) { | |
181 | ||
648472a7 | 182 | db_query($link, "UPDATE ttrss_entries SET unread=false,last_read = NOW() |
c3b81db0 AD |
183 | WHERE id = '$id'"); |
184 | ||
185 | } | |
186 | ||
187 | print "Marked active page as read."; | |
188 | } | |
189 | ||
190 | } | |
191 | ||
192 | if ($op == "feeds") { | |
193 | ||
194 | $subop = $_GET["subop"]; | |
195 | ||
196 | if ($subop == "catchupAll") { | |
648472a7 | 197 | db_query($link, "UPDATE ttrss_entries SET last_read = NOW(),unread = false"); |
c3b81db0 AD |
198 | } |
199 | ||
200 | outputFeedList($link); | |
201 | ||
1cd17194 AD |
202 | } |
203 | ||
204 | if ($op == "view") { | |
205 | ||
d76a3b03 AD |
206 | $id = $_GET["id"]; |
207 | ||
648472a7 | 208 | $result = db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'"); |
a1a8a2be | 209 | |
70830c87 AD |
210 | $addheader = $_GET["addheader"]; |
211 | ||
648472a7 | 212 | $result = db_query($link, "SELECT title,link,content,feed_id,comments, |
b7f4bda2 AD |
213 | (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url |
214 | FROM ttrss_entries | |
d76a3b03 | 215 | WHERE id = '$id'"); |
1cd17194 | 216 | |
70830c87 | 217 | if ($addheader) { |
f0601b87 | 218 | print "<html><head> |
70830c87 AD |
219 | <title>Tiny Tiny RSS : Article $id</title> |
220 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
c05608c2 | 221 | <script type=\"text/javascript\" src=\"functions.js\"></script> |
70830c87 | 222 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> |
f0601b87 | 223 | </head><body>"; |
70830c87 AD |
224 | } |
225 | ||
d76a3b03 | 226 | if ($result) { |
1cd17194 | 227 | |
648472a7 | 228 | $line = db_fetch_assoc($result); |
1cd17194 | 229 | |
b7f4bda2 AD |
230 | if ($line["icon_url"]) { |
231 | $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">"; | |
232 | } else { | |
233 | $feed_icon = " "; | |
234 | } | |
d76a3b03 | 235 | |
f7181e9b AD |
236 | if ($line["comments"] && $line["link"] != $line["comments"]) { |
237 | $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)"; | |
238 | } else { | |
239 | $entry_comments = ""; | |
240 | } | |
241 | ||
e828e31e AD |
242 | print "<div class=\"postReply\">"; |
243 | ||
244 | print "<div class=\"postHeader\"><table>"; | |
245 | ||
246 | print "<tr><td><b>Title:</b></td> | |
247 | <td width='100%'>" . $line["title"] . "</td></tr>"; | |
f7181e9b | 248 | |
e828e31e | 249 | print "<tr><td><b>Link:</b></td> |
f7181e9b AD |
250 | <td width='100%'> |
251 | <a href=\"" . $line["link"] . "\">".$line["link"]."</a> | |
252 | $entry_comments</td></tr>"; | |
e828e31e AD |
253 | |
254 | print "</table></div>"; | |
255 | ||
256 | print "<div class=\"postIcon\">" . $feed_icon . "</div>"; | |
257 | print "<div class=\"postContent\">" . $line["content"] . "</div>"; | |
258 | ||
259 | print "</div>"; | |
260 | ||
d76a3b03 | 261 | } |
70830c87 AD |
262 | |
263 | if ($addheader) { | |
264 | print "</body></html>"; | |
265 | } | |
1cd17194 AD |
266 | } |
267 | ||
268 | if ($op == "viewfeed") { | |
269 | ||
270 | $feed = $_GET["feed"]; | |
d76a3b03 | 271 | $skip = $_GET["skip"]; |
476cac42 | 272 | $subop = $_GET["subop"]; |
f175937c | 273 | $view_mode = $_GET["view"]; |
f0601b87 | 274 | $addheader = $_GET["addheader"]; |
cb1083a1 | 275 | $limit = $_GET["limit"]; |
a1a8a2be | 276 | |
ac53063a AD |
277 | if (!$skip) $skip = 0; |
278 | ||
476cac42 | 279 | if ($subop == "undefined") $subop = ""; |
1cd17194 | 280 | |
f0601b87 AD |
281 | if ($addheader) { |
282 | print "<html><head> | |
ac43eba1 | 283 | <title>Tiny Tiny RSS : Feed $feed</title> |
f0601b87 AD |
284 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> |
285 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
286 | <script type=\"text/javascript\" src=\"functions.js\"></script> | |
287 | <script type=\"text/javascript\" src=\"viewfeed.js\"></script> | |
288 | </head><body>"; | |
289 | } | |
290 | ||
ac53063a AD |
291 | // FIXME: check for null value here |
292 | ||
648472a7 | 293 | $result = db_query($link, "SELECT *,SUBSTRING(last_updated,1,16) as last_updated_s, |
82baad4a AD |
294 | EXTRACT(EPOCH FROM NOW()) - EXTRACT(EPOCH FROM last_updated) as update_timeout |
295 | FROM ttrss_feeds WHERE id = '$feed'"); | |
1cd17194 | 296 | |
d76a3b03 | 297 | if ($result) { |
1cd17194 | 298 | |
648472a7 | 299 | $line = db_fetch_assoc($result); |
1cd17194 | 300 | |
6113ef7d | 301 | if ($subop == "ForceUpdate" || |
1a66d16e AD |
302 | $line["last_updated"] == "" || |
303 | $line["update_timeout"] > MIN_UPDATE_TIME) { | |
d76a3b03 | 304 | |
f0601b87 AD |
305 | update_rss_feed($link, $line["feed_url"], $feed); |
306 | ||
a1a8a2be | 307 | } else { |
d76a3b03 | 308 | |
476cac42 | 309 | if ($subop == "MarkAllRead") { |
d76a3b03 | 310 | |
648472a7 | 311 | db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() |
a1a8a2be AD |
312 | WHERE feed_id = '$feed'"); |
313 | } | |
a1a8a2be AD |
314 | } |
315 | } | |
d76a3b03 | 316 | |
175847de | 317 | print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">"; |
ac53063a | 318 | |
a2015351 AD |
319 | $feed_last_updated = "Updated: " . $line["last_updated"]; |
320 | ||
c374a3fe AD |
321 | $search = $_GET["search"]; |
322 | ||
f175937c | 323 | if ($search) { |
ac53063a AD |
324 | $search_query_part = "(upper(title) LIKE upper('%$search%') |
325 | OR content LIKE '%$search%') AND"; | |
f175937c AD |
326 | } else { |
327 | $search_query_part = ""; | |
328 | } | |
329 | ||
330 | $view_query_part = ""; | |
331 | ||
332 | if ($view_mode == "Starred") { | |
333 | $view_query_part = " marked = true AND "; | |
ac53063a AD |
334 | } |
335 | ||
ac43eba1 AD |
336 | if ($view_mode == "Unread") { |
337 | $view_query_part = " unread = true AND "; | |
338 | } | |
339 | ||
648472a7 | 340 | $result = db_query($link, "SELECT count(id) AS total_entries |
36bf7496 AD |
341 | FROM ttrss_entries WHERE |
342 | $search_query_part | |
343 | feed_id = '$feed'"); | |
e6d1c0a0 | 344 | |
648472a7 | 345 | $total_entries = db_fetch_result($result, 0, "total_entries"); |
e6d1c0a0 | 346 | |
648472a7 | 347 | /* $result = db_query("SELECT count(id) AS unread_entries |
ac43eba1 AD |
348 | FROM ttrss_entries WHERE |
349 | $search_query_part | |
350 | unread = true AND | |
351 | feed_id = '$feed'"); | |
352 | ||
648472a7 | 353 | $unread_entries = db_fetch_result($result, 0, "unread_entries"); */ |
ac43eba1 | 354 | |
82c9223c AD |
355 | if ($limit != "All") { |
356 | $limit_query_part = "LIMIT " . $limit; | |
ad3cb710 | 357 | } |
f0601b87 | 358 | |
648472a7 | 359 | $result = db_query($link, "SELECT |
ac43eba1 | 360 | id,title,updated,unread,feed_id,marked,link, |
b197f117 AD |
361 | EXTRACT(EPOCH FROM last_read) AS last_read_ts, |
362 | EXTRACT(EPOCH FROM updated) AS updated_ts | |
363 | FROM | |
364 | ttrss_entries | |
365 | WHERE | |
ac53063a | 366 | $search_query_part |
f175937c | 367 | $view_query_part |
f0601b87 AD |
368 | feed_id = '$feed' ORDER BY updated DESC |
369 | $limit_query_part"); | |
d76a3b03 | 370 | |
a1a8a2be | 371 | $lnum = 0; |
e1123aee AD |
372 | |
373 | $num_unread = 0; | |
d76a3b03 | 374 | |
648472a7 | 375 | while ($line = db_fetch_assoc($result)) { |
d76a3b03 | 376 | |
a1a8a2be | 377 | $class = ($lnum % 2) ? "even" : "odd"; |
d76a3b03 | 378 | |
ad99045e AD |
379 | $id = $line["id"]; |
380 | $feed_id = $line["feed_id"]; | |
381 | ||
b197f117 | 382 | if ($line["last_read_ts"] < $line["updated_ts"] && $line["unread"] == "f") { |
ad99045e AD |
383 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\" |
384 | alt=\"Updated\">"; | |
e1123aee | 385 | ++$num_unread; |
b197f117 | 386 | } else { |
ad99045e AD |
387 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.png\" |
388 | alt=\"Updated\">"; | |
b197f117 AD |
389 | } |
390 | ||
e1123aee | 391 | if ($line["unread"] == "t") { |
a1a8a2be | 392 | $class .= "Unread"; |
e1123aee AD |
393 | ++$num_unread; |
394 | } | |
d76a3b03 | 395 | |
f4c10d44 AD |
396 | if ($line["marked"] == "t") { |
397 | $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\" | |
398 | alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>"; | |
399 | } else { | |
400 | $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\" | |
401 | alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>"; | |
402 | } | |
403 | ||
ac43eba1 | 404 | $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" . |
b197f117 AD |
405 | $line["title"] . "</a>"; |
406 | ||
5f89f780 AD |
407 | print "<tr class='$class' id='RROW-$id'"; |
408 | // onclick=\"javascript:view($id,$feed_id)\"> | |
b197f117 | 409 | |
ad99045e | 410 | print "<td valign='center' align='center' |
f4c10d44 AD |
411 | class='headlineUpdateMark'>$update_pic</td>"; |
412 | ||
c80e2175 | 413 | print "<td valign='center' align='center' |
f4c10d44 | 414 | class='headlineUpdateMark'>$marked_pic</td>"; |
b197f117 | 415 | |
c80e2175 | 416 | print "<td class='headlineUpdated' width='25%'> |
a3ee2a38 | 417 | <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>"; |
c80e2175 | 418 | print "<td width='70%' class='headlineTitle'>$content_link</td>"; |
d76a3b03 | 419 | |
a1a8a2be | 420 | print "</tr>"; |
d76a3b03 | 421 | |
a1a8a2be AD |
422 | ++$lnum; |
423 | } | |
d76a3b03 | 424 | |
ac53063a AD |
425 | if ($lnum == 0) { |
426 | print "<tr><td align='center'>No entries found.</td></tr>"; | |
047bae73 | 427 | } |
ac53063a | 428 | |
047bae73 AD |
429 | while ($lnum < HEADLINES_PER_PAGE) { |
430 | ++$lnum; | |
431 | print "<tr><td> </td></tr>"; | |
ac53063a | 432 | } |
a2015351 | 433 | |
a1a8a2be | 434 | print "</table>"; |
d76a3b03 | 435 | |
648472a7 | 436 | $result = db_query($link, "SELECT id, (SELECT count(id) FROM ttrss_entries |
a1a8a2be AD |
437 | WHERE feed_id = ttrss_feeds.id) AS total, |
438 | (SELECT count(id) FROM ttrss_entries | |
439 | WHERE feed_id = ttrss_feeds.id AND unread = true) as unread | |
440 | FROM ttrss_feeds WHERE id = '$feed'"); | |
d76a3b03 | 441 | |
648472a7 AD |
442 | $total = db_fetch_result($result, 0, "total"); |
443 | $unread = db_fetch_result($result, 0, "unread"); | |
d76a3b03 | 444 | |
6113ef7d AD |
445 | // update unread/total counters and status for active feed in the feedlist |
446 | // kludge, because iframe doesn't seem to support onload() | |
447 | ||
448 | print "<script type=\"text/javascript\"> | |
bb7cface AD |
449 | document.onkeydown = hotkey_handler; |
450 | ||
1a66d16e AD |
451 | var p_document = parent.frames['feeds-frame'].document; |
452 | ||
453 | var feedr = p_document.getElementById(\"FEEDR-\" + $feed); | |
1a66d16e | 454 | var feedu = p_document.getElementById(\"FEEDU-\" + $feed); |
6113ef7d | 455 | |
0c674406 AD |
456 | if (feedu) { |
457 | feedu.innerHTML = \"$unread\"; | |
458 | } | |
459 | ||
460 | var feedctr = p_document.getElementById(\"FEEDCTR-\" + $feed); | |
6113ef7d AD |
461 | |
462 | if ($unread > 0 && !feedr.className.match(\"Unread\")) { | |
463 | feedr.className = feedr.className + \"Unread\"; | |
0c674406 | 464 | feedctr.className = ''; |
6113ef7d AD |
465 | } else if ($unread <= 0) { |
466 | feedr.className = feedr.className.replace(\"Unread\", \"\"); | |
0c674406 | 467 | feedctr.className = 'invisible'; |
6113ef7d | 468 | } |
c05608c2 | 469 | |
90e395dc | 470 | // p_notify(\"\"); |
0c674406 | 471 | |
6113ef7d | 472 | </script>"; |
d76a3b03 | 473 | |
f0601b87 AD |
474 | if ($addheader) { |
475 | print "</body></html>"; | |
476 | } | |
477 | ||
1cd17194 AD |
478 | } |
479 | ||
0e091d38 | 480 | if ($op == "pref-rpc") { |
331900c6 | 481 | |
0e091d38 | 482 | $subop = $_GET["subop"]; |
331900c6 | 483 | |
83fe4d6d AD |
484 | if ($subop == "unread") { |
485 | $ids = split(",", $_GET["ids"]); | |
486 | foreach ($ids as $id) { | |
648472a7 | 487 | db_query($link, "UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'"); |
83fe4d6d | 488 | } |
0e091d38 AD |
489 | |
490 | print "Marked selected feeds as read."; | |
83fe4d6d AD |
491 | } |
492 | ||
493 | if ($subop == "read") { | |
494 | $ids = split(",", $_GET["ids"]); | |
495 | foreach ($ids as $id) { | |
648472a7 | 496 | db_query($link, "UPDATE ttrss_entries |
b197f117 | 497 | SET unread = false,last_read = NOW() WHERE feed_id = '$id'"); |
83fe4d6d | 498 | } |
0e091d38 AD |
499 | |
500 | print "Marked selected feeds as unread."; | |
501 | ||
502 | } | |
503 | ||
504 | } | |
505 | ||
506 | if ($op == "pref-feeds") { | |
507 | ||
508 | $subop = $_GET["subop"]; | |
509 | ||
508a81e1 | 510 | if ($subop == "editSave") { |
648472a7 AD |
511 | $feed_title = db_escape_string($_GET["t"]); |
512 | $feed_link = db_escape_string($_GET["l"]); | |
508a81e1 AD |
513 | $feed_id = $_GET["id"]; |
514 | ||
648472a7 | 515 | $result = db_query($link, "UPDATE ttrss_feeds SET |
508a81e1 AD |
516 | title = '$feed_title', feed_url = '$feed_link' WHERE id = '$feed_id'"); |
517 | ||
83fe4d6d AD |
518 | } |
519 | ||
331900c6 | 520 | if ($subop == "remove") { |
331900c6 | 521 | |
b0b4abcf | 522 | if (!WEB_DEMO_MODE) { |
331900c6 | 523 | |
b0b4abcf AD |
524 | $ids = split(",", $_GET["ids"]); |
525 | ||
526 | foreach ($ids as $id) { | |
648472a7 AD |
527 | db_query($link, "BEGIN"); |
528 | db_query($link, "DELETE FROM ttrss_entries WHERE feed_id = '$id'"); | |
529 | db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'"); | |
530 | db_query($link, "COMMIT"); | |
d5caaae5 AD |
531 | |
532 | if (file_exists(ICONS_DIR . "/$id.ico")) { | |
533 | unlink(ICONS_DIR . "/$id.ico"); | |
534 | } | |
b0b4abcf | 535 | } |
331900c6 AD |
536 | } |
537 | } | |
538 | ||
539 | if ($subop == "add") { | |
b0b4abcf AD |
540 | |
541 | if (!WEB_DEMO_MODE) { | |
331900c6 | 542 | |
648472a7 | 543 | $feed_link = db_escape_string($_GET["link"]); |
b0b4abcf | 544 | |
648472a7 | 545 | $result = db_query($link, |
b0b4abcf | 546 | "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')"); |
331900c6 | 547 | |
648472a7 | 548 | $result = db_query($link, |
e9c54861 | 549 | "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'"); |
331900c6 | 550 | |
648472a7 | 551 | $feed_id = db_fetch_result($result, 0, "id"); |
331900c6 | 552 | |
b0b4abcf AD |
553 | if ($feed_id) { |
554 | update_rss_feed($link, $feed_link, $feed_id); | |
555 | } | |
556 | } | |
331900c6 | 557 | } |
a0d53889 AD |
558 | |
559 | print "<table class=\"prefAddFeed\"><tr> | |
560 | <td><input id=\"fadd_link\"></td> | |
561 | <td colspan=\"4\" align=\"right\"> | |
562 | <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr> | |
563 | </table>"; | |
564 | ||
648472a7 | 565 | $result = db_query($link, "SELECT |
c0e5a40e AD |
566 | id,title,feed_url,substring(last_updated,1,16) as last_updated |
567 | FROM | |
568 | ttrss_feeds ORDER by title"); | |
1cd17194 | 569 | |
331900c6 | 570 | print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">"; |
007bda35 | 571 | print "<tr class=\"title\"> |
603c27f8 | 572 | <td> </td><td>Select</td><td width=\"40%\">Title</td> |
0afbd851 | 573 | <td width=\"40%\">Link</td><td>Last updated</td></tr>"; |
007bda35 AD |
574 | |
575 | $lnum = 0; | |
576 | ||
648472a7 | 577 | while ($line = db_fetch_assoc($result)) { |
007bda35 AD |
578 | |
579 | $class = ($lnum % 2) ? "even" : "odd"; | |
9b307248 | 580 | |
331900c6 | 581 | $feed_id = $line["id"]; |
603c27f8 AD |
582 | |
583 | $edit_feed_id = $_GET["id"]; | |
584 | ||
9b307248 AD |
585 | if ($subop == "edit" && $feed_id != $edit_feed_id) { |
586 | $class .= "Grayed"; | |
587 | } | |
588 | ||
331900c6 | 589 | print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">"; |
007bda35 | 590 | |
c0e5a40e AD |
591 | $icon_file = ICONS_DIR . "/$feed_id.ico"; |
592 | ||
593 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
594 | $feed_icon = "<img width=\"16\" height=\"16\" | |
595 | src=\"" . ICONS_URL . "/$feed_id.ico\">"; | |
596 | } else { | |
597 | $feed_icon = " "; | |
598 | } | |
599 | print "<td align='center'>$feed_icon</td>"; | |
600 | ||
9b307248 | 601 | if (!$edit_feed_id || $subop != "edit") { |
603c27f8 AD |
602 | |
603 | print "<td><input onclick='toggleSelectRow(this);' | |
331900c6 | 604 | type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>"; |
603c27f8 AD |
605 | |
606 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
607 | $line["title"] . "</td>"; | |
608 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
609 | $line["feed_url"] . "</td>"; | |
9b307248 AD |
610 | |
611 | ||
612 | } else if ($feed_id != $edit_feed_id) { | |
613 | ||
e9c54861 AD |
614 | print "<td><input disabled=\"true\" type=\"checkbox\" |
615 | id=\"FRCHK-".$line["id"]."\"></td>"; | |
9b307248 AD |
616 | |
617 | print "<td>".$line["title"]."</td>"; | |
618 | print "<td>".$line["feed_url"]."</td>"; | |
619 | ||
603c27f8 AD |
620 | } else { |
621 | ||
e9c54861 | 622 | print "<td><input disabled=\"true\" type=\"checkbox\"></td>"; |
603c27f8 AD |
623 | |
624 | print "<td><input id=\"iedit_title\" value=\"".$line["title"]."\"></td>"; | |
625 | print "<td><input id=\"iedit_link\" value=\"".$line["feed_url"]."\"></td>"; | |
626 | ||
627 | } | |
0afbd851 AD |
628 | |
629 | if (!$line["last_updated"]) $line["last_updated"] = "Never"; | |
630 | ||
007bda35 | 631 | print "<td>" . $line["last_updated"] . "</td>"; |
603c27f8 | 632 | |
007bda35 AD |
633 | print "</tr>"; |
634 | ||
635 | ++$lnum; | |
636 | } | |
637 | ||
0afbd851 AD |
638 | if ($lnum == 0) { |
639 | print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>"; | |
640 | } | |
641 | ||
007bda35 AD |
642 | print "</table>"; |
643 | ||
603c27f8 AD |
644 | print "<p>"; |
645 | ||
646 | if ($subop == "edit") { | |
647 | print "Edit feed: | |
e828e31e AD |
648 | <input type=\"submit\" class=\"button\" |
649 | onclick=\"javascript:feedEditCancel()\" value=\"Cancel\"> | |
650 | <input type=\"submit\" class=\"button\" | |
651 | onclickf=\"javascript:feedEditSave()\" value=\"Save\">"; | |
603c27f8 AD |
652 | } else { |
653 | ||
603c27f8 AD |
654 | print " |
655 | Selection: | |
e828e31e AD |
656 | <input type=\"submit\" class=\"button\" |
657 | onclick=\"javascript:editSelectedFeed()\" value=\"Edit\"> | |
658 | <input type=\"submit\" class=\"button\" | |
659 | onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">"; | |
660 | ||
f92db4f5 AD |
661 | if (ENABLE_PREFS_CATCHUP_UNCATCHUP) { |
662 | print " | |
e828e31e AD |
663 | <input type=\"submit\" class=\"button\" |
664 | onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\"> | |
665 | <input type=\"submit\" class=\"button\" | |
666 | onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\"> "; | |
f92db4f5 AD |
667 | } |
668 | print " | |
e828e31e AD |
669 | All feeds: |
670 | <input type=\"submit\" | |
671 | class=\"button\" onclick=\"opml.php?op=Export\" value=\"Export OPML\">"; | |
10c5820d | 672 | |
603c27f8 AD |
673 | } |
674 | ||
007bda35 AD |
675 | } |
676 | ||
a0d53889 AD |
677 | if ($op == "pref-filters") { |
678 | ||
679 | $subop = $_GET["subop"]; | |
680 | ||
681 | if ($subop == "editSave") { | |
a0d53889 | 682 | |
648472a7 AD |
683 | $regexp = db_escape_string($_GET["r"]); |
684 | $descr = db_escape_string($_GET["d"]); | |
685 | $match = db_escape_string($_GET["m"]); | |
686 | $filter_id = db_escape_string($_GET["id"]); | |
0afbd851 | 687 | |
648472a7 | 688 | $result = db_query($link, "UPDATE ttrss_filters SET |
0afbd851 AD |
689 | regexp = '$regexp', |
690 | description = '$descr', | |
691 | filter_type = (SELECT id FROM ttrss_filter_types WHERE | |
692 | description = '$match') | |
693 | WHERE id = '$filter_id'"); | |
a0d53889 AD |
694 | } |
695 | ||
696 | if ($subop == "remove") { | |
697 | ||
698 | if (!WEB_DEMO_MODE) { | |
699 | ||
700 | $ids = split(",", $_GET["ids"]); | |
701 | ||
702 | foreach ($ids as $id) { | |
648472a7 | 703 | db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'"); |
a0d53889 AD |
704 | |
705 | } | |
706 | } | |
707 | } | |
708 | ||
709 | if ($subop == "add") { | |
710 | ||
de435974 | 711 | if (!WEB_DEMO_MODE) { |
a0d53889 | 712 | |
648472a7 AD |
713 | $regexp = db_escape_string($_GET["regexp"]); |
714 | $match = db_escape_string($_GET["match"]); | |
a0d53889 | 715 | |
648472a7 | 716 | $result = db_query($link, |
de435974 AD |
717 | "INSERT INTO ttrss_filters (regexp,filter_type) VALUES |
718 | ('$regexp', (SELECT id FROM ttrss_filter_types WHERE | |
719 | description = '$match'))"); | |
720 | } | |
a0d53889 AD |
721 | } |
722 | ||
648472a7 | 723 | $result = db_query($link, "SELECT description |
a0d53889 AD |
724 | FROM ttrss_filter_types ORDER BY description"); |
725 | ||
726 | $filter_types = array(); | |
727 | ||
648472a7 | 728 | while ($line = db_fetch_assoc($result)) { |
a0d53889 AD |
729 | array_push($filter_types, $line["description"]); |
730 | } | |
731 | ||
732 | print "<table class=\"prefAddFeed\"><tr> | |
ea6774cf | 733 | <td><input id=\"fadd_regexp\"></td> |
a0d53889 | 734 | <td>"; |
bdc00fe0 | 735 | print_select("fadd_match", "Title", $filter_types); |
a0d53889 AD |
736 | |
737 | print"</td><td colspan=\"4\" align=\"right\"> | |
738 | <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr> | |
739 | </table>"; | |
740 | ||
648472a7 | 741 | $result = db_query($link, "SELECT |
a0d53889 AD |
742 | id,regexp,description, |
743 | (SELECT name FROM ttrss_filter_types WHERE | |
744 | id = filter_type) as filter_type_name, | |
745 | (SELECT description FROM ttrss_filter_types | |
746 | WHERE id = filter_type) as filter_type_descr | |
747 | FROM | |
ea6774cf | 748 | ttrss_filters ORDER by regexp"); |
a0d53889 AD |
749 | |
750 | print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">"; | |
751 | ||
752 | print "<tr class=\"title\"> | |
0afbd851 AD |
753 | <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td> |
754 | <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>"; | |
a0d53889 AD |
755 | |
756 | $lnum = 0; | |
757 | ||
648472a7 | 758 | while ($line = db_fetch_assoc($result)) { |
a0d53889 AD |
759 | |
760 | $class = ($lnum % 2) ? "even" : "odd"; | |
761 | ||
762 | $filter_id = $line["id"]; | |
763 | $edit_filter_id = $_GET["id"]; | |
764 | ||
765 | if ($subop == "edit" && $filter_id != $edit_filter_id) { | |
766 | $class .= "Grayed"; | |
767 | } | |
768 | ||
769 | print "<tr class=\"$class\" id=\"FILRR-$filter_id\">"; | |
770 | ||
ea6774cf AD |
771 | $line["regexp"] = htmlspecialchars($line["regexp"]); |
772 | $line["description"] = htmlspecialchars($line["description"]); | |
773 | ||
a0d53889 AD |
774 | if (!$edit_filter_id || $subop != "edit") { |
775 | ||
0afbd851 AD |
776 | if (!$line["description"]) $line["description"] = "[No description]"; |
777 | ||
a0d53889 AD |
778 | print "<td><input onclick='toggleSelectRow(this);' |
779 | type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>"; | |
780 | ||
781 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
782 | $line["regexp"] . "</td>"; | |
783 | ||
784 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
785 | $line["description"] . "</td>"; | |
786 | ||
787 | print "<td>".$line["filter_type_descr"]."</td>"; | |
788 | ||
789 | } else if ($filter_id != $edit_filter_id) { | |
790 | ||
0afbd851 AD |
791 | if (!$line["description"]) $line["description"] = "[No description]"; |
792 | ||
a0d53889 AD |
793 | print "<td><input disabled=\"true\" type=\"checkbox\" |
794 | id=\"FICHK-".$line["id"]."\"></td>"; | |
795 | ||
796 | print "<td>".$line["regexp"]."</td>"; | |
797 | print "<td>".$line["description"]."</td>"; | |
798 | print "<td>".$line["filter_type_descr"]."</td>"; | |
799 | ||
800 | } else { | |
801 | ||
802 | print "<td><input disabled=\"true\" type=\"checkbox\"></td>"; | |
803 | ||
804 | print "<td><input id=\"iedit_regexp\" value=\"".$line["regexp"]. | |
805 | "\"></td>"; | |
806 | ||
807 | print "<td><input id=\"iedit_descr\" value=\"".$line["description"]. | |
808 | "\"></td>"; | |
809 | ||
810 | print "<td>"; | |
811 | print_select("iedit_match", $line["filter_type_descr"], $filter_types); | |
812 | print "</td>"; | |
813 | ||
814 | } | |
815 | ||
816 | ||
817 | print "</tr>"; | |
818 | ||
819 | ++$lnum; | |
820 | } | |
821 | ||
0afbd851 AD |
822 | if ($lnum == 0) { |
823 | print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>"; | |
824 | } | |
825 | ||
a0d53889 AD |
826 | print "</table>"; |
827 | ||
828 | print "<p>"; | |
829 | ||
830 | if ($subop == "edit") { | |
e828e31e AD |
831 | print "Edit feed: |
832 | <input type=\"submit\" class=\"button\" | |
833 | onclick=\"javascript:filterEditCancel()\" value=\"Cancel\"> | |
834 | <input type=\"submit\" class=\"button\" | |
835 | onclick=\"javascript:filterEditSave()\" value=\"Save\">"; | |
a0d53889 AD |
836 | |
837 | } else { | |
838 | ||
839 | print " | |
e828e31e AD |
840 | Selection: |
841 | <input type=\"submit\" class=\"button\" | |
842 | onclick=\"javascript:editSelectedFilter()\" value=\"Edit\"> | |
843 | <input type=\"submit\" class=\"button\" | |
844 | onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">"; | |
a0d53889 AD |
845 | } |
846 | } | |
847 | ||
e828e31e AD |
848 | if ($op == "error") { |
849 | print "<div width=\"100%\" align='center'>"; | |
850 | $msg = $_GET["msg"]; | |
851 | print $msg; | |
852 | print "</div>"; | |
853 | } | |
854 | ||
007bda35 | 855 | pg_close($link); |
1cd17194 | 856 | ?> |