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