]>
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 | ||
8158c57a AD |
291 | if (DB_TYPE == "pgsql") { |
292 | $result = db_query($link, | |
293 | "SELECT *,SUBSTRING(last_updated,1,16) as last_updated_s, | |
294 | EXTRACT(EPOCH FROM NOW()) - EXTRACT(EPOCH FROM last_updated) as update_timeout | |
295 | FROM ttrss_feeds WHERE id = '$feed'"); | |
296 | } else { | |
297 | $result = db_query($link, | |
298 | "SELECT *,SUBSTRING(last_updated,1,16) as last_updated_s | |
299 | FROM ttrss_feeds WHERE id = '$feed'"); | |
300 | } | |
1cd17194 | 301 | |
d76a3b03 | 302 | if ($result) { |
1cd17194 | 303 | |
648472a7 | 304 | $line = db_fetch_assoc($result); |
1cd17194 | 305 | |
deaaa02c | 306 | update_rss_feed($link, $line["feed_url"], $feed); |
f0601b87 | 307 | |
deaaa02c | 308 | if ($subop == "MarkAllRead") { |
d76a3b03 | 309 | |
deaaa02c AD |
310 | db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() |
311 | WHERE feed_id = '$feed'"); | |
a1a8a2be AD |
312 | } |
313 | } | |
d76a3b03 | 314 | |
175847de | 315 | print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">"; |
ac53063a | 316 | |
a2015351 AD |
317 | $feed_last_updated = "Updated: " . $line["last_updated"]; |
318 | ||
c374a3fe AD |
319 | $search = $_GET["search"]; |
320 | ||
f175937c | 321 | if ($search) { |
ac53063a AD |
322 | $search_query_part = "(upper(title) LIKE upper('%$search%') |
323 | OR content LIKE '%$search%') AND"; | |
f175937c AD |
324 | } else { |
325 | $search_query_part = ""; | |
326 | } | |
327 | ||
328 | $view_query_part = ""; | |
329 | ||
330 | if ($view_mode == "Starred") { | |
331 | $view_query_part = " marked = true AND "; | |
ac53063a AD |
332 | } |
333 | ||
ac43eba1 AD |
334 | if ($view_mode == "Unread") { |
335 | $view_query_part = " unread = true AND "; | |
336 | } | |
337 | ||
648472a7 | 338 | $result = db_query($link, "SELECT count(id) AS total_entries |
36bf7496 AD |
339 | FROM ttrss_entries WHERE |
340 | $search_query_part | |
341 | feed_id = '$feed'"); | |
e6d1c0a0 | 342 | |
648472a7 | 343 | $total_entries = db_fetch_result($result, 0, "total_entries"); |
e6d1c0a0 | 344 | |
648472a7 | 345 | /* $result = db_query("SELECT count(id) AS unread_entries |
ac43eba1 AD |
346 | FROM ttrss_entries WHERE |
347 | $search_query_part | |
348 | unread = true AND | |
349 | feed_id = '$feed'"); | |
350 | ||
648472a7 | 351 | $unread_entries = db_fetch_result($result, 0, "unread_entries"); */ |
ac43eba1 | 352 | |
82c9223c AD |
353 | if ($limit != "All") { |
354 | $limit_query_part = "LIMIT " . $limit; | |
ad3cb710 | 355 | } |
f0601b87 | 356 | |
648472a7 | 357 | $result = db_query($link, "SELECT |
deaaa02c | 358 | id,title,updated,unread,feed_id,marked,link,last_read |
b197f117 AD |
359 | FROM |
360 | ttrss_entries | |
361 | WHERE | |
ac53063a | 362 | $search_query_part |
f175937c | 363 | $view_query_part |
f0601b87 AD |
364 | feed_id = '$feed' ORDER BY updated DESC |
365 | $limit_query_part"); | |
d76a3b03 | 366 | |
a1a8a2be | 367 | $lnum = 0; |
e1123aee AD |
368 | |
369 | $num_unread = 0; | |
d76a3b03 | 370 | |
648472a7 | 371 | while ($line = db_fetch_assoc($result)) { |
d76a3b03 | 372 | |
a1a8a2be | 373 | $class = ($lnum % 2) ? "even" : "odd"; |
d76a3b03 | 374 | |
ad99045e AD |
375 | $id = $line["id"]; |
376 | $feed_id = $line["feed_id"]; | |
377 | ||
deaaa02c AD |
378 | // printf("%d %s - %d %s<br>", strtotime($line["last_read"]), $line["last_read"], |
379 | // strtotime($line["updated"]), $line["updated"]); | |
380 | ||
381 | if (strtotime($line["last_read"]) < strtotime($line["updated"]) && | |
382 | ($line["unread"] == "f" || $line["unread"] == "0")) { | |
383 | ||
ad99045e AD |
384 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\" |
385 | alt=\"Updated\">"; | |
e1123aee | 386 | ++$num_unread; |
b197f117 | 387 | } else { |
ad99045e AD |
388 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.png\" |
389 | alt=\"Updated\">"; | |
b197f117 AD |
390 | } |
391 | ||
8158c57a | 392 | if ($line["unread"] == "t" || $line["unread"] == "1") { |
a1a8a2be | 393 | $class .= "Unread"; |
e1123aee AD |
394 | ++$num_unread; |
395 | } | |
d76a3b03 | 396 | |
8158c57a | 397 | if ($line["marked"] == "t" || $line["marked"] == "1") { |
f4c10d44 AD |
398 | $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\" |
399 | alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>"; | |
400 | } else { | |
401 | $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\" | |
402 | alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>"; | |
403 | } | |
404 | ||
ac43eba1 | 405 | $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" . |
b197f117 AD |
406 | $line["title"] . "</a>"; |
407 | ||
5f89f780 AD |
408 | print "<tr class='$class' id='RROW-$id'"; |
409 | // onclick=\"javascript:view($id,$feed_id)\"> | |
b197f117 | 410 | |
ad99045e | 411 | print "<td valign='center' align='center' |
f4c10d44 AD |
412 | class='headlineUpdateMark'>$update_pic</td>"; |
413 | ||
c80e2175 | 414 | print "<td valign='center' align='center' |
f4c10d44 | 415 | class='headlineUpdateMark'>$marked_pic</td>"; |
b197f117 | 416 | |
c80e2175 | 417 | print "<td class='headlineUpdated' width='25%'> |
a3ee2a38 | 418 | <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>"; |
c80e2175 | 419 | print "<td width='70%' class='headlineTitle'>$content_link</td>"; |
d76a3b03 | 420 | |
a1a8a2be | 421 | print "</tr>"; |
d76a3b03 | 422 | |
a1a8a2be AD |
423 | ++$lnum; |
424 | } | |
d76a3b03 | 425 | |
ac53063a AD |
426 | if ($lnum == 0) { |
427 | print "<tr><td align='center'>No entries found.</td></tr>"; | |
047bae73 | 428 | } |
ac53063a | 429 | |
047bae73 AD |
430 | while ($lnum < HEADLINES_PER_PAGE) { |
431 | ++$lnum; | |
432 | print "<tr><td> </td></tr>"; | |
ac53063a | 433 | } |
a2015351 | 434 | |
a1a8a2be | 435 | print "</table>"; |
d76a3b03 | 436 | |
648472a7 | 437 | $result = db_query($link, "SELECT id, (SELECT count(id) FROM ttrss_entries |
a1a8a2be AD |
438 | WHERE feed_id = ttrss_feeds.id) AS total, |
439 | (SELECT count(id) FROM ttrss_entries | |
440 | WHERE feed_id = ttrss_feeds.id AND unread = true) as unread | |
441 | FROM ttrss_feeds WHERE id = '$feed'"); | |
d76a3b03 | 442 | |
648472a7 AD |
443 | $total = db_fetch_result($result, 0, "total"); |
444 | $unread = db_fetch_result($result, 0, "unread"); | |
d76a3b03 | 445 | |
6113ef7d AD |
446 | // update unread/total counters and status for active feed in the feedlist |
447 | // kludge, because iframe doesn't seem to support onload() | |
448 | ||
449 | print "<script type=\"text/javascript\"> | |
bb7cface AD |
450 | document.onkeydown = hotkey_handler; |
451 | ||
1a66d16e AD |
452 | var p_document = parent.frames['feeds-frame'].document; |
453 | ||
454 | var feedr = p_document.getElementById(\"FEEDR-\" + $feed); | |
1a66d16e | 455 | var feedu = p_document.getElementById(\"FEEDU-\" + $feed); |
6113ef7d | 456 | |
0c674406 AD |
457 | if (feedu) { |
458 | feedu.innerHTML = \"$unread\"; | |
459 | } | |
460 | ||
461 | var feedctr = p_document.getElementById(\"FEEDCTR-\" + $feed); | |
6113ef7d AD |
462 | |
463 | if ($unread > 0 && !feedr.className.match(\"Unread\")) { | |
464 | feedr.className = feedr.className + \"Unread\"; | |
0c674406 | 465 | feedctr.className = ''; |
6113ef7d AD |
466 | } else if ($unread <= 0) { |
467 | feedr.className = feedr.className.replace(\"Unread\", \"\"); | |
0c674406 | 468 | feedctr.className = 'invisible'; |
6113ef7d | 469 | } |
c05608c2 | 470 | |
90e395dc | 471 | // p_notify(\"\"); |
0c674406 | 472 | |
6113ef7d | 473 | </script>"; |
d76a3b03 | 474 | |
f0601b87 AD |
475 | if ($addheader) { |
476 | print "</body></html>"; | |
477 | } | |
478 | ||
1cd17194 AD |
479 | } |
480 | ||
0e091d38 | 481 | if ($op == "pref-rpc") { |
331900c6 | 482 | |
0e091d38 | 483 | $subop = $_GET["subop"]; |
331900c6 | 484 | |
83fe4d6d AD |
485 | if ($subop == "unread") { |
486 | $ids = split(",", $_GET["ids"]); | |
487 | foreach ($ids as $id) { | |
648472a7 | 488 | db_query($link, "UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'"); |
83fe4d6d | 489 | } |
0e091d38 AD |
490 | |
491 | print "Marked selected feeds as read."; | |
83fe4d6d AD |
492 | } |
493 | ||
494 | if ($subop == "read") { | |
495 | $ids = split(",", $_GET["ids"]); | |
496 | foreach ($ids as $id) { | |
648472a7 | 497 | db_query($link, "UPDATE ttrss_entries |
b197f117 | 498 | SET unread = false,last_read = NOW() WHERE feed_id = '$id'"); |
83fe4d6d | 499 | } |
0e091d38 AD |
500 | |
501 | print "Marked selected feeds as unread."; | |
502 | ||
503 | } | |
504 | ||
505 | } | |
506 | ||
507 | if ($op == "pref-feeds") { | |
508 | ||
509 | $subop = $_GET["subop"]; | |
510 | ||
508a81e1 | 511 | if ($subop == "editSave") { |
648472a7 AD |
512 | $feed_title = db_escape_string($_GET["t"]); |
513 | $feed_link = db_escape_string($_GET["l"]); | |
508a81e1 AD |
514 | $feed_id = $_GET["id"]; |
515 | ||
648472a7 | 516 | $result = db_query($link, "UPDATE ttrss_feeds SET |
508a81e1 AD |
517 | title = '$feed_title', feed_url = '$feed_link' WHERE id = '$feed_id'"); |
518 | ||
83fe4d6d AD |
519 | } |
520 | ||
331900c6 | 521 | if ($subop == "remove") { |
331900c6 | 522 | |
b0b4abcf | 523 | if (!WEB_DEMO_MODE) { |
331900c6 | 524 | |
b0b4abcf AD |
525 | $ids = split(",", $_GET["ids"]); |
526 | ||
527 | foreach ($ids as $id) { | |
648472a7 AD |
528 | db_query($link, "BEGIN"); |
529 | db_query($link, "DELETE FROM ttrss_entries WHERE feed_id = '$id'"); | |
530 | db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'"); | |
531 | db_query($link, "COMMIT"); | |
d5caaae5 AD |
532 | |
533 | if (file_exists(ICONS_DIR . "/$id.ico")) { | |
534 | unlink(ICONS_DIR . "/$id.ico"); | |
535 | } | |
b0b4abcf | 536 | } |
331900c6 AD |
537 | } |
538 | } | |
539 | ||
540 | if ($subop == "add") { | |
b0b4abcf AD |
541 | |
542 | if (!WEB_DEMO_MODE) { | |
331900c6 | 543 | |
648472a7 | 544 | $feed_link = db_escape_string($_GET["link"]); |
b0b4abcf | 545 | |
648472a7 | 546 | $result = db_query($link, |
b0b4abcf | 547 | "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')"); |
331900c6 | 548 | |
648472a7 | 549 | $result = db_query($link, |
e9c54861 | 550 | "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'"); |
331900c6 | 551 | |
648472a7 | 552 | $feed_id = db_fetch_result($result, 0, "id"); |
331900c6 | 553 | |
b0b4abcf AD |
554 | if ($feed_id) { |
555 | update_rss_feed($link, $feed_link, $feed_id); | |
556 | } | |
557 | } | |
331900c6 | 558 | } |
a0d53889 AD |
559 | |
560 | print "<table class=\"prefAddFeed\"><tr> | |
561 | <td><input id=\"fadd_link\"></td> | |
562 | <td colspan=\"4\" align=\"right\"> | |
563 | <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr> | |
564 | </table>"; | |
565 | ||
648472a7 | 566 | $result = db_query($link, "SELECT |
c0e5a40e AD |
567 | id,title,feed_url,substring(last_updated,1,16) as last_updated |
568 | FROM | |
569 | ttrss_feeds ORDER by title"); | |
1cd17194 | 570 | |
331900c6 | 571 | print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">"; |
007bda35 | 572 | print "<tr class=\"title\"> |
603c27f8 | 573 | <td> </td><td>Select</td><td width=\"40%\">Title</td> |
0afbd851 | 574 | <td width=\"40%\">Link</td><td>Last updated</td></tr>"; |
007bda35 AD |
575 | |
576 | $lnum = 0; | |
577 | ||
648472a7 | 578 | while ($line = db_fetch_assoc($result)) { |
007bda35 AD |
579 | |
580 | $class = ($lnum % 2) ? "even" : "odd"; | |
9b307248 | 581 | |
331900c6 | 582 | $feed_id = $line["id"]; |
603c27f8 AD |
583 | |
584 | $edit_feed_id = $_GET["id"]; | |
585 | ||
9b307248 AD |
586 | if ($subop == "edit" && $feed_id != $edit_feed_id) { |
587 | $class .= "Grayed"; | |
588 | } | |
589 | ||
331900c6 | 590 | print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">"; |
007bda35 | 591 | |
c0e5a40e AD |
592 | $icon_file = ICONS_DIR . "/$feed_id.ico"; |
593 | ||
594 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
595 | $feed_icon = "<img width=\"16\" height=\"16\" | |
596 | src=\"" . ICONS_URL . "/$feed_id.ico\">"; | |
597 | } else { | |
598 | $feed_icon = " "; | |
599 | } | |
600 | print "<td align='center'>$feed_icon</td>"; | |
601 | ||
9b307248 | 602 | if (!$edit_feed_id || $subop != "edit") { |
603c27f8 AD |
603 | |
604 | print "<td><input onclick='toggleSelectRow(this);' | |
331900c6 | 605 | type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>"; |
603c27f8 AD |
606 | |
607 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
608 | $line["title"] . "</td>"; | |
609 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
610 | $line["feed_url"] . "</td>"; | |
9b307248 AD |
611 | |
612 | ||
613 | } else if ($feed_id != $edit_feed_id) { | |
614 | ||
e9c54861 AD |
615 | print "<td><input disabled=\"true\" type=\"checkbox\" |
616 | id=\"FRCHK-".$line["id"]."\"></td>"; | |
9b307248 AD |
617 | |
618 | print "<td>".$line["title"]."</td>"; | |
619 | print "<td>".$line["feed_url"]."</td>"; | |
620 | ||
603c27f8 AD |
621 | } else { |
622 | ||
e9c54861 | 623 | print "<td><input disabled=\"true\" type=\"checkbox\"></td>"; |
603c27f8 AD |
624 | |
625 | print "<td><input id=\"iedit_title\" value=\"".$line["title"]."\"></td>"; | |
626 | print "<td><input id=\"iedit_link\" value=\"".$line["feed_url"]."\"></td>"; | |
627 | ||
628 | } | |
0afbd851 AD |
629 | |
630 | if (!$line["last_updated"]) $line["last_updated"] = "Never"; | |
631 | ||
007bda35 | 632 | print "<td>" . $line["last_updated"] . "</td>"; |
603c27f8 | 633 | |
007bda35 AD |
634 | print "</tr>"; |
635 | ||
636 | ++$lnum; | |
637 | } | |
638 | ||
0afbd851 AD |
639 | if ($lnum == 0) { |
640 | print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>"; | |
641 | } | |
642 | ||
007bda35 AD |
643 | print "</table>"; |
644 | ||
603c27f8 AD |
645 | print "<p>"; |
646 | ||
647 | if ($subop == "edit") { | |
648 | print "Edit feed: | |
e828e31e AD |
649 | <input type=\"submit\" class=\"button\" |
650 | onclick=\"javascript:feedEditCancel()\" value=\"Cancel\"> | |
651 | <input type=\"submit\" class=\"button\" | |
8158c57a | 652 | onclick=\"javascript:feedEditSave()\" value=\"Save\">"; |
603c27f8 AD |
653 | } else { |
654 | ||
603c27f8 AD |
655 | print " |
656 | Selection: | |
e828e31e AD |
657 | <input type=\"submit\" class=\"button\" |
658 | onclick=\"javascript:editSelectedFeed()\" value=\"Edit\"> | |
659 | <input type=\"submit\" class=\"button\" | |
660 | onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">"; | |
661 | ||
f92db4f5 AD |
662 | if (ENABLE_PREFS_CATCHUP_UNCATCHUP) { |
663 | print " | |
e828e31e AD |
664 | <input type=\"submit\" class=\"button\" |
665 | onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\"> | |
666 | <input type=\"submit\" class=\"button\" | |
667 | onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\"> "; | |
f92db4f5 AD |
668 | } |
669 | print " | |
e828e31e AD |
670 | All feeds: |
671 | <input type=\"submit\" | |
8158c57a | 672 | class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">"; |
10c5820d | 673 | |
603c27f8 AD |
674 | } |
675 | ||
007bda35 AD |
676 | } |
677 | ||
a0d53889 AD |
678 | if ($op == "pref-filters") { |
679 | ||
680 | $subop = $_GET["subop"]; | |
681 | ||
682 | if ($subop == "editSave") { | |
a0d53889 | 683 | |
648472a7 AD |
684 | $regexp = db_escape_string($_GET["r"]); |
685 | $descr = db_escape_string($_GET["d"]); | |
686 | $match = db_escape_string($_GET["m"]); | |
687 | $filter_id = db_escape_string($_GET["id"]); | |
0afbd851 | 688 | |
648472a7 | 689 | $result = db_query($link, "UPDATE ttrss_filters SET |
4b3dff6e | 690 | reg_exp = '$regexp', |
0afbd851 AD |
691 | description = '$descr', |
692 | filter_type = (SELECT id FROM ttrss_filter_types WHERE | |
693 | description = '$match') | |
694 | WHERE id = '$filter_id'"); | |
a0d53889 AD |
695 | } |
696 | ||
697 | if ($subop == "remove") { | |
698 | ||
699 | if (!WEB_DEMO_MODE) { | |
700 | ||
701 | $ids = split(",", $_GET["ids"]); | |
702 | ||
703 | foreach ($ids as $id) { | |
648472a7 | 704 | db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'"); |
a0d53889 AD |
705 | |
706 | } | |
707 | } | |
708 | } | |
709 | ||
710 | if ($subop == "add") { | |
711 | ||
de435974 | 712 | if (!WEB_DEMO_MODE) { |
a0d53889 | 713 | |
8158c57a | 714 | $regexp = db_escape_string($_GET["regexp"]); |
648472a7 | 715 | $match = db_escape_string($_GET["match"]); |
a0d53889 | 716 | |
648472a7 | 717 | $result = db_query($link, |
4b3dff6e | 718 | "INSERT INTO ttrss_filters (reg_exp,filter_type) VALUES |
de435974 AD |
719 | ('$regexp', (SELECT id FROM ttrss_filter_types WHERE |
720 | description = '$match'))"); | |
721 | } | |
a0d53889 AD |
722 | } |
723 | ||
648472a7 | 724 | $result = db_query($link, "SELECT description |
a0d53889 AD |
725 | FROM ttrss_filter_types ORDER BY description"); |
726 | ||
727 | $filter_types = array(); | |
728 | ||
648472a7 | 729 | while ($line = db_fetch_assoc($result)) { |
a0d53889 AD |
730 | array_push($filter_types, $line["description"]); |
731 | } | |
732 | ||
733 | print "<table class=\"prefAddFeed\"><tr> | |
ea6774cf | 734 | <td><input id=\"fadd_regexp\"></td> |
a0d53889 | 735 | <td>"; |
bdc00fe0 | 736 | print_select("fadd_match", "Title", $filter_types); |
a0d53889 AD |
737 | |
738 | print"</td><td colspan=\"4\" align=\"right\"> | |
739 | <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr> | |
740 | </table>"; | |
741 | ||
648472a7 | 742 | $result = db_query($link, "SELECT |
4b3dff6e | 743 | id,reg_exp,description, |
a0d53889 AD |
744 | (SELECT name FROM ttrss_filter_types WHERE |
745 | id = filter_type) as filter_type_name, | |
746 | (SELECT description FROM ttrss_filter_types | |
747 | WHERE id = filter_type) as filter_type_descr | |
748 | FROM | |
4b3dff6e | 749 | ttrss_filters ORDER by reg_exp"); |
a0d53889 AD |
750 | |
751 | print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">"; | |
752 | ||
753 | print "<tr class=\"title\"> | |
0afbd851 AD |
754 | <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td> |
755 | <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>"; | |
a0d53889 AD |
756 | |
757 | $lnum = 0; | |
758 | ||
648472a7 | 759 | while ($line = db_fetch_assoc($result)) { |
a0d53889 AD |
760 | |
761 | $class = ($lnum % 2) ? "even" : "odd"; | |
762 | ||
763 | $filter_id = $line["id"]; | |
764 | $edit_filter_id = $_GET["id"]; | |
765 | ||
766 | if ($subop == "edit" && $filter_id != $edit_filter_id) { | |
767 | $class .= "Grayed"; | |
768 | } | |
769 | ||
770 | print "<tr class=\"$class\" id=\"FILRR-$filter_id\">"; | |
771 | ||
4b3dff6e | 772 | $line["regexp"] = htmlspecialchars($line["reg_exp"]); |
ea6774cf AD |
773 | $line["description"] = htmlspecialchars($line["description"]); |
774 | ||
a0d53889 AD |
775 | if (!$edit_filter_id || $subop != "edit") { |
776 | ||
0afbd851 AD |
777 | if (!$line["description"]) $line["description"] = "[No description]"; |
778 | ||
a0d53889 AD |
779 | print "<td><input onclick='toggleSelectRow(this);' |
780 | type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>"; | |
781 | ||
782 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
4b3dff6e | 783 | $line["reg_exp"] . "</td>"; |
a0d53889 AD |
784 | |
785 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
786 | $line["description"] . "</td>"; | |
787 | ||
788 | print "<td>".$line["filter_type_descr"]."</td>"; | |
789 | ||
790 | } else if ($filter_id != $edit_filter_id) { | |
791 | ||
0afbd851 AD |
792 | if (!$line["description"]) $line["description"] = "[No description]"; |
793 | ||
a0d53889 AD |
794 | print "<td><input disabled=\"true\" type=\"checkbox\" |
795 | id=\"FICHK-".$line["id"]."\"></td>"; | |
796 | ||
4b3dff6e | 797 | print "<td>".$line["reg_exp"]."</td>"; |
a0d53889 AD |
798 | print "<td>".$line["description"]."</td>"; |
799 | print "<td>".$line["filter_type_descr"]."</td>"; | |
800 | ||
801 | } else { | |
802 | ||
803 | print "<td><input disabled=\"true\" type=\"checkbox\"></td>"; | |
804 | ||
4b3dff6e | 805 | print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"]. |
a0d53889 AD |
806 | "\"></td>"; |
807 | ||
808 | print "<td><input id=\"iedit_descr\" value=\"".$line["description"]. | |
809 | "\"></td>"; | |
810 | ||
811 | print "<td>"; | |
812 | print_select("iedit_match", $line["filter_type_descr"], $filter_types); | |
813 | print "</td>"; | |
814 | ||
815 | } | |
816 | ||
817 | ||
818 | print "</tr>"; | |
819 | ||
820 | ++$lnum; | |
821 | } | |
822 | ||
0afbd851 AD |
823 | if ($lnum == 0) { |
824 | print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>"; | |
825 | } | |
826 | ||
a0d53889 AD |
827 | print "</table>"; |
828 | ||
829 | print "<p>"; | |
830 | ||
831 | if ($subop == "edit") { | |
e828e31e AD |
832 | print "Edit feed: |
833 | <input type=\"submit\" class=\"button\" | |
834 | onclick=\"javascript:filterEditCancel()\" value=\"Cancel\"> | |
835 | <input type=\"submit\" class=\"button\" | |
836 | onclick=\"javascript:filterEditSave()\" value=\"Save\">"; | |
a0d53889 AD |
837 | |
838 | } else { | |
839 | ||
840 | print " | |
e828e31e AD |
841 | Selection: |
842 | <input type=\"submit\" class=\"button\" | |
843 | onclick=\"javascript:editSelectedFilter()\" value=\"Edit\"> | |
844 | <input type=\"submit\" class=\"button\" | |
845 | onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">"; | |
a0d53889 AD |
846 | } |
847 | } | |
848 | ||
e828e31e AD |
849 | if ($op == "error") { |
850 | print "<div width=\"100%\" align='center'>"; | |
851 | $msg = $_GET["msg"]; | |
852 | print $msg; | |
853 | print "</div>"; | |
854 | } | |
855 | ||
4b3dff6e | 856 | db_close($link); |
1cd17194 | 857 | ?> |