]>
git.wh0rd.org - tt-rss.git/blob - classes/handler/public.php
e89318c6f8dd236676d83f2f18cabc3d8ebda38e
2 class Handler_Public
extends Handler
{
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, $start_ts = false) {
8 require_once "lib/MiniTemplator.class.php";
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;";
15 if (!$limit) $limit = 60;
17 $date_sort_field = "date_entered DESC, updated DESC";
18 $date_check_field = "date_entered";
20 if ($feed == -2 && !$is_cat) {
21 $date_sort_field = "last_published DESC";
22 $date_check_field = "last_published";
23 } else if ($feed == -1 && !$is_cat) {
24 $date_sort_field = "last_marked DESC";
25 $date_check_field = "last_marked";
30 $date_sort_field = "ttrss_entries.title";
33 $date_sort_field = "date_entered, updated";
36 $date_sort_field = "updated DESC";
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) {
43 $qfh_ret = queryFeedHeadlines($feed,
44 1, $view_mode, $is_cat, $search, $search_mode,
45 $date_sort_field, $offset, $owner_uid,
46 false, 0, false, true, false, false, $start_ts);
48 $result = $qfh_ret[0];
50 if ($this->dbh
->num_rows($result) != 0) {
52 $ts = strtotime($this->dbh
->fetch_result($result, 0, $date_check_field));
54 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) &&
55 strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $ts) {
56 header('HTTP/1.0 304 Not Modified');
60 $last_modified = gmdate("D, d M Y H:i:s", $ts) . " GMT";
61 header("Last-Modified: $last_modified", true);
64 $qfh_ret = queryFeedHeadlines($feed,
65 $limit, $view_mode, $is_cat, $search, $search_mode,
66 $date_sort_field, $offset, $owner_uid,
67 false, 0, false, true, false, false, $start_ts);
70 $result = $qfh_ret[0];
71 $feed_title = htmlspecialchars($qfh_ret[1]);
72 $feed_site_url = $qfh_ret[2];
73 /* $last_error = $qfh_ret[3]; */
75 $feed_self_url = get_self_url_prefix() .
76 "/public.php?op=rss&id=$feed&key=" .
77 get_feed_access_key($feed, false, $owner_uid);
79 if (!$feed_site_url) $feed_site_url = get_self_url_prefix();
81 if ($format == 'atom') {
82 $tpl = new MiniTemplator
;
84 $tpl->readTemplateFromFile("templates/generated_feed.txt");
86 $tpl->setVariable('FEED_TITLE', $feed_title, true);
87 $tpl->setVariable('VERSION', VERSION
, true);
88 $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
90 if (PUBSUBHUBBUB_HUB
&& $feed == -2) {
91 $tpl->setVariable('HUB_URL', htmlspecialchars(PUBSUBHUBBUB_HUB
), true);
92 $tpl->addBlock('feed_hub');
95 $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
96 while ($line = $this->dbh
->fetch_assoc($result)) {
97 $line["content_preview"] = truncate_string(strip_tags($line["content"]), 100, '...');
99 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_QUERY_HEADLINES
) as $p) {
100 $line = $p->hook_query_headlines($line);
103 $tpl->setVariable('ARTICLE_ID',
104 htmlspecialchars($orig_guid ?
$line['link'] :
105 get_self_url_prefix() .
106 "/public.php?url=" . urlencode($line['link'])), true);
107 $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
108 $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
109 $tpl->setVariable('ARTICLE_EXCERPT', $line["content_preview"], true);
111 $content = sanitize($line["content"], false, $owner_uid,
115 $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" .
117 $tpl->setVariable('ARTICLE_NOTE', htmlspecialchars($line['note']), true);
120 $tpl->setVariable('ARTICLE_CONTENT', $content, true);
122 $tpl->setVariable('ARTICLE_UPDATED_ATOM',
123 date('c', strtotime($line["updated"])), true);
124 $tpl->setVariable('ARTICLE_UPDATED_RFC822',
125 date(DATE_RFC822
, strtotime($line["updated"])), true);
127 $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true);
129 $tpl->setVariable('ARTICLE_SOURCE_LINK', htmlspecialchars($line['site_url']), true);
130 $tpl->setVariable('ARTICLE_SOURCE_TITLE', htmlspecialchars($line['feed_title'] ?
$line['feed_title'] : $feed_title), true);
132 $tags = get_article_tags($line["id"], $owner_uid);
134 foreach ($tags as $tag) {
135 $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true);
136 $tpl->addBlock('category');
139 $enclosures = get_article_enclosures($line["id"]);
141 foreach ($enclosures as $e) {
142 $type = htmlspecialchars($e['content_type']);
143 $url = htmlspecialchars($e['content_url']);
144 $length = $e['duration'];
146 $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
147 $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
148 $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
150 $tpl->addBlock('enclosure');
153 $tpl->addBlock('entry');
158 $tpl->addBlock('feed');
159 $tpl->generateOutputToString($tmp);
161 if (@!$_REQUEST["noxml"]) {
162 header("Content-Type: text/xml; charset=utf-8");
164 header("Content-Type: text/plain; charset=utf-8");
168 } else if ($format == 'json') {
172 $feed['title'] = $feed_title;
173 $feed['version'] = VERSION
;
174 $feed['feed_url'] = $feed_self_url;
176 if (PUBSUBHUBBUB_HUB
&& $feed == -2) {
177 $feed['hub_url'] = PUBSUBHUBBUB_HUB
;
180 $feed['self_url'] = get_self_url_prefix();
182 $feed['articles'] = array();
184 while ($line = $this->dbh
->fetch_assoc($result)) {
185 $line["content_preview"] = truncate_string(strip_tags($line["content_preview"]), 100, '...');
186 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_QUERY_HEADLINES
) as $p) {
187 $line = $p->hook_query_headlines($line, 100);
191 $article['id'] = $line['link'];
192 $article['link'] = $line['link'];
193 $article['title'] = $line['title'];
194 $article['excerpt'] = $line["content_preview"];
195 $article['content'] = sanitize($line["content"], false, $owner_uid);
196 $article['updated'] = date('c', strtotime($line["updated"]));
198 if ($line['note']) $article['note'] = $line['note'];
199 if ($article['author']) $article['author'] = $line['author'];
201 $tags = get_article_tags($line["id"], $owner_uid);
203 if (count($tags) > 0) {
204 $article['tags'] = array();
206 foreach ($tags as $tag) {
207 array_push($article['tags'], $tag);
211 $enclosures = get_article_enclosures($line["id"]);
213 if (count($enclosures) > 0) {
214 $article['enclosures'] = array();
216 foreach ($enclosures as $e) {
217 $type = $e['content_type'];
218 $url = $e['content_url'];
219 $length = $e['duration'];
221 array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length));
225 array_push($feed['articles'], $article);
228 header("Content-Type: text/json; charset=utf-8");
229 print json_encode($feed);
232 header("Content-Type: text/plain; charset=utf-8");
233 print json_encode(array("error" => array("message" => "Unknown format")));
237 function getUnread() {
238 $login = $this->dbh
->escape_string($_REQUEST["login"]);
239 $fresh = $_REQUEST["fresh"] == "1";
241 $result = $this->dbh
->query("SELECT id FROM ttrss_users WHERE login = '$login'");
243 if ($this->dbh
->num_rows($result) == 1) {
244 $uid = $this->dbh
->fetch_result($result, 0, "id");
246 print getGlobalUnread($uid);
250 print getFeedArticles(-3, false, true, $uid);
254 print "-1;User not found";
259 function getProfiles() {
260 $login = $this->dbh
->escape_string($_REQUEST["login"]);
262 $result = $this->dbh
->query("SELECT ttrss_settings_profiles.* FROM ttrss_settings_profiles,ttrss_users
263 WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = '$login' ORDER BY title");
265 print "<select dojoType='dijit.form.Select' style='width : 220px; margin : 0px' name='profile'>";
267 print "<option value='0'>" . __("Default profile") . "</option>";
269 while ($line = $this->dbh
->fetch_assoc($result)) {
271 $title = $line["title"];
273 print "<option value='$id'>$title</option>";
280 $mode = $this->dbh
->escape_string($_REQUEST['hub_mode']);
281 if (!$mode) $mode = $this->dbh
->escape_string($_REQUEST['hub.mode']);
283 $feed_id = (int) $this->dbh
->escape_string($_REQUEST['id']);
284 $feed_url = $this->dbh
->escape_string($_REQUEST['hub_topic']);
286 if (!$feed_url) $feed_url = $this->dbh
->escape_string($_REQUEST['hub.topic']);
288 if (!PUBSUBHUBBUB_ENABLED
) {
289 header('HTTP/1.0 404 Not Found');
290 echo "404 Not found (Disabled by server)";
294 // TODO: implement hub_verifytoken checking
295 // TODO: store requested rel=self or whatever for verification
296 // (may be different from stored feed url) e.g. http://url/ or http://url
298 $result = $this->dbh
->query("SELECT feed_url FROM ttrss_feeds
299 WHERE id = '$feed_id'");
301 if ($this->dbh
->num_rows($result) != 0) {
303 $check_feed_url = $this->dbh
->fetch_result($result, 0, "feed_url");
305 // ignore url checking for the time being
306 if ($check_feed_url && (true ||
$check_feed_url == $feed_url ||
!$feed_url)) {
307 if ($mode == "subscribe") {
309 $this->dbh
->query("UPDATE ttrss_feeds SET pubsub_state = 2
310 WHERE id = '$feed_id'");
312 print $_REQUEST['hub_challenge'];
315 } else if ($mode == "unsubscribe") {
317 $this->dbh
->query("UPDATE ttrss_feeds SET pubsub_state = 0
318 WHERE id = '$feed_id'");
320 print $_REQUEST['hub_challenge'];
325 // Received update ping, schedule feed update.
326 //update_rss_feed($feed_id, true, true);
328 $this->dbh
->query("UPDATE ttrss_feeds SET
329 last_update_started = '1970-01-01',
330 last_updated = '1970-01-01' WHERE id = '$feed_id'");
334 header('HTTP/1.0 404 Not Found');
335 echo "404 Not found (URL check failed)";
338 header('HTTP/1.0 404 Not Found');
339 echo "404 Not found (Feed not found)";
346 header("Location: index.php");
350 $uuid = $this->dbh
->escape_string($_REQUEST["key"]);
352 $result = $this->dbh
->query("SELECT ref_id, owner_uid FROM ttrss_user_entries WHERE
355 if ($this->dbh
->num_rows($result) != 0) {
356 header("Content-Type: text/html");
358 $id = $this->dbh
->fetch_result($result, 0, "ref_id");
359 $owner_uid = $this->dbh
->fetch_result($result, 0, "owner_uid");
361 $article = format_article($id, false, true, $owner_uid);
363 print_r($article['content']);
366 print "Article not found.";
372 $feed = $this->dbh
->escape_string($_REQUEST["id"]);
373 $key = $this->dbh
->escape_string($_REQUEST["key"]);
374 $is_cat = sql_bool_to_bool($_REQUEST["is_cat"]);
375 $limit = (int)$this->dbh
->escape_string($_REQUEST["limit"]);
376 $offset = (int)$this->dbh
->escape_string($_REQUEST["offset"]);
378 $search = $this->dbh
->escape_string($_REQUEST["q"]);
379 $search_mode = $this->dbh
->escape_string($_REQUEST["smode"]);
380 $view_mode = $this->dbh
->escape_string($_REQUEST["view-mode"]);
381 $order = $this->dbh
->escape_string($_REQUEST["order"]);
382 $start_ts = $this->dbh
->escape_string($_REQUEST["ts"]);
384 $format = $this->dbh
->escape_string($_REQUEST['format']);
385 $orig_guid = sql_bool_to_bool($_REQUEST["orig_guid"]);
387 if (!$format) $format = 'atom';
389 if (SINGLE_USER_MODE
) {
390 authenticate_user("admin", null);
396 $result = $this->dbh
->query("SELECT owner_uid FROM
397 ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'");
399 if ($this->dbh
->num_rows($result) == 1)
400 $owner_id = $this->dbh
->fetch_result($result, 0, "owner_uid");
404 $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit,
405 $offset, $search, $search_mode, $view_mode, $format, $order, $orig_guid, $start_ts);
407 header('HTTP/1.1 403 Forbidden');
411 function updateTask() {
412 PluginHost
::getInstance()->run_hooks(PluginHost
::HOOK_UPDATE_TASK
, "hook_update_task", false);
415 function housekeepingTask() {
416 PluginHost
::getInstance()->run_hooks(PluginHost
::HOOK_HOUSE_KEEPING
, "hook_house_keeping", false);
419 function globalUpdateFeeds() {
420 RPC
::updaterandomfeed_real($this->dbh
);
422 PluginHost
::getInstance()->run_hooks(PluginHost
::HOOK_UPDATE_TASK
, "hook_update_task", false);
425 function sharepopup() {
426 if (SINGLE_USER_MODE
) {
430 header('Content-Type: text/html; charset=utf-8');
431 print "<html><head><title>Tiny Tiny RSS</title>
432 <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">
433 <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">";
435 echo stylesheet_tag("css/utility.css");
436 echo stylesheet_tag("css/dijit.css");
437 echo javascript_tag("lib/prototype.js");
438 echo javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,controls");
439 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
440 </head><body id='sharepopup'>";
442 $action = $_REQUEST["action"];
444 if ($_SESSION["uid"]) {
446 if ($action == 'share') {
448 $title = $this->dbh
->escape_string(strip_tags($_REQUEST["title"]));
449 $url = $this->dbh
->escape_string(strip_tags($_REQUEST["url"]));
450 $content = $this->dbh
->escape_string(strip_tags($_REQUEST["content"]));
451 $labels = $this->dbh
->escape_string(strip_tags($_REQUEST["labels"]));
453 Article
::create_published_article($title, $url, $content, $labels,
456 print "<script type='text/javascript'>";
457 print "window.close();";
461 $title = htmlspecialchars($_REQUEST["title"]);
462 $url = htmlspecialchars($_REQUEST["url"]);
466 <table height
='100%' width
='100%'><tr
><td colspan
='2'>
467 <h1
><?php
echo __("Share with Tiny Tiny RSS") ?
></h1
>
470 <form id
='share_form' name
='share_form'>
472 <input type
="hidden" name
="op" value
="sharepopup">
473 <input type
="hidden" name
="action" value
="share">
475 <tr
><td align
='right'><?php
echo __("Title:") ?
></td
>
476 <td width
='80%'><input name
='title' value
="<?php echo $title ?>"></td
></tr
>
477 <tr
><td align
='right'><?php
echo __("URL:") ?
></td
>
478 <td
><input name
='url' value
="<?php echo $url ?>"></td
></tr
>
479 <tr
><td align
='right'><?php
echo __("Content:") ?
></td
>
480 <td
><input name
='content' value
=""></td
></tr
>
481 <tr
><td align
='right'><?php
echo __("Labels:") ?
></td
>
482 <td
><input name
='labels' id
="labels_value"
483 placeholder
='Alpha, Beta, Gamma' value
="">
487 <div
class="autocomplete" id
="labels_choices"
488 style
="display : block"></div
></td
></tr
>
490 <script type
='text/javascript'>document
.forms
[0].title
.focus();</script
>
492 <script type
='text/javascript'>
493 new Ajax
.Autocompleter('labels_value', 'labels_choices',
494 "backend.php?op=rpc&method=completeLabels",
495 { tokens
: ',', paramName
: "search" });
499 <div style
='float : right' class='insensitive-small'>
500 <?php
echo __("Shared article will appear in the Published feed.") ?
>
502 <button type
="submit"><?php
echo __('Share') ?
></button
>
503 <button onclick
="return window.close()"><?php
echo __('Cancel') ?
></button
>
515 $return = urlencode($_SERVER["REQUEST_URI"])
518 <form action
="public.php?return=<?php echo $return ?>"
519 method
="POST" id
="loginForm" name
="loginForm">
521 <input type
="hidden" name
="op" value
="login">
523 <table height
='100%' width
='100%'><tr
><td colspan
='2'>
524 <h1
><?php
echo __("Not logged in") ?
></h1
></td
></tr
>
526 <tr
><td align
="right"><?php
echo __("Login:") ?
></td
>
527 <td align
="right"><input name
="login"
528 value
="<?php echo $_SESSION["fake_login
"] ?>"></td
></tr
>
529 <tr
><td align
="right"><?php
echo __("Password:") ?
></td
>
530 <td align
="right"><input type
="password" name
="password"
531 value
="<?php echo $_SESSION["fake_password
"] ?>"></td
></tr
>
533 <button type
="submit">
534 <?php
echo __('Log in') ?
></button
>
536 <button onclick
="return window.close()">
537 <?php
echo __('Cancel') ?
></button
>
547 if (!SINGLE_USER_MODE
) {
549 $login = $this->dbh
->escape_string($_POST["login"]);
550 $password = $_POST["password"];
551 $remember_me = $_POST["remember_me"];
554 session_set_cookie_params(SESSION_COOKIE_LIFETIME
);
556 session_set_cookie_params(0);
561 if (authenticate_user($login, $password)) {
562 $_POST["password"] = "";
564 if (get_schema_version() >= 120) {
565 $_SESSION["language"] = get_pref("USER_LANGUAGE", $_SESSION["uid"]);
568 $_SESSION["ref_schema_version"] = get_schema_version(true);
569 $_SESSION["bw_limit"] = !!$_POST["bw_limit"];
571 if ($_POST["profile"]) {
573 $profile = $this->dbh
->escape_string($_POST["profile"]);
575 $result = $this->dbh
->query("SELECT id FROM ttrss_settings_profiles
576 WHERE id = '$profile' AND owner_uid = " . $_SESSION["uid"]);
578 if ($this->dbh
->num_rows($result) != 0) {
579 $_SESSION["profile"] = $profile;
583 $_SESSION["login_error_msg"] = __("Incorrect username or password");
584 user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING
);
587 if ($_REQUEST['return']) {
588 header("Location: " . $_REQUEST['return']);
590 header("Location: " . SELF_URL_PATH
);
595 /* function subtest() {
596 header("Content-type: text/plain; charset=utf-8");
598 $url = $_REQUEST["url"];
603 print_r(get_feeds_from_html($url, fetch_file_contents($url)));
607 function subscribe() {
608 if (SINGLE_USER_MODE
) {
612 if ($_SESSION["uid"]) {
614 $feed_url = $this->dbh
->escape_string(trim($_REQUEST["feed_url"]));
616 header('Content-Type: text/html; charset=utf-8');
619 <title>Tiny Tiny RSS</title>
620 <link rel=\"stylesheet\" type=\"text/css\" href=\"css/utility.css\">
621 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
622 <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">
623 <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">
627 <img class=\"floatingLogo\" src=\"images/logo_small.png\"
628 alt=\"Tiny Tiny RSS\"/>
629 <h1>".__("Subscribe to feed...")."</h1><div class='content'>";
631 $rc = subscribe_to_feed($feed_url);
633 switch ($rc['code']) {
635 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
638 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
641 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
644 print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
647 print_notice(__("Multiple feed URLs found."));
648 $feed_urls = $rc["feeds"];
651 print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
657 print "<form action=\"public.php\">";
658 print "<input type=\"hidden\" name=\"op\" value=\"subscribe\">";
660 print "<select name=\"feed_url\">";
662 foreach ($feed_urls as $url => $name) {
663 $url = htmlspecialchars($url);
664 $name = htmlspecialchars($name);
666 print "<option value=\"$url\">$name</option>";
669 print "<input type=\"submit\" value=\"".__("Subscribe to selected feed").
675 $tp_uri = get_self_url_prefix() . "/prefs.php";
676 $tt_uri = get_self_url_prefix();
678 if ($rc['code'] <= 2){
679 $result = $this->dbh
->query("SELECT id FROM ttrss_feeds WHERE
680 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
682 $feed_id = $this->dbh
->fetch_result($result, 0, "id");
689 print "<form method=\"GET\" style='display: inline'
691 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
692 <input type=\"hidden\" name=\"method\" value=\"editFeed\">
693 <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
694 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
698 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
699 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
702 print "</div></body></html>";
710 header("Content-Type: text/plain");
711 print json_encode(array("error" => array("code" => 7)));
714 function forgotpass() {
717 @$hash = $_REQUEST["hash"];
719 header('Content-Type: text/html; charset=utf-8');
720 print "<html><head><title>Tiny Tiny RSS</title>
721 <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">
722 <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">";
724 echo stylesheet_tag("css/utility.css");
725 echo javascript_tag("lib/prototype.js");
727 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
728 </head><body id='forgotpass'>";
730 print '<div class="floatingLogo"><img src="images/logo_small.png"></div>';
731 print "<h1>".__("Password recovery")."</h1>";
732 print "<div class='content'>";
734 @$method = $_POST['method'];
737 $login = $_REQUEST["login"];
740 $result = $this->dbh
->query("SELECT id, resetpass_token FROM ttrss_users
741 WHERE login = '$login'");
743 if ($this->dbh
->num_rows($result) != 0) {
744 $id = $this->dbh
->fetch_result($result, 0, "id");
745 $resetpass_token_full = $this->dbh
->fetch_result($result, 0, "resetpass_token");
746 list($timestamp, $resetpass_token) = explode(":", $resetpass_token_full);
748 if ($timestamp && $resetpass_token &&
749 $timestamp >= time() - 15*60*60 &&
750 $resetpass_token == $hash) {
752 $result = $this->dbh
->query("UPDATE ttrss_users SET resetpass_token = NULL
755 Pref_Users
::resetUserPassword($id, true);
757 print "<p>"."Completed."."</p>";
760 print_error("Some of the information provided is missing or incorrect.");
763 print_error("Some of the information provided is missing or incorrect.");
766 print_error("Some of the information provided is missing or incorrect.");
769 print "<form method=\"GET\" action=\"index.php\">
770 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
773 } else if (!$method) {
774 print_notice(__("You will need to provide valid account name and email. A password reset link will be sent to your email address."));
776 print "<form method='POST' action='public.php'>";
777 print "<input type='hidden' name='method' value='do'>";
778 print "<input type='hidden' name='op' value='forgotpass'>";
781 print "<label>".__("Login:")."</label>";
782 print "<input type='text' name='login' value='' required>";
786 print "<label>".__("Email:")."</label>";
787 print "<input type='email' name='email' value='' required>";
791 print "<label>".__("How much is two plus two:")."</label>";
792 print "<input type='text' name='test' value='' required>";
796 print "<button type='submit'>".__("Reset password")."</button>";
799 } else if ($method == 'do') {
801 $login = $this->dbh
->escape_string($_POST["login"]);
802 $email = $this->dbh
->escape_string($_POST["email"]);
803 $test = $this->dbh
->escape_string($_POST["test"]);
805 if (($test != 4 && $test != 'four') ||
!$email ||
!$login) {
806 print_error(__('Some of the required form parameters are missing or incorrect.'));
808 print "<form method=\"GET\" action=\"public.php\">
809 <input type=\"hidden\" name=\"op\" value=\"forgotpass\">
810 <input type=\"submit\" value=\"".__("Go back")."\">
815 print_notice("Password reset instructions are being sent to your email address.");
817 $result = $this->dbh
->query("SELECT id FROM ttrss_users
818 WHERE login = '$login' AND email = '$email'");
820 if ($this->dbh
->num_rows($result) != 0) {
821 $id = $this->dbh
->fetch_result($result, 0, "id");
824 $resetpass_token = sha1(get_random_bytes(128));
825 $resetpass_link = get_self_url_prefix() . "/public.php?op=forgotpass&hash=" . $resetpass_token .
826 "&login=" . urlencode($login);
828 require_once 'classes/ttrssmailer.php';
829 require_once "lib/MiniTemplator.class.php";
831 $tpl = new MiniTemplator
;
833 $tpl->readTemplateFromFile("templates/resetpass_link_template.txt");
835 $tpl->setVariable('LOGIN', $login);
836 $tpl->setVariable('RESETPASS_LINK', $resetpass_link);
838 $tpl->addBlock('message');
842 $tpl->generateOutputToString($message);
844 $mail = new ttrssMailer();
846 $rc = $mail->quickMail($email, $login,
847 __("[tt-rss] Password reset request"),
850 if (!$rc) print_error($mail->ErrorInfo
);
852 $resetpass_token_full = $this->dbh
->escape_string(time() . ":" . $resetpass_token);
854 $result = $this->dbh
->query("UPDATE ttrss_users
855 SET resetpass_token = '$resetpass_token_full'
856 WHERE login = '$login' AND email = '$email'");
858 //Pref_Users::resetUserPassword($id, false);
862 print "<p>"."Completed."."</p>";
864 print_error("User ID not found.");
867 print "<form method=\"GET\" action=\"index.php\">
868 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
872 print_error(__("Sorry, login and email combination not found."));
874 print "<form method=\"GET\" action=\"public.php\">
875 <input type=\"hidden\" name=\"op\" value=\"forgotpass\">
876 <input type=\"submit\" value=\"".__("Go back")."\">
890 function dbupdate() {
893 if (!SINGLE_USER_MODE
&& $_SESSION["access_level"] < 10) {
894 $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script.");
901 <title
>Database Updater
</title
>
902 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8"/>
903 <link rel
="stylesheet" type
="text/css" href
="css/utility.css"/>
904 <link rel
=\"shortcut icon\" type
=\"image
/png\" href
=\"images
/favicon
.png\"
>
905 <link rel
=\"icon\" type
=\"image
/png\" sizes
=\"72x72\" href
=\"images
/favicon
-72px
.png\"
>
907 <style type
="text/css">
908 span
.ok
{ color
: #009000; font-weight : bold; }
909 span
.err
{ color
: #ff0000; font-weight : bold; }
912 <script type
='text/javascript'>
913 function confirmOP() {
914 return confirm("Update the database?");
918 <div
class="floatingLogo"><img src
="images/logo_small.png"></div
>
920 <h1
><?php
echo __("Database Updater") ?
></h1
>
922 <div
class="content">
925 @$op = $_REQUEST["subop"];
926 $updater = new DbUpdater(Db
::get(), DB_TYPE
, SCHEMA_VERSION
);
928 if ($op == "performupdate") {
929 if ($updater->isUpdateRequired()) {
931 print "<h2>Performing updates</h2>";
933 print "<h3>Updating to schema version " . SCHEMA_VERSION
. "</h3>";
937 for ($i = $updater->getSchemaVersion() +
1; $i <= SCHEMA_VERSION
; $i++
) {
938 print "<li>Performing update up to version $i...";
940 $result = $updater->performUpdateTo($i);
943 print "<span class='err'>FAILED!</span></li></ul>";
945 print_warning("One of the updates failed. Either retry the process or perform updates manually.");
946 print "<p><form method=\"GET\" action=\"index.php\">
947 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
952 print "<span class='ok'>OK!</span></li>";
958 print_notice("Your Tiny Tiny RSS database is now updated to the latest version.");
960 print "<p><form method=\"GET\" action=\"index.php\">
961 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
965 print "<h2>Your database is up to date.</h2>";
967 print "<p><form method=\"GET\" action=\"index.php\">
968 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
972 if ($updater->isUpdateRequired()) {
974 print "<h2>Database update required</h2>";
977 printf("Your Tiny Tiny RSS database needs update to the latest version: %d to %d.",
978 $updater->getSchemaVersion(), SCHEMA_VERSION
);
981 print_warning("Please backup your database before proceeding.");
983 print "<form method='POST'>
984 <input type='hidden' name='subop' value='performupdate'>
985 <input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'>
990 print_notice("Tiny Tiny RSS database is up to date.");
992 print "<p><form method=\"GET\" action=\"index.php\">
993 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">