]>
git.wh0rd.org - tt-rss.git/blob - classes/handler/public.php
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) {
42 $qfh_ret = queryFeedHeadlines($feed,
43 1, $view_mode, $is_cat, $search, $search_mode,
44 $date_sort_field, $offset, $owner_uid,
45 false, 0, true, true, false, false, $start_ts);
47 $result = $qfh_ret[0];
49 if ($this->dbh
->num_rows($result) != 0) {
51 $ts = strtotime($this->dbh
->fetch_result($result, 0, $date_check_field));
53 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) &&
54 strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $ts) {
55 header('HTTP/1.0 304 Not Modified');
59 $last_modified = gmdate("D, d M Y H:i:s", $ts) . " GMT";
60 header("Last-Modified: $last_modified", true);
63 $qfh_ret = queryFeedHeadlines($feed,
64 $limit, $view_mode, $is_cat, $search, $search_mode,
65 $date_sort_field, $offset, $owner_uid,
66 false, 0, true, true, false, false, $start_ts);
69 $result = $qfh_ret[0];
70 $feed_title = htmlspecialchars($qfh_ret[1]);
71 $feed_site_url = $qfh_ret[2];
72 /* $last_error = $qfh_ret[3]; */
74 $feed_self_url = get_self_url_prefix() .
75 "/public.php?op=rss&id=$feed&key=" .
76 get_feed_access_key($feed, false, $owner_uid);
78 if (!$feed_site_url) $feed_site_url = get_self_url_prefix();
80 if ($format == 'atom') {
81 $tpl = new MiniTemplator
;
83 $tpl->readTemplateFromFile("templates/generated_feed.txt");
85 $tpl->setVariable('FEED_TITLE', $feed_title, true);
86 $tpl->setVariable('VERSION', VERSION
, true);
87 $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
89 if (PUBSUBHUBBUB_HUB
&& $feed == -2) {
90 $tpl->setVariable('HUB_URL', htmlspecialchars(PUBSUBHUBBUB_HUB
), true);
91 $tpl->addBlock('feed_hub');
94 $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
95 while ($line = $this->dbh
->fetch_assoc($result)) {
96 $line["content_preview"] = truncate_string(strip_tags($line["content"]), 100, '...');
98 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_QUERY_HEADLINES
) as $p) {
99 $line = $p->hook_query_headlines($line);
102 $tpl->setVariable('ARTICLE_ID',
103 htmlspecialchars($orig_guid ?
$line['link'] :
104 get_self_url_prefix() .
105 "/public.php?url=" . urlencode($line['link'])), true);
106 $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
107 $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
108 $tpl->setVariable('ARTICLE_EXCERPT', $line["content_preview"], true);
110 $content = sanitize($line["content"], false, $owner_uid,
114 $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" .
116 $tpl->setVariable('ARTICLE_NOTE', htmlspecialchars($line['note']), true);
119 $tpl->setVariable('ARTICLE_CONTENT', $content, true);
121 $tpl->setVariable('ARTICLE_UPDATED_ATOM',
122 date('c', strtotime($line["updated"])), true);
123 $tpl->setVariable('ARTICLE_UPDATED_RFC822',
124 date(DATE_RFC822
, strtotime($line["updated"])), true);
126 $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true);
128 $tpl->setVariable('ARTICLE_SOURCE_LINK', htmlspecialchars($line['site_url']), true);
129 $tpl->setVariable('ARTICLE_SOURCE_TITLE', htmlspecialchars($line['feed_title'] ?
$line['feed_title'] : $feed_title), true);
131 $tags = get_article_tags($line["id"], $owner_uid);
133 foreach ($tags as $tag) {
134 $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true);
135 $tpl->addBlock('category');
138 $enclosures = get_article_enclosures($line["id"]);
140 foreach ($enclosures as $e) {
141 $type = htmlspecialchars($e['content_type']);
142 $url = htmlspecialchars($e['content_url']);
143 $length = $e['duration'];
145 $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
146 $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
147 $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
149 $tpl->addBlock('enclosure');
152 $tpl->addBlock('entry');
157 $tpl->addBlock('feed');
158 $tpl->generateOutputToString($tmp);
160 if (@!$_REQUEST["noxml"]) {
161 header("Content-Type: text/xml; charset=utf-8");
163 header("Content-Type: text/plain; charset=utf-8");
167 } else if ($format == 'json') {
171 $feed['title'] = $feed_title;
172 $feed['version'] = VERSION
;
173 $feed['feed_url'] = $feed_self_url;
175 if (PUBSUBHUBBUB_HUB
&& $feed == -2) {
176 $feed['hub_url'] = PUBSUBHUBBUB_HUB
;
179 $feed['self_url'] = get_self_url_prefix();
181 $feed['articles'] = array();
183 while ($line = $this->dbh
->fetch_assoc($result)) {
184 $line["content_preview"] = truncate_string(strip_tags($line["content_preview"]), 100, '...');
185 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_QUERY_HEADLINES
) as $p) {
186 $line = $p->hook_query_headlines($line, 100);
190 $article['id'] = $line['link'];
191 $article['link'] = $line['link'];
192 $article['title'] = $line['title'];
193 $article['excerpt'] = $line["content_preview"];
194 $article['content'] = sanitize($line["content"], false, $owner_uid);
195 $article['updated'] = date('c', strtotime($line["updated"]));
197 if ($line['note']) $article['note'] = $line['note'];
198 if ($article['author']) $article['author'] = $line['author'];
200 $tags = get_article_tags($line["id"], $owner_uid);
202 if (count($tags) > 0) {
203 $article['tags'] = array();
205 foreach ($tags as $tag) {
206 array_push($article['tags'], $tag);
210 $enclosures = get_article_enclosures($line["id"]);
212 if (count($enclosures) > 0) {
213 $article['enclosures'] = array();
215 foreach ($enclosures as $e) {
216 $type = $e['content_type'];
217 $url = $e['content_url'];
218 $length = $e['duration'];
220 array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length));
224 array_push($feed['articles'], $article);
227 header("Content-Type: text/json; charset=utf-8");
228 print json_encode($feed);
231 header("Content-Type: text/plain; charset=utf-8");
232 print json_encode(array("error" => array("message" => "Unknown format")));
236 function getUnread() {
237 $login = $this->dbh
->escape_string($_REQUEST["login"]);
238 $fresh = $_REQUEST["fresh"] == "1";
240 $result = $this->dbh
->query("SELECT id FROM ttrss_users WHERE login = '$login'");
242 if ($this->dbh
->num_rows($result) == 1) {
243 $uid = $this->dbh
->fetch_result($result, 0, "id");
245 print getGlobalUnread($uid);
249 print getFeedArticles(-3, false, true, $uid);
253 print "-1;User not found";
258 function getProfiles() {
259 $login = $this->dbh
->escape_string($_REQUEST["login"]);
261 $result = $this->dbh
->query("SELECT ttrss_settings_profiles.* FROM ttrss_settings_profiles,ttrss_users
262 WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = '$login' ORDER BY title");
264 print "<select dojoType='dijit.form.Select' style='width : 220px; margin : 0px' name='profile'>";
266 print "<option value='0'>" . __("Default profile") . "</option>";
268 while ($line = $this->dbh
->fetch_assoc($result)) {
270 $title = $line["title"];
272 print "<option value='$id'>$title</option>";
279 $mode = $this->dbh
->escape_string($_REQUEST['hub_mode']);
280 if (!$mode) $mode = $this->dbh
->escape_string($_REQUEST['hub.mode']);
282 $feed_id = (int) $this->dbh
->escape_string($_REQUEST['id']);
283 $feed_url = $this->dbh
->escape_string($_REQUEST['hub_topic']);
285 if (!$feed_url) $feed_url = $this->dbh
->escape_string($_REQUEST['hub.topic']);
287 if (!PUBSUBHUBBUB_ENABLED
) {
288 header('HTTP/1.0 404 Not Found');
289 echo "404 Not found (Disabled by server)";
293 // TODO: implement hub_verifytoken checking
294 // TODO: store requested rel=self or whatever for verification
295 // (may be different from stored feed url) e.g. http://url/ or http://url
297 $result = $this->dbh
->query("SELECT feed_url FROM ttrss_feeds
298 WHERE id = '$feed_id'");
300 if ($this->dbh
->num_rows($result) != 0) {
302 $check_feed_url = $this->dbh
->fetch_result($result, 0, "feed_url");
304 // ignore url checking for the time being
305 if ($check_feed_url && (true ||
$check_feed_url == $feed_url ||
!$feed_url)) {
306 if ($mode == "subscribe") {
308 $this->dbh
->query("UPDATE ttrss_feeds SET pubsub_state = 2
309 WHERE id = '$feed_id'");
311 print $_REQUEST['hub_challenge'];
314 } else if ($mode == "unsubscribe") {
316 $this->dbh
->query("UPDATE ttrss_feeds SET pubsub_state = 0
317 WHERE id = '$feed_id'");
319 print $_REQUEST['hub_challenge'];
324 // Received update ping, schedule feed update.
325 //update_rss_feed($feed_id, true, true);
327 $this->dbh
->query("UPDATE ttrss_feeds SET
328 last_update_started = '1970-01-01',
329 last_updated = '1970-01-01' WHERE id = '$feed_id'");
333 header('HTTP/1.0 404 Not Found');
334 echo "404 Not found (URL check failed)";
337 header('HTTP/1.0 404 Not Found');
338 echo "404 Not found (Feed not found)";
345 header("Location: index.php");
349 $uuid = $this->dbh
->escape_string($_REQUEST["key"]);
351 $result = $this->dbh
->query("SELECT ref_id, owner_uid FROM ttrss_user_entries WHERE
354 if ($this->dbh
->num_rows($result) != 0) {
355 header("Content-Type: text/html");
357 $id = $this->dbh
->fetch_result($result, 0, "ref_id");
358 $owner_uid = $this->dbh
->fetch_result($result, 0, "owner_uid");
360 $article = format_article($id, false, true, $owner_uid);
362 print_r($article['content']);
365 print "Article not found.";
371 $feed = $this->dbh
->escape_string($_REQUEST["id"]);
372 $key = $this->dbh
->escape_string($_REQUEST["key"]);
373 $is_cat = sql_bool_to_bool($_REQUEST["is_cat"]);
374 $limit = (int)$this->dbh
->escape_string($_REQUEST["limit"]);
375 $offset = (int)$this->dbh
->escape_string($_REQUEST["offset"]);
377 $search = $this->dbh
->escape_string($_REQUEST["q"]);
378 $search_mode = $this->dbh
->escape_string($_REQUEST["smode"]);
379 $view_mode = $this->dbh
->escape_string($_REQUEST["view-mode"]);
380 $order = $this->dbh
->escape_string($_REQUEST["order"]);
381 $start_ts = $this->dbh
->escape_string($_REQUEST["ts"]);
383 $format = $this->dbh
->escape_string($_REQUEST['format']);
384 $orig_guid = sql_bool_to_bool($_REQUEST["orig_guid"]);
386 if (!$format) $format = 'atom';
388 if (SINGLE_USER_MODE
) {
389 authenticate_user("admin", null);
395 $result = $this->dbh
->query("SELECT owner_uid FROM
396 ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'");
398 if ($this->dbh
->num_rows($result) == 1)
399 $owner_id = $this->dbh
->fetch_result($result, 0, "owner_uid");
403 $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit,
404 $offset, $search, $search_mode, $view_mode, $format, $order, $orig_guid, $start_ts);
406 header('HTTP/1.1 403 Forbidden');
410 function updateTask() {
411 PluginHost
::getInstance()->run_hooks(PluginHost
::HOOK_UPDATE_TASK
, "hook_update_task", false);
414 function housekeepingTask() {
415 PluginHost
::getInstance()->run_hooks(PluginHost
::HOOK_HOUSE_KEEPING
, "hook_house_keeping", false);
418 function globalUpdateFeeds() {
419 RPC
::updaterandomfeed_real($this->dbh
);
421 PluginHost
::getInstance()->run_hooks(PluginHost
::HOOK_UPDATE_TASK
, "hook_update_task", false);
424 function sharepopup() {
425 if (SINGLE_USER_MODE
) {
429 header('Content-Type: text/html; charset=utf-8');
430 print "<html><head><title>Tiny Tiny RSS</title>
431 <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">
432 <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">";
434 echo stylesheet_tag("css/utility.css");
435 echo stylesheet_tag("css/dijit.css");
436 echo javascript_tag("lib/prototype.js");
437 echo javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,controls");
438 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
439 </head><body id='sharepopup'>";
441 $action = $_REQUEST["action"];
443 if ($_SESSION["uid"]) {
445 if ($action == 'share') {
447 $title = $this->dbh
->escape_string(strip_tags($_REQUEST["title"]));
448 $url = $this->dbh
->escape_string(strip_tags($_REQUEST["url"]));
449 $content = $this->dbh
->escape_string(strip_tags($_REQUEST["content"]));
450 $labels = $this->dbh
->escape_string(strip_tags($_REQUEST["labels"]));
452 Article
::create_published_article($title, $url, $content, $labels,
455 print "<script type='text/javascript'>";
456 print "window.close();";
460 $title = htmlspecialchars($_REQUEST["title"]);
461 $url = htmlspecialchars($_REQUEST["url"]);
465 <table height
='100%' width
='100%'><tr
><td colspan
='2'>
466 <h1
><?php
echo __("Share with Tiny Tiny RSS") ?
></h1
>
469 <form id
='share_form' name
='share_form'>
471 <input type
="hidden" name
="op" value
="sharepopup">
472 <input type
="hidden" name
="action" value
="share">
474 <tr
><td align
='right'><?php
echo __("Title:") ?
></td
>
475 <td width
='80%'><input name
='title' value
="<?php echo $title ?>"></td
></tr
>
476 <tr
><td align
='right'><?php
echo __("URL:") ?
></td
>
477 <td
><input name
='url' value
="<?php echo $url ?>"></td
></tr
>
478 <tr
><td align
='right'><?php
echo __("Content:") ?
></td
>
479 <td
><input name
='content' value
=""></td
></tr
>
480 <tr
><td align
='right'><?php
echo __("Labels:") ?
></td
>
481 <td
><input name
='labels' id
="labels_value"
482 placeholder
='Alpha, Beta, Gamma' value
="">
486 <div
class="autocomplete" id
="labels_choices"
487 style
="display : block"></div
></td
></tr
>
489 <script type
='text/javascript'>document
.forms
[0].title
.focus();</script
>
491 <script type
='text/javascript'>
492 new Ajax
.Autocompleter('labels_value', 'labels_choices',
493 "backend.php?op=rpc&method=completeLabels",
494 { tokens
: ',', paramName
: "search" });
498 <div style
='float : right' class='insensitive-small'>
499 <?php
echo __("Shared article will appear in the Published feed.") ?
>
501 <button type
="submit"><?php
echo __('Share') ?
></button
>
502 <button onclick
="return window.close()"><?php
echo __('Cancel') ?
></button
>
514 $return = urlencode($_SERVER["REQUEST_URI"])
517 <form action
="public.php?return=<?php echo $return ?>"
518 method
="POST" id
="loginForm" name
="loginForm">
520 <input type
="hidden" name
="op" value
="login">
522 <table height
='100%' width
='100%'><tr
><td colspan
='2'>
523 <h1
><?php
echo __("Not logged in") ?
></h1
></td
></tr
>
525 <tr
><td align
="right"><?php
echo __("Login:") ?
></td
>
526 <td align
="right"><input name
="login"
527 value
="<?php echo $_SESSION["fake_login
"] ?>"></td
></tr
>
528 <tr
><td align
="right"><?php
echo __("Password:") ?
></td
>
529 <td align
="right"><input type
="password" name
="password"
530 value
="<?php echo $_SESSION["fake_password
"] ?>"></td
></tr
>
532 <button type
="submit">
533 <?php
echo __('Log in') ?
></button
>
535 <button onclick
="return window.close()">
536 <?php
echo __('Cancel') ?
></button
>
546 if (!SINGLE_USER_MODE
) {
548 $login = $this->dbh
->escape_string($_POST["login"]);
549 $password = $_POST["password"];
550 $remember_me = $_POST["remember_me"];
553 session_set_cookie_params(SESSION_COOKIE_LIFETIME
);
555 session_set_cookie_params(0);
560 if (authenticate_user($login, $password)) {
561 $_POST["password"] = "";
563 if (get_schema_version() >= 120) {
564 $_SESSION["language"] = get_pref("USER_LANGUAGE", $_SESSION["uid"]);
567 $_SESSION["ref_schema_version"] = get_schema_version(true);
568 $_SESSION["bw_limit"] = !!$_POST["bw_limit"];
570 if ($_POST["profile"]) {
572 $profile = $this->dbh
->escape_string($_POST["profile"]);
574 $result = $this->dbh
->query("SELECT id FROM ttrss_settings_profiles
575 WHERE id = '$profile' AND owner_uid = " . $_SESSION["uid"]);
577 if ($this->dbh
->num_rows($result) != 0) {
578 $_SESSION["profile"] = $profile;
582 $_SESSION["login_error_msg"] = __("Incorrect username or password");
583 user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING
);
586 if ($_REQUEST['return']) {
587 header("Location: " . $_REQUEST['return']);
589 header("Location: " . SELF_URL_PATH
);
594 /* function subtest() {
595 header("Content-type: text/plain; charset=utf-8");
597 $url = $_REQUEST["url"];
602 print_r(get_feeds_from_html($url, fetch_file_contents($url)));
606 function subscribe() {
607 if (SINGLE_USER_MODE
) {
611 if ($_SESSION["uid"]) {
613 $feed_url = $this->dbh
->escape_string(trim($_REQUEST["feed_url"]));
615 header('Content-Type: text/html; charset=utf-8');
618 <title>Tiny Tiny RSS</title>
619 <link rel=\"stylesheet\" type=\"text/css\" href=\"css/utility.css\">
620 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
621 <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">
622 <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">
626 <img class=\"floatingLogo\" src=\"images/logo_small.png\"
627 alt=\"Tiny Tiny RSS\"/>
628 <h1>".__("Subscribe to feed...")."</h1><div class='content'>";
630 $rc = subscribe_to_feed($feed_url);
632 switch ($rc['code']) {
634 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
637 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
640 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
643 print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
646 print_notice(__("Multiple feed URLs found."));
647 $feed_urls = $rc["feeds"];
650 print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
656 print "<form action=\"public.php\">";
657 print "<input type=\"hidden\" name=\"op\" value=\"subscribe\">";
659 print "<select name=\"feed_url\">";
661 foreach ($feed_urls as $url => $name) {
662 $url = htmlspecialchars($url);
663 $name = htmlspecialchars($name);
665 print "<option value=\"$url\">$name</option>";
668 print "<input type=\"submit\" value=\"".__("Subscribe to selected feed").
674 $tp_uri = get_self_url_prefix() . "/prefs.php";
675 $tt_uri = get_self_url_prefix();
677 if ($rc['code'] <= 2){
678 $result = $this->dbh
->query("SELECT id FROM ttrss_feeds WHERE
679 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
681 $feed_id = $this->dbh
->fetch_result($result, 0, "id");
688 print "<form method=\"GET\" style='display: inline'
690 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
691 <input type=\"hidden\" name=\"method\" value=\"editFeed\">
692 <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
693 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
697 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
698 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
701 print "</div></body></html>";
709 header("Content-Type: text/plain");
710 print json_encode(array("error" => array("code" => 7)));
713 function forgotpass() {
716 @$hash = $_REQUEST["hash"];
718 header('Content-Type: text/html; charset=utf-8');
719 print "<html><head><title>Tiny Tiny RSS</title>
720 <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">
721 <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">";
723 echo stylesheet_tag("css/utility.css");
724 echo javascript_tag("lib/prototype.js");
726 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
727 </head><body id='forgotpass'>";
729 print '<div class="floatingLogo"><img src="images/logo_small.png"></div>';
730 print "<h1>".__("Password recovery")."</h1>";
731 print "<div class='content'>";
733 @$method = $_POST['method'];
736 $login = $_REQUEST["login"];
739 $result = $this->dbh
->query("SELECT id, resetpass_token FROM ttrss_users
740 WHERE login = '$login'");
742 if ($this->dbh
->num_rows($result) != 0) {
743 $id = $this->dbh
->fetch_result($result, 0, "id");
744 $resetpass_token_full = $this->dbh
->fetch_result($result, 0, "resetpass_token");
745 list($timestamp, $resetpass_token) = explode(":", $resetpass_token_full);
747 if ($timestamp && $resetpass_token &&
748 $timestamp >= time() - 15*60*60 &&
749 $resetpass_token == $hash) {
751 $result = $this->dbh
->query("UPDATE ttrss_users SET resetpass_token = NULL
754 Pref_Users
::resetUserPassword($id, true);
756 print "<p>"."Completed."."</p>";
759 print_error("Some of the information provided is missing or incorrect.");
762 print_error("Some of the information provided is missing or incorrect.");
765 print_error("Some of the information provided is missing or incorrect.");
768 print "<form method=\"GET\" action=\"index.php\">
769 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
772 } else if (!$method) {
773 print_notice(__("You will need to provide valid account name and email. A password reset link will be sent to your email address."));
775 print "<form method='POST' action='public.php'>";
776 print "<input type='hidden' name='method' value='do'>";
777 print "<input type='hidden' name='op' value='forgotpass'>";
780 print "<label>".__("Login:")."</label>";
781 print "<input type='text' name='login' value='' required>";
785 print "<label>".__("Email:")."</label>";
786 print "<input type='email' name='email' value='' required>";
790 print "<label>".__("How much is two plus two:")."</label>";
791 print "<input type='text' name='test' value='' required>";
795 print "<button type='submit'>".__("Reset password")."</button>";
798 } else if ($method == 'do') {
800 $login = $this->dbh
->escape_string($_POST["login"]);
801 $email = $this->dbh
->escape_string($_POST["email"]);
802 $test = $this->dbh
->escape_string($_POST["test"]);
804 if (($test != 4 && $test != 'four') ||
!$email ||
!$login) {
805 print_error(__('Some of the required form parameters are missing or incorrect.'));
807 print "<form method=\"GET\" action=\"public.php\">
808 <input type=\"hidden\" name=\"op\" value=\"forgotpass\">
809 <input type=\"submit\" value=\"".__("Go back")."\">
814 print_notice("Password reset instructions are being sent to your email address.");
816 $result = $this->dbh
->query("SELECT id FROM ttrss_users
817 WHERE login = '$login' AND email = '$email'");
819 if ($this->dbh
->num_rows($result) != 0) {
820 $id = $this->dbh
->fetch_result($result, 0, "id");
823 $resetpass_token = sha1(get_random_bytes(128));
824 $resetpass_link = get_self_url_prefix() . "/public.php?op=forgotpass&hash=" . $resetpass_token .
825 "&login=" . urlencode($login);
827 require_once 'classes/ttrssmailer.php';
828 require_once "lib/MiniTemplator.class.php";
830 $tpl = new MiniTemplator
;
832 $tpl->readTemplateFromFile("templates/resetpass_link_template.txt");
834 $tpl->setVariable('LOGIN', $login);
835 $tpl->setVariable('RESETPASS_LINK', $resetpass_link);
837 $tpl->addBlock('message');
841 $tpl->generateOutputToString($message);
843 $mail = new ttrssMailer();
845 $rc = $mail->quickMail($email, $login,
846 __("[tt-rss] Password reset request"),
849 if (!$rc) print_error($mail->ErrorInfo
);
851 $resetpass_token_full = $this->dbh
->escape_string(time() . ":" . $resetpass_token);
853 $result = $this->dbh
->query("UPDATE ttrss_users
854 SET resetpass_token = '$resetpass_token_full'
855 WHERE login = '$login' AND email = '$email'");
857 //Pref_Users::resetUserPassword($id, false);
861 print "<p>"."Completed."."</p>";
863 print_error("User ID not found.");
866 print "<form method=\"GET\" action=\"index.php\">
867 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
871 print_error(__("Sorry, login and email combination not found."));
873 print "<form method=\"GET\" action=\"public.php\">
874 <input type=\"hidden\" name=\"op\" value=\"forgotpass\">
875 <input type=\"submit\" value=\"".__("Go back")."\">
889 function dbupdate() {
892 if (!SINGLE_USER_MODE
&& $_SESSION["access_level"] < 10) {
893 $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script.");
900 <title
>Database Updater
</title
>
901 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8"/>
902 <link rel
="stylesheet" type
="text/css" href
="css/utility.css"/>
903 <link rel
=\"shortcut icon\" type
=\"image
/png\" href
=\"images
/favicon
.png\"
>
904 <link rel
=\"icon\" type
=\"image
/png\" sizes
=\"72x72\" href
=\"images
/favicon
-72px
.png\"
>
906 <style type
="text/css">
907 span
.ok
{ color
: #009000; font-weight : bold; }
908 span
.err
{ color
: #ff0000; font-weight : bold; }
911 <script type
='text/javascript'>
912 function confirmOP() {
913 return confirm("Update the database?");
917 <div
class="floatingLogo"><img src
="images/logo_small.png"></div
>
919 <h1
><?php
echo __("Database Updater") ?
></h1
>
921 <div
class="content">
924 @$op = $_REQUEST["subop"];
925 $updater = new DbUpdater(Db
::get(), DB_TYPE
, SCHEMA_VERSION
);
927 if ($op == "performupdate") {
928 if ($updater->isUpdateRequired()) {
930 print "<h2>Performing updates</h2>";
932 print "<h3>Updating to schema version " . SCHEMA_VERSION
. "</h3>";
936 for ($i = $updater->getSchemaVersion() +
1; $i <= SCHEMA_VERSION
; $i++
) {
937 print "<li>Performing update up to version $i...";
939 $result = $updater->performUpdateTo($i);
942 print "<span class='err'>FAILED!</span></li></ul>";
944 print_warning("One of the updates failed. Either retry the process or perform updates manually.");
945 print "<p><form method=\"GET\" action=\"index.php\">
946 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
951 print "<span class='ok'>OK!</span></li>";
957 print_notice("Your Tiny Tiny RSS database is now updated to the latest version.");
959 print "<p><form method=\"GET\" action=\"index.php\">
960 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
964 print "<h2>Your database is up to date.</h2>";
966 print "<p><form method=\"GET\" action=\"index.php\">
967 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
971 if ($updater->isUpdateRequired()) {
973 print "<h2>Database update required</h2>";
976 printf("Your Tiny Tiny RSS database needs update to the latest version: %d to %d.",
977 $updater->getSchemaVersion(), SCHEMA_VERSION
);
980 print_warning("Please backup your database before proceeding.");
982 print "<form method='POST'>
983 <input type='hidden' name='subop' value='performupdate'>
984 <input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'>
989 print_notice("Tiny Tiny RSS database is up to date.");
991 print "<p><form method=\"GET\" action=\"index.php\">
992 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
1005 function cached_image() {
1006 @$hash = basename($_GET['hash']);
1010 $filename = CACHE_DIR
. '/images/' . $hash . '.png';
1012 if (file_exists($filename)) {
1013 /* See if we can use X-Sendfile */
1015 if (function_exists('apache_get_modules') &&
1016 array_search('mod_xsendfile', apache_get_modules()))
1020 header("X-Sendfile: $filename");
1021 header("Content-type: application/octet-stream");
1022 header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
1024 header("Content-type: image/png");
1025 $stamp = gmdate("D, d M Y H:i:s", filemtime($filename)). " GMT";
1026 header("Last-Modified: $stamp", true);
1027 readfile($filename);
1030 header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
1031 echo "File not found.";