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