]>
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,
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 $qfh_ret = queryFeedHeadlines($feed,
41 1, $view_mode, $is_cat, $search, false,
42 $date_sort_field, $offset, $owner_uid,
43 false, 0, true, true, false, false, $start_ts);
45 $result = $qfh_ret[0];
47 if ($this->dbh
->num_rows($result) != 0) {
49 $ts = strtotime($this->dbh
->fetch_result($result, 0, $date_check_field));
51 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) &&
52 strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $ts) {
53 header('HTTP/1.0 304 Not Modified');
57 $last_modified = gmdate("D, d M Y H:i:s", $ts) . " GMT";
58 header("Last-Modified: $last_modified", true);
61 $qfh_ret = queryFeedHeadlines($feed,
62 $limit, $view_mode, $is_cat, $search, false,
63 $date_sort_field, $offset, $owner_uid,
64 false, 0, true, true, false, false, $start_ts);
67 $result = $qfh_ret[0];
68 $feed_title = htmlspecialchars($qfh_ret[1]);
69 $feed_site_url = $qfh_ret[2];
70 /* $last_error = $qfh_ret[3]; */
72 $feed_self_url = get_self_url_prefix() .
73 "/public.php?op=rss&id=$feed&key=" .
74 get_feed_access_key($feed, false, $owner_uid);
76 if (!$feed_site_url) $feed_site_url = get_self_url_prefix();
78 if ($format == 'atom') {
79 $tpl = new MiniTemplator
;
81 $tpl->readTemplateFromFile("templates/generated_feed.txt");
83 $tpl->setVariable('FEED_TITLE', $feed_title, true);
84 $tpl->setVariable('VERSION', VERSION
, true);
85 $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
87 if (PUBSUBHUBBUB_HUB
&& $feed == -2) {
88 $tpl->setVariable('HUB_URL', htmlspecialchars(PUBSUBHUBBUB_HUB
), true);
89 $tpl->addBlock('feed_hub');
92 $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
93 while ($line = $this->dbh
->fetch_assoc($result)) {
94 $line["content_preview"] = truncate_string(strip_tags($line["content"]), 100, '...');
96 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_QUERY_HEADLINES
) as $p) {
97 $line = $p->hook_query_headlines($line);
100 $tpl->setVariable('ARTICLE_ID',
101 htmlspecialchars($orig_guid ?
$line['link'] :
102 $this->make_article_tag_uri($line['id'], $line['date_entered'])), true);
103 $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
104 $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
105 $tpl->setVariable('ARTICLE_EXCERPT', $line["content_preview"], true);
107 $content = sanitize($line["content"], false, $owner_uid,
111 $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" .
113 $tpl->setVariable('ARTICLE_NOTE', htmlspecialchars($line['note']), true);
116 $tpl->setVariable('ARTICLE_CONTENT', $content, true);
118 $tpl->setVariable('ARTICLE_UPDATED_ATOM',
119 date('c', strtotime($line["updated"])), true);
120 $tpl->setVariable('ARTICLE_UPDATED_RFC822',
121 date(DATE_RFC822
, strtotime($line["updated"])), true);
123 $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true);
125 $tpl->setVariable('ARTICLE_SOURCE_LINK', htmlspecialchars($line['site_url'] ?
$line["site_url"] : get_self_url_prefix()), true);
126 $tpl->setVariable('ARTICLE_SOURCE_TITLE', htmlspecialchars($line['feed_title'] ?
$line['feed_title'] : $feed_title), true);
128 $tags = get_article_tags($line["id"], $owner_uid);
130 foreach ($tags as $tag) {
131 $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true);
132 $tpl->addBlock('category');
135 $enclosures = get_article_enclosures($line["id"]);
137 foreach ($enclosures as $e) {
138 $type = htmlspecialchars($e['content_type']);
139 $url = htmlspecialchars($e['content_url']);
140 $length = $e['duration'] ?
$e['duration'] : 1;
142 $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
143 $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
144 $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
146 $tpl->addBlock('enclosure');
149 $tpl->addBlock('entry');
154 $tpl->addBlock('feed');
155 $tpl->generateOutputToString($tmp);
157 if (@!$_REQUEST["noxml"]) {
158 header("Content-Type: text/xml; charset=utf-8");
160 header("Content-Type: text/plain; charset=utf-8");
164 } else if ($format == 'json') {
168 $feed['title'] = $feed_title;
169 $feed['version'] = VERSION
;
170 $feed['feed_url'] = $feed_self_url;
172 if (PUBSUBHUBBUB_HUB
&& $feed == -2) {
173 $feed['hub_url'] = PUBSUBHUBBUB_HUB
;
176 $feed['self_url'] = get_self_url_prefix();
178 $feed['articles'] = array();
180 while ($line = $this->dbh
->fetch_assoc($result)) {
181 $line["content_preview"] = truncate_string(strip_tags($line["content_preview"]), 100, '...');
182 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_QUERY_HEADLINES
) as $p) {
183 $line = $p->hook_query_headlines($line, 100);
187 $article['id'] = $line['link'];
188 $article['link'] = $line['link'];
189 $article['title'] = $line['title'];
190 $article['excerpt'] = $line["content_preview"];
191 $article['content'] = sanitize($line["content"], false, $owner_uid);
192 $article['updated'] = date('c', strtotime($line["updated"]));
194 if ($line['note']) $article['note'] = $line['note'];
195 if ($article['author']) $article['author'] = $line['author'];
197 $tags = get_article_tags($line["id"], $owner_uid);
199 if (count($tags) > 0) {
200 $article['tags'] = array();
202 foreach ($tags as $tag) {
203 array_push($article['tags'], $tag);
207 $enclosures = get_article_enclosures($line["id"]);
209 if (count($enclosures) > 0) {
210 $article['enclosures'] = array();
212 foreach ($enclosures as $e) {
213 $type = $e['content_type'];
214 $url = $e['content_url'];
215 $length = $e['duration'];
217 array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length));
221 array_push($feed['articles'], $article);
224 header("Content-Type: text/json; charset=utf-8");
225 print json_encode($feed);
228 header("Content-Type: text/plain; charset=utf-8");
229 print json_encode(array("error" => array("message" => "Unknown format")));
233 function getUnread() {
234 $login = $this->dbh
->escape_string($_REQUEST["login"]);
235 $fresh = $_REQUEST["fresh"] == "1";
237 $result = $this->dbh
->query("SELECT id FROM ttrss_users WHERE login = '$login'");
239 if ($this->dbh
->num_rows($result) == 1) {
240 $uid = $this->dbh
->fetch_result($result, 0, "id");
242 print getGlobalUnread($uid);
246 print getFeedArticles(-3, false, true, $uid);
250 print "-1;User not found";
255 function getProfiles() {
256 $login = $this->dbh
->escape_string($_REQUEST["login"]);
258 $result = $this->dbh
->query("SELECT ttrss_settings_profiles.* FROM ttrss_settings_profiles,ttrss_users
259 WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = '$login' ORDER BY title");
261 print "<select dojoType='dijit.form.Select' style='width : 220px; margin : 0px' name='profile'>";
263 print "<option value='0'>" . __("Default profile") . "</option>";
265 while ($line = $this->dbh
->fetch_assoc($result)) {
267 $title = $line["title"];
269 print "<option value='$id'>$title</option>";
276 $mode = $this->dbh
->escape_string($_REQUEST['hub_mode']);
277 if (!$mode) $mode = $this->dbh
->escape_string($_REQUEST['hub.mode']);
279 $feed_id = (int) $this->dbh
->escape_string($_REQUEST['id']);
280 $feed_url = $this->dbh
->escape_string($_REQUEST['hub_topic']);
282 if (!$feed_url) $feed_url = $this->dbh
->escape_string($_REQUEST['hub.topic']);
284 if (!PUBSUBHUBBUB_ENABLED
) {
285 header('HTTP/1.0 404 Not Found');
286 echo "404 Not found (Disabled by server)";
290 // TODO: implement hub_verifytoken checking
291 // TODO: store requested rel=self or whatever for verification
292 // (may be different from stored feed url) e.g. http://url/ or http://url
294 $result = $this->dbh
->query("SELECT feed_url FROM ttrss_feeds
295 WHERE id = '$feed_id'");
297 if ($this->dbh
->num_rows($result) != 0) {
299 $check_feed_url = $this->dbh
->fetch_result($result, 0, "feed_url");
301 // ignore url checking for the time being
302 if ($check_feed_url && (true ||
$check_feed_url == $feed_url ||
!$feed_url)) {
303 if ($mode == "subscribe") {
305 $this->dbh
->query("UPDATE ttrss_feeds SET pubsub_state = 2
306 WHERE id = '$feed_id'");
308 print $_REQUEST['hub_challenge'];
311 } else if ($mode == "unsubscribe") {
313 $this->dbh
->query("UPDATE ttrss_feeds SET pubsub_state = 0
314 WHERE id = '$feed_id'");
316 print $_REQUEST['hub_challenge'];
321 // Received update ping, schedule feed update.
322 //update_rss_feed($feed_id, true, true);
324 $this->dbh
->query("UPDATE ttrss_feeds SET
325 last_update_started = '1970-01-01',
326 last_updated = '1970-01-01' WHERE id = '$feed_id'");
330 header('HTTP/1.0 404 Not Found');
331 echo "404 Not found (URL check failed)";
334 header('HTTP/1.0 404 Not Found');
335 echo "404 Not found (Feed not found)";
342 header("Location: index.php");
346 $uuid = $this->dbh
->escape_string($_REQUEST["key"]);
348 $result = $this->dbh
->query("SELECT ref_id, owner_uid FROM ttrss_user_entries WHERE
351 if ($this->dbh
->num_rows($result) != 0) {
352 header("Content-Type: text/html");
354 $id = $this->dbh
->fetch_result($result, 0, "ref_id");
355 $owner_uid = $this->dbh
->fetch_result($result, 0, "owner_uid");
357 $article = format_article($id, false, true, $owner_uid);
359 print_r($article['content']);
362 print "Article not found.";
368 $feed = $this->dbh
->escape_string($_REQUEST["id"]);
369 $key = $this->dbh
->escape_string($_REQUEST["key"]);
370 $is_cat = sql_bool_to_bool($_REQUEST["is_cat"]);
371 $limit = (int)$this->dbh
->escape_string($_REQUEST["limit"]);
372 $offset = (int)$this->dbh
->escape_string($_REQUEST["offset"]);
374 $search = $this->dbh
->escape_string($_REQUEST["q"]);
375 $view_mode = $this->dbh
->escape_string($_REQUEST["view-mode"]);
376 $order = $this->dbh
->escape_string($_REQUEST["order"]);
377 $start_ts = $this->dbh
->escape_string($_REQUEST["ts"]);
379 $format = $this->dbh
->escape_string($_REQUEST['format']);
380 $orig_guid = sql_bool_to_bool($_REQUEST["orig_guid"]);
382 if (!$format) $format = 'atom';
384 if (SINGLE_USER_MODE
) {
385 authenticate_user("admin", null);
391 $result = $this->dbh
->query("SELECT owner_uid FROM
392 ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'");
394 if ($this->dbh
->num_rows($result) == 1)
395 $owner_id = $this->dbh
->fetch_result($result, 0, "owner_uid");
399 $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit,
400 $offset, $search, $view_mode, $format, $order, $orig_guid, $start_ts);
402 header('HTTP/1.1 403 Forbidden');
406 function updateTask() {
407 PluginHost
::getInstance()->run_hooks(PluginHost
::HOOK_UPDATE_TASK
, "hook_update_task", false);
410 function housekeepingTask() {
411 PluginHost
::getInstance()->run_hooks(PluginHost
::HOOK_HOUSE_KEEPING
, "hook_house_keeping", false);
414 function globalUpdateFeeds() {
415 RPC
::updaterandomfeed_real($this->dbh
);
417 PluginHost
::getInstance()->run_hooks(PluginHost
::HOOK_UPDATE_TASK
, "hook_update_task", false);
420 function sharepopup() {
421 if (SINGLE_USER_MODE
) {
425 header('Content-Type: text/html; charset=utf-8');
426 print "<html><head><title>Tiny Tiny RSS</title>
427 <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">
428 <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">";
430 echo stylesheet_tag("css/utility.css");
431 echo stylesheet_tag("css/dijit.css");
432 echo javascript_tag("lib/prototype.js");
433 echo javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,controls");
434 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
435 </head><body id='sharepopup'>";
437 $action = $_REQUEST["action"];
439 if ($_SESSION["uid"]) {
441 if ($action == 'share') {
443 $title = $this->dbh
->escape_string(strip_tags($_REQUEST["title"]));
444 $url = $this->dbh
->escape_string(strip_tags($_REQUEST["url"]));
445 $content = $this->dbh
->escape_string(strip_tags($_REQUEST["content"]));
446 $labels = $this->dbh
->escape_string(strip_tags($_REQUEST["labels"]));
448 Article
::create_published_article($title, $url, $content, $labels,
451 print "<script type='text/javascript'>";
452 print "window.close();";
456 $title = htmlspecialchars($_REQUEST["title"]);
457 $url = htmlspecialchars($_REQUEST["url"]);
461 <table height
='100%' width
='100%'><tr
><td colspan
='2'>
462 <h1
><?php
echo __("Share with Tiny Tiny RSS") ?
></h1
>
465 <form id
='share_form' name
='share_form'>
467 <input type
="hidden" name
="op" value
="sharepopup">
468 <input type
="hidden" name
="action" value
="share">
470 <tr
><td align
='right'><?php
echo __("Title:") ?
></td
>
471 <td width
='80%'><input name
='title' value
="<?php echo $title ?>"></td
></tr
>
472 <tr
><td align
='right'><?php
echo __("URL:") ?
></td
>
473 <td
><input name
='url' value
="<?php echo $url ?>"></td
></tr
>
474 <tr
><td align
='right'><?php
echo __("Content:") ?
></td
>
475 <td
><input name
='content' value
=""></td
></tr
>
476 <tr
><td align
='right'><?php
echo __("Labels:") ?
></td
>
477 <td
><input name
='labels' id
="labels_value"
478 placeholder
='Alpha, Beta, Gamma' value
="">
482 <div
class="autocomplete" id
="labels_choices"
483 style
="display : block"></div
></td
></tr
>
485 <script type
='text/javascript'>document
.forms
[0].title
.focus();</script
>
487 <script type
='text/javascript'>
488 new Ajax
.Autocompleter('labels_value', 'labels_choices',
489 "backend.php?op=rpc&method=completeLabels",
490 { tokens
: ',', paramName
: "search" });
494 <div style
='float : right' class='insensitive-small'>
495 <?php
echo __("Shared article will appear in the Published feed.") ?
>
497 <button type
="submit"><?php
echo __('Share') ?
></button
>
498 <button onclick
="return window.close()"><?php
echo __('Cancel') ?
></button
>
510 $return = urlencode($_SERVER["REQUEST_URI"])
513 <form action
="public.php?return=<?php echo $return ?>"
514 method
="POST" id
="loginForm" name
="loginForm">
516 <input type
="hidden" name
="op" value
="login">
518 <table height
='100%' width
='100%'><tr
><td colspan
='2'>
519 <h1
><?php
echo __("Not logged in") ?
></h1
></td
></tr
>
521 <tr
><td align
="right"><?php
echo __("Login:") ?
></td
>
522 <td align
="right"><input name
="login"
523 value
="<?php echo $_SESSION["fake_login
"] ?>"></td
></tr
>
524 <tr
><td align
="right"><?php
echo __("Password:") ?
></td
>
525 <td align
="right"><input type
="password" name
="password"
526 value
="<?php echo $_SESSION["fake_password
"] ?>"></td
></tr
>
528 <button type
="submit">
529 <?php
echo __('Log in') ?
></button
>
531 <button onclick
="return window.close()">
532 <?php
echo __('Cancel') ?
></button
>
542 if (!SINGLE_USER_MODE
) {
544 $login = $this->dbh
->escape_string($_POST["login"]);
545 $password = $_POST["password"];
546 $remember_me = $_POST["remember_me"];
549 session_set_cookie_params(SESSION_COOKIE_LIFETIME
);
551 session_set_cookie_params(0);
556 if (authenticate_user($login, $password)) {
557 $_POST["password"] = "";
559 if (get_schema_version() >= 120) {
560 $_SESSION["language"] = get_pref("USER_LANGUAGE", $_SESSION["uid"]);
563 $_SESSION["ref_schema_version"] = get_schema_version(true);
564 $_SESSION["bw_limit"] = !!$_POST["bw_limit"];
566 if ($_POST["profile"]) {
568 $profile = $this->dbh
->escape_string($_POST["profile"]);
570 $result = $this->dbh
->query("SELECT id FROM ttrss_settings_profiles
571 WHERE id = '$profile' AND owner_uid = " . $_SESSION["uid"]);
573 if ($this->dbh
->num_rows($result) != 0) {
574 $_SESSION["profile"] = $profile;
578 $_SESSION["login_error_msg"] = __("Incorrect username or password");
579 user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING
);
582 if ($_REQUEST['return']) {
583 header("Location: " . $_REQUEST['return']);
585 header("Location: " . SELF_URL_PATH
);
590 /* function subtest() {
591 header("Content-type: text/plain; charset=utf-8");
593 $url = $_REQUEST["url"];
598 print_r(get_feeds_from_html($url, fetch_file_contents($url)));
602 function subscribe() {
603 if (SINGLE_USER_MODE
) {
607 if ($_SESSION["uid"]) {
609 $feed_url = $this->dbh
->escape_string(trim($_REQUEST["feed_url"]));
611 header('Content-Type: text/html; charset=utf-8');
614 <title>Tiny Tiny RSS</title>
615 <link rel=\"stylesheet\" type=\"text/css\" href=\"css/utility.css\">
616 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
617 <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">
618 <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">
622 <img class=\"floatingLogo\" src=\"images/logo_small.png\"
623 alt=\"Tiny Tiny RSS\"/>
624 <h1>".__("Subscribe to feed...")."</h1><div class='content'>";
626 $rc = subscribe_to_feed($feed_url);
628 switch ($rc['code']) {
630 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
633 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
636 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
639 print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
642 print_notice(__("Multiple feed URLs found."));
643 $feed_urls = $rc["feeds"];
646 print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
652 print "<form action=\"public.php\">";
653 print "<input type=\"hidden\" name=\"op\" value=\"subscribe\">";
655 print "<select name=\"feed_url\">";
657 foreach ($feed_urls as $url => $name) {
658 $url = htmlspecialchars($url);
659 $name = htmlspecialchars($name);
661 print "<option value=\"$url\">$name</option>";
664 print "<input type=\"submit\" value=\"".__("Subscribe to selected feed").
670 $tp_uri = get_self_url_prefix() . "/prefs.php";
671 $tt_uri = get_self_url_prefix();
673 if ($rc['code'] <= 2){
674 $result = $this->dbh
->query("SELECT id FROM ttrss_feeds WHERE
675 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
677 $feed_id = $this->dbh
->fetch_result($result, 0, "id");
684 print "<form method=\"GET\" style='display: inline'
686 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
687 <input type=\"hidden\" name=\"method\" value=\"editFeed\">
688 <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
689 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
693 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
694 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
697 print "</div></body></html>";
705 header("Content-Type: text/plain");
706 print error_json(13);
709 function forgotpass() {
712 @$hash = $_REQUEST["hash"];
714 header('Content-Type: text/html; charset=utf-8');
715 print "<html><head><title>Tiny Tiny RSS</title>
716 <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">
717 <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">";
719 echo stylesheet_tag("css/utility.css");
720 echo javascript_tag("lib/prototype.js");
722 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
723 </head><body id='forgotpass'>";
725 print '<div class="floatingLogo"><img src="images/logo_small.png"></div>';
726 print "<h1>".__("Password recovery")."</h1>";
727 print "<div class='content'>";
729 @$method = $_POST['method'];
732 $login = $_REQUEST["login"];
735 $result = $this->dbh
->query("SELECT id, resetpass_token FROM ttrss_users
736 WHERE login = '$login'");
738 if ($this->dbh
->num_rows($result) != 0) {
739 $id = $this->dbh
->fetch_result($result, 0, "id");
740 $resetpass_token_full = $this->dbh
->fetch_result($result, 0, "resetpass_token");
741 list($timestamp, $resetpass_token) = explode(":", $resetpass_token_full);
743 if ($timestamp && $resetpass_token &&
744 $timestamp >= time() - 15*60*60 &&
745 $resetpass_token == $hash) {
747 $result = $this->dbh
->query("UPDATE ttrss_users SET resetpass_token = NULL
750 Pref_Users
::resetUserPassword($id, true);
752 print "<p>"."Completed."."</p>";
755 print_error("Some of the information provided is missing or incorrect.");
758 print_error("Some of the information provided is missing or incorrect.");
761 print_error("Some of the information provided is missing or incorrect.");
764 print "<form method=\"GET\" action=\"index.php\">
765 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
768 } else if (!$method) {
769 print_notice(__("You will need to provide valid account name and email. A password reset link will be sent to your email address."));
771 print "<form method='POST' action='public.php'>";
772 print "<input type='hidden' name='method' value='do'>";
773 print "<input type='hidden' name='op' value='forgotpass'>";
776 print "<label>".__("Login:")."</label>";
777 print "<input type='text' name='login' value='' required>";
781 print "<label>".__("Email:")."</label>";
782 print "<input type='email' name='email' value='' required>";
786 print "<label>".__("How much is two plus two:")."</label>";
787 print "<input type='text' name='test' value='' required>";
791 print "<button type='submit'>".__("Reset password")."</button>";
794 } else if ($method == 'do') {
796 $login = $this->dbh
->escape_string($_POST["login"]);
797 $email = $this->dbh
->escape_string($_POST["email"]);
798 $test = $this->dbh
->escape_string($_POST["test"]);
800 if (($test != 4 && $test != 'four') ||
!$email ||
!$login) {
801 print_error(__('Some of the required form parameters are missing or incorrect.'));
803 print "<form method=\"GET\" action=\"public.php\">
804 <input type=\"hidden\" name=\"op\" value=\"forgotpass\">
805 <input type=\"submit\" value=\"".__("Go back")."\">
810 print_notice("Password reset instructions are being sent to your email address.");
812 $result = $this->dbh
->query("SELECT id FROM ttrss_users
813 WHERE login = '$login' AND email = '$email'");
815 if ($this->dbh
->num_rows($result) != 0) {
816 $id = $this->dbh
->fetch_result($result, 0, "id");
819 $resetpass_token = sha1(get_random_bytes(128));
820 $resetpass_link = get_self_url_prefix() . "/public.php?op=forgotpass&hash=" . $resetpass_token .
821 "&login=" . urlencode($login);
823 require_once 'classes/ttrssmailer.php';
824 require_once "lib/MiniTemplator.class.php";
826 $tpl = new MiniTemplator
;
828 $tpl->readTemplateFromFile("templates/resetpass_link_template.txt");
830 $tpl->setVariable('LOGIN', $login);
831 $tpl->setVariable('RESETPASS_LINK', $resetpass_link);
833 $tpl->addBlock('message');
837 $tpl->generateOutputToString($message);
839 $mail = new ttrssMailer();
841 $rc = $mail->quickMail($email, $login,
842 __("[tt-rss] Password reset request"),
845 if (!$rc) print_error($mail->ErrorInfo
);
847 $resetpass_token_full = $this->dbh
->escape_string(time() . ":" . $resetpass_token);
849 $result = $this->dbh
->query("UPDATE ttrss_users
850 SET resetpass_token = '$resetpass_token_full'
851 WHERE login = '$login' AND email = '$email'");
853 //Pref_Users::resetUserPassword($id, false);
857 print "<p>"."Completed."."</p>";
859 print_error("User ID not found.");
862 print "<form method=\"GET\" action=\"index.php\">
863 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
867 print_error(__("Sorry, login and email combination not found."));
869 print "<form method=\"GET\" action=\"public.php\">
870 <input type=\"hidden\" name=\"op\" value=\"forgotpass\">
871 <input type=\"submit\" value=\"".__("Go back")."\">
885 function dbupdate() {
888 if (!SINGLE_USER_MODE
&& $_SESSION["access_level"] < 10) {
889 $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script.");
896 <title
>Database Updater
</title
>
897 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8"/>
898 <link rel
="stylesheet" type
="text/css" href
="css/utility.css"/>
899 <link rel
=\"shortcut icon\" type
=\"image
/png\" href
=\"images
/favicon
.png\"
>
900 <link rel
=\"icon\" type
=\"image
/png\" sizes
=\"72x72\" href
=\"images
/favicon
-72px
.png\"
>
902 <style type
="text/css">
903 span
.ok
{ color
: #009000; font-weight : bold; }
904 span
.err
{ color
: #ff0000; font-weight : bold; }
907 <script type
='text/javascript'>
908 function confirmOP() {
909 return confirm("Update the database?");
913 <div
class="floatingLogo"><img src
="images/logo_small.png"></div
>
915 <h1
><?php
echo __("Database Updater") ?
></h1
>
917 <div
class="content">
920 @$op = $_REQUEST["subop"];
921 $updater = new DbUpdater(Db
::get(), DB_TYPE
, SCHEMA_VERSION
);
923 if ($op == "performupdate") {
924 if ($updater->isUpdateRequired()) {
926 print "<h2>Performing updates</h2>";
928 print "<h3>Updating to schema version " . SCHEMA_VERSION
. "</h3>";
932 for ($i = $updater->getSchemaVersion() +
1; $i <= SCHEMA_VERSION
; $i++
) {
933 print "<li>Performing update up to version $i...";
935 $result = $updater->performUpdateTo($i);
938 print "<span class='err'>FAILED!</span></li></ul>";
940 print_warning("One of the updates failed. Either retry the process or perform updates manually.");
941 print "<p><form method=\"GET\" action=\"index.php\">
942 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
947 print "<span class='ok'>OK!</span></li>";
953 print_notice("Your Tiny Tiny RSS database is now updated to the latest version.");
955 print "<p><form method=\"GET\" action=\"index.php\">
956 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
960 print "<h2>Your database is up to date.</h2>";
962 print "<p><form method=\"GET\" action=\"index.php\">
963 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
967 if ($updater->isUpdateRequired()) {
969 print "<h2>Database update required</h2>";
972 printf("Your Tiny Tiny RSS database needs update to the latest version: %d to %d.",
973 $updater->getSchemaVersion(), SCHEMA_VERSION
);
976 print_warning("Please backup your database before proceeding.");
978 print "<form method='POST'>
979 <input type='hidden' name='subop' value='performupdate'>
980 <input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'>
985 print_notice("Tiny Tiny RSS database is up to date.");
987 print "<p><form method=\"GET\" action=\"index.php\">
988 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
1001 function cached_image() {
1002 @$hash = basename($_GET['hash']);
1006 $filename = CACHE_DIR
. '/images/' . $hash . '.png';
1008 if (file_exists($filename)) {
1009 /* See if we can use X-Sendfile */
1011 if (function_exists('apache_get_modules') &&
1012 array_search('mod_xsendfile', apache_get_modules()))
1016 header("X-Sendfile: $filename");
1017 header("Content-type: application/octet-stream");
1018 header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
1020 header("Content-type: image/png");
1021 $stamp = gmdate("D, d M Y H:i:s", filemtime($filename)). " GMT";
1022 header("Last-Modified: $stamp", true);
1023 readfile($filename);
1026 header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
1027 echo "File not found.";
1032 private function make_article_tag_uri($id, $timestamp) {
1034 $timestamp = date("Y-m-d", strtotime($timestamp));
1036 return "tag:" . parse_url(get_self_url_prefix(), PHP_URL_HOST
) . ",$timestamp:/$id";