]>
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 AD |
74 | |
75 | print "<feed id=\"$id\" counter=\"$count\"/>"; | |
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 | |
090e250b AD |
316 | print "<rpc-reply>"; |
317 | getLabelCounters($link); | |
318 | getFeedCounters($link); | |
8143ae1f | 319 | getTagCounters($link); |
090e250b | 320 | print "</rpc-reply>"; |
c3b81db0 AD |
321 | } |
322 | ||
323 | if ($subop == "catchupPage") { | |
324 | ||
325 | $ids = split(",", $_GET["ids"]); | |
326 | ||
327 | foreach ($ids as $id) { | |
328 | ||
648472a7 | 329 | db_query($link, "UPDATE ttrss_entries SET unread=false,last_read = NOW() |
c3b81db0 AD |
330 | WHERE id = '$id'"); |
331 | ||
332 | } | |
333 | ||
334 | print "Marked active page as read."; | |
335 | } | |
c3b81db0 AD |
336 | } |
337 | ||
338 | if ($op == "feeds") { | |
339 | ||
8143ae1f AD |
340 | $tags = $_GET["tags"]; |
341 | ||
c3b81db0 AD |
342 | $subop = $_GET["subop"]; |
343 | ||
344 | if ($subop == "catchupAll") { | |
648472a7 | 345 | db_query($link, "UPDATE ttrss_entries SET last_read = NOW(),unread = false"); |
c3b81db0 AD |
346 | } |
347 | ||
8143ae1f | 348 | outputFeedList($link, $tags); |
c3b81db0 | 349 | |
1cd17194 AD |
350 | } |
351 | ||
352 | if ($op == "view") { | |
353 | ||
d76a3b03 | 354 | $id = $_GET["id"]; |
8073cce7 | 355 | $feed_id = $_GET["feed"]; |
d76a3b03 | 356 | |
648472a7 | 357 | $result = db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'"); |
a1a8a2be | 358 | |
70830c87 AD |
359 | $addheader = $_GET["addheader"]; |
360 | ||
648472a7 | 361 | $result = db_query($link, "SELECT title,link,content,feed_id,comments, |
b7f4bda2 AD |
362 | (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url |
363 | FROM ttrss_entries | |
d76a3b03 | 364 | WHERE id = '$id'"); |
1cd17194 | 365 | |
70830c87 | 366 | if ($addheader) { |
f0601b87 | 367 | print "<html><head> |
70830c87 AD |
368 | <title>Tiny Tiny RSS : Article $id</title> |
369 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
c05608c2 | 370 | <script type=\"text/javascript\" src=\"functions.js\"></script> |
70830c87 | 371 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> |
f0601b87 | 372 | </head><body>"; |
70830c87 AD |
373 | } |
374 | ||
d76a3b03 | 375 | if ($result) { |
1cd17194 | 376 | |
648472a7 | 377 | $line = db_fetch_assoc($result); |
1cd17194 | 378 | |
b7f4bda2 AD |
379 | if ($line["icon_url"]) { |
380 | $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">"; | |
381 | } else { | |
382 | $feed_icon = " "; | |
383 | } | |
d76a3b03 | 384 | |
f7181e9b AD |
385 | if ($line["comments"] && $line["link"] != $line["comments"]) { |
386 | $entry_comments = "(<a href=\"".$line["comments"]."\">Comments</a>)"; | |
387 | } else { | |
388 | $entry_comments = ""; | |
389 | } | |
390 | ||
e828e31e AD |
391 | print "<div class=\"postReply\">"; |
392 | ||
393 | print "<div class=\"postHeader\"><table>"; | |
394 | ||
395 | print "<tr><td><b>Title:</b></td> | |
396 | <td width='100%'>" . $line["title"] . "</td></tr>"; | |
f7181e9b | 397 | |
e828e31e | 398 | print "<tr><td><b>Link:</b></td> |
f7181e9b AD |
399 | <td width='100%'> |
400 | <a href=\"" . $line["link"] . "\">".$line["link"]."</a> | |
401 | $entry_comments</td></tr>"; | |
e828e31e AD |
402 | |
403 | print "</table></div>"; | |
404 | ||
405 | print "<div class=\"postIcon\">" . $feed_icon . "</div>"; | |
406 | print "<div class=\"postContent\">" . $line["content"] . "</div>"; | |
407 | ||
408 | print "</div>"; | |
409 | ||
090e250b | 410 | print "<script type=\"text/javascript\"> |
8143ae1f | 411 | update_label_counters('$feed_id'); |
090e250b | 412 | </script>"; |
d76a3b03 | 413 | } |
70830c87 AD |
414 | |
415 | if ($addheader) { | |
416 | print "</body></html>"; | |
417 | } | |
1cd17194 AD |
418 | } |
419 | ||
420 | if ($op == "viewfeed") { | |
421 | ||
422 | $feed = $_GET["feed"]; | |
d76a3b03 | 423 | $skip = $_GET["skip"]; |
476cac42 | 424 | $subop = $_GET["subop"]; |
f175937c | 425 | $view_mode = $_GET["view"]; |
f0601b87 | 426 | $addheader = $_GET["addheader"]; |
cb1083a1 | 427 | $limit = $_GET["limit"]; |
a1a8a2be | 428 | |
8d7008c7 AD |
429 | if (!$feed) { |
430 | print "Error: no feed to display."; | |
431 | return; | |
432 | } | |
433 | ||
ac53063a AD |
434 | if (!$skip) $skip = 0; |
435 | ||
476cac42 | 436 | if ($subop == "undefined") $subop = ""; |
1cd17194 | 437 | |
f0601b87 AD |
438 | if ($addheader) { |
439 | print "<html><head> | |
ac43eba1 | 440 | <title>Tiny Tiny RSS : Feed $feed</title> |
f0601b87 AD |
441 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> |
442 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
443 | <script type=\"text/javascript\" src=\"functions.js\"></script> | |
444 | <script type=\"text/javascript\" src=\"viewfeed.js\"></script> | |
445 | </head><body>"; | |
446 | } | |
447 | ||
8143ae1f | 448 | if (sprintf("%d", $feed) != 0 && $feed >= 0) { |
d76a3b03 | 449 | |
254e0e4b AD |
450 | $result = db_query($link, |
451 | "SELECT *,SUBSTRING(last_updated,1,16) as last_updated_s | |
452 | FROM ttrss_feeds WHERE id = '$feed'"); | |
453 | ||
454 | if ($result) { | |
455 | ||
456 | $line = db_fetch_assoc($result); | |
457 | ||
458 | update_rss_feed($link, $line["feed_url"], $feed); | |
459 | ||
460 | if ($subop == "MarkAllRead") { | |
461 | ||
462 | db_query($link, "UPDATE ttrss_entries SET unread = false,last_read = NOW() | |
463 | WHERE feed_id = '$feed'"); | |
464 | } | |
a1a8a2be AD |
465 | } |
466 | } | |
d76a3b03 | 467 | |
175847de | 468 | print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">"; |
ac53063a | 469 | |
c374a3fe AD |
470 | $search = $_GET["search"]; |
471 | ||
f175937c | 472 | if ($search) { |
ac53063a AD |
473 | $search_query_part = "(upper(title) LIKE upper('%$search%') |
474 | OR content LIKE '%$search%') AND"; | |
f175937c AD |
475 | } else { |
476 | $search_query_part = ""; | |
477 | } | |
478 | ||
479 | $view_query_part = ""; | |
480 | ||
481 | if ($view_mode == "Starred") { | |
482 | $view_query_part = " marked = true AND "; | |
ac53063a AD |
483 | } |
484 | ||
ac43eba1 AD |
485 | if ($view_mode == "Unread") { |
486 | $view_query_part = " unread = true AND "; | |
487 | } | |
488 | ||
254e0e4b | 489 | /* $result = db_query($link, "SELECT count(id) AS total_entries |
36bf7496 AD |
490 | FROM ttrss_entries WHERE |
491 | $search_query_part | |
492 | feed_id = '$feed'"); | |
e6d1c0a0 | 493 | |
254e0e4b | 494 | $total_entries = db_fetch_result($result, 0, "total_entries"); */ |
e6d1c0a0 | 495 | |
648472a7 | 496 | /* $result = db_query("SELECT count(id) AS unread_entries |
ac43eba1 AD |
497 | FROM ttrss_entries WHERE |
498 | $search_query_part | |
499 | unread = true AND | |
500 | feed_id = '$feed'"); | |
501 | ||
648472a7 | 502 | $unread_entries = db_fetch_result($result, 0, "unread_entries"); */ |
ac43eba1 | 503 | |
8d7008c7 | 504 | if ($limit && $limit != "All") { |
82c9223c | 505 | $limit_query_part = "LIMIT " . $limit; |
ad3cb710 | 506 | } |
f0601b87 | 507 | |
254e0e4b AD |
508 | $vfeed_query_part = ""; |
509 | ||
8143ae1f AD |
510 | if (sprintf("%d", $feed) == 0) { |
511 | $query_strategy_part = "ttrss_entries.id > 0"; | |
512 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE | |
513 | id = feed_id) as feed_title,"; | |
514 | } else if ($feed >= 0) { | |
254e0e4b | 515 | $query_strategy_part = "feed_id = '$feed'"; |
48f0adb0 | 516 | } else if ($feed == -1) { // starred virtual feed |
254e0e4b | 517 | $query_strategy_part = "marked = true"; |
48f0adb0 AD |
518 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE |
519 | id = feed_id) as feed_title,"; | |
520 | } else if ($feed <= -10) { // labels | |
521 | $label_id = -$feed - 11; | |
522 | ||
523 | $tmp_result = db_query($link, "SELECT sql_exp FROM ttrss_labels | |
524 | WHERE id = '$label_id'"); | |
525 | ||
526 | $query_strategy_part = db_fetch_result($tmp_result, 0, "sql_exp"); | |
527 | ||
254e0e4b AD |
528 | $vfeed_query_part = "(SELECT title FROM ttrss_feeds WHERE |
529 | id = feed_id) as feed_title,"; | |
530 | } else { | |
48f0adb0 | 531 | $query_strategy_part = "id > 0"; // dumb |
254e0e4b AD |
532 | } |
533 | ||
f99321a3 AD |
534 | $order_by = "updated DESC"; |
535 | ||
536 | // if ($feed < -10) { | |
537 | // $order_by = "feed_id,updated DESC"; | |
538 | // } | |
539 | ||
48f0adb0 AD |
540 | if ($feed < -10) error_reporting (0); |
541 | ||
8143ae1f AD |
542 | if (sprintf("%d", $feed) != 0) { |
543 | ||
544 | $result = db_query($link, "SELECT | |
545 | id,title,updated,unread,feed_id,marked,link,last_read, | |
546 | SUBSTRING(last_read,1,19) as last_read_noms, | |
547 | $vfeed_query_part | |
548 | SUBSTRING(updated,1,19) as updated_noms | |
549 | FROM | |
550 | ttrss_entries | |
551 | WHERE | |
552 | $search_query_part | |
553 | $view_query_part | |
554 | $query_strategy_part ORDER BY $order_by | |
555 | $limit_query_part"); | |
556 | ||
557 | } else { | |
558 | // browsing by tag | |
559 | ||
560 | $result = db_query($link, "SELECT | |
561 | ttrss_entries.id as id,title,updated,unread,feed_id, | |
562 | marked,link,last_read, | |
c05a19f3 | 563 | SUBSTRING(last_read,1,19) as last_read_noms, |
254e0e4b | 564 | $vfeed_query_part |
c05a19f3 | 565 | SUBSTRING(updated,1,19) as updated_noms |
8143ae1f AD |
566 | FROM |
567 | ttrss_entries,ttrss_tags | |
568 | WHERE | |
569 | post_id = ttrss_entries.id AND tag_name = '$feed' AND | |
570 | $view_query_part | |
571 | $search_query_part | |
572 | $query_strategy_part ORDER BY $order_by | |
573 | $limit_query_part"); | |
574 | } | |
d76a3b03 | 575 | |
48f0adb0 AD |
576 | if (!$result) { |
577 | print "<tr><td colspan='4' align='center'> | |
578 | Could not display feed (query failed). Please check match syntax or local configuration.</td></tr>"; | |
579 | return; | |
580 | } | |
581 | ||
a1a8a2be | 582 | $lnum = 0; |
48f0adb0 AD |
583 | |
584 | error_reporting (E_ERROR | E_WARNING | E_PARSE); | |
585 | ||
e1123aee | 586 | $num_unread = 0; |
d76a3b03 | 587 | |
648472a7 | 588 | while ($line = db_fetch_assoc($result)) { |
d76a3b03 | 589 | |
a1a8a2be | 590 | $class = ($lnum % 2) ? "even" : "odd"; |
d76a3b03 | 591 | |
ad99045e AD |
592 | $id = $line["id"]; |
593 | $feed_id = $line["feed_id"]; | |
594 | ||
c43f77f5 | 595 | // printf("L %d (%s) > U %d (%s) = %d<br>", |
c05a19f3 | 596 | // strtotime($line["last_read_noms"]), $line["last_read_noms"], |
c43f77f5 AD |
597 | // strtotime($line["updated"]), $line["updated"], |
598 | // strtotime($line["last_read"]) >= strtotime($line["updated"])); | |
599 | ||
ecb14114 | 600 | /* if ($line["last_read"] != "" && $line["updated"] != "" && |
c05a19f3 | 601 | strtotime($line["last_read_noms"]) < strtotime($line["updated_noms"])) { |
c43f77f5 AD |
602 | |
603 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\" | |
604 | alt=\"Updated\">"; | |
605 | ||
606 | } else { | |
607 | ||
5bfef089 | 608 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\" |
c43f77f5 AD |
609 | alt=\"Updated\">"; |
610 | ||
ecb14114 AD |
611 | } */ |
612 | ||
613 | if ($line["last_read"] == "") { | |
614 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/updated.png\" | |
615 | alt=\"Updated\">"; | |
616 | } else { | |
617 | $update_pic = "<img id='FUPDPIC-$id' src=\"images/blank_icon.gif\" | |
618 | alt=\"Updated\">"; | |
c43f77f5 | 619 | } |
b197f117 | 620 | |
8158c57a | 621 | if ($line["unread"] == "t" || $line["unread"] == "1") { |
a1a8a2be | 622 | $class .= "Unread"; |
e1123aee AD |
623 | ++$num_unread; |
624 | } | |
d76a3b03 | 625 | |
8158c57a | 626 | if ($line["marked"] == "t" || $line["marked"] == "1") { |
f4c10d44 AD |
627 | $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_set.png\" |
628 | alt=\"Reset mark\" onclick='javascript:toggleMark($id, false)'>"; | |
629 | } else { | |
630 | $marked_pic = "<img id=\"FMARKPIC-$id\" src=\"images/mark_unset.png\" | |
631 | alt=\"Set mark\" onclick='javascript:toggleMark($id, true)'>"; | |
632 | } | |
633 | ||
ac43eba1 | 634 | $content_link = "<a id=\"FTITLE-$id\" href=\"javascript:view($id,$feed_id);\">" . |
b197f117 AD |
635 | $line["title"] . "</a>"; |
636 | ||
d5224f0d | 637 | print "<tr class='$class' id='RROW-$id'>"; |
5f89f780 | 638 | // onclick=\"javascript:view($id,$feed_id)\"> |
b197f117 | 639 | |
8d7008c7 AD |
640 | print "<td valign='center' align='center'>$update_pic</td>"; |
641 | print "<td valign='center' align='center'>$marked_pic</td>"; | |
b197f117 | 642 | |
8d7008c7 | 643 | print "<td width='25%'> |
a3ee2a38 | 644 | <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>"; |
254e0e4b AD |
645 | |
646 | if ($line["feed_title"]) { | |
647 | print "<td width='50%'>$content_link</td>"; | |
648 | print "<td width='20%'>".$line["feed_title"]."</td>"; | |
649 | } else { | |
650 | print "<td width='70%'>$content_link</td>"; | |
651 | } | |
d76a3b03 | 652 | |
a1a8a2be | 653 | print "</tr>"; |
d76a3b03 | 654 | |
a1a8a2be AD |
655 | ++$lnum; |
656 | } | |
d76a3b03 | 657 | |
ac53063a | 658 | if ($lnum == 0) { |
a82065a1 | 659 | print "<tr><td align='center'>No articles found.</td></tr>"; |
047bae73 | 660 | } |
a2015351 | 661 | |
a1a8a2be | 662 | print "</table>"; |
6113ef7d AD |
663 | |
664 | print "<script type=\"text/javascript\"> | |
bb7cface | 665 | document.onkeydown = hotkey_handler; |
8143ae1f | 666 | update_label_counters('$feed'); |
6113ef7d | 667 | </script>"; |
d76a3b03 | 668 | |
f0601b87 AD |
669 | if ($addheader) { |
670 | print "</body></html>"; | |
671 | } | |
672 | ||
1cd17194 AD |
673 | } |
674 | ||
0e091d38 | 675 | if ($op == "pref-rpc") { |
331900c6 | 676 | |
0e091d38 | 677 | $subop = $_GET["subop"]; |
331900c6 | 678 | |
83fe4d6d AD |
679 | if ($subop == "unread") { |
680 | $ids = split(",", $_GET["ids"]); | |
681 | foreach ($ids as $id) { | |
648472a7 | 682 | db_query($link, "UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'"); |
83fe4d6d | 683 | } |
0e091d38 AD |
684 | |
685 | print "Marked selected feeds as read."; | |
83fe4d6d AD |
686 | } |
687 | ||
688 | if ($subop == "read") { | |
689 | $ids = split(",", $_GET["ids"]); | |
690 | foreach ($ids as $id) { | |
648472a7 | 691 | db_query($link, "UPDATE ttrss_entries |
b197f117 | 692 | SET unread = false,last_read = NOW() WHERE feed_id = '$id'"); |
83fe4d6d | 693 | } |
0e091d38 AD |
694 | |
695 | print "Marked selected feeds as unread."; | |
696 | ||
697 | } | |
698 | ||
699 | } | |
700 | ||
701 | if ($op == "pref-feeds") { | |
702 | ||
703 | $subop = $_GET["subop"]; | |
704 | ||
508a81e1 | 705 | if ($subop == "editSave") { |
648472a7 AD |
706 | $feed_title = db_escape_string($_GET["t"]); |
707 | $feed_link = db_escape_string($_GET["l"]); | |
d148926e | 708 | $upd_intl = db_escape_string($_GET["ui"]); |
508a81e1 AD |
709 | $feed_id = $_GET["id"]; |
710 | ||
d148926e AD |
711 | if (strtoupper($upd_intl) == "DEFAULT") |
712 | $upd_intl = 0; | |
713 | ||
648472a7 | 714 | $result = db_query($link, "UPDATE ttrss_feeds SET |
d148926e AD |
715 | title = '$feed_title', feed_url = '$feed_link', |
716 | update_interval = '$upd_intl' WHERE id = '$feed_id'"); | |
508a81e1 | 717 | |
83fe4d6d AD |
718 | } |
719 | ||
331900c6 | 720 | if ($subop == "remove") { |
331900c6 | 721 | |
b0b4abcf | 722 | if (!WEB_DEMO_MODE) { |
331900c6 | 723 | |
b0b4abcf AD |
724 | $ids = split(",", $_GET["ids"]); |
725 | ||
726 | foreach ($ids as $id) { | |
648472a7 | 727 | db_query($link, "DELETE FROM ttrss_feeds WHERE id = '$id'"); |
d5caaae5 AD |
728 | |
729 | if (file_exists(ICONS_DIR . "/$id.ico")) { | |
730 | unlink(ICONS_DIR . "/$id.ico"); | |
731 | } | |
b0b4abcf | 732 | } |
331900c6 AD |
733 | } |
734 | } | |
735 | ||
736 | if ($subop == "add") { | |
b0b4abcf AD |
737 | |
738 | if (!WEB_DEMO_MODE) { | |
331900c6 | 739 | |
648472a7 | 740 | $feed_link = db_escape_string($_GET["link"]); |
b0b4abcf | 741 | |
648472a7 | 742 | $result = db_query($link, |
b0b4abcf | 743 | "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')"); |
331900c6 | 744 | |
648472a7 | 745 | $result = db_query($link, |
e9c54861 | 746 | "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'"); |
331900c6 | 747 | |
648472a7 | 748 | $feed_id = db_fetch_result($result, 0, "id"); |
331900c6 | 749 | |
b0b4abcf AD |
750 | if ($feed_id) { |
751 | update_rss_feed($link, $feed_link, $feed_id); | |
752 | } | |
753 | } | |
331900c6 | 754 | } |
a0d53889 AD |
755 | |
756 | print "<table class=\"prefAddFeed\"><tr> | |
757 | <td><input id=\"fadd_link\"></td> | |
758 | <td colspan=\"4\" align=\"right\"> | |
759 | <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr> | |
760 | </table>"; | |
761 | ||
648472a7 | 762 | $result = db_query($link, "SELECT |
d148926e AD |
763 | id,title,feed_url,substring(last_updated,1,16) as last_updated, |
764 | update_interval | |
c0e5a40e AD |
765 | FROM |
766 | ttrss_feeds ORDER by title"); | |
1cd17194 | 767 | |
331900c6 | 768 | print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">"; |
007bda35 | 769 | print "<tr class=\"title\"> |
603c27f8 | 770 | <td> </td><td>Select</td><td width=\"40%\">Title</td> |
d148926e AD |
771 | <td width=\"30%\">Link</td><td width=\"10%\">Update Interval</td> |
772 | <td>Last updated</td></tr>"; | |
007bda35 AD |
773 | |
774 | $lnum = 0; | |
775 | ||
648472a7 | 776 | while ($line = db_fetch_assoc($result)) { |
007bda35 AD |
777 | |
778 | $class = ($lnum % 2) ? "even" : "odd"; | |
9b307248 | 779 | |
331900c6 | 780 | $feed_id = $line["id"]; |
603c27f8 AD |
781 | |
782 | $edit_feed_id = $_GET["id"]; | |
783 | ||
9b307248 AD |
784 | if ($subop == "edit" && $feed_id != $edit_feed_id) { |
785 | $class .= "Grayed"; | |
786 | } | |
787 | ||
331900c6 | 788 | print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">"; |
007bda35 | 789 | |
c0e5a40e AD |
790 | $icon_file = ICONS_DIR . "/$feed_id.ico"; |
791 | ||
792 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
793 | $feed_icon = "<img width=\"16\" height=\"16\" | |
794 | src=\"" . ICONS_URL . "/$feed_id.ico\">"; | |
795 | } else { | |
796 | $feed_icon = " "; | |
797 | } | |
798 | print "<td align='center'>$feed_icon</td>"; | |
799 | ||
9b307248 | 800 | if (!$edit_feed_id || $subop != "edit") { |
603c27f8 AD |
801 | |
802 | print "<td><input onclick='toggleSelectRow(this);' | |
331900c6 | 803 | type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>"; |
603c27f8 AD |
804 | |
805 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
806 | $line["title"] . "</td>"; | |
807 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
808 | $line["feed_url"] . "</td>"; | |
d148926e AD |
809 | |
810 | if ($line["update_interval"] == "0") | |
811 | $line["update_interval"] = "Default"; | |
812 | ||
813 | print "<td>" . $line["update_interval"] . "</td>"; | |
814 | ||
9b307248 AD |
815 | |
816 | } else if ($feed_id != $edit_feed_id) { | |
817 | ||
e9c54861 AD |
818 | print "<td><input disabled=\"true\" type=\"checkbox\" |
819 | id=\"FRCHK-".$line["id"]."\"></td>"; | |
9b307248 AD |
820 | |
821 | print "<td>".$line["title"]."</td>"; | |
822 | print "<td>".$line["feed_url"]."</td>"; | |
823 | ||
d148926e AD |
824 | if ($line["update_interval"] == "0") |
825 | $line["update_interval"] = "Default"; | |
826 | ||
827 | print "<td>" . $line["update_interval"] . "</td>"; | |
828 | ||
603c27f8 AD |
829 | } else { |
830 | ||
e9c54861 | 831 | print "<td><input disabled=\"true\" type=\"checkbox\"></td>"; |
603c27f8 AD |
832 | |
833 | print "<td><input id=\"iedit_title\" value=\"".$line["title"]."\"></td>"; | |
834 | print "<td><input id=\"iedit_link\" value=\"".$line["feed_url"]."\"></td>"; | |
d148926e AD |
835 | print "<td><input id=\"iedit_updintl\" value=\"".$line["update_interval"]."\"></td>"; |
836 | ||
603c27f8 | 837 | } |
0afbd851 AD |
838 | |
839 | if (!$line["last_updated"]) $line["last_updated"] = "Never"; | |
840 | ||
007bda35 | 841 | print "<td>" . $line["last_updated"] . "</td>"; |
603c27f8 | 842 | |
007bda35 AD |
843 | print "</tr>"; |
844 | ||
845 | ++$lnum; | |
846 | } | |
847 | ||
0afbd851 AD |
848 | if ($lnum == 0) { |
849 | print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>"; | |
850 | } | |
851 | ||
007bda35 AD |
852 | print "</table>"; |
853 | ||
603c27f8 AD |
854 | print "<p>"; |
855 | ||
856 | if ($subop == "edit") { | |
857 | print "Edit feed: | |
e828e31e AD |
858 | <input type=\"submit\" class=\"button\" |
859 | onclick=\"javascript:feedEditCancel()\" value=\"Cancel\"> | |
860 | <input type=\"submit\" class=\"button\" | |
8158c57a | 861 | onclick=\"javascript:feedEditSave()\" value=\"Save\">"; |
603c27f8 AD |
862 | } else { |
863 | ||
603c27f8 AD |
864 | print " |
865 | Selection: | |
e828e31e AD |
866 | <input type=\"submit\" class=\"button\" |
867 | onclick=\"javascript:editSelectedFeed()\" value=\"Edit\"> | |
868 | <input type=\"submit\" class=\"button\" | |
869 | onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">"; | |
870 | ||
f92db4f5 AD |
871 | if (ENABLE_PREFS_CATCHUP_UNCATCHUP) { |
872 | print " | |
e828e31e AD |
873 | <input type=\"submit\" class=\"button\" |
874 | onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\"> | |
875 | <input type=\"submit\" class=\"button\" | |
876 | onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\"> "; | |
f92db4f5 AD |
877 | } |
878 | print " | |
e828e31e AD |
879 | All feeds: |
880 | <input type=\"submit\" | |
8158c57a | 881 | class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">"; |
10c5820d | 882 | |
603c27f8 AD |
883 | } |
884 | ||
007bda35 AD |
885 | } |
886 | ||
a0d53889 AD |
887 | if ($op == "pref-filters") { |
888 | ||
889 | $subop = $_GET["subop"]; | |
890 | ||
891 | if ($subop == "editSave") { | |
a0d53889 | 892 | |
648472a7 AD |
893 | $regexp = db_escape_string($_GET["r"]); |
894 | $descr = db_escape_string($_GET["d"]); | |
895 | $match = db_escape_string($_GET["m"]); | |
896 | $filter_id = db_escape_string($_GET["id"]); | |
0afbd851 | 897 | |
648472a7 | 898 | $result = db_query($link, "UPDATE ttrss_filters SET |
4b3dff6e | 899 | reg_exp = '$regexp', |
0afbd851 AD |
900 | description = '$descr', |
901 | filter_type = (SELECT id FROM ttrss_filter_types WHERE | |
902 | description = '$match') | |
903 | WHERE id = '$filter_id'"); | |
a0d53889 AD |
904 | } |
905 | ||
906 | if ($subop == "remove") { | |
907 | ||
908 | if (!WEB_DEMO_MODE) { | |
909 | ||
910 | $ids = split(",", $_GET["ids"]); | |
911 | ||
912 | foreach ($ids as $id) { | |
648472a7 | 913 | db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'"); |
a0d53889 AD |
914 | |
915 | } | |
916 | } | |
917 | } | |
918 | ||
919 | if ($subop == "add") { | |
920 | ||
de435974 | 921 | if (!WEB_DEMO_MODE) { |
a0d53889 | 922 | |
8158c57a | 923 | $regexp = db_escape_string($_GET["regexp"]); |
648472a7 | 924 | $match = db_escape_string($_GET["match"]); |
a0d53889 | 925 | |
648472a7 | 926 | $result = db_query($link, |
4b3dff6e | 927 | "INSERT INTO ttrss_filters (reg_exp,filter_type) VALUES |
de435974 AD |
928 | ('$regexp', (SELECT id FROM ttrss_filter_types WHERE |
929 | description = '$match'))"); | |
930 | } | |
a0d53889 AD |
931 | } |
932 | ||
648472a7 | 933 | $result = db_query($link, "SELECT description |
a0d53889 AD |
934 | FROM ttrss_filter_types ORDER BY description"); |
935 | ||
936 | $filter_types = array(); | |
937 | ||
648472a7 | 938 | while ($line = db_fetch_assoc($result)) { |
a0d53889 AD |
939 | array_push($filter_types, $line["description"]); |
940 | } | |
941 | ||
942 | print "<table class=\"prefAddFeed\"><tr> | |
ea6774cf | 943 | <td><input id=\"fadd_regexp\"></td> |
a0d53889 | 944 | <td>"; |
bdc00fe0 | 945 | print_select("fadd_match", "Title", $filter_types); |
a0d53889 AD |
946 | |
947 | print"</td><td colspan=\"4\" align=\"right\"> | |
948 | <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr> | |
949 | </table>"; | |
950 | ||
648472a7 | 951 | $result = db_query($link, "SELECT |
4b3dff6e | 952 | id,reg_exp,description, |
a0d53889 AD |
953 | (SELECT name FROM ttrss_filter_types WHERE |
954 | id = filter_type) as filter_type_name, | |
955 | (SELECT description FROM ttrss_filter_types | |
956 | WHERE id = filter_type) as filter_type_descr | |
957 | FROM | |
4b3dff6e | 958 | ttrss_filters ORDER by reg_exp"); |
a0d53889 AD |
959 | |
960 | print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">"; | |
961 | ||
962 | print "<tr class=\"title\"> | |
0afbd851 AD |
963 | <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td> |
964 | <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>"; | |
a0d53889 AD |
965 | |
966 | $lnum = 0; | |
967 | ||
648472a7 | 968 | while ($line = db_fetch_assoc($result)) { |
a0d53889 AD |
969 | |
970 | $class = ($lnum % 2) ? "even" : "odd"; | |
971 | ||
972 | $filter_id = $line["id"]; | |
973 | $edit_filter_id = $_GET["id"]; | |
974 | ||
975 | if ($subop == "edit" && $filter_id != $edit_filter_id) { | |
976 | $class .= "Grayed"; | |
977 | } | |
978 | ||
979 | print "<tr class=\"$class\" id=\"FILRR-$filter_id\">"; | |
980 | ||
4b3dff6e | 981 | $line["regexp"] = htmlspecialchars($line["reg_exp"]); |
ea6774cf AD |
982 | $line["description"] = htmlspecialchars($line["description"]); |
983 | ||
a0d53889 AD |
984 | if (!$edit_filter_id || $subop != "edit") { |
985 | ||
0afbd851 AD |
986 | if (!$line["description"]) $line["description"] = "[No description]"; |
987 | ||
a0d53889 AD |
988 | print "<td><input onclick='toggleSelectRow(this);' |
989 | type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>"; | |
990 | ||
991 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
4b3dff6e | 992 | $line["reg_exp"] . "</td>"; |
a0d53889 AD |
993 | |
994 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
995 | $line["description"] . "</td>"; | |
996 | ||
997 | print "<td>".$line["filter_type_descr"]."</td>"; | |
998 | ||
999 | } else if ($filter_id != $edit_filter_id) { | |
1000 | ||
0afbd851 AD |
1001 | if (!$line["description"]) $line["description"] = "[No description]"; |
1002 | ||
a0d53889 AD |
1003 | print "<td><input disabled=\"true\" type=\"checkbox\" |
1004 | id=\"FICHK-".$line["id"]."\"></td>"; | |
1005 | ||
4b3dff6e | 1006 | print "<td>".$line["reg_exp"]."</td>"; |
a0d53889 AD |
1007 | print "<td>".$line["description"]."</td>"; |
1008 | print "<td>".$line["filter_type_descr"]."</td>"; | |
1009 | ||
1010 | } else { | |
1011 | ||
1012 | print "<td><input disabled=\"true\" type=\"checkbox\"></td>"; | |
1013 | ||
4b3dff6e | 1014 | print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"]. |
a0d53889 AD |
1015 | "\"></td>"; |
1016 | ||
1017 | print "<td><input id=\"iedit_descr\" value=\"".$line["description"]. | |
1018 | "\"></td>"; | |
1019 | ||
1020 | print "<td>"; | |
1021 | print_select("iedit_match", $line["filter_type_descr"], $filter_types); | |
1022 | print "</td>"; | |
1023 | ||
1024 | } | |
1025 | ||
1026 | ||
1027 | print "</tr>"; | |
1028 | ||
1029 | ++$lnum; | |
1030 | } | |
1031 | ||
0afbd851 AD |
1032 | if ($lnum == 0) { |
1033 | print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>"; | |
1034 | } | |
1035 | ||
a0d53889 AD |
1036 | print "</table>"; |
1037 | ||
1038 | print "<p>"; | |
1039 | ||
1040 | if ($subop == "edit") { | |
e828e31e AD |
1041 | print "Edit feed: |
1042 | <input type=\"submit\" class=\"button\" | |
1043 | onclick=\"javascript:filterEditCancel()\" value=\"Cancel\"> | |
1044 | <input type=\"submit\" class=\"button\" | |
1045 | onclick=\"javascript:filterEditSave()\" value=\"Save\">"; | |
a0d53889 AD |
1046 | |
1047 | } else { | |
1048 | ||
1049 | print " | |
e828e31e AD |
1050 | Selection: |
1051 | <input type=\"submit\" class=\"button\" | |
1052 | onclick=\"javascript:editSelectedFilter()\" value=\"Edit\"> | |
1053 | <input type=\"submit\" class=\"button\" | |
1054 | onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">"; | |
a0d53889 AD |
1055 | } |
1056 | } | |
1057 | ||
48f0adb0 AD |
1058 | if ($op == "pref-labels") { |
1059 | ||
1060 | $subop = $_GET["subop"]; | |
1061 | ||
1062 | if ($subop == "editSave") { | |
1063 | ||
1064 | $sql_exp = $_GET["s"]; | |
1065 | $descr = $_GET["d"]; | |
1066 | $label_id = db_escape_string($_GET["id"]); | |
1067 | ||
1068 | // print "$sql_exp : $descr : $label_id"; | |
1069 | ||
1070 | $result = db_query($link, "UPDATE ttrss_labels SET | |
1071 | sql_exp = '$sql_exp', | |
1072 | description = '$descr' | |
1073 | WHERE id = '$label_id'"); | |
1074 | } | |
1075 | ||
1076 | if ($subop == "remove") { | |
1077 | ||
1078 | if (!WEB_DEMO_MODE) { | |
1079 | ||
1080 | $ids = split(",", $_GET["ids"]); | |
1081 | ||
1082 | foreach ($ids as $id) { | |
1083 | db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'"); | |
1084 | ||
1085 | } | |
1086 | } | |
1087 | } | |
1088 | ||
1089 | if ($subop == "add") { | |
1090 | ||
1091 | if (!WEB_DEMO_MODE) { | |
1092 | ||
1093 | $exp = $_GET["exp"]; | |
1094 | ||
1095 | $result = db_query($link, | |
1096 | "INSERT INTO ttrss_labels (sql_exp,description) | |
1097 | VALUES ('$exp', '$exp')"); | |
1098 | } | |
1099 | } | |
1100 | ||
1101 | print "<table class=\"prefAddFeed\"><tr> | |
1102 | <td><input id=\"ladd_expr\"></td>"; | |
1103 | ||
1104 | print"<td colspan=\"4\" align=\"right\"> | |
1105 | <a class=\"button\" href=\"javascript:addLabel()\">Add label</a></td></tr> | |
1106 | </table>"; | |
1107 | ||
1108 | $result = db_query($link, "SELECT | |
1109 | id,sql_exp,description | |
1110 | FROM | |
1111 | ttrss_labels ORDER by description"); | |
1112 | ||
1113 | print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">"; | |
1114 | ||
1115 | print "<tr class=\"title\"> | |
1116 | <td width=\"5%\">Select</td><td width=\"40%\">SQL expression</td> | |
1117 | <td width=\"40%\">Caption</td></tr>"; | |
1118 | ||
1119 | $lnum = 0; | |
1120 | ||
1121 | while ($line = db_fetch_assoc($result)) { | |
1122 | ||
1123 | $class = ($lnum % 2) ? "even" : "odd"; | |
1124 | ||
1125 | $label_id = $line["id"]; | |
1126 | $edit_label_id = $_GET["id"]; | |
1127 | ||
1128 | if ($subop == "edit" && $label_id != $edit_label_id) { | |
1129 | $class .= "Grayed"; | |
1130 | } | |
1131 | ||
1132 | print "<tr class=\"$class\" id=\"LILRR-$label_id\">"; | |
1133 | ||
1134 | $line["sql_exp"] = htmlspecialchars($line["sql_exp"]); | |
1135 | $line["description"] = htmlspecialchars($line["description"]); | |
1136 | ||
1137 | if (!$edit_label_id || $subop != "edit") { | |
1138 | ||
1139 | if (!$line["description"]) $line["description"] = "[No caption]"; | |
1140 | ||
1141 | print "<td><input onclick='toggleSelectRow(this);' | |
1142 | type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>"; | |
1143 | ||
1144 | print "<td><a href=\"javascript:editLabel($label_id);\">" . | |
1145 | $line["sql_exp"] . "</td>"; | |
1146 | ||
1147 | print "<td><a href=\"javascript:editLabel($label_id);\">" . | |
1148 | $line["description"] . "</td>"; | |
1149 | ||
1150 | } else if ($label_id != $edit_label_id) { | |
1151 | ||
1152 | if (!$line["description"]) $line["description"] = "[No description]"; | |
1153 | ||
1154 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
1155 | id=\"LICHK-".$line["id"]."\"></td>"; | |
1156 | ||
1157 | print "<td>".$line["sql_exp"]."</td>"; | |
1158 | print "<td>".$line["description"]."</td>"; | |
1159 | ||
1160 | } else { | |
1161 | ||
1162 | print "<td><input disabled=\"true\" type=\"checkbox\"></td>"; | |
1163 | ||
1164 | print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"]. | |
1165 | "\"></td>"; | |
1166 | ||
1167 | print "<td><input id=\"iedit_descr\" value=\"".$line["description"]. | |
1168 | "\"></td>"; | |
1169 | ||
1170 | } | |
1171 | ||
1172 | ||
1173 | print "</tr>"; | |
1174 | ||
1175 | ++$lnum; | |
1176 | } | |
1177 | ||
1178 | if ($lnum == 0) { | |
1179 | print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>"; | |
1180 | } | |
1181 | ||
1182 | print "</table>"; | |
1183 | ||
1184 | print "<p>"; | |
1185 | ||
1186 | if ($subop == "edit") { | |
1187 | print "Edit label: | |
1188 | <input type=\"submit\" class=\"button\" | |
1189 | onclick=\"javascript:labelEditCancel()\" value=\"Cancel\"> | |
1190 | <input type=\"submit\" class=\"button\" | |
1191 | onclick=\"javascript:labelEditSave()\" value=\"Save\">"; | |
1192 | ||
1193 | } else { | |
1194 | ||
1195 | print " | |
1196 | Selection: | |
1197 | <input type=\"submit\" class=\"button\" | |
1198 | onclick=\"javascript:editSelectedLabel()\" value=\"Edit\"> | |
1199 | <input type=\"submit\" class=\"button\" | |
1200 | onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">"; | |
1201 | } | |
1202 | } | |
1203 | ||
e828e31e AD |
1204 | if ($op == "error") { |
1205 | print "<div width=\"100%\" align='center'>"; | |
1206 | $msg = $_GET["msg"]; | |
1207 | print $msg; | |
1208 | print "</div>"; | |
1209 | } | |
1210 | ||
4b3dff6e | 1211 | db_close($link); |
1cd17194 | 1212 | ?> |