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