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