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