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