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