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