]>
Commit | Line | Data |
---|---|---|
5f0a3741 | 1 | <?php |
369dbc19 | 2 | class Handler_Public extends Handler { |
5f0a3741 | 3 | |
79178062 | 4 | private function generate_syndicated_feed($owner_uid, $feed, $is_cat, |
ca5d9be4 | 5 | $limit, $offset, $search, $search_mode, |
d1e631f3 | 6 | $view_mode = false, $format = 'atom', $order = false, $orig_guid = false, $start_ts = false) { |
79178062 AD |
7 | |
8 | require_once "lib/MiniTemplator.class.php"; | |
9 | ||
10 | $note_style = "background-color : #fff7d5; | |
11 | border-width : 1px; ". | |
12 | "padding : 5px; border-style : dashed; border-color : #e7d796;". | |
13 | "margin-bottom : 1em; color : #9a8c59;"; | |
14 | ||
2faef834 | 15 | if (!$limit) $limit = 60; |
79178062 | 16 | |
8aa01d79 | 17 | $date_sort_field = "date_entered DESC, updated DESC"; |
84c53d0e | 18 | $date_check_field = "date_entered"; |
79178062 | 19 | |
84c53d0e | 20 | if ($feed == -2 && !$is_cat) { |
7ef7dd31 | 21 | $date_sort_field = "last_published DESC"; |
84c53d0e AD |
22 | $date_check_field = "last_published"; |
23 | } else if ($feed == -1 && !$is_cat) { | |
7ef7dd31 | 24 | $date_sort_field = "last_marked DESC"; |
84c53d0e AD |
25 | $date_check_field = "last_marked"; |
26 | } | |
008ebad9 | 27 | |
25051fb8 AD |
28 | switch ($order) { |
29 | case "title": | |
30 | $date_sort_field = "ttrss_entries.title"; | |
31 | break; | |
32 | case "date_reverse": | |
33 | $date_sort_field = "date_entered, updated"; | |
34 | break; | |
35 | case "feed_dates": | |
36 | $date_sort_field = "updated DESC"; | |
37 | break; | |
38 | } | |
39 | ||
d1e631f3 AD |
40 | //function queryFeedHeadlines($feed, $limit, $view_mode, $cat_view, $search, $search_mode, $override_order = false, $offset = 0, $owner_uid = 0, $filter = false, $since_id = 0, $include_children = false, $ignore_vfeed_group = false, $override_strategy = false, $override_vfeed = false, $start_ts = false) { |
41 | ||
a42c55f0 | 42 | $qfh_ret = queryFeedHeadlines($feed, |
2e35a707 AD |
43 | 1, $view_mode, $is_cat, $search, $search_mode, |
44 | $date_sort_field, $offset, $owner_uid, | |
9b1e5918 | 45 | false, 0, true, true, false, false, $start_ts); |
2e35a707 AD |
46 | |
47 | $result = $qfh_ret[0]; | |
48 | ||
d9c85e0f | 49 | if ($this->dbh->num_rows($result) != 0) { |
84c53d0e AD |
50 | |
51 | $ts = strtotime($this->dbh->fetch_result($result, 0, $date_check_field)); | |
2e35a707 AD |
52 | |
53 | if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && | |
d6ba77f3 | 54 | strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $ts) { |
2e35a707 AD |
55 | header('HTTP/1.0 304 Not Modified'); |
56 | return; | |
57 | } | |
58 | ||
59 | $last_modified = gmdate("D, d M Y H:i:s", $ts) . " GMT"; | |
60 | header("Last-Modified: $last_modified", true); | |
61 | } | |
62 | ||
a42c55f0 | 63 | $qfh_ret = queryFeedHeadlines($feed, |
79178062 | 64 | $limit, $view_mode, $is_cat, $search, $search_mode, |
8aa01d79 | 65 | $date_sort_field, $offset, $owner_uid, |
9b1e5918 | 66 | false, 0, true, true, false, false, $start_ts); |
79178062 | 67 | |
2e35a707 | 68 | |
79178062 AD |
69 | $result = $qfh_ret[0]; |
70 | $feed_title = htmlspecialchars($qfh_ret[1]); | |
71 | $feed_site_url = $qfh_ret[2]; | |
4a80c57c | 72 | /* $last_error = $qfh_ret[3]; */ |
79178062 AD |
73 | |
74 | $feed_self_url = get_self_url_prefix() . | |
39119f02 JT |
75 | "/public.php?op=rss&id=$feed&key=" . |
76 | get_feed_access_key($feed, false, $owner_uid); | |
79178062 AD |
77 | |
78 | if (!$feed_site_url) $feed_site_url = get_self_url_prefix(); | |
79 | ||
2ebf38a9 AD |
80 | if ($format == 'atom') { |
81 | $tpl = new MiniTemplator; | |
79178062 | 82 | |
2ebf38a9 | 83 | $tpl->readTemplateFromFile("templates/generated_feed.txt"); |
79178062 | 84 | |
2ebf38a9 AD |
85 | $tpl->setVariable('FEED_TITLE', $feed_title, true); |
86 | $tpl->setVariable('VERSION', VERSION, true); | |
87 | $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true); | |
79178062 | 88 | |
2ebf38a9 AD |
89 | if (PUBSUBHUBBUB_HUB && $feed == -2) { |
90 | $tpl->setVariable('HUB_URL', htmlspecialchars(PUBSUBHUBBUB_HUB), true); | |
91 | $tpl->addBlock('feed_hub'); | |
92 | } | |
79178062 | 93 | |
2ebf38a9 | 94 | $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true); |
d9c85e0f | 95 | while ($line = $this->dbh->fetch_assoc($result)) { |
bf5bcb8e | 96 | $line["content_preview"] = truncate_string(strip_tags($line["content"]), 100, '...'); |
bc262b67 | 97 | |
891e36f5 | 98 | foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { |
99 | $line = $p->hook_query_headlines($line); | |
100 | } | |
2e35a707 | 101 | |
fcf6bfba AD |
102 | $tpl->setVariable('ARTICLE_ID', |
103 | htmlspecialchars($orig_guid ? $line['link'] : | |
104 | get_self_url_prefix() . | |
105 | "/public.php?url=" . urlencode($line['link'])), true); | |
2ebf38a9 AD |
106 | $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true); |
107 | $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true); | |
67631438 | 108 | $tpl->setVariable('ARTICLE_EXCERPT', $line["content_preview"], true); |
79178062 | 109 | |
4b19d4ac AD |
110 | $content = sanitize($line["content"], false, $owner_uid, |
111 | $feed_site_url); | |
79178062 | 112 | |
2ebf38a9 AD |
113 | if ($line['note']) { |
114 | $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" . | |
115 | $content; | |
e9c6e27d | 116 | $tpl->setVariable('ARTICLE_NOTE', htmlspecialchars($line['note']), true); |
117 | } | |
2ebf38a9 AD |
118 | |
119 | $tpl->setVariable('ARTICLE_CONTENT', $content, true); | |
120 | ||
121 | $tpl->setVariable('ARTICLE_UPDATED_ATOM', | |
122 | date('c', strtotime($line["updated"])), true); | |
123 | $tpl->setVariable('ARTICLE_UPDATED_RFC822', | |
124 | date(DATE_RFC822, strtotime($line["updated"])), true); | |
125 | ||
126 | $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true); | |
127 | ||
fcf6bfba | 128 | $tpl->setVariable('ARTICLE_SOURCE_LINK', htmlspecialchars($line['site_url']), true); |
0ee126ee | 129 | $tpl->setVariable('ARTICLE_SOURCE_TITLE', htmlspecialchars($line['feed_title'] ? $line['feed_title'] : $feed_title), true); |
2ebf38a9 | 130 | |
a42c55f0 | 131 | $tags = get_article_tags($line["id"], $owner_uid); |
2ebf38a9 AD |
132 | |
133 | foreach ($tags as $tag) { | |
134 | $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true); | |
135 | $tpl->addBlock('category'); | |
136 | } | |
79178062 | 137 | |
a42c55f0 | 138 | $enclosures = get_article_enclosures($line["id"]); |
79178062 | 139 | |
2ebf38a9 AD |
140 | foreach ($enclosures as $e) { |
141 | $type = htmlspecialchars($e['content_type']); | |
142 | $url = htmlspecialchars($e['content_url']); | |
143 | $length = $e['duration']; | |
9c97041d | 144 | |
2ebf38a9 AD |
145 | $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true); |
146 | $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true); | |
147 | $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true); | |
79178062 | 148 | |
2ebf38a9 AD |
149 | $tpl->addBlock('enclosure'); |
150 | } | |
79178062 | 151 | |
2ebf38a9 | 152 | $tpl->addBlock('entry'); |
79178062 AD |
153 | } |
154 | ||
2ebf38a9 AD |
155 | $tmp = ""; |
156 | ||
157 | $tpl->addBlock('feed'); | |
158 | $tpl->generateOutputToString($tmp); | |
159 | ||
10bdeb4b AD |
160 | if (@!$_REQUEST["noxml"]) { |
161 | header("Content-Type: text/xml; charset=utf-8"); | |
162 | } else { | |
163 | header("Content-Type: text/plain; charset=utf-8"); | |
164 | } | |
2ebf38a9 AD |
165 | |
166 | print $tmp; | |
167 | } else if ($format == 'json') { | |
79178062 | 168 | |
2ebf38a9 | 169 | $feed = array(); |
79178062 | 170 | |
2ebf38a9 AD |
171 | $feed['title'] = $feed_title; |
172 | $feed['version'] = VERSION; | |
173 | $feed['feed_url'] = $feed_self_url; | |
79178062 | 174 | |
2ebf38a9 AD |
175 | if (PUBSUBHUBBUB_HUB && $feed == -2) { |
176 | $feed['hub_url'] = PUBSUBHUBBUB_HUB; | |
79178062 AD |
177 | } |
178 | ||
2ebf38a9 AD |
179 | $feed['self_url'] = get_self_url_prefix(); |
180 | ||
181 | $feed['articles'] = array(); | |
182 | ||
d9c85e0f | 183 | while ($line = $this->dbh->fetch_assoc($result)) { |
575a5287 | 184 | $line["content_preview"] = truncate_string(strip_tags($line["content_preview"]), 100, '...'); |
891e36f5 | 185 | foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { |
186 | $line = $p->hook_query_headlines($line, 100); | |
187 | } | |
2ebf38a9 | 188 | $article = array(); |
79178062 | 189 | |
2ebf38a9 AD |
190 | $article['id'] = $line['link']; |
191 | $article['link'] = $line['link']; | |
192 | $article['title'] = $line['title']; | |
67631438 | 193 | $article['excerpt'] = $line["content_preview"]; |
891e36f5 | 194 | $article['content'] = sanitize($line["content"], false, $owner_uid); |
2ebf38a9 | 195 | $article['updated'] = date('c', strtotime($line["updated"])); |
79178062 | 196 | |
2ebf38a9 AD |
197 | if ($line['note']) $article['note'] = $line['note']; |
198 | if ($article['author']) $article['author'] = $line['author']; | |
79178062 | 199 | |
a42c55f0 | 200 | $tags = get_article_tags($line["id"], $owner_uid); |
2ebf38a9 AD |
201 | |
202 | if (count($tags) > 0) { | |
203 | $article['tags'] = array(); | |
204 | ||
205 | foreach ($tags as $tag) { | |
206 | array_push($article['tags'], $tag); | |
207 | } | |
208 | } | |
209 | ||
a42c55f0 | 210 | $enclosures = get_article_enclosures($line["id"]); |
2ebf38a9 AD |
211 | |
212 | if (count($enclosures) > 0) { | |
213 | $article['enclosures'] = array(); | |
214 | ||
215 | foreach ($enclosures as $e) { | |
216 | $type = $e['content_type']; | |
217 | $url = $e['content_url']; | |
218 | $length = $e['duration']; | |
219 | ||
220 | array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length)); | |
221 | } | |
222 | } | |
223 | ||
224 | array_push($feed['articles'], $article); | |
225 | } | |
226 | ||
10bdeb4b | 227 | header("Content-Type: text/json; charset=utf-8"); |
2ebf38a9 AD |
228 | print json_encode($feed); |
229 | ||
230 | } else { | |
231 | header("Content-Type: text/plain; charset=utf-8"); | |
232 | print json_encode(array("error" => array("message" => "Unknown format"))); | |
233 | } | |
79178062 AD |
234 | } |
235 | ||
5f0a3741 | 236 | function getUnread() { |
d9c85e0f | 237 | $login = $this->dbh->escape_string($_REQUEST["login"]); |
5f0a3741 AD |
238 | $fresh = $_REQUEST["fresh"] == "1"; |
239 | ||
d9c85e0f | 240 | $result = $this->dbh->query("SELECT id FROM ttrss_users WHERE login = '$login'"); |
5f0a3741 | 241 | |
d9c85e0f AD |
242 | if ($this->dbh->num_rows($result) == 1) { |
243 | $uid = $this->dbh->fetch_result($result, 0, "id"); | |
5f0a3741 | 244 | |
a42c55f0 | 245 | print getGlobalUnread($uid); |
5f0a3741 AD |
246 | |
247 | if ($fresh) { | |
248 | print ";"; | |
a42c55f0 | 249 | print getFeedArticles(-3, false, true, $uid); |
5f0a3741 AD |
250 | } |
251 | ||
252 | } else { | |
253 | print "-1;User not found"; | |
254 | } | |
255 | ||
256 | } | |
257 | ||
258 | function getProfiles() { | |
d9c85e0f | 259 | $login = $this->dbh->escape_string($_REQUEST["login"]); |
5f0a3741 | 260 | |
0806d68b | 261 | $result = $this->dbh->query("SELECT ttrss_settings_profiles.* FROM ttrss_settings_profiles,ttrss_users |
97acbaf1 | 262 | WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = '$login' ORDER BY title"); |
5f0a3741 | 263 | |
eeee2ccf | 264 | print "<select dojoType='dijit.form.Select' style='width : 220px; margin : 0px' name='profile'>"; |
5f0a3741 | 265 | |
97acbaf1 | 266 | print "<option value='0'>" . __("Default profile") . "</option>"; |
5f0a3741 | 267 | |
d9c85e0f | 268 | while ($line = $this->dbh->fetch_assoc($result)) { |
97acbaf1 AD |
269 | $id = $line["id"]; |
270 | $title = $line["title"]; | |
5f0a3741 | 271 | |
97acbaf1 | 272 | print "<option value='$id'>$title</option>"; |
5f0a3741 | 273 | } |
97acbaf1 AD |
274 | |
275 | print "</select>"; | |
5f0a3741 AD |
276 | } |
277 | ||
278 | function pubsub() { | |
d9c85e0f | 279 | $mode = $this->dbh->escape_string($_REQUEST['hub_mode']); |
43d790f0 AD |
280 | if (!$mode) $mode = $this->dbh->escape_string($_REQUEST['hub.mode']); |
281 | ||
d9c85e0f AD |
282 | $feed_id = (int) $this->dbh->escape_string($_REQUEST['id']); |
283 | $feed_url = $this->dbh->escape_string($_REQUEST['hub_topic']); | |
5f0a3741 | 284 | |
43d790f0 AD |
285 | if (!$feed_url) $feed_url = $this->dbh->escape_string($_REQUEST['hub.topic']); |
286 | ||
5f0a3741 AD |
287 | if (!PUBSUBHUBBUB_ENABLED) { |
288 | header('HTTP/1.0 404 Not Found'); | |
43d790f0 | 289 | echo "404 Not found (Disabled by server)"; |
5f0a3741 AD |
290 | return; |
291 | } | |
292 | ||
293 | // TODO: implement hub_verifytoken checking | |
43d790f0 AD |
294 | // TODO: store requested rel=self or whatever for verification |
295 | // (may be different from stored feed url) e.g. http://url/ or http://url | |
5f0a3741 | 296 | |
d9c85e0f | 297 | $result = $this->dbh->query("SELECT feed_url FROM ttrss_feeds |
5f0a3741 AD |
298 | WHERE id = '$feed_id'"); |
299 | ||
d9c85e0f | 300 | if ($this->dbh->num_rows($result) != 0) { |
5f0a3741 | 301 | |
d9c85e0f | 302 | $check_feed_url = $this->dbh->fetch_result($result, 0, "feed_url"); |
5f0a3741 | 303 | |
43d790f0 AD |
304 | // ignore url checking for the time being |
305 | if ($check_feed_url && (true || $check_feed_url == $feed_url || !$feed_url)) { | |
5f0a3741 AD |
306 | if ($mode == "subscribe") { |
307 | ||
d9c85e0f | 308 | $this->dbh->query("UPDATE ttrss_feeds SET pubsub_state = 2 |
5f0a3741 AD |
309 | WHERE id = '$feed_id'"); |
310 | ||
311 | print $_REQUEST['hub_challenge']; | |
312 | return; | |
313 | ||
314 | } else if ($mode == "unsubscribe") { | |
315 | ||
d9c85e0f | 316 | $this->dbh->query("UPDATE ttrss_feeds SET pubsub_state = 0 |
5f0a3741 AD |
317 | WHERE id = '$feed_id'"); |
318 | ||
319 | print $_REQUEST['hub_challenge']; | |
320 | return; | |
321 | ||
322 | } else if (!$mode) { | |
323 | ||
324 | // Received update ping, schedule feed update. | |
a42c55f0 | 325 | //update_rss_feed($feed_id, true, true); |
5f0a3741 | 326 | |
d9c85e0f | 327 | $this->dbh->query("UPDATE ttrss_feeds SET |
5f0a3741 AD |
328 | last_update_started = '1970-01-01', |
329 | last_updated = '1970-01-01' WHERE id = '$feed_id'"); | |
330 | ||
331 | } | |
332 | } else { | |
333 | header('HTTP/1.0 404 Not Found'); | |
43d790f0 | 334 | echo "404 Not found (URL check failed)"; |
5f0a3741 AD |
335 | } |
336 | } else { | |
337 | header('HTTP/1.0 404 Not Found'); | |
43d790f0 | 338 | echo "404 Not found (Feed not found)"; |
5f0a3741 AD |
339 | } |
340 | ||
341 | } | |
342 | ||
343 | function logout() { | |
344 | logout_user(); | |
345 | header("Location: index.php"); | |
346 | } | |
347 | ||
5f0a3741 | 348 | function share() { |
d9c85e0f | 349 | $uuid = $this->dbh->escape_string($_REQUEST["key"]); |
5f0a3741 | 350 | |
d9c85e0f | 351 | $result = $this->dbh->query("SELECT ref_id, owner_uid FROM ttrss_user_entries WHERE |
5f0a3741 AD |
352 | uuid = '$uuid'"); |
353 | ||
d9c85e0f | 354 | if ($this->dbh->num_rows($result) != 0) { |
5f0a3741 AD |
355 | header("Content-Type: text/html"); |
356 | ||
d9c85e0f AD |
357 | $id = $this->dbh->fetch_result($result, 0, "ref_id"); |
358 | $owner_uid = $this->dbh->fetch_result($result, 0, "owner_uid"); | |
5f0a3741 | 359 | |
a42c55f0 | 360 | $article = format_article($id, false, true, $owner_uid); |
5f0a3741 AD |
361 | |
362 | print_r($article['content']); | |
363 | ||
364 | } else { | |
365 | print "Article not found."; | |
366 | } | |
367 | ||
368 | } | |
369 | ||
370 | function rss() { | |
d9c85e0f AD |
371 | $feed = $this->dbh->escape_string($_REQUEST["id"]); |
372 | $key = $this->dbh->escape_string($_REQUEST["key"]); | |
356e13b1 | 373 | $is_cat = sql_bool_to_bool($_REQUEST["is_cat"]); |
d9c85e0f AD |
374 | $limit = (int)$this->dbh->escape_string($_REQUEST["limit"]); |
375 | $offset = (int)$this->dbh->escape_string($_REQUEST["offset"]); | |
5f0a3741 | 376 | |
d9c85e0f AD |
377 | $search = $this->dbh->escape_string($_REQUEST["q"]); |
378 | $search_mode = $this->dbh->escape_string($_REQUEST["smode"]); | |
379 | $view_mode = $this->dbh->escape_string($_REQUEST["view-mode"]); | |
25051fb8 | 380 | $order = $this->dbh->escape_string($_REQUEST["order"]); |
d1e631f3 | 381 | $start_ts = $this->dbh->escape_string($_REQUEST["ts"]); |
5f0a3741 | 382 | |
d9c85e0f | 383 | $format = $this->dbh->escape_string($_REQUEST['format']); |
5bcb7b61 | 384 | $orig_guid = sql_bool_to_bool($_REQUEST["orig_guid"]); |
2ebf38a9 AD |
385 | |
386 | if (!$format) $format = 'atom'; | |
387 | ||
5f0a3741 | 388 | if (SINGLE_USER_MODE) { |
a42c55f0 | 389 | authenticate_user("admin", null); |
5f0a3741 AD |
390 | } |
391 | ||
392 | $owner_id = false; | |
393 | ||
394 | if ($key) { | |
d9c85e0f | 395 | $result = $this->dbh->query("SELECT owner_uid FROM |
5f0a3741 AD |
396 | ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'"); |
397 | ||
d9c85e0f AD |
398 | if ($this->dbh->num_rows($result) == 1) |
399 | $owner_id = $this->dbh->fetch_result($result, 0, "owner_uid"); | |
5f0a3741 AD |
400 | } |
401 | ||
402 | if ($owner_id) { | |
2fb947eb | 403 | $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit, |
d1e631f3 | 404 | $offset, $search, $search_mode, $view_mode, $format, $order, $orig_guid, $start_ts); |
5f0a3741 AD |
405 | } else { |
406 | header('HTTP/1.1 403 Forbidden'); | |
407 | } | |
408 | } | |
409 | ||
910592b4 | 410 | function updateTask() { |
4a80c57c | 411 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", false); |
910592b4 AD |
412 | } |
413 | ||
4e5ddeaf | 414 | function housekeepingTask() { |
4a80c57c | 415 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_HOUSE_KEEPING, "hook_house_keeping", false); |
4e5ddeaf AD |
416 | } |
417 | ||
07391e36 | 418 | function globalUpdateFeeds() { |
113c3dec | 419 | RPC::updaterandomfeed_real($this->dbh); |
cda55d67 | 420 | |
4a80c57c | 421 | PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", false); |
07391e36 | 422 | } |
8361e724 AD |
423 | |
424 | function sharepopup() { | |
61a748f8 | 425 | if (SINGLE_USER_MODE) { |
6322ac79 | 426 | login_sequence(); |
61a748f8 AD |
427 | } |
428 | ||
8361e724 | 429 | header('Content-Type: text/html; charset=utf-8'); |
d0ee0f52 AD |
430 | print "<html><head><title>Tiny Tiny RSS</title> |
431 | <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\"> | |
432 | <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">"; | |
9a2aed91 | 433 | |
cdbcb277 | 434 | echo stylesheet_tag("css/utility.css"); |
6214a076 | 435 | echo stylesheet_tag("css/dijit.css"); |
cdbcb277 | 436 | echo javascript_tag("lib/prototype.js"); |
6214a076 | 437 | echo javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,controls"); |
9a2aed91 AD |
438 | print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/> |
439 | </head><body id='sharepopup'>"; | |
8361e724 AD |
440 | |
441 | $action = $_REQUEST["action"]; | |
442 | ||
443 | if ($_SESSION["uid"]) { | |
444 | ||
d493aba2 | 445 | if ($action == 'share') { |
8361e724 | 446 | |
d9c85e0f AD |
447 | $title = $this->dbh->escape_string(strip_tags($_REQUEST["title"])); |
448 | $url = $this->dbh->escape_string(strip_tags($_REQUEST["url"])); | |
449 | $content = $this->dbh->escape_string(strip_tags($_REQUEST["content"])); | |
450 | $labels = $this->dbh->escape_string(strip_tags($_REQUEST["labels"])); | |
8361e724 | 451 | |
a42c55f0 | 452 | Article::create_published_article($title, $url, $content, $labels, |
1b4d1a6b | 453 | $_SESSION["uid"]); |
8361e724 | 454 | |
d493aba2 AD |
455 | print "<script type='text/javascript'>"; |
456 | print "window.close();"; | |
457 | print "</script>"; | |
8361e724 | 458 | |
d493aba2 | 459 | } else { |
8361e724 AD |
460 | $title = htmlspecialchars($_REQUEST["title"]); |
461 | $url = htmlspecialchars($_REQUEST["url"]); | |
462 | ||
d493aba2 | 463 | ?> |
8361e724 | 464 | |
d493aba2 AD |
465 | <table height='100%' width='100%'><tr><td colspan='2'> |
466 | <h1><?php echo __("Share with Tiny Tiny RSS") ?></h1> | |
467 | </td></tr> | |
8361e724 | 468 | |
d493aba2 | 469 | <form id='share_form' name='share_form'> |
8361e724 | 470 | |
d493aba2 AD |
471 | <input type="hidden" name="op" value="sharepopup"> |
472 | <input type="hidden" name="action" value="share"> | |
8361e724 | 473 | |
22439dad | 474 | <tr><td align='right'><?php echo __("Title:") ?></td> |
d493aba2 | 475 | <td width='80%'><input name='title' value="<?php echo $title ?>"></td></tr> |
22439dad | 476 | <tr><td align='right'><?php echo __("URL:") ?></td> |
d493aba2 | 477 | <td><input name='url' value="<?php echo $url ?>"></td></tr> |
22439dad | 478 | <tr><td align='right'><?php echo __("Content:") ?></td> |
d493aba2 | 479 | <td><input name='content' value=""></td></tr> |
1b4d1a6b AD |
480 | <tr><td align='right'><?php echo __("Labels:") ?></td> |
481 | <td><input name='labels' id="labels_value" | |
482 | placeholder='Alpha, Beta, Gamma' value=""> | |
483 | </td></tr> | |
484 | ||
485 | <tr><td> | |
486 | <div class="autocomplete" id="labels_choices" | |
487 | style="display : block"></div></td></tr> | |
8361e724 | 488 | |
d493aba2 | 489 | <script type='text/javascript'>document.forms[0].title.focus();</script> |
8361e724 | 490 | |
1b4d1a6b AD |
491 | <script type='text/javascript'> |
492 | new Ajax.Autocompleter('labels_value', 'labels_choices', | |
493 | "backend.php?op=rpc&method=completeLabels", | |
494 | { tokens: ',', paramName: "search" }); | |
495 | </script> | |
496 | ||
d493aba2 AD |
497 | <tr><td colspan='2'> |
498 | <div style='float : right' class='insensitive-small'> | |
499 | <?php echo __("Shared article will appear in the Published feed.") ?> | |
500 | </div> | |
501 | <button type="submit"><?php echo __('Share') ?></button> | |
502 | <button onclick="return window.close()"><?php echo __('Cancel') ?></button> | |
503 | </div> | |
8361e724 | 504 | |
d493aba2 AD |
505 | </form> |
506 | </td></tr></table> | |
507 | </body></html> | |
508 | <?php | |
8361e724 | 509 | |
8361e724 AD |
510 | } |
511 | ||
512 | } else { | |
513 | ||
d493aba2 AD |
514 | $return = urlencode($_SERVER["REQUEST_URI"]) |
515 | ?> | |
516 | ||
517 | <form action="public.php?return=<?php echo $return ?>" | |
22439dad | 518 | method="POST" id="loginForm" name="loginForm"> |
d493aba2 AD |
519 | |
520 | <input type="hidden" name="op" value="login"> | |
521 | ||
522 | <table height='100%' width='100%'><tr><td colspan='2'> | |
22439dad | 523 | <h1><?php echo __("Not logged in") ?></h1></td></tr> |
d493aba2 AD |
524 | |
525 | <tr><td align="right"><?php echo __("Login:") ?></td> | |
526 | <td align="right"><input name="login" | |
527 | value="<?php echo $_SESSION["fake_login"] ?>"></td></tr> | |
528 | <tr><td align="right"><?php echo __("Password:") ?></td> | |
529 | <td align="right"><input type="password" name="password" | |
530 | value="<?php echo $_SESSION["fake_password"] ?>"></td></tr> | |
d493aba2 AD |
531 | <tr><td colspan='2'> |
532 | <button type="submit"> | |
533 | <?php echo __('Log in') ?></button> | |
534 | ||
535 | <button onclick="return window.close()"> | |
536 | <?php echo __('Cancel') ?></button> | |
537 | </td></tr> | |
538 | </table> | |
539 | ||
540 | </form> | |
541 | <?php | |
8361e724 AD |
542 | } |
543 | } | |
544 | ||
97acbaf1 | 545 | function login() { |
97acbaf1 AD |
546 | if (!SINGLE_USER_MODE) { |
547 | ||
d9c85e0f | 548 | $login = $this->dbh->escape_string($_POST["login"]); |
97acbaf1 | 549 | $password = $_POST["password"]; |
aadd636a | 550 | $remember_me = $_POST["remember_me"]; |
97acbaf1 | 551 | |
f231f438 AD |
552 | if ($remember_me) { |
553 | session_set_cookie_params(SESSION_COOKIE_LIFETIME); | |
554 | } else { | |
555 | session_set_cookie_params(0); | |
556 | } | |
557 | ||
aadd636a | 558 | @session_start(); |
60ed4c9a | 559 | |
a42c55f0 | 560 | if (authenticate_user($login, $password)) { |
97acbaf1 AD |
561 | $_POST["password"] = ""; |
562 | ||
b18d109f AD |
563 | if (get_schema_version() >= 120) { |
564 | $_SESSION["language"] = get_pref("USER_LANGUAGE", $_SESSION["uid"]); | |
565 | } | |
566 | ||
a42c55f0 | 567 | $_SESSION["ref_schema_version"] = get_schema_version(true); |
97acbaf1 AD |
568 | $_SESSION["bw_limit"] = !!$_POST["bw_limit"]; |
569 | ||
570 | if ($_POST["profile"]) { | |
571 | ||
d9c85e0f | 572 | $profile = $this->dbh->escape_string($_POST["profile"]); |
97acbaf1 | 573 | |
d9c85e0f | 574 | $result = $this->dbh->query("SELECT id FROM ttrss_settings_profiles |
97acbaf1 AD |
575 | WHERE id = '$profile' AND owner_uid = " . $_SESSION["uid"]); |
576 | ||
d9c85e0f | 577 | if ($this->dbh->num_rows($result) != 0) { |
97acbaf1 | 578 | $_SESSION["profile"] = $profile; |
97acbaf1 AD |
579 | } |
580 | } | |
581 | } else { | |
582 | $_SESSION["login_error_msg"] = __("Incorrect username or password"); | |
fd94d631 | 583 | user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING); |
97acbaf1 AD |
584 | } |
585 | ||
586 | if ($_REQUEST['return']) { | |
587 | header("Location: " . $_REQUEST['return']); | |
588 | } else { | |
589 | header("Location: " . SELF_URL_PATH); | |
590 | } | |
591 | } | |
592 | } | |
593 | ||
f7439d69 | 594 | /* function subtest() { |
97b7d5c0 AD |
595 | header("Content-type: text/plain; charset=utf-8"); |
596 | ||
597 | $url = $_REQUEST["url"]; | |
598 | ||
599 | print "$url\n\n"; | |
600 | ||
601 | ||
602 | print_r(get_feeds_from_html($url, fetch_file_contents($url))); | |
603 | ||
f7439d69 | 604 | } */ |
97b7d5c0 | 605 | |
97acbaf1 | 606 | function subscribe() { |
61a748f8 | 607 | if (SINGLE_USER_MODE) { |
6322ac79 | 608 | login_sequence(); |
61a748f8 AD |
609 | } |
610 | ||
97acbaf1 AD |
611 | if ($_SESSION["uid"]) { |
612 | ||
d9c85e0f | 613 | $feed_url = $this->dbh->escape_string(trim($_REQUEST["feed_url"])); |
97acbaf1 AD |
614 | |
615 | header('Content-Type: text/html; charset=utf-8'); | |
616 | print "<html> | |
617 | <head> | |
618 | <title>Tiny Tiny RSS</title> | |
5bbc4bb4 | 619 | <link rel=\"stylesheet\" type=\"text/css\" href=\"css/utility.css\"> |
97acbaf1 | 620 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/> |
d0ee0f52 AD |
621 | <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\"> |
622 | <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\"> | |
623 | ||
97acbaf1 AD |
624 | </head> |
625 | <body> | |
884d1650 | 626 | <img class=\"floatingLogo\" src=\"images/logo_small.png\" |
97acbaf1 | 627 | alt=\"Tiny Tiny RSS\"/> |
884d1650 | 628 | <h1>".__("Subscribe to feed...")."</h1><div class='content'>"; |
97acbaf1 | 629 | |
a42c55f0 | 630 | $rc = subscribe_to_feed($feed_url); |
97acbaf1 AD |
631 | |
632 | switch ($rc['code']) { | |
633 | case 0: | |
634 | print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url)); | |
635 | break; | |
636 | case 1: | |
637 | print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url)); | |
638 | break; | |
639 | case 2: | |
640 | print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url)); | |
641 | break; | |
642 | case 3: | |
643 | print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url)); | |
644 | break; | |
645 | case 4: | |
646 | print_notice(__("Multiple feed URLs found.")); | |
759e5132 | 647 | $feed_urls = $rc["feeds"]; |
97acbaf1 AD |
648 | break; |
649 | case 5: | |
650 | print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url)); | |
651 | break; | |
652 | } | |
653 | ||
654 | if ($feed_urls) { | |
655 | ||
656 | print "<form action=\"public.php\">"; | |
657 | print "<input type=\"hidden\" name=\"op\" value=\"subscribe\">"; | |
658 | ||
659 | print "<select name=\"feed_url\">"; | |
660 | ||
661 | foreach ($feed_urls as $url => $name) { | |
662 | $url = htmlspecialchars($url); | |
663 | $name = htmlspecialchars($name); | |
664 | ||
665 | print "<option value=\"$url\">$name</option>"; | |
666 | } | |
667 | ||
668 | print "<input type=\"submit\" value=\"".__("Subscribe to selected feed"). | |
669 | "\">"; | |
670 | ||
671 | print "</form>"; | |
672 | } | |
673 | ||
674 | $tp_uri = get_self_url_prefix() . "/prefs.php"; | |
675 | $tt_uri = get_self_url_prefix(); | |
676 | ||
677 | if ($rc['code'] <= 2){ | |
d9c85e0f | 678 | $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE |
97acbaf1 AD |
679 | feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]); |
680 | ||
d9c85e0f | 681 | $feed_id = $this->dbh->fetch_result($result, 0, "id"); |
97acbaf1 AD |
682 | } else { |
683 | $feed_id = 0; | |
684 | } | |
685 | print "<p>"; | |
686 | ||
687 | if ($feed_id) { | |
688 | print "<form method=\"GET\" style='display: inline' | |
689 | action=\"$tp_uri\"> | |
690 | <input type=\"hidden\" name=\"tab\" value=\"feedConfig\"> | |
691 | <input type=\"hidden\" name=\"method\" value=\"editFeed\"> | |
692 | <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\"> | |
693 | <input type=\"submit\" value=\"".__("Edit subscription options")."\"> | |
694 | </form>"; | |
695 | } | |
696 | ||
697 | print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\"> | |
698 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> | |
699 | </form></p>"; | |
700 | ||
884d1650 | 701 | print "</div></body></html>"; |
97acbaf1 AD |
702 | |
703 | } else { | |
6322ac79 | 704 | render_login_form(); |
97acbaf1 AD |
705 | } |
706 | } | |
707 | ||
97acbaf1 AD |
708 | function index() { |
709 | header("Content-Type: text/plain"); | |
710 | print json_encode(array("error" => array("code" => 7))); | |
711 | } | |
712 | ||
f43e9e97 | 713 | function forgotpass() { |
67e0cf9a AD |
714 | startup_gettext(); |
715 | ||
5303f9a7 AD |
716 | @$hash = $_REQUEST["hash"]; |
717 | ||
f43e9e97 | 718 | header('Content-Type: text/html; charset=utf-8'); |
d0ee0f52 AD |
719 | print "<html><head><title>Tiny Tiny RSS</title> |
720 | <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\"> | |
721 | <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">"; | |
e216d302 | 722 | |
cdbcb277 AD |
723 | echo stylesheet_tag("css/utility.css"); |
724 | echo javascript_tag("lib/prototype.js"); | |
e216d302 AD |
725 | |
726 | print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/> | |
727 | </head><body id='forgotpass'>"; | |
f43e9e97 | 728 | |
884d1650 | 729 | print '<div class="floatingLogo"><img src="images/logo_small.png"></div>'; |
483f15d5 | 730 | print "<h1>".__("Password recovery")."</h1>"; |
884d1650 | 731 | print "<div class='content'>"; |
f43e9e97 AD |
732 | |
733 | @$method = $_POST['method']; | |
734 | ||
5303f9a7 AD |
735 | if ($hash) { |
736 | $login = $_REQUEST["login"]; | |
737 | ||
738 | if ($login) { | |
739 | $result = $this->dbh->query("SELECT id, resetpass_token FROM ttrss_users | |
740 | WHERE login = '$login'"); | |
741 | ||
742 | if ($this->dbh->num_rows($result) != 0) { | |
743 | $id = $this->dbh->fetch_result($result, 0, "id"); | |
744 | $resetpass_token_full = $this->dbh->fetch_result($result, 0, "resetpass_token"); | |
745 | list($timestamp, $resetpass_token) = explode(":", $resetpass_token_full); | |
746 | ||
747 | if ($timestamp && $resetpass_token && | |
748 | $timestamp >= time() - 15*60*60 && | |
749 | $resetpass_token == $hash) { | |
750 | ||
751 | $result = $this->dbh->query("UPDATE ttrss_users SET resetpass_token = NULL | |
752 | WHERE id = $id"); | |
753 | ||
754 | Pref_Users::resetUserPassword($id, true); | |
755 | ||
756 | print "<p>"."Completed."."</p>"; | |
757 | ||
758 | } else { | |
759 | print_error("Some of the information provided is missing or incorrect."); | |
760 | } | |
761 | } else { | |
762 | print_error("Some of the information provided is missing or incorrect."); | |
763 | } | |
764 | } else { | |
765 | print_error("Some of the information provided is missing or incorrect."); | |
766 | } | |
767 | ||
768 | print "<form method=\"GET\" action=\"index.php\"> | |
769 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> | |
770 | </form>"; | |
771 | ||
772 | } else if (!$method) { | |
773 | print_notice(__("You will need to provide valid account name and email. A password reset link will be sent to your email address.")); | |
483f15d5 | 774 | |
f43e9e97 | 775 | print "<form method='POST' action='public.php'>"; |
f43e9e97 AD |
776 | print "<input type='hidden' name='method' value='do'>"; |
777 | print "<input type='hidden' name='op' value='forgotpass'>"; | |
778 | ||
779 | print "<fieldset>"; | |
780 | print "<label>".__("Login:")."</label>"; | |
781 | print "<input type='text' name='login' value='' required>"; | |
782 | print "</fieldset>"; | |
783 | ||
784 | print "<fieldset>"; | |
785 | print "<label>".__("Email:")."</label>"; | |
786 | print "<input type='email' name='email' value='' required>"; | |
787 | print "</fieldset>"; | |
788 | ||
789 | print "<fieldset>"; | |
790 | print "<label>".__("How much is two plus two:")."</label>"; | |
791 | print "<input type='text' name='test' value='' required>"; | |
792 | print "</fieldset>"; | |
793 | ||
794 | print "<p/>"; | |
795 | print "<button type='submit'>".__("Reset password")."</button>"; | |
796 | ||
797 | print "</form>"; | |
798 | } else if ($method == 'do') { | |
799 | ||
d9c85e0f AD |
800 | $login = $this->dbh->escape_string($_POST["login"]); |
801 | $email = $this->dbh->escape_string($_POST["email"]); | |
802 | $test = $this->dbh->escape_string($_POST["test"]); | |
f43e9e97 AD |
803 | |
804 | if (($test != 4 && $test != 'four') || !$email || !$login) { | |
805 | print_error(__('Some of the required form parameters are missing or incorrect.')); | |
806 | ||
483f15d5 AD |
807 | print "<form method=\"GET\" action=\"public.php\"> |
808 | <input type=\"hidden\" name=\"op\" value=\"forgotpass\"> | |
809 | <input type=\"submit\" value=\"".__("Go back")."\"> | |
810 | </form>"; | |
f43e9e97 | 811 | |
e216d302 | 812 | } else { |
f43e9e97 | 813 | |
5303f9a7 AD |
814 | print_notice("Password reset instructions are being sent to your email address."); |
815 | ||
d9c85e0f | 816 | $result = $this->dbh->query("SELECT id FROM ttrss_users |
f43e9e97 AD |
817 | WHERE login = '$login' AND email = '$email'"); |
818 | ||
d9c85e0f AD |
819 | if ($this->dbh->num_rows($result) != 0) { |
820 | $id = $this->dbh->fetch_result($result, 0, "id"); | |
f43e9e97 | 821 | |
5303f9a7 AD |
822 | if ($id) { |
823 | $resetpass_token = sha1(get_random_bytes(128)); | |
824 | $resetpass_link = get_self_url_prefix() . "/public.php?op=forgotpass&hash=" . $resetpass_token . | |
825 | "&login=" . urlencode($login); | |
826 | ||
827 | require_once 'classes/ttrssmailer.php'; | |
828 | require_once "lib/MiniTemplator.class.php"; | |
829 | ||
830 | $tpl = new MiniTemplator; | |
831 | ||
832 | $tpl->readTemplateFromFile("templates/resetpass_link_template.txt"); | |
833 | ||
834 | $tpl->setVariable('LOGIN', $login); | |
835 | $tpl->setVariable('RESETPASS_LINK', $resetpass_link); | |
836 | ||
837 | $tpl->addBlock('message'); | |
838 | ||
839 | $message = ""; | |
f43e9e97 | 840 | |
5303f9a7 | 841 | $tpl->generateOutputToString($message); |
483f15d5 | 842 | |
5303f9a7 AD |
843 | $mail = new ttrssMailer(); |
844 | ||
845 | $rc = $mail->quickMail($email, $login, | |
846 | __("[tt-rss] Password reset request"), | |
847 | $message, false); | |
848 | ||
849 | if (!$rc) print_error($mail->ErrorInfo); | |
850 | ||
851 | $resetpass_token_full = $this->dbh->escape_string(time() . ":" . $resetpass_token); | |
852 | ||
853 | $result = $this->dbh->query("UPDATE ttrss_users | |
854 | SET resetpass_token = '$resetpass_token_full' | |
855 | WHERE login = '$login' AND email = '$email'"); | |
856 | ||
857 | //Pref_Users::resetUserPassword($id, false); | |
858 | ||
859 | print "<p>"; | |
860 | ||
861 | print "<p>"."Completed."."</p>"; | |
862 | } else { | |
863 | print_error("User ID not found."); | |
864 | } | |
483f15d5 AD |
865 | |
866 | print "<form method=\"GET\" action=\"index.php\"> | |
867 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> | |
868 | </form>"; | |
f43e9e97 AD |
869 | |
870 | } else { | |
871 | print_error(__("Sorry, login and email combination not found.")); | |
483f15d5 AD |
872 | |
873 | print "<form method=\"GET\" action=\"public.php\"> | |
874 | <input type=\"hidden\" name=\"op\" value=\"forgotpass\"> | |
875 | <input type=\"submit\" value=\"".__("Go back")."\"> | |
876 | </form>"; | |
877 | ||
f43e9e97 | 878 | } |
f43e9e97 AD |
879 | } |
880 | ||
881 | } | |
882 | ||
884d1650 | 883 | print "</div>"; |
f43e9e97 AD |
884 | print "</body>"; |
885 | print "</html>"; | |
886 | ||
b4c47f7e AD |
887 | } |
888 | ||
889 | function dbupdate() { | |
67e0cf9a AD |
890 | startup_gettext(); |
891 | ||
f240d26e AD |
892 | if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) { |
893 | $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script."); | |
6322ac79 | 894 | render_login_form(); |
f240d26e AD |
895 | exit; |
896 | } | |
897 | ||
898 | ?><html> | |
899 | <head> | |
900 | <title>Database Updater</title> | |
901 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> | |
5bbc4bb4 | 902 | <link rel="stylesheet" type="text/css" href="css/utility.css"/> |
d0ee0f52 AD |
903 | <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\"> |
904 | <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\"> | |
f240d26e AD |
905 | </head> |
906 | <style type="text/css"> | |
907 | span.ok { color : #009000; font-weight : bold; } | |
908 | span.err { color : #ff0000; font-weight : bold; } | |
909 | </style> | |
910 | <body> | |
911 | <script type='text/javascript'> | |
912 | function confirmOP() { | |
913 | return confirm("Update the database?"); | |
914 | } | |
915 | </script> | |
916 | ||
917 | <div class="floatingLogo"><img src="images/logo_small.png"></div> | |
918 | ||
919 | <h1><?php echo __("Database Updater") ?></h1> | |
920 | ||
921 | <div class="content"> | |
922 | ||
923 | <?php | |
924 | @$op = $_REQUEST["subop"]; | |
0630a100 | 925 | $updater = new DbUpdater(Db::get(), DB_TYPE, SCHEMA_VERSION); |
f240d26e AD |
926 | |
927 | if ($op == "performupdate") { | |
928 | if ($updater->isUpdateRequired()) { | |
929 | ||
930 | print "<h2>Performing updates</h2>"; | |
931 | ||
932 | print "<h3>Updating to schema version " . SCHEMA_VERSION . "</h3>"; | |
933 | ||
934 | print "<ul>"; | |
935 | ||
936 | for ($i = $updater->getSchemaVersion() + 1; $i <= SCHEMA_VERSION; $i++) { | |
937 | print "<li>Performing update up to version $i..."; | |
938 | ||
939 | $result = $updater->performUpdateTo($i); | |
940 | ||
941 | if (!$result) { | |
942 | print "<span class='err'>FAILED!</span></li></ul>"; | |
943 | ||
944 | print_warning("One of the updates failed. Either retry the process or perform updates manually."); | |
945 | print "<p><form method=\"GET\" action=\"index.php\"> | |
946 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> | |
947 | </form>"; | |
948 | ||
949 | break; | |
950 | } else { | |
951 | print "<span class='ok'>OK!</span></li>"; | |
952 | } | |
953 | } | |
954 | ||
955 | print "</ul>"; | |
b4c47f7e | 956 | |
f240d26e | 957 | print_notice("Your Tiny Tiny RSS database is now updated to the latest version."); |
b4c47f7e | 958 | |
f240d26e AD |
959 | print "<p><form method=\"GET\" action=\"index.php\"> |
960 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> | |
961 | </form>"; | |
962 | ||
963 | } else { | |
964 | print "<h2>Your database is up to date.</h2>"; | |
965 | ||
966 | print "<p><form method=\"GET\" action=\"index.php\"> | |
967 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> | |
968 | </form>"; | |
969 | } | |
970 | } else { | |
971 | if ($updater->isUpdateRequired()) { | |
972 | ||
973 | print "<h2>Database update required</h2>"; | |
b4c47f7e | 974 | |
f240d26e AD |
975 | print "<h3>"; |
976 | printf("Your Tiny Tiny RSS database needs update to the latest version: %d to %d.", | |
977 | $updater->getSchemaVersion(), SCHEMA_VERSION); | |
978 | print "</h3>"; | |
b4c47f7e | 979 | |
f240d26e | 980 | print_warning("Please backup your database before proceeding."); |
b4c47f7e | 981 | |
f240d26e AD |
982 | print "<form method='POST'> |
983 | <input type='hidden' name='subop' value='performupdate'> | |
984 | <input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'> | |
985 | </form>"; | |
986 | ||
987 | } else { | |
988 | ||
3c200461 | 989 | print_notice("Tiny Tiny RSS database is up to date."); |
f240d26e AD |
990 | |
991 | print "<p><form method=\"GET\" action=\"index.php\"> | |
992 | <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> | |
993 | </form>"; | |
994 | ||
995 | } | |
996 | } | |
997 | ?> | |
b4c47f7e | 998 | |
f240d26e AD |
999 | </div> |
1000 | </body> | |
1001 | </html> | |
1002 | <?php | |
f43e9e97 AD |
1003 | } |
1004 | ||
0c6f7b31 AD |
1005 | function cached_image() { |
1006 | @$hash = basename($_GET['hash']); | |
1007 | ||
1008 | if ($hash) { | |
1009 | ||
1010 | $filename = CACHE_DIR . '/images/' . $hash . '.png'; | |
1011 | ||
1012 | if (file_exists($filename)) { | |
1013 | /* See if we can use X-Sendfile */ | |
1014 | $xsendfile = false; | |
1015 | if (function_exists('apache_get_modules') && | |
1016 | array_search('mod_xsendfile', apache_get_modules())) | |
1017 | $xsendfile = true; | |
1018 | ||
1019 | if ($xsendfile) { | |
1020 | header("X-Sendfile: $filename"); | |
1021 | header("Content-type: application/octet-stream"); | |
1022 | header('Content-Disposition: attachment; filename="' . basename($filename) . '"'); | |
1023 | } else { | |
1024 | header("Content-type: image/png"); | |
1025 | $stamp = gmdate("D, d M Y H:i:s", filemtime($filename)). " GMT"; | |
1026 | header("Last-Modified: $stamp", true); | |
1027 | readfile($filename); | |
1028 | } | |
1029 | } else { | |
1030 | header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); | |
1031 | echo "File not found."; | |
1032 | } | |
1033 | } | |
1034 | } | |
1035 | ||
5f0a3741 AD |
1036 | } |
1037 | ?> |