]>
git.wh0rd.org - tt-rss.git/blob - backend.php
2 header("Content-Type: application/xml");
6 require_once('magpierss/rss_fetch.inc');
8 $link = pg_connect(DB_CONN
);
10 pg_query("set client_encoding = 'utf-8'");
16 $result = pg_query("SELECT *,
17 (SELECT count(id) FROM ttrss_entries
18 WHERE feed_id = ttrss_feeds.id) AS total,
19 (SELECT count(id) FROM ttrss_entries
20 WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
21 FROM ttrss_feeds ORDER BY title");
23 print "<table width=\"100%\">";
27 while ($line = pg_fetch_assoc($result)) {
29 $feed = $line["title"];
30 $feed_id = $line["id"];
32 $total = $line["total"];
33 $unread = $line["unread"];
35 $class = ($lnum %
2) ?
"even" : "odd";
37 // if ($lnum == 2 || $lnum == 0) $feed = "<b>$feed</b>";
39 if ($unread > 0) $class .= "Unread";
41 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
43 $feed = "<a href=\"javascript:viewfeed($feed_id, 0);\">$feed</a>";
44 print "<td id=\"FEEDN-$feed_id\">$feed</td>";
45 print "<td id=\"FEEDU-$feed_id\">$unread</td>";
46 print "<td id=\"FEEDT-$feed_id\">$total</td>";
60 $result = pg_query("UPDATE ttrss_entries SET unread = false WHERE id = '$id'");
62 $result = pg_query("SELECT title,link,content FROM ttrss_entries
67 $line = pg_fetch_assoc($result);
69 print "<table class=\"feedOverview\">";
70 print "<tr><td><b>Title:</b></td><td>".$line["title"]."</td></tr>";
71 print "<tr><td><b>Link:</b></td><td><a href=\"".$line["link"]."\">".$line["link"]."</a></td></tr>";
75 print $line["content"];
81 if ($op == "viewfeed") {
83 $feed = $_GET["feed"];
84 $skip = $_GET["skip"];
87 if ($ext == "undefined") $ext = "";
89 $result = pg_query("SELECT * FROM ttrss_feeds WHERE id = '$feed'");
93 $line = pg_fetch_assoc($result);
97 $rss = fetch_rss($line["feed_url"]);
101 foreach ($rss->items
as $item) {
103 $entry_guid = $item["id"];
105 if (!$entry_guid) $entry_guid = $item["guid"];
106 if (!$entry_guid) $entry_guid = $item["link"];
108 $entry_timestamp = $item["pubdate"];
109 if (!$entry_timestamp) $entry_timestamp = $item["modified"];
110 if (!$entry_timestamp) $entry_timestamp = $item["updated"];
112 $entry_timestamp = strtotime($entry_timestamp);
114 $entry_title = $item["title"];
115 $entry_link = $item["link"];
117 $entry_content = $item["description"];
118 if (!$entry_content) $entry_content = $item["content"];
120 $entry_content = pg_escape_string($entry_content);
121 $entry_title = pg_escape_string($entry_title);
123 $content_md5 = md5($entry_content);
131 guid = '$entry_guid' OR md5_hash = '$content_md5'");
133 if (pg_num_rows($result) == 0) {
135 $entry_timestamp = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp);
137 $query = "INSERT INTO ttrss_entries
138 (title, guid, link, updated, content, feed_id, md5_hash)
140 ('$entry_title', '$entry_guid', '$entry_link',
141 '$entry_timestamp', '$entry_content', '$feed',
148 $entry_id = pg_fetch_result($result, 0, "id");
149 $entry_timestamp = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp);
151 $unread = pg_fetch_result($result, 0, "unread");
152 $md5_hash = pg_fetch_result($result, 0, "md5_hash");
154 if ($md5_hash != $content_md5)
157 $query = "UPDATE ttrss_entries
159 title ='$entry_title',
160 link = '$entry_link',
161 updated = '$entry_timestamp',
162 content = '$entry_content',
163 md5_hash = '$content_md5',
168 $result = pg_query($query);
170 // print "$entry_guid - $entry_timestamp - $entry_title -
171 // $entry_link - $entry_id<br>";
181 if ($ext == "MarkAllRead") {
183 pg_query("UPDATE ttrss_entries SET unread = false
184 WHERE feed_id = '$feed'");
190 print "<table class=\"headlines\" width=\"100%\">";
191 print "<tr><td colspan=\"2\" class=\"title\">" . $line["title"] . "</td></tr>";
193 $result = pg_query("SELECT id,title,updated,unread,feed_id FROM
195 feed_id = '$feed' ORDER BY updated LIMIT ".HEADLINES_PER_PAGE
." OFFSET $skip");
199 while ($line = pg_fetch_assoc($result)) {
201 $class = ($lnum %
2) ?
"even" : "odd";
203 if ($line["unread"] == "t")
206 $content_link = "<a href=\"javascript:view(".$line["id"].",".$line["feed_id"].");\">".$line["title"]."</a>";
208 print "<tr class='$class' id='RROW-".$line["id"]."'>";
209 print "<td class='headlineUpdated'>".$line["updated"]."</td>";
210 print "<td class='headlineTitle'>$content_link</td>";
217 print "<tr><td colspan=\"2\" class=\"headlineToolbar\">";
219 $next_skip = $skip + HEADLINES_PER_PAGE
;
220 $prev_skip = $skip - HEADLINES_PER_PAGE
;
222 print "<a class=\"button\"
223 href=\"javascript:viewfeed($feed, $prev_skip);\">Previous Page</a>";
225 print "<a class=\"button\"
226 href=\"javascript:viewfeed($feed, $next_skip);\">Next Page</a>";
227 print " ";
229 print "<a class=\"button\"
230 href=\"javascript:viewfeed($feed, 0, 'MarkAllRead');\">Mark all as read</a>";
235 $result = pg_query("SELECT id, (SELECT count(id) FROM ttrss_entries
236 WHERE feed_id = ttrss_feeds.id) AS total,
237 (SELECT count(id) FROM ttrss_entries
238 WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
239 FROM ttrss_feeds WHERE id = '$feed'");
241 $total = pg_fetch_result($result, 0, "total");
242 $unread = pg_fetch_result($result, 0, "unread");
244 print "<div class=\"invisible\" id=\"FACTIVE\">$feed</div>";
245 print "<div class=\"invisible\" id=\"FTOTAL\">$total</div>";
246 print "<div class=\"invisible\" id=\"FUNREAD\">$unread</div>";