2 // header("Content-Type: application/xml");
4 require_once "config.php";
5 require_once "functions.php";
6 require_once "magpierss/rss_fetch.inc";
10 $link = pg_connect(DB_CONN
);
12 error_reporting (E_ERROR | E_WARNING | E_PARSE
);
15 print "Could not connect to database. Please check local configuration.";
19 pg_query("set client_encoding = 'utf-8'");
22 $fetch = $_GET["fetch"];
24 function outputFeedList($link) {
26 $result = pg_query($link, "SELECT *,
27 (SELECT count(id) FROM ttrss_entries
28 WHERE feed_id = ttrss_feeds.id) AS total,
29 (SELECT count(id) FROM ttrss_entries
30 WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
31 FROM ttrss_feeds ORDER BY title");
33 print "<table width=\"100%\" class=\"feeds\" id=\"feedsList\">";
39 while ($line = pg_fetch_assoc($result)) {
41 $feed = $line["title"];
42 $feed_id = $line["id"];
44 $subop = $_GET["subop"];
46 $total = $line["total"];
47 $unread = $line["unread"];
49 $class = ($lnum %
2) ?
"even" : "odd";
51 if ($unread > 0) $class .= "Unread";
53 $total_unread +
= $unread;
55 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
57 $icon_file = ICONS_DIR
. "/$feed_id.ico";
59 if ($subop != "piggie") {
61 if (file_exists($icon_file) && filesize($icon_file) > 0) {
62 $feed_icon = "<img width=\"16\" height=\"16\"
63 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
65 $feed_icon = " ";
68 $feed_icon = "<img width=\"16\" height=\"16\"
69 src=\"http://madoka.spb.ru/stuff/fox/tiny_piggie.png\">";
72 $feed = "<a href=\"javascript:viewfeed($feed_id, 0);\">$feed</a>";
73 if (ENABLE_FEED_ICONS
) {
74 print "<td>$feed_icon</td>";
76 print "<td id=\"FEEDN-$feed_id\">$feed</td>";
78 print "<span id=\"FEEDU-$feed_id\">$unread</span> / ";
79 print "<span id=\"FEEDT-$feed_id\">$total</span>";
86 // print "<tr><td class=\"footer\" colspan=\"3\">
87 // <a href=\"javascript:update_feed_list(false,true)\">Update all feeds</a></td></tr>";
89 // print "<tr><td class=\"footer\" colspan=\"2\"> ";
90 // print "</td></tr>";
94 print "<p align=\"center\">All feeds:
96 href=\"javascript:scheduleFeedUpdate(true)\">Update</a>";
98 print " <a class=\"button\"
99 href=\"javascript:catchupAllFeeds()\">Mark as read</a></p>";
101 print "<div class=\"invisible\" id=\"FEEDTU\">$total_unread</div>";
110 $subop = $_GET["subop"];
112 if ($subop == "getRelativeId") {
113 $mode = $_GET["mode"];
115 $feed_id = $_GET["feed"];
117 if ($id != 'false' && $feed_id != 'false') {
119 if ($mode == 'next') {
120 $check_qpart = "updated >= ";
122 $idcheck_qpart = "id < '$id'";
125 $result = pg_query("SELECT id FROM ttrss_entries WHERE
128 ORDER BY updated DESC LIMIT 1");
130 $result_id = pg_fetch_result($result, 0, "id");
132 print "M $mode : P $id -> P $result_id : F $feed_id";
137 if ($subop == "forceUpdateAllFeeds") {
138 update_all_feeds($link, true);
139 outputFeedList($link);
142 if ($subop == "updateAllFeeds") {
143 update_all_feeds($link, false);
144 outputFeedList($link);
147 if ($subop == "catchupPage") {
149 $ids = split(",", $_GET["ids"]);
151 foreach ($ids as $id) {
153 pg_query("UPDATE ttrss_entries SET unread=false,last_read = NOW()
158 print "Marked active page as read.";
163 if ($op == "feeds") {
165 $subop = $_GET["subop"];
167 if ($subop == "catchupAll") {
168 pg_query("UPDATE ttrss_entries SET last_read = NOW(),unread = false");
171 outputFeedList($link);
179 $result = pg_query("UPDATE ttrss_entries SET unread = false,last_read = NOW() WHERE id = '$id'");
181 $result = pg_query("SELECT title,link,content,feed_id,comments,
182 (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url
188 $line = pg_fetch_assoc($result);
190 if ($line["icon_url"]) {
191 $feed_icon = "<img class=\"feedIcon\" src=\"" . $line["icon_url"] . "\">";
193 $feed_icon = " ";
196 print "<table class=\"postTable\" width=\"100%\" cellspacing=\"0\"
199 print "<tr class=\"titleTop\"><td align=\"right\"><b>Title:</b></td>
200 <td width=\"100%\">".$line["title"]."</td>
201 <td> </td></tr>";
203 if ($line["comments"] && $line["comments"] != $line["link"]) {
204 // print "<tr class=\"titleInner\"><td align=\"right\"><b>Comments:</b></td>
205 // <td><a href=\"".$line["comments"]."\">".$line["comments"]."</a></td>
206 // <td> </td> </tr>";
208 $comments_prompt = "(<a href=\"".$line["comments"]."\">Comments</a>)";
211 print "<tr class=\"titleBottom\"><td align=\"right\"><b>Link:</b></td>
212 <td><a href=\"".$line["link"]."\">".$line["link"]."</a> $comments_prompt</td>
213 <td> </td></tr>";
214 print "<tr><td valign=\"top\" class=\"post\"
215 colspan=\"2\">" . $line["content"] . "</td>
216 <td valign=\"top\">$feed_icon</td>
223 if ($op == "viewfeed") {
225 $feed = $_GET["feed"];
226 $skip = $_GET["skip"];
227 $subop = $_GET["subop"];
229 if (!$skip) $skip = 0;
231 if ($subop == "undefined") $subop = "";
233 // FIXME: check for null value here
235 $result = pg_query("SELECT *,SUBSTRING(last_updated,1,16) as last_updated,
236 EXTRACT(EPOCH FROM NOW()) - EXTRACT(EPOCH FROM last_updated) as update_timeout
237 FROM ttrss_feeds WHERE id = '$feed'");
241 $line = pg_fetch_assoc($result);
243 if ($subop == "ForceUpdate" ||
244 (!$subop && $line["update_timeout"] > MIN_UPDATE_TIME
)) {
246 update_rss_feed($link, $line["feed_url"], $feed);
250 if ($subop == "MarkAllRead") {
252 pg_query("UPDATE ttrss_entries SET unread = false,last_read = NOW()
253 WHERE feed_id = '$feed'");
258 print "<table class=\"headlinesList\" id=\"headlinesList\" width=\"100%\">";
260 $feed_last_updated = "Updated: " . $line["last_updated"];
262 print "<tr><td class=\"search\" colspan=\"3\">
263 Search: <input id=\"searchbox\"
264 onblur=\"javascript:enableHotkeys()\" onfocus=\"javascript:disableHotkeys()\"
265 onchange=\"javascript:search($feed);\">
266 <a class=\"button\" href=\"javascript:resetSearch()\">Reset</a>
269 <td colspan=\"3\" class=\"title\">" . $line["title"] . "</td></tr>";
271 $search = $_GET["search"];
274 $search_query_part = "(upper(title) LIKE upper('%$search%')
275 OR content LIKE '%$search%') AND";
278 $result = pg_query("SELECT count(id) AS total_entries
279 FROM ttrss_entries WHERE
283 $total_entries = pg_fetch_result($result, 0, "total_entries");
285 $result = pg_query("SELECT
286 id,title,updated,unread,feed_id,
287 EXTRACT(EPOCH FROM last_read) AS last_read_ts,
288 EXTRACT(EPOCH FROM updated) AS updated_ts
293 feed_id = '$feed' ORDER BY updated DESC LIMIT ".HEADLINES_PER_PAGE
." OFFSET $skip");
299 while ($line = pg_fetch_assoc($result)) {
301 $class = ($lnum %
2) ?
"even" : "odd";
303 if ($line["last_read_ts"] < $line["updated_ts"] && $line["unread"] == "f") {
304 $update_pic = "<img src=\"images/updated.png\" alt=\"Updated\">";
307 $update_pic = " ";
310 if ($line["unread"] == "t") {
316 $feed_id = $line["feed_id"];
318 $content_link = "<a href=\"javascript:view($id,$feed_id);\">" .
319 $line["title"] . "</a>";
321 print "<tr class='$class' id='RROW-$id'>";
323 print "<td id='FUPDPIC-$id' valign='center' class='headlineUpdateMark'>$update_pic</td>";
325 print "<td class='headlineUpdated'>
326 <a href=\"javascript:view($id,$feed_id);\">".$line["updated"]."</a></td>";
327 print "<td class='headlineTitle'>$content_link</td>";
335 print "<tr><td align='center'>No entries found.</td></tr>";
338 while ($lnum < HEADLINES_PER_PAGE
) {
340 print "<tr><td> </td></tr>";
343 // start unholy navbar block
345 print "<tr><td colspan=\"3\" class=\"headlineToolbar\">";
347 $next_skip = $skip + HEADLINES_PER_PAGE
;
348 $prev_skip = $skip - HEADLINES_PER_PAGE
;
352 if ($prev_skip >= 0) {
353 print "<a class=\"button\"
354 href=\"javascript:viewfeed($feed, $prev_skip);\">Previous Page</a>";
356 print "<a class=\"disabledButton\">Previous Page</a>";
360 if ($next_skip < $total_entries) {
361 print "<a class=\"button\"
362 href=\"javascript:viewfeed($feed, $next_skip);\">Next Page</a>";
364 print "<a class=\"disabledButton\">Next Page</a>";
366 print " Feed: ";
368 print "<a class=\"button\"
369 href=\"javascript:viewfeed($feed, 0, 'ForceUpdate');\">Update</a>";
371 print " Mark as read: ";
373 if ($num_unread > 0) {
374 print "<a class=\"button\" id=\"btnCatchupPage\"
375 href=\"javascript:catchupPage($feed);\">This Page</a>";
378 print "<a class=\"disabledButton\">This Page</a>";
382 print "<a class=\"button\"
383 href=\"javascript:viewfeed($feed, $skip, 'MarkAllRead');\">All Posts</a>";
387 // end unholy navbar block
391 $result = pg_query("SELECT id, (SELECT count(id) FROM ttrss_entries
392 WHERE feed_id = ttrss_feeds.id) AS total,
393 (SELECT count(id) FROM ttrss_entries
394 WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
395 FROM ttrss_feeds WHERE id = '$feed'");
397 $total = pg_fetch_result($result, 0, "total");
398 $unread = pg_fetch_result($result, 0, "unread");
400 print "<div class=\"invisible\" id=\"FACTIVE\">$feed</div>";
401 print "<div class=\"invisible\" id=\"FTOTAL\">$total</div>";
402 print "<div class=\"invisible\" id=\"FUNREAD\">$unread</div>";
406 if ($op == "pref-rpc") {
408 $subop = $_GET["subop"];
410 if ($subop == "unread") {
411 $ids = split(",", $_GET["ids"]);
412 foreach ($ids as $id) {
413 pg_query("UPDATE ttrss_entries SET unread = true WHERE feed_id = '$id'");
416 print "Marked selected feeds as read.";
419 if ($subop == "read") {
420 $ids = split(",", $_GET["ids"]);
421 foreach ($ids as $id) {
422 pg_query("UPDATE ttrss_entries
423 SET unread = false,last_read = NOW() WHERE feed_id = '$id'");
426 print "Marked selected feeds as unread.";
432 if ($op == "pref-feeds") {
434 $subop = $_GET["subop"];
436 if ($subop == "editSave") {
437 $feed_title = pg_escape_string($_GET["t"]);
438 $feed_link = pg_escape_string($_GET["l"]);
439 $feed_id = $_GET["id"];
441 $result = pg_query("UPDATE ttrss_feeds SET
442 title = '$feed_title', feed_url = '$feed_link' WHERE id = '$feed_id'");
446 if ($subop == "remove") {
448 if (!WEB_DEMO_MODE
) {
450 $ids = split(",", $_GET["ids"]);
452 foreach ($ids as $id) {
454 pg_query("DELETE FROM ttrss_entries WHERE feed_id = '$id'");
455 pg_query("DELETE FROM ttrss_feeds WHERE id = '$id'");
458 if (file_exists(ICONS_DIR
. "/$id.ico")) {
459 unlink(ICONS_DIR
. "/$id.ico");
465 if ($subop == "add") {
467 if (!WEB_DEMO_MODE
) {
469 $feed_link = pg_escape_string($_GET["link"]);
472 "INSERT INTO ttrss_feeds (feed_url,title) VALUES ('$feed_link', '')");
475 "SELECT id FROM ttrss_feeds WHERE feed_url = '$feed_link'");
477 $feed_id = pg_fetch_result($result, 0, "id");
480 update_rss_feed($link, $feed_link, $feed_id);
485 $result = pg_query("SELECT
486 id,title,feed_url,substring(last_updated,1,16) as last_updated
488 ttrss_feeds ORDER by title");
490 print "<p><table width=\"100%\" class=\"prefFeedList\" id=\"prefFeedList\">";
491 print "<tr class=\"title\">
492 <td> </td><td>Select</td><td width=\"40%\">Title</td>
493 <td width=\"40%\">Link</td><td>Last Updated</td></tr>";
497 while ($line = pg_fetch_assoc($result)) {
499 $class = ($lnum %
2) ?
"even" : "odd";
501 $feed_id = $line["id"];
503 $edit_feed_id = $_GET["id"];
505 if ($subop == "edit" && $feed_id != $edit_feed_id) {
509 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
511 $icon_file = ICONS_DIR
. "/$feed_id.ico";
513 if (file_exists($icon_file) && filesize($icon_file) > 0) {
514 $feed_icon = "<img width=\"16\" height=\"16\"
515 src=\"" . ICONS_URL
. "/$feed_id.ico\">";
517 $feed_icon = " ";
519 print "<td align='center'>$feed_icon</td>";
521 if (!$edit_feed_id ||
$subop != "edit") {
523 print "<td><input onclick='toggleSelectRow(this);'
524 type=\"checkbox\" id=\"FRCHK-".$line["id"]."\"></td>";
526 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
527 $line["title"] . "</td>";
528 print "<td><a href=\"javascript:editFeed($feed_id);\">" .
529 $line["feed_url"] . "</td>";
532 } else if ($feed_id != $edit_feed_id) {
534 print "<td><input disabled=\"true\" type=\"checkbox\"
535 id=\"FRCHK-".$line["id"]."\"></td>";
537 print "<td>".$line["title"]."</td>";
538 print "<td>".$line["feed_url"]."</td>";
542 print "<td><input disabled=\"true\" type=\"checkbox\"></td>";
544 print "<td><input id=\"iedit_title\" value=\"".$line["title"]."\"></td>";
545 print "<td><input id=\"iedit_link\" value=\"".$line["feed_url"]."\"></td>";
549 print "<td>" . $line["last_updated"] . "</td>";
560 if ($subop == "edit") {
561 print "Edit feed:
562 <a class=\"button\" href=\"javascript:feedEditCancel()\">Cancel</a>
563 <a class=\"button\" href=\"javascript:feedEditSave()\">Save</a>";
569 href=\"javascript:editSelectedFeed()\">Edit</a>
570 <a class=\"buttonWarn\"
571 href=\"javascript:removeSelectedFeeds()\">Remove</a>
573 href=\"javascript:readSelectedFeeds()\">Mark as read</a>
575 href=\"javascript:unreadSelectedFeeds()\">Mark as unread</a>
578 href=\"javascript:updateFeedList()\">Refresh</a>";