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