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