]>
Commit | Line | Data |
---|---|---|
1cd17194 AD |
1 | <? |
2 | header("Content-Type: application/xml"); | |
3 | ||
6f428bc5 | 4 | include "config.php"; |
1cd17194 | 5 | |
d76a3b03 AD |
6 | require_once('magpierss/rss_fetch.inc'); |
7 | ||
8 | $link = pg_connect(DB_CONN); | |
9 | ||
10 | pg_query("set client_encoding = 'utf-8'"); | |
11 | ||
6f428bc5 AD |
12 | $op = $_GET["op"]; |
13 | ||
1cd17194 AD |
14 | if ($op == "feeds") { |
15 | ||
d76a3b03 AD |
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"); | |
1cd17194 AD |
22 | |
23 | print "<ul>"; | |
24 | ||
25 | $lnum = 0; | |
26 | ||
6f428bc5 AD |
27 | while ($line = pg_fetch_assoc($result)) { |
28 | ||
29 | $feed = $line["title"]; | |
2c1dd701 AD |
30 | $feed_id = $line["id"]; |
31 | ||
d76a3b03 AD |
32 | $total = $line["total"]; |
33 | $unread = $line["unread"]; | |
34 | ||
1cd17194 AD |
35 | $class = ($lnum % 2) ? "even" : "odd"; |
36 | ||
37 | // if ($lnum == 2 || $lnum == 0) $feed = "<b>$feed</b>"; | |
38 | ||
d76a3b03 | 39 | $feed = "<a href=\"javascript:viewfeed($feed_id, 0);\">$feed ($unread/$total)</a>"; |
1cd17194 AD |
40 | |
41 | print "<li class=\"$class\">$feed</li>"; | |
42 | ++$lnum; | |
43 | } | |
44 | ||
45 | print "</ul>"; | |
46 | ||
47 | } | |
48 | ||
49 | if ($op == "view") { | |
50 | ||
d76a3b03 AD |
51 | $id = $_GET["id"]; |
52 | ||
53 | $result = pg_query("SELECT title,link,content FROM ttrss_entries | |
54 | WHERE id = '$id'"); | |
1cd17194 | 55 | |
d76a3b03 | 56 | if ($result) { |
1cd17194 | 57 | |
d76a3b03 | 58 | $line = pg_fetch_assoc($result); |
1cd17194 | 59 | |
d76a3b03 AD |
60 | print "<table class=\"feedOverview\">"; |
61 | print "<tr><td><b>Title:</b></td><td>".$line["title"]."</td></tr>"; | |
62 | print "<tr><td><b>Link:</b></td><td><a href=\"".$line["link"]."\">".$line["link"]."</a></td></tr>"; | |
63 | ||
64 | print "</table>"; | |
65 | ||
66 | print $line["content"]; | |
67 | ||
68 | ||
69 | } | |
1cd17194 AD |
70 | } |
71 | ||
72 | if ($op == "viewfeed") { | |
73 | ||
74 | $feed = $_GET["feed"]; | |
d76a3b03 | 75 | // $feed = 0; // for speed |
1cd17194 | 76 | |
d76a3b03 | 77 | $skip = $_GET["skip"]; |
1cd17194 | 78 | |
d76a3b03 | 79 | $result = pg_query("SELECT * FROM ttrss_feeds WHERE id = '$feed'"); |
1cd17194 | 80 | |
d76a3b03 | 81 | if ($result) { |
1cd17194 | 82 | |
d76a3b03 | 83 | $line = pg_fetch_assoc($result); |
1cd17194 | 84 | |
d76a3b03 | 85 | $rss = fetch_rss($line["feed_url"]); |
1cd17194 | 86 | |
d76a3b03 AD |
87 | if ($rss) { |
88 | ||
89 | foreach ($rss->items as $item) { | |
90 | ||
91 | $entry_guid = $item["id"]; | |
92 | ||
93 | if (!$entry_guid) $entry_guid = $item["guid"]; | |
94 | if (!$entry_guid) $entry_guid = $item["link"]; | |
95 | ||
96 | $entry_timestamp = $item["pubdate"]; | |
97 | if (!$entry_timestamp) $entry_timestamp = $item["modified"]; | |
98 | if (!$entry_timestamp) $entry_timestamp = $item["updated"]; | |
99 | ||
100 | $entry_timestamp = strtotime($entry_timestamp); | |
101 | ||
102 | $entry_title = $item["title"]; | |
103 | $entry_link = $item["link"]; | |
104 | ||
105 | $entry_content = $item["description"]; | |
106 | if (!$entry_content) $entry_content = $item["content"]; | |
107 | ||
108 | $entry_content = pg_escape_string($entry_content); | |
109 | $entry_title = pg_escape_string($entry_title); | |
110 | ||
111 | $content_md5 = md5($entry_content); | |
112 | ||
113 | $result = pg_query(" | |
114 | SELECT | |
115 | id,unread,md5_hash | |
116 | FROM | |
117 | ttrss_entries | |
118 | WHERE | |
119 | guid = '$entry_guid' OR md5_hash = '$content_md5'"); | |
120 | ||
121 | if (pg_num_rows($result) == 0) { | |
122 | ||
123 | $entry_timestamp = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp); | |
124 | ||
125 | $query = "INSERT INTO ttrss_entries | |
126 | (title, guid, link, updated, content, feed_id, md5_hash) | |
127 | VALUES | |
128 | ('$entry_title', '$entry_guid', '$entry_link', | |
129 | '$entry_timestamp', '$entry_content', '$feed', | |
130 | '$content_md5')"; | |
131 | ||
132 | pg_query($query); | |
133 | ||
134 | } else { | |
135 | ||
136 | $entry_id = pg_fetch_result($result, 0, "id"); | |
137 | $entry_timestamp = strftime("%Y/%m/%d %H:%M:%S", $entry_timestamp); | |
138 | ||
139 | $unread = pg_fetch_result($result, 0, "unread"); | |
140 | $md5_hash = pg_fetch_result($result, 0, "md5_hash"); | |
141 | ||
142 | if ($md5_hash != $content_md5) | |
143 | $unread = "false"; | |
144 | ||
145 | $query = "UPDATE ttrss_entries | |
146 | SET | |
147 | title ='$entry_title', | |
148 | link = '$entry_link', | |
149 | updated = '$entry_timestamp', | |
150 | content = '$entry_content', | |
151 | md5_hash = '$content_md5', | |
152 | unread = '$unread' | |
153 | WHERE | |
154 | id = '$entry_id'"; | |
155 | ||
156 | $result = pg_query($query); | |
157 | ||
158 | // print "$entry_guid - $entry_timestamp - $entry_title - | |
159 | // $entry_link - $entry_id<br>"; | |
160 | ||
161 | } | |
162 | ||
163 | } | |
1cd17194 | 164 | |
d76a3b03 AD |
165 | print "<table class=\"headlines\" width=\"100%\">"; |
166 | print "<tr><td colspan=\"2\" class=\"title\">" . $rss->channel["title"] . "</td></tr>"; | |
1cd17194 | 167 | |
d76a3b03 AD |
168 | $result = pg_query("SELECT id,title,updated,unread FROM ttrss_entries WHERE |
169 | feed_id = '$feed' ORDER BY updated LIMIT 10 OFFSET $skip"); | |
1cd17194 | 170 | |
d76a3b03 AD |
171 | $lnum = 0; |
172 | ||
173 | while ($line = pg_fetch_assoc($result)) { | |
174 | ||
175 | $class = ($lnum % 2) ? "even" : "odd"; | |
176 | ||
177 | if ($line["unread"] == "t") | |
178 | $class .= "Unread"; | |
179 | ||
180 | $content_link = "<a href=\"javascript:view(".$line["id"].");\">".$line["title"]."</a>"; | |
181 | ||
182 | print "<tr class='$class' id='RROW-".$line["id"]."'>"; | |
183 | print "<td class='headlineUpdated'>".$line["updated"]."</td>"; | |
184 | print "<td class='headlineTitle'>$content_link</td>"; | |
185 | ||
186 | print "</tr>"; | |
187 | ||
188 | ++$lnum; | |
189 | } | |
190 | ||
191 | print "<tr><td colspan=\"2\" class=\"headlineToolbar\">"; | |
192 | ||
193 | $next_skip = $skip + 10; | |
194 | $prev_skip = $skip - 10; | |
195 | ||
196 | print "<a class=\"button\" | |
197 | href=\"javascript:viewfeed($feed, $prev_skip);\">Previous Page</a>"; | |
198 | print " "; | |
199 | print "<a class=\"button\" | |
200 | href=\"javascript:viewfeed($feed, $next_skip);\">Next Page</a>"; | |
201 | ||
202 | print "</td></tr>"; | |
203 | print "</table>"; | |
204 | ||
205 | } | |
206 | ||
207 | } | |
1cd17194 AD |
208 | } |
209 | ||
210 | ||
211 | ?> |