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