]>
Commit | Line | Data |
---|---|---|
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>"; | |
47 | print "<span id=\"FEEDU-$feed_id\">$unread</span> / "; | |
48 | print "<span id=\"FEEDT-$feed_id\">$total</span>"; | |
49 | print "</td>"; | |
50 | ||
51 | print "</tr>"; | |
52 | ++$lnum; | |
53 | } | |
54 | ||
55 | print "<tr><td class=\"footer\" colspan=\"3\"> | |
56 | <a href=\"javascript:update_feed_list()\">Update all feeds</a></td></tr>"; | |
57 | ||
58 | print "</table>"; | |
59 | ||
60 | } | |
61 | ||
62 | if ($op == "view") { | |
63 | ||
64 | $id = $_GET["id"]; | |
65 | ||
66 | $result = pg_query("UPDATE ttrss_entries SET unread = false WHERE id = '$id'"); | |
67 | ||
68 | $result = pg_query("SELECT title,link,content FROM ttrss_entries | |
69 | WHERE id = '$id'"); | |
70 | ||
71 | if ($result) { | |
72 | ||
73 | $line = pg_fetch_assoc($result); | |
74 | ||
75 | print "<table class=\"feedOverview\">"; | |
76 | print "<tr><td><b>Title:</b></td><td>".$line["title"]."</td></tr>"; | |
77 | print "<tr><td><b>Link:</b></td><td><a href=\"".$line["link"]."\">".$line["link"]."</a></td></tr>"; | |
78 | ||
79 | print "</table>"; | |
80 | ||
81 | print $line["content"]; | |
82 | ||
83 | ||
84 | } | |
85 | } | |
86 | ||
87 | if ($op == "viewfeed") { | |
88 | ||
89 | $feed = $_GET["feed"]; | |
90 | $skip = $_GET["skip"]; | |
91 | $ext = $_GET["ext"]; | |
92 | ||
93 | if (!$skip) $skip = 0; | |
94 | ||
95 | if ($ext == "undefined") $ext = ""; | |
96 | ||
97 | // FIXME: check for null value here | |
98 | ||
99 | $result = pg_query("SELECT *, | |
100 | EXTRACT(EPOCH FROM NOW()) - EXTRACT(EPOCH FROM last_updated) as update_timeout | |
101 | FROM ttrss_feeds WHERE id = '$feed'"); | |
102 | ||
103 | if ($result) { | |
104 | ||
105 | $line = pg_fetch_assoc($result); | |
106 | ||
107 | if (!$ext && $line["update_timeout"] > MIN_UPDATE_TIME) { | |
108 | ||
109 | update_rss_feed($link, $line["feed_url"], $feed); | |
110 | ||
111 | } else { | |
112 | ||
113 | if ($ext == "MarkAllRead") { | |
114 | ||
115 | pg_query("UPDATE ttrss_entries SET unread = false | |
116 | WHERE feed_id = '$feed'"); | |
117 | } | |
118 | } | |
119 | } | |
120 | ||
121 | print "<table class=\"headlines\" width=\"100%\">"; | |
122 | /* print "<tr><td class=\"search\"> | |
123 | Search: <input onchange=\"javascript:search($feed,this);\"></td>"; | |
124 | print "<td class=\"title\">" . $line["title"] . "</td></tr>"; */ | |
125 | ||
126 | print "<tr><td class=\"search\" colspan=\"2\"> | |
127 | Search: <input onchange=\"javascript:search($feed,this);\"></td></tr>"; | |
128 | print "<tr><td colspan=\"2\" class=\"title\">" . $line["title"] . "</td></tr>"; | |
129 | ||
130 | if ($ext == "SEARCH") { | |
131 | $search = $_GET["search"]; | |
132 | $search_query_part = "(upper(title) LIKE upper('%$search%') | |
133 | OR content LIKE '%$search%') AND"; | |
134 | } | |
135 | ||
136 | $result = pg_query("SELECT id,title,updated,unread,feed_id FROM | |
137 | ttrss_entries WHERE | |
138 | $search_query_part | |
139 | feed_id = '$feed' ORDER BY updated DESC LIMIT ".HEADLINES_PER_PAGE." OFFSET $skip"); | |
140 | ||
141 | $lnum = 0; | |
142 | ||
143 | while ($line = pg_fetch_assoc($result)) { | |
144 | ||
145 | $class = ($lnum % 2) ? "even" : "odd"; | |
146 | ||
147 | if ($line["unread"] == "t") | |
148 | $class .= "Unread"; | |
149 | ||
150 | $content_link = "<a href=\"javascript:view(".$line["id"].",".$line["feed_id"].");\">".$line["title"]."</a>"; | |
151 | ||
152 | print "<tr class='$class' id='RROW-".$line["id"]."'>"; | |
153 | print "<td class='headlineUpdated'>".$line["updated"]."</td>"; | |
154 | print "<td class='headlineTitle'>$content_link</td>"; | |
155 | ||
156 | print "</tr>"; | |
157 | ||
158 | ++$lnum; | |
159 | } | |
160 | ||
161 | if ($lnum == 0) { | |
162 | print "<tr><td align='center'>No entries found.</td></tr>"; | |
163 | ||
164 | } | |
165 | ||
166 | print "<tr><td colspan=\"2\" class=\"headlineToolbar\">"; | |
167 | ||
168 | $next_skip = $skip + HEADLINES_PER_PAGE; | |
169 | $prev_skip = $skip - HEADLINES_PER_PAGE; | |
170 | ||
171 | print "<a class=\"button\" | |
172 | href=\"javascript:viewfeed($feed, $prev_skip);\">Previous Page</a>"; | |
173 | print " "; | |
174 | print "<a class=\"button\" | |
175 | href=\"javascript:viewfeed($feed, $next_skip);\">Next Page</a>"; | |
176 | print " "; | |
177 | ||
178 | print "<a class=\"button\" | |
179 | href=\"javascript:viewfeed($feed, 0, '');\">Refresh</a>"; | |
180 | print " "; | |
181 | print "<a class=\"button\" | |
182 | href=\"javascript:viewfeed($feed, 0, 'MarkAllRead');\">Mark all as read</a>"; | |
183 | ||
184 | print "</td></tr>"; | |
185 | print "</table>"; | |
186 | ||
187 | $result = pg_query("SELECT id, (SELECT count(id) FROM ttrss_entries | |
188 | WHERE feed_id = ttrss_feeds.id) AS total, | |
189 | (SELECT count(id) FROM ttrss_entries | |
190 | WHERE feed_id = ttrss_feeds.id AND unread = true) as unread | |
191 | FROM ttrss_feeds WHERE id = '$feed'"); | |
192 | ||
193 | $total = pg_fetch_result($result, 0, "total"); | |
194 | $unread = pg_fetch_result($result, 0, "unread"); | |
195 | ||
196 | print "<div class=\"invisible\" id=\"FACTIVE\">$feed</div>"; | |
197 | print "<div class=\"invisible\" id=\"FTOTAL\">$total</div>"; | |
198 | print "<div class=\"invisible\" id=\"FUNREAD\">$unread</div>"; | |
199 | ||
200 | } | |
201 | ||
202 | if ($op == "pref-feeds") { | |
203 | ||
204 | $result = pg_query("SELECT * FROM ttrss_feeds ORDER by title"); | |
205 | ||
206 | print "<p><table width=\"100%\" class=\"prefFeedList\">"; | |
207 | print "<tr class=\"title\"> | |
208 | <td>Select</td><td>Title</td><td>Link</td><td>Last Updated</td></tr>"; | |
209 | ||
210 | $lnum = 0; | |
211 | ||
212 | while ($line = pg_fetch_assoc($result)) { | |
213 | ||
214 | $class = ($lnum % 2) ? "even" : "odd"; | |
215 | ||
216 | print "<tr class=\"$class\">"; | |
217 | ||
218 | print "<td><input onclick='toggleSelectRow(this);' | |
219 | type=\"checkbox\" id=\"FROW-".$line["id"]."\"></td>"; | |
220 | print "<td>" . $line["title"] . "</td>"; | |
221 | print "<td>" . $line["feed_url"] . "</td>"; | |
222 | print "<td>" . $line["last_updated"] . "</td>"; | |
223 | print "</tr>"; | |
224 | ||
225 | ++$lnum; | |
226 | } | |
227 | ||
228 | print "</table>"; | |
229 | ||
230 | } | |
231 | ||
232 | pg_close($link); | |
233 | ?> |