]> git.wh0rd.org - tt-rss.git/blob - backend.php
basic functionality pass 4
[tt-rss.git] / backend.php
1 <?
2 header("Content-Type: application/xml");
3
4 require_once "config.php";
5 require_once "functions.php";
6 require_once "magpierss/rss_fetch.inc";
7
8
9 $link = pg_connect(DB_CONN);
10
11 pg_query("set client_encoding = 'utf-8'");
12
13 $op = $_GET["op"];
14
15 if ($op == "feeds") {
16
17 update_all_feeds($link);
18
19 $result = pg_query("SELECT *,
20 (SELECT count(id) FROM ttrss_entries
21 WHERE feed_id = ttrss_feeds.id) AS total,
22 (SELECT count(id) FROM ttrss_entries
23 WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
24 FROM ttrss_feeds ORDER BY title");
25
26 print "<table width=\"100%\" class=\"feeds\">";
27
28 $lnum = 0;
29
30 while ($line = pg_fetch_assoc($result)) {
31
32 $feed = $line["title"];
33 $feed_id = $line["id"];
34
35 $total = $line["total"];
36 $unread = $line["unread"];
37
38 $class = ($lnum % 2) ? "even" : "odd";
39
40 if ($unread > 0) $class .= "Unread";
41
42 print "<tr class=\"$class\" id=\"FEEDR-$feed_id\">";
43
44 $feed = "<a href=\"javascript:viewfeed($feed_id, 0);\">$feed</a>";
45 print "<td id=\"FEEDN-$feed_id\">$feed</td>";
46 print "<td id=\"FEEDU-$feed_id\">$unread</td>";
47 print "<td id=\"FEEDT-$feed_id\">$total</td>";
48
49 print "</tr>";
50 ++$lnum;
51 }
52
53 print "<tr><td class=\"footer\" colspan=\"3\">
54 <a href=\"javascript:update_feed_list()\">Update all feeds</a></td></tr>";
55
56 print "</table>";
57
58 }
59
60 if ($op == "view") {
61
62 $id = $_GET["id"];
63
64 $result = pg_query("UPDATE ttrss_entries SET unread = false WHERE id = '$id'");
65
66 $result = pg_query("SELECT title,link,content FROM ttrss_entries
67 WHERE id = '$id'");
68
69 if ($result) {
70
71 $line = pg_fetch_assoc($result);
72
73 print "<table class=\"feedOverview\">";
74 print "<tr><td><b>Title:</b></td><td>".$line["title"]."</td></tr>";
75 print "<tr><td><b>Link:</b></td><td><a href=\"".$line["link"]."\">".$line["link"]."</a></td></tr>";
76
77 print "</table>";
78
79 print $line["content"];
80
81
82 }
83 }
84
85 if ($op == "viewfeed") {
86
87 $feed = $_GET["feed"];
88 $skip = $_GET["skip"];
89 $ext = $_GET["ext"];
90
91 if (!$skip) $skip = 0;
92
93 if ($ext == "undefined") $ext = "";
94
95 // FIXME: check for null value here
96
97 $result = pg_query("SELECT *,
98 EXTRACT(EPOCH FROM NOW()) - EXTRACT(EPOCH FROM last_updated) as update_timeout
99 FROM ttrss_feeds WHERE id = '$feed'");
100
101 if ($result) {
102
103 $line = pg_fetch_assoc($result);
104
105 if (!$ext && $line["update_timeout"] > MIN_UPDATE_TIME) {
106
107 update_rss_feed($link, $line["feed_url"], $feed);
108
109 } else {
110
111 if ($ext == "MarkAllRead") {
112
113 pg_query("UPDATE ttrss_entries SET unread = false
114 WHERE feed_id = '$feed'");
115 }
116 }
117 }
118
119 print "<table class=\"headlines\" width=\"100%\">";
120 /* print "<tr><td class=\"search\">
121 Search: <input onchange=\"javascript:search($feed,this);\"></td>";
122 print "<td class=\"title\">" . $line["title"] . "</td></tr>"; */
123
124 print "<tr><td class=\"search\" colspan=\"2\">
125 Search: <input onchange=\"javascript:search($feed,this);\"></td></tr>";
126 print "<tr><td colspan=\"2\" class=\"title\">" . $line["title"] . "</td></tr>";
127
128 if ($ext == "SEARCH") {
129 $search = $_GET["search"];
130 $search_query_part = "(upper(title) LIKE upper('%$search%')
131 OR content LIKE '%$search%') AND";
132 }
133
134 $result = pg_query("SELECT id,title,updated,unread,feed_id FROM
135 ttrss_entries WHERE
136 $search_query_part
137 feed_id = '$feed' ORDER BY updated DESC LIMIT ".HEADLINES_PER_PAGE." OFFSET $skip");
138
139 $lnum = 0;
140
141 while ($line = pg_fetch_assoc($result)) {
142
143 $class = ($lnum % 2) ? "even" : "odd";
144
145 if ($line["unread"] == "t")
146 $class .= "Unread";
147
148 $content_link = "<a href=\"javascript:view(".$line["id"].",".$line["feed_id"].");\">".$line["title"]."</a>";
149
150 print "<tr class='$class' id='RROW-".$line["id"]."'>";
151 print "<td class='headlineUpdated'>".$line["updated"]."</td>";
152 print "<td class='headlineTitle'>$content_link</td>";
153
154 print "</tr>";
155
156 ++$lnum;
157 }
158
159 if ($lnum == 0) {
160 print "<tr><td align='center'>No entries found.</td></tr>";
161
162 }
163
164 print "<tr><td colspan=\"2\" class=\"headlineToolbar\">";
165
166 $next_skip = $skip + HEADLINES_PER_PAGE;
167 $prev_skip = $skip - HEADLINES_PER_PAGE;
168
169 print "<a class=\"button\"
170 href=\"javascript:viewfeed($feed, $prev_skip);\">Previous Page</a>";
171 print "&nbsp;";
172 print "<a class=\"button\"
173 href=\"javascript:viewfeed($feed, $next_skip);\">Next Page</a>";
174 print "&nbsp;&nbsp;&nbsp;";
175
176 print "<a class=\"button\"
177 href=\"javascript:viewfeed($feed, 0, '');\">Refresh</a>";
178 print "&nbsp;&nbsp;&nbsp;";
179 print "<a class=\"button\"
180 href=\"javascript:viewfeed($feed, 0, 'MarkAllRead');\">Mark all as read</a>";
181
182 print "</td></tr>";
183 print "</table>";
184
185 $result = pg_query("SELECT id, (SELECT count(id) FROM ttrss_entries
186 WHERE feed_id = ttrss_feeds.id) AS total,
187 (SELECT count(id) FROM ttrss_entries
188 WHERE feed_id = ttrss_feeds.id AND unread = true) as unread
189 FROM ttrss_feeds WHERE id = '$feed'");
190
191 $total = pg_fetch_result($result, 0, "total");
192 $unread = pg_fetch_result($result, 0, "unread");
193
194 print "<div class=\"invisible\" id=\"FACTIVE\">$feed</div>";
195 print "<div class=\"invisible\" id=\"FTOTAL\">$total</div>";
196 print "<div class=\"invisible\" id=\"FUNREAD\">$unread</div>";
197
198 }
199
200
201 ?>