]>
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 | 817 | |
ab3d0b99 AD |
818 | $result = db_query($link, "SELECT id,title,feed_url,last_error |
819 | FROM ttrss_feeds WHERE last_error != ''"); | |
820 | ||
821 | if (db_num_rows($result) > 0) { | |
822 | ||
823 | print "<div class=\"warning\">"; | |
824 | ||
825 | print "<b>Feeds with update errors:</b>"; | |
826 | ||
827 | print "<ul class=\"nomarks\">"; | |
828 | ||
829 | while ($line = db_fetch_assoc($result)) { | |
830 | print "<li>" . $line["title"] . " (" . $line["feed_url"] . "): " . | |
831 | $line["last_error"]; | |
832 | } | |
833 | ||
834 | print "</ul>"; | |
835 | print "</div>"; | |
836 | ||
837 | } | |
838 | ||
a0d53889 AD |
839 | print "<table class=\"prefAddFeed\"><tr> |
840 | <td><input id=\"fadd_link\"></td> | |
841 | <td colspan=\"4\" align=\"right\"> | |
842 | <a class=\"button\" href=\"javascript:addFeed()\">Add feed</a></td></tr> | |
843 | </table>"; | |
844 | ||
648472a7 | 845 | $result = db_query($link, "SELECT |
d148926e AD |
846 | id,title,feed_url,substring(last_updated,1,16) as last_updated, |
847 | update_interval | |
c0e5a40e AD |
848 | FROM |
849 | ttrss_feeds ORDER by title"); | |
1cd17194 | 850 | |
331900c6 | 851 | print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">"; |
007bda35 | 852 | print "<tr class=\"title\"> |
603c27f8 | 853 | <td> </td><td>Select</td><td width=\"40%\">Title</td> |
d148926e AD |
854 | <td width=\"30%\">Link</td><td width=\"10%\">Update Interval</td> |
855 | <td>Last updated</td></tr>"; | |
007bda35 AD |
856 | |
857 | $lnum = 0; | |
858 | ||
648472a7 | 859 | while ($line = db_fetch_assoc($result)) { |
007bda35 AD |
860 | |
861 | $class = ($lnum % 2) ? "even" : "odd"; | |
9b307248 | 862 | |
331900c6 | 863 | $feed_id = $line["id"]; |
603c27f8 AD |
864 | |
865 | $edit_feed_id = $_GET["id"]; | |
866 | ||
9b307248 AD |
867 | if ($subop == "edit" && $feed_id != $edit_feed_id) { |
868 | $class .= "Grayed"; | |
869 | } | |
870 | ||
331900c6 | 871 | print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">"; |
007bda35 | 872 | |
c0e5a40e AD |
873 | $icon_file = ICONS_DIR . "/$feed_id.ico"; |
874 | ||
875 | if (file_exists($icon_file) && filesize($icon_file) > 0) { | |
876 | $feed_icon = "<img width=\"16\" height=\"16\" | |
877 | src=\"" . ICONS_URL . "/$feed_id.ico\">"; | |
878 | } else { | |
879 | $feed_icon = " "; | |
880 | } | |
881 | print "<td align='center'>$feed_icon</td>"; | |
882 | ||
6e0584e9 AD |
883 | $edit_title = htmlspecialchars(db_unescape_string($line["title"])); |
884 | $edit_link = htmlspecialchars(db_unescape_string($line["feed_url"])); | |
885 | ||
9b307248 | 886 | if (!$edit_feed_id || $subop != "edit") { |
603c27f8 AD |
887 | |
888 | print "<td><input onclick='toggleSelectRow(this);' | |
331900c6 | 889 | type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>"; |
603c27f8 AD |
890 | |
891 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . | |
6e0584e9 | 892 | $edit_title . "</td>"; |
603c27f8 | 893 | print "<td><a href=\"javascript:editFeed($feed_id);\">" . |
6e0584e9 | 894 | $edit_link . "</td>"; |
d148926e AD |
895 | |
896 | if ($line["update_interval"] == "0") | |
897 | $line["update_interval"] = "Default"; | |
898 | ||
899 | print "<td>" . $line["update_interval"] . "</td>"; | |
900 | ||
9b307248 AD |
901 | |
902 | } else if ($feed_id != $edit_feed_id) { | |
903 | ||
e9c54861 AD |
904 | print "<td><input disabled=\"true\" type=\"checkbox\" |
905 | id=\"FRCHK-".$line["id"]."\"></td>"; | |
9b307248 | 906 | |
6e0584e9 AD |
907 | print "<td>$edit_title</td>"; |
908 | print "<td>$edit_link</td>"; | |
9b307248 | 909 | |
d148926e AD |
910 | if ($line["update_interval"] == "0") |
911 | $line["update_interval"] = "Default"; | |
912 | ||
913 | print "<td>" . $line["update_interval"] . "</td>"; | |
914 | ||
603c27f8 AD |
915 | } else { |
916 | ||
e9c54861 | 917 | print "<td><input disabled=\"true\" type=\"checkbox\"></td>"; |
603c27f8 | 918 | |
6e0584e9 AD |
919 | print "<td><input id=\"iedit_title\" value=\"$edit_title\"></td>"; |
920 | print "<td><input id=\"iedit_link\" value=\"$edit_link\"></td>"; | |
d148926e AD |
921 | print "<td><input id=\"iedit_updintl\" value=\"".$line["update_interval"]."\"></td>"; |
922 | ||
603c27f8 | 923 | } |
0afbd851 AD |
924 | |
925 | if (!$line["last_updated"]) $line["last_updated"] = "Never"; | |
926 | ||
007bda35 | 927 | print "<td>" . $line["last_updated"] . "</td>"; |
603c27f8 | 928 | |
007bda35 AD |
929 | print "</tr>"; |
930 | ||
931 | ++$lnum; | |
932 | } | |
933 | ||
0afbd851 AD |
934 | if ($lnum == 0) { |
935 | print "<tr><td colspan=\"5\" align=\"center\">No feeds defined.</td></tr>"; | |
936 | } | |
937 | ||
007bda35 AD |
938 | print "</table>"; |
939 | ||
603c27f8 AD |
940 | print "<p>"; |
941 | ||
942 | if ($subop == "edit") { | |
943 | print "Edit feed: | |
e828e31e AD |
944 | <input type=\"submit\" class=\"button\" |
945 | onclick=\"javascript:feedEditCancel()\" value=\"Cancel\"> | |
946 | <input type=\"submit\" class=\"button\" | |
8158c57a | 947 | onclick=\"javascript:feedEditSave()\" value=\"Save\">"; |
603c27f8 AD |
948 | } else { |
949 | ||
603c27f8 AD |
950 | print " |
951 | Selection: | |
e828e31e AD |
952 | <input type=\"submit\" class=\"button\" |
953 | onclick=\"javascript:editSelectedFeed()\" value=\"Edit\"> | |
954 | <input type=\"submit\" class=\"button\" | |
955 | onclick=\"javascript:removeSelectedFeeds()\" value=\"Remove\">"; | |
956 | ||
f92db4f5 AD |
957 | if (ENABLE_PREFS_CATCHUP_UNCATCHUP) { |
958 | print " | |
e828e31e AD |
959 | <input type=\"submit\" class=\"button\" |
960 | onclick=\"javascript:readSelectedFeeds()\" value=\"Mark as read\"> | |
961 | <input type=\"submit\" class=\"button\" | |
962 | onclick=\"javascript:unreadSelectedFeeds()\" value=\"Mark as unread\"> "; | |
f92db4f5 AD |
963 | } |
964 | print " | |
e828e31e AD |
965 | All feeds: |
966 | <input type=\"submit\" | |
8158c57a | 967 | class=\"button\" onclick=\"gotoExportOpml()\" value=\"Export OPML\">"; |
10c5820d | 968 | |
603c27f8 AD |
969 | } |
970 | ||
f5a50b25 AD |
971 | print "<h3>OPML Import</h3> |
972 | <form enctype=\"multipart/form-data\" method=\"POST\" action=\"opml.php\"> | |
973 | File: <input id=\"opml_file\" name=\"opml_file\" type=\"file\"> | |
974 | <input class=\"button\" name=\"op\" onclick=\"return validateOpmlImport();\" | |
975 | type=\"submit\" value=\"Import\"> | |
976 | </form>"; | |
977 | ||
007bda35 AD |
978 | } |
979 | ||
a0d53889 AD |
980 | if ($op == "pref-filters") { |
981 | ||
982 | $subop = $_GET["subop"]; | |
983 | ||
984 | if ($subop == "editSave") { | |
a0d53889 | 985 | |
648472a7 AD |
986 | $regexp = db_escape_string($_GET["r"]); |
987 | $descr = db_escape_string($_GET["d"]); | |
988 | $match = db_escape_string($_GET["m"]); | |
989 | $filter_id = db_escape_string($_GET["id"]); | |
0afbd851 | 990 | |
648472a7 | 991 | $result = db_query($link, "UPDATE ttrss_filters SET |
4b3dff6e | 992 | reg_exp = '$regexp', |
0afbd851 AD |
993 | description = '$descr', |
994 | filter_type = (SELECT id FROM ttrss_filter_types WHERE | |
995 | description = '$match') | |
996 | WHERE id = '$filter_id'"); | |
a0d53889 AD |
997 | } |
998 | ||
999 | if ($subop == "remove") { | |
1000 | ||
1001 | if (!WEB_DEMO_MODE) { | |
1002 | ||
1003 | $ids = split(",", $_GET["ids"]); | |
1004 | ||
1005 | foreach ($ids as $id) { | |
648472a7 | 1006 | db_query($link, "DELETE FROM ttrss_filters WHERE id = '$id'"); |
a0d53889 AD |
1007 | |
1008 | } | |
1009 | } | |
1010 | } | |
1011 | ||
1012 | if ($subop == "add") { | |
1013 | ||
de435974 | 1014 | if (!WEB_DEMO_MODE) { |
a0d53889 | 1015 | |
8158c57a | 1016 | $regexp = db_escape_string($_GET["regexp"]); |
648472a7 | 1017 | $match = db_escape_string($_GET["match"]); |
a0d53889 | 1018 | |
648472a7 | 1019 | $result = db_query($link, |
4b3dff6e | 1020 | "INSERT INTO ttrss_filters (reg_exp,filter_type) VALUES |
de435974 AD |
1021 | ('$regexp', (SELECT id FROM ttrss_filter_types WHERE |
1022 | description = '$match'))"); | |
1023 | } | |
a0d53889 AD |
1024 | } |
1025 | ||
648472a7 | 1026 | $result = db_query($link, "SELECT description |
a0d53889 AD |
1027 | FROM ttrss_filter_types ORDER BY description"); |
1028 | ||
1029 | $filter_types = array(); | |
1030 | ||
648472a7 | 1031 | while ($line = db_fetch_assoc($result)) { |
a0d53889 AD |
1032 | array_push($filter_types, $line["description"]); |
1033 | } | |
1034 | ||
1035 | print "<table class=\"prefAddFeed\"><tr> | |
ea6774cf | 1036 | <td><input id=\"fadd_regexp\"></td> |
a0d53889 | 1037 | <td>"; |
bdc00fe0 | 1038 | print_select("fadd_match", "Title", $filter_types); |
a0d53889 AD |
1039 | |
1040 | print"</td><td colspan=\"4\" align=\"right\"> | |
1041 | <a class=\"button\" href=\"javascript:addFilter()\">Add filter</a></td></tr> | |
1042 | </table>"; | |
1043 | ||
648472a7 | 1044 | $result = db_query($link, "SELECT |
4b3dff6e | 1045 | id,reg_exp,description, |
a0d53889 AD |
1046 | (SELECT name FROM ttrss_filter_types WHERE |
1047 | id = filter_type) as filter_type_name, | |
1048 | (SELECT description FROM ttrss_filter_types | |
1049 | WHERE id = filter_type) as filter_type_descr | |
1050 | FROM | |
4b3dff6e | 1051 | ttrss_filters ORDER by reg_exp"); |
a0d53889 AD |
1052 | |
1053 | print "<p><table width=\"100%\" class=\"prefFilterList\" id=\"prefFilterList\">"; | |
1054 | ||
1055 | print "<tr class=\"title\"> | |
0afbd851 AD |
1056 | <td width=\"5%\">Select</td><td width=\"40%\">Filter expression</td> |
1057 | <td width=\"40%\">Description</td><td width=\"10%\">Match</td></tr>"; | |
a0d53889 AD |
1058 | |
1059 | $lnum = 0; | |
1060 | ||
648472a7 | 1061 | while ($line = db_fetch_assoc($result)) { |
a0d53889 AD |
1062 | |
1063 | $class = ($lnum % 2) ? "even" : "odd"; | |
1064 | ||
1065 | $filter_id = $line["id"]; | |
1066 | $edit_filter_id = $_GET["id"]; | |
1067 | ||
1068 | if ($subop == "edit" && $filter_id != $edit_filter_id) { | |
1069 | $class .= "Grayed"; | |
1070 | } | |
1071 | ||
1072 | print "<tr class=\"$class\" id=\"FILRR-$filter_id\">"; | |
1073 | ||
4b3dff6e | 1074 | $line["regexp"] = htmlspecialchars($line["reg_exp"]); |
ea6774cf AD |
1075 | $line["description"] = htmlspecialchars($line["description"]); |
1076 | ||
a0d53889 AD |
1077 | if (!$edit_filter_id || $subop != "edit") { |
1078 | ||
0afbd851 AD |
1079 | if (!$line["description"]) $line["description"] = "[No description]"; |
1080 | ||
a0d53889 AD |
1081 | print "<td><input onclick='toggleSelectRow(this);' |
1082 | type=\"checkbox\" id=\"FICHK-".$line["id"]."\"></td>"; | |
1083 | ||
1084 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
4b3dff6e | 1085 | $line["reg_exp"] . "</td>"; |
a0d53889 AD |
1086 | |
1087 | print "<td><a href=\"javascript:editFilter($filter_id);\">" . | |
1088 | $line["description"] . "</td>"; | |
1089 | ||
1090 | print "<td>".$line["filter_type_descr"]."</td>"; | |
1091 | ||
1092 | } else if ($filter_id != $edit_filter_id) { | |
1093 | ||
0afbd851 AD |
1094 | if (!$line["description"]) $line["description"] = "[No description]"; |
1095 | ||
a0d53889 AD |
1096 | print "<td><input disabled=\"true\" type=\"checkbox\" |
1097 | id=\"FICHK-".$line["id"]."\"></td>"; | |
1098 | ||
4b3dff6e | 1099 | print "<td>".$line["reg_exp"]."</td>"; |
a0d53889 AD |
1100 | print "<td>".$line["description"]."</td>"; |
1101 | print "<td>".$line["filter_type_descr"]."</td>"; | |
1102 | ||
1103 | } else { | |
1104 | ||
1105 | print "<td><input disabled=\"true\" type=\"checkbox\"></td>"; | |
1106 | ||
4b3dff6e | 1107 | print "<td><input id=\"iedit_regexp\" value=\"".$line["reg_exp"]. |
a0d53889 AD |
1108 | "\"></td>"; |
1109 | ||
1110 | print "<td><input id=\"iedit_descr\" value=\"".$line["description"]. | |
1111 | "\"></td>"; | |
1112 | ||
1113 | print "<td>"; | |
1114 | print_select("iedit_match", $line["filter_type_descr"], $filter_types); | |
1115 | print "</td>"; | |
1116 | ||
1117 | } | |
1118 | ||
1119 | ||
1120 | print "</tr>"; | |
1121 | ||
1122 | ++$lnum; | |
1123 | } | |
1124 | ||
0afbd851 AD |
1125 | if ($lnum == 0) { |
1126 | print "<tr><td colspan=\"4\" align=\"center\">No filters defined.</td></tr>"; | |
1127 | } | |
1128 | ||
a0d53889 AD |
1129 | print "</table>"; |
1130 | ||
1131 | print "<p>"; | |
1132 | ||
1133 | if ($subop == "edit") { | |
e828e31e AD |
1134 | print "Edit feed: |
1135 | <input type=\"submit\" class=\"button\" | |
1136 | onclick=\"javascript:filterEditCancel()\" value=\"Cancel\"> | |
1137 | <input type=\"submit\" class=\"button\" | |
1138 | onclick=\"javascript:filterEditSave()\" value=\"Save\">"; | |
a0d53889 AD |
1139 | |
1140 | } else { | |
1141 | ||
1142 | print " | |
e828e31e AD |
1143 | Selection: |
1144 | <input type=\"submit\" class=\"button\" | |
1145 | onclick=\"javascript:editSelectedFilter()\" value=\"Edit\"> | |
1146 | <input type=\"submit\" class=\"button\" | |
1147 | onclick=\"javascript:removeSelectedFilters()\" value=\"Remove\">"; | |
a0d53889 AD |
1148 | } |
1149 | } | |
1150 | ||
48f0adb0 AD |
1151 | if ($op == "pref-labels") { |
1152 | ||
1153 | $subop = $_GET["subop"]; | |
1154 | ||
1155 | if ($subop == "editSave") { | |
1156 | ||
1157 | $sql_exp = $_GET["s"]; | |
1158 | $descr = $_GET["d"]; | |
1159 | $label_id = db_escape_string($_GET["id"]); | |
1160 | ||
1161 | // print "$sql_exp : $descr : $label_id"; | |
1162 | ||
1163 | $result = db_query($link, "UPDATE ttrss_labels SET | |
1164 | sql_exp = '$sql_exp', | |
1165 | description = '$descr' | |
1166 | WHERE id = '$label_id'"); | |
1167 | } | |
1168 | ||
1169 | if ($subop == "remove") { | |
1170 | ||
1171 | if (!WEB_DEMO_MODE) { | |
1172 | ||
1173 | $ids = split(",", $_GET["ids"]); | |
1174 | ||
1175 | foreach ($ids as $id) { | |
1176 | db_query($link, "DELETE FROM ttrss_labels WHERE id = '$id'"); | |
1177 | ||
1178 | } | |
1179 | } | |
1180 | } | |
1181 | ||
1182 | if ($subop == "add") { | |
1183 | ||
1184 | if (!WEB_DEMO_MODE) { | |
1185 | ||
1186 | $exp = $_GET["exp"]; | |
1187 | ||
1188 | $result = db_query($link, | |
1189 | "INSERT INTO ttrss_labels (sql_exp,description) | |
1190 | VALUES ('$exp', '$exp')"); | |
1191 | } | |
1192 | } | |
1193 | ||
1194 | print "<table class=\"prefAddFeed\"><tr> | |
1195 | <td><input id=\"ladd_expr\"></td>"; | |
1196 | ||
1197 | print"<td colspan=\"4\" align=\"right\"> | |
1198 | <a class=\"button\" href=\"javascript:addLabel()\">Add label</a></td></tr> | |
1199 | </table>"; | |
1200 | ||
1201 | $result = db_query($link, "SELECT | |
1202 | id,sql_exp,description | |
1203 | FROM | |
1204 | ttrss_labels ORDER by description"); | |
1205 | ||
1206 | print "<p><table width=\"100%\" class=\"prefLabelList\" id=\"prefLabelList\">"; | |
1207 | ||
1208 | print "<tr class=\"title\"> | |
7dc66a61 AD |
1209 | <td width=\"5%\">Select</td><td width=\"40%\">SQL expression |
1210 | <a class=\"helpLink\" href=\"javascript:popupHelp(1)\">(?)</a> | |
1211 | </td> | |
48f0adb0 AD |
1212 | <td width=\"40%\">Caption</td></tr>"; |
1213 | ||
1214 | $lnum = 0; | |
1215 | ||
1216 | while ($line = db_fetch_assoc($result)) { | |
1217 | ||
1218 | $class = ($lnum % 2) ? "even" : "odd"; | |
1219 | ||
1220 | $label_id = $line["id"]; | |
1221 | $edit_label_id = $_GET["id"]; | |
1222 | ||
1223 | if ($subop == "edit" && $label_id != $edit_label_id) { | |
1224 | $class .= "Grayed"; | |
1225 | } | |
1226 | ||
1227 | print "<tr class=\"$class\" id=\"LILRR-$label_id\">"; | |
1228 | ||
1229 | $line["sql_exp"] = htmlspecialchars($line["sql_exp"]); | |
1230 | $line["description"] = htmlspecialchars($line["description"]); | |
1231 | ||
1232 | if (!$edit_label_id || $subop != "edit") { | |
1233 | ||
1234 | if (!$line["description"]) $line["description"] = "[No caption]"; | |
1235 | ||
1236 | print "<td><input onclick='toggleSelectRow(this);' | |
1237 | type=\"checkbox\" id=\"LICHK-".$line["id"]."\"></td>"; | |
1238 | ||
1239 | print "<td><a href=\"javascript:editLabel($label_id);\">" . | |
1240 | $line["sql_exp"] . "</td>"; | |
1241 | ||
1242 | print "<td><a href=\"javascript:editLabel($label_id);\">" . | |
1243 | $line["description"] . "</td>"; | |
1244 | ||
1245 | } else if ($label_id != $edit_label_id) { | |
1246 | ||
1247 | if (!$line["description"]) $line["description"] = "[No description]"; | |
1248 | ||
1249 | print "<td><input disabled=\"true\" type=\"checkbox\" | |
1250 | id=\"LICHK-".$line["id"]."\"></td>"; | |
1251 | ||
1252 | print "<td>".$line["sql_exp"]."</td>"; | |
1253 | print "<td>".$line["description"]."</td>"; | |
1254 | ||
1255 | } else { | |
1256 | ||
1257 | print "<td><input disabled=\"true\" type=\"checkbox\"></td>"; | |
1258 | ||
1259 | print "<td><input id=\"iedit_expr\" value=\"".$line["sql_exp"]. | |
1260 | "\"></td>"; | |
1261 | ||
1262 | print "<td><input id=\"iedit_descr\" value=\"".$line["description"]. | |
1263 | "\"></td>"; | |
1264 | ||
1265 | } | |
1266 | ||
1267 | ||
1268 | print "</tr>"; | |
1269 | ||
1270 | ++$lnum; | |
1271 | } | |
1272 | ||
1273 | if ($lnum == 0) { | |
1274 | print "<tr><td colspan=\"4\" align=\"center\">No labels defined.</td></tr>"; | |
1275 | } | |
1276 | ||
1277 | print "</table>"; | |
1278 | ||
1279 | print "<p>"; | |
1280 | ||
1281 | if ($subop == "edit") { | |
1282 | print "Edit label: | |
1283 | <input type=\"submit\" class=\"button\" | |
1284 | onclick=\"javascript:labelEditCancel()\" value=\"Cancel\"> | |
1285 | <input type=\"submit\" class=\"button\" | |
1286 | onclick=\"javascript:labelEditSave()\" value=\"Save\">"; | |
1287 | ||
1288 | } else { | |
1289 | ||
1290 | print " | |
1291 | Selection: | |
1292 | <input type=\"submit\" class=\"button\" | |
1293 | onclick=\"javascript:editSelectedLabel()\" value=\"Edit\"> | |
1294 | <input type=\"submit\" class=\"button\" | |
1295 | onclick=\"javascript:removeSelectedLabels()\" value=\"Remove\">"; | |
1296 | } | |
1297 | } | |
1298 | ||
e828e31e AD |
1299 | if ($op == "error") { |
1300 | print "<div width=\"100%\" align='center'>"; | |
1301 | $msg = $_GET["msg"]; | |
1302 | print $msg; | |
1303 | print "</div>"; | |
1304 | } | |
1305 | ||
7dc66a61 AD |
1306 | if ($op == "help") { |
1307 | print "<html><head> | |
1308 | <title>Tiny Tiny RSS : Help</title> | |
1309 | <link rel=\"stylesheet\" href=\"tt-rss.css\" type=\"text/css\"> | |
1310 | <script type=\"text/javascript\" src=\"functions.js\"></script> | |
1311 | <script type=\"text/javascript\" src=\"feedlist.js\"></script> | |
1312 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"> | |
1313 | </head><body>"; | |
1314 | ||
1315 | $tid = sprintf("%d", $_GET["tid"]); | |
1316 | ||
1317 | /* FIXME this badly needs real implementation */ | |
1318 | ||
1319 | print "<div class='helpResponse'>"; | |
1320 | ||
1321 | ?> | |
1322 | ||
1323 | <h1>Help for SQL expressions</h1> | |
1324 | ||
1325 | <h2>Description</h2> | |
1326 | ||
1327 | <p>The «SQL expression» is added to WHERE clause of | |
d1f948d1 | 1328 | view feed query. You can match on ttrss_entries table fields |
7dc66a61 AD |
1329 | and even use subselect to query additional information. This |
1330 | functionality is considered to be advanced and requires basic | |
1331 | understanding of SQL.</p> | |
1332 | ||
1333 | <h2>Examples</h2> | |
1334 | ||
1335 | <pre>unread = true</pre> | |
1336 | ||
1337 | Matches all unread articles | |
1338 | ||
1339 | <pre>title like '%Linux%'</pre> | |
1340 | ||
1341 | Matches all articles which mention Linux in the title. You get the idea. | |
1342 | ||
1343 | <p>See the database schema included in the distribution package for gruesome | |
1344 | details.</p> | |
1345 | ||
1346 | <? | |
1347 | ||
1348 | print "<div align='center'> | |
1349 | <a class=\"helpLink\" | |
1350 | href=\"javascript:window.close()\">(Close this window)</a></div>"; | |
1351 | ||
1352 | print "</div>"; | |
1353 | ||
1354 | print "</body></html>"; | |
1355 | ||
1356 | } | |
1357 | ||
f84a97a3 AD |
1358 | if ($op == "dlg") { |
1359 | $id = $_GET["id"]; | |
6de5d056 | 1360 | $param = $_GET["param"]; |
f84a97a3 AD |
1361 | |
1362 | if ($id == "quickAddFeed") { | |
033e47e0 AD |
1363 | print "Feed URL: <input |
1364 | onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\" | |
1365 | id=\"qafInput\"> | |
f84a97a3 AD |
1366 | <input class=\"button\" |
1367 | type=\"submit\" onclick=\"javascript:qafAdd()\" value=\"Add feed\"> | |
1368 | <input class=\"button\" | |
1369 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
1370 | value=\"Cancel\">"; | |
1371 | } | |
6de5d056 AD |
1372 | |
1373 | if ($id == "quickDelFeed") { | |
1374 | ||
1375 | $param = db_escape_string($param); | |
1376 | ||
1377 | $result = db_query($link, "SELECT title FROM ttrss_feeds WHERE id = '$param'"); | |
1378 | ||
1379 | if ($result) { | |
1380 | ||
1381 | $f_title = db_fetch_result($result, 0, "title"); | |
1382 | ||
1383 | print "Remove current feed ($f_title)? | |
1384 | <input class=\"button\" | |
1385 | type=\"submit\" onclick=\"javascript:qfdDelete($param)\" value=\"Remove\"> | |
1386 | <input class=\"button\" | |
1387 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
1388 | value=\"Cancel\">"; | |
1389 | } else { | |
1390 | print "Error: Feed $param not found. | |
1391 | <input class=\"button\" | |
1392 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
1393 | value=\"Cancel\">"; | |
1394 | } | |
1395 | } | |
1396 | ||
033e47e0 AD |
1397 | if ($id == "search") { |
1398 | ||
1399 | print "<input id=\"searchbox\" class=\"extSearch\" | |
1400 | onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\" | |
1401 | onchange=\"javascript:search()\"> | |
1402 | <select id=\"searchmodebox\"> | |
1403 | <option selected>All feeds</option> | |
1404 | <option>This feed</option> | |
1405 | </select> | |
1406 | <input type=\"submit\" | |
1407 | class=\"button\" onclick=\"javascript:search()\" value=\"Search\"> | |
1408 | <input class=\"button\" | |
1409 | type=\"submit\" onclick=\"javascript:closeDlg()\" | |
1410 | value=\"Close\">"; | |
1411 | ||
1412 | } | |
1413 | ||
f84a97a3 AD |
1414 | } |
1415 | ||
4b3dff6e | 1416 | db_close($link); |
1cd17194 | 1417 | ?> |
406d9489 AD |
1418 | |
1419 | <!-- <?= sprintf("Backend execution time: %.4f seconds", getmicrotime() - $script_started) ?> --> | |
1420 |