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