]>
Commit | Line | Data |
---|---|---|
1cd17194 AD |
1 | <? |
2 | header("Content-Type: application/xml"); | |
3 | ||
82baad4a AD |
4 | require_once "config.php"; |
5 | require_once "functions.php"; | |
6 | require_once "magpierss/rss_fetch.inc"; | |
1cd17194 | 7 | |
d76a3b03 AD |
8 | |
9 | $link = pg_connect(DB_CONN); | |
10 | ||
11 | pg_query("set client_encoding = 'utf-8'"); | |
12 | ||
6f428bc5 | 13 | $op = $_GET["op"]; |
82baad4a | 14 | |
1cd17194 AD |
15 | if ($op == "feeds") { |
16 | ||
82baad4a AD |
17 | update_all_feeds($link); |
18 | ||
d76a3b03 AD |
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"); | |
1cd17194 | 25 | |
82baad4a | 26 | print "<table width=\"100%\" class=\"feeds\">"; |
1cd17194 AD |
27 | |
28 | $lnum = 0; | |
29 | ||
6f428bc5 | 30 | while ($line = pg_fetch_assoc($result)) { |
a1a8a2be | 31 | |
6f428bc5 | 32 | $feed = $line["title"]; |
2c1dd701 AD |
33 | $feed_id = $line["id"]; |
34 | ||
d76a3b03 AD |
35 | $total = $line["total"]; |
36 | $unread = $line["unread"]; | |
37 | ||
1cd17194 | 38 | $class = ($lnum % 2) ? "even" : "odd"; |
a1a8a2be AD |
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>"; | |
1cd17194 AD |
50 | ++$lnum; |
51 | } | |
52 | ||
82baad4a AD |
53 | print "<tr><td class=\"footer\" colspan=\"3\"> |
54 | <a href=\"javascript:update_feed_list()\">Update all feeds</a></td></tr>"; | |
55 | ||
a1a8a2be | 56 | print "</table>"; |
1cd17194 AD |
57 | |
58 | } | |
59 | ||
60 | if ($op == "view") { | |
61 | ||
d76a3b03 AD |
62 | $id = $_GET["id"]; |
63 | ||
a1a8a2be AD |
64 | $result = pg_query("UPDATE ttrss_entries SET unread = false WHERE id = '$id'"); |
65 | ||
d76a3b03 AD |
66 | $result = pg_query("SELECT title,link,content FROM ttrss_entries |
67 | WHERE id = '$id'"); | |
1cd17194 | 68 | |
d76a3b03 | 69 | if ($result) { |
1cd17194 | 70 | |
d76a3b03 | 71 | $line = pg_fetch_assoc($result); |
1cd17194 | 72 | |
d76a3b03 AD |
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 | } | |
1cd17194 AD |
83 | } |
84 | ||
85 | if ($op == "viewfeed") { | |
86 | ||
87 | $feed = $_GET["feed"]; | |
d76a3b03 | 88 | $skip = $_GET["skip"]; |
a1a8a2be AD |
89 | $ext = $_GET["ext"]; |
90 | ||
ac53063a AD |
91 | if (!$skip) $skip = 0; |
92 | ||
a1a8a2be | 93 | if ($ext == "undefined") $ext = ""; |
1cd17194 | 94 | |
ac53063a AD |
95 | // FIXME: check for null value here |
96 | ||
82baad4a AD |
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'"); | |
1cd17194 | 100 | |
d76a3b03 | 101 | if ($result) { |
1cd17194 | 102 | |
d76a3b03 | 103 | $line = pg_fetch_assoc($result); |
1cd17194 | 104 | |
82baad4a AD |
105 | if (!$ext && $line["update_timeout"] > MIN_UPDATE_TIME) { |
106 | ||
107 | update_rss_feed($link, $line["feed_url"], $feed); | |
d76a3b03 | 108 | |
a1a8a2be | 109 | } else { |
d76a3b03 | 110 | |
a1a8a2be | 111 | if ($ext == "MarkAllRead") { |
d76a3b03 | 112 | |
a1a8a2be AD |
113 | pg_query("UPDATE ttrss_entries SET unread = false |
114 | WHERE feed_id = '$feed'"); | |
115 | } | |
a1a8a2be AD |
116 | } |
117 | } | |
d76a3b03 | 118 | |
a1a8a2be | 119 | print "<table class=\"headlines\" width=\"100%\">"; |
ac53063a AD |
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>"; | |
a1a8a2be | 126 | print "<tr><td colspan=\"2\" class=\"title\">" . $line["title"] . "</td></tr>"; |
d76a3b03 | 127 | |
ac53063a AD |
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 | ||
a1a8a2be AD |
134 | $result = pg_query("SELECT id,title,updated,unread,feed_id FROM |
135 | ttrss_entries WHERE | |
ac53063a AD |
136 | $search_query_part |
137 | feed_id = '$feed' ORDER BY updated DESC LIMIT ".HEADLINES_PER_PAGE." OFFSET $skip"); | |
d76a3b03 | 138 | |
a1a8a2be | 139 | $lnum = 0; |
d76a3b03 | 140 | |
a1a8a2be | 141 | while ($line = pg_fetch_assoc($result)) { |
d76a3b03 | 142 | |
a1a8a2be | 143 | $class = ($lnum % 2) ? "even" : "odd"; |
d76a3b03 | 144 | |
a1a8a2be AD |
145 | if ($line["unread"] == "t") |
146 | $class .= "Unread"; | |
d76a3b03 | 147 | |
a1a8a2be | 148 | $content_link = "<a href=\"javascript:view(".$line["id"].",".$line["feed_id"].");\">".$line["title"]."</a>"; |
1cd17194 | 149 | |
a1a8a2be AD |
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>"; | |
d76a3b03 | 153 | |
a1a8a2be | 154 | print "</tr>"; |
d76a3b03 | 155 | |
a1a8a2be AD |
156 | ++$lnum; |
157 | } | |
d76a3b03 | 158 | |
ac53063a AD |
159 | if ($lnum == 0) { |
160 | print "<tr><td align='center'>No entries found.</td></tr>"; | |
161 | ||
162 | } | |
163 | ||
a1a8a2be | 164 | print "<tr><td colspan=\"2\" class=\"headlineToolbar\">"; |
d76a3b03 | 165 | |
a1a8a2be AD |
166 | $next_skip = $skip + HEADLINES_PER_PAGE; |
167 | $prev_skip = $skip - HEADLINES_PER_PAGE; | |
d76a3b03 | 168 | |
a1a8a2be AD |
169 | print "<a class=\"button\" |
170 | href=\"javascript:viewfeed($feed, $prev_skip);\">Previous Page</a>"; | |
171 | print " "; | |
172 | print "<a class=\"button\" | |
173 | href=\"javascript:viewfeed($feed, $next_skip);\">Next Page</a>"; | |
174 | print " "; | |
ac53063a AD |
175 | |
176 | print "<a class=\"button\" | |
177 | href=\"javascript:viewfeed($feed, 0, '');\">Refresh</a>"; | |
178 | print " "; | |
a1a8a2be AD |
179 | print "<a class=\"button\" |
180 | href=\"javascript:viewfeed($feed, 0, 'MarkAllRead');\">Mark all as read</a>"; | |
d76a3b03 | 181 | |
a1a8a2be AD |
182 | print "</td></tr>"; |
183 | print "</table>"; | |
d76a3b03 | 184 | |
a1a8a2be AD |
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'"); | |
d76a3b03 | 190 | |
a1a8a2be AD |
191 | $total = pg_fetch_result($result, 0, "total"); |
192 | $unread = pg_fetch_result($result, 0, "unread"); | |
d76a3b03 | 193 | |
a1a8a2be AD |
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>"; | |
d76a3b03 | 197 | |
1cd17194 AD |
198 | } |
199 | ||
200 | ||
201 | ?> |