]>
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 $this->make_article_tag_uri($line['id'], $line['date_entered'])), true);
105 $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
106 $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
107 $tpl->setVariable('ARTICLE_EXCERPT', $line["content_preview"], true);
109 $content = sanitize($line["content"], false, $owner_uid,
113 $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" .
115 $tpl->setVariable('ARTICLE_NOTE', htmlspecialchars($line['note']), true);
118 $tpl->setVariable('ARTICLE_CONTENT', $content, true);
120 $tpl->setVariable('ARTICLE_UPDATED_ATOM',
121 date('c', strtotime($line["updated"])), true);
122 $tpl->setVariable('ARTICLE_UPDATED_RFC822',
123 date(DATE_RFC822
, strtotime($line["updated"])), true);
125 $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true);
127 $tpl->setVariable('ARTICLE_SOURCE_LINK', htmlspecialchars($line['site_url'] ?
$line["site_url"] : get_self_url_prefix()), true);
128 $tpl->setVariable('ARTICLE_SOURCE_TITLE', htmlspecialchars($line['feed_title'] ?
$line['feed_title'] : $feed_title), true);
130 $tags = get_article_tags($line["id"], $owner_uid);
132 foreach ($tags as $tag) {
133 $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true);
134 $tpl->addBlock('category');
137 $enclosures = get_article_enclosures($line["id"]);
139 foreach ($enclosures as $e) {
140 $type = htmlspecialchars($e['content_type']);
141 $url = htmlspecialchars($e['content_url']);
142 $length = $e['duration'] ?
$e['duration'] : 1;
144 $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
145 $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
146 $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
148 $tpl->addBlock('enclosure');
151 $tpl->addBlock('entry');
156 $tpl->addBlock('feed');
157 $tpl->generateOutputToString($tmp);
159 if (@!$_REQUEST["noxml"]) {
160 header("Content-Type: text/xml; charset=utf-8");
162 header("Content-Type: text/plain; charset=utf-8");
166 } else if ($format == 'json') {
170 $feed['title'] = $feed_title;
171 $feed['version'] = VERSION
;
172 $feed['feed_url'] = $feed_self_url;
174 if (PUBSUBHUBBUB_HUB
&& $feed == -2) {
175 $feed['hub_url'] = PUBSUBHUBBUB_HUB
;
178 $feed['self_url'] = get_self_url_prefix();
180 $feed['articles'] = array();
182 while ($line = $this->dbh
->fetch_assoc($result)) {
183 $line["content_preview"] = truncate_string(strip_tags($line["content_preview"]), 100, '...');
184 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_QUERY_HEADLINES
) as $p) {
185 $line = $p->hook_query_headlines($line, 100);
189 $article['id'] = $line['link'];
190 $article['link'] = $line['link'];
191 $article['title'] = $line['title'];
192 $article['excerpt'] = $line["content_preview"];
193 $article['content'] = sanitize($line["content"], false, $owner_uid);
194 $article['updated'] = date('c', strtotime($line["updated"]));
196 if ($line['note']) $article['note'] = $line['note'];
197 if ($article['author']) $article['author'] = $line['author'];
199 $tags = get_article_tags($line["id"], $owner_uid);
201 if (count($tags) > 0) {
202 $article['tags'] = array();
204 foreach ($tags as $tag) {
205 array_push($article['tags'], $tag);
209 $enclosures = get_article_enclosures($line["id"]);
211 if (count($enclosures) > 0) {
212 $article['enclosures'] = array();
214 foreach ($enclosures as $e) {
215 $type = $e['content_type'];
216 $url = $e['content_url'];
217 $length = $e['duration'];
219 array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length));
223 array_push($feed['articles'], $article);
226 header("Content-Type: text/json; charset=utf-8");
227 print json_encode($feed);
230 header("Content-Type: text/plain; charset=utf-8");
231 print json_encode(array("error" => array("message" => "Unknown format")));
235 function getUnread() {
236 $login = $this->dbh
->escape_string($_REQUEST["login"]);
237 $fresh = $_REQUEST["fresh"] == "1";
239 $result = $this->dbh
->query("SELECT id FROM ttrss_users WHERE login = '$login'");
241 if ($this->dbh
->num_rows($result) == 1) {
242 $uid = $this->dbh
->fetch_result($result, 0, "id");
244 print getGlobalUnread($uid);
248 print getFeedArticles(-3, false, true, $uid);
252 print "-1;User not found";
257 function getProfiles() {
258 $login = $this->dbh
->escape_string($_REQUEST["login"]);
260 $result = $this->dbh
->query("SELECT ttrss_settings_profiles.* FROM ttrss_settings_profiles,ttrss_users
261 WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = '$login' ORDER BY title");
263 print "<select dojoType='dijit.form.Select' style='width : 220px; margin : 0px' name='profile'>";
265 print "<option value='0'>" . __("Default profile") . "</option>";
267 while ($line = $this->dbh
->fetch_assoc($result)) {
269 $title = $line["title"];
271 print "<option value='$id'>$title</option>";
278 $mode = $this->dbh
->escape_string($_REQUEST['hub_mode']);
279 if (!$mode) $mode = $this->dbh
->escape_string($_REQUEST['hub.mode']);
281 $feed_id = (int) $this->dbh
->escape_string($_REQUEST['id']);
282 $feed_url = $this->dbh
->escape_string($_REQUEST['hub_topic']);
284 if (!$feed_url) $feed_url = $this->dbh
->escape_string($_REQUEST['hub.topic']);
286 if (!PUBSUBHUBBUB_ENABLED
) {
287 header('HTTP/1.0 404 Not Found');
288 echo "404 Not found (Disabled by server)";
292 // TODO: implement hub_verifytoken checking
293 // TODO: store requested rel=self or whatever for verification
294 // (may be different from stored feed url) e.g. http://url/ or http://url
296 $result = $this->dbh
->query("SELECT feed_url FROM ttrss_feeds
297 WHERE id = '$feed_id'");
299 if ($this->dbh
->num_rows($result) != 0) {
301 $check_feed_url = $this->dbh
->fetch_result($result, 0, "feed_url");
303 // ignore url checking for the time being
304 if ($check_feed_url && (true ||
$check_feed_url == $feed_url ||
!$feed_url)) {
305 if ($mode == "subscribe") {
307 $this->dbh
->query("UPDATE ttrss_feeds SET pubsub_state = 2
308 WHERE id = '$feed_id'");
310 print $_REQUEST['hub_challenge'];
313 } else if ($mode == "unsubscribe") {
315 $this->dbh
->query("UPDATE ttrss_feeds SET pubsub_state = 0
316 WHERE id = '$feed_id'");
318 print $_REQUEST['hub_challenge'];
323 // Received update ping, schedule feed update.
324 //update_rss_feed($feed_id, true, true);
326 $this->dbh
->query("UPDATE ttrss_feeds SET
327 last_update_started = '1970-01-01',
328 last_updated = '1970-01-01' WHERE id = '$feed_id'");
332 header('HTTP/1.0 404 Not Found');
333 echo "404 Not found (URL check failed)";
336 header('HTTP/1.0 404 Not Found');
337 echo "404 Not found (Feed not found)";
344 header("Location: index.php");
348 $uuid = $this->dbh
->escape_string($_REQUEST["key"]);
350 $result = $this->dbh
->query("SELECT ref_id, owner_uid FROM ttrss_user_entries WHERE
353 if ($this->dbh
->num_rows($result) != 0) {
354 header("Content-Type: text/html");
356 $id = $this->dbh
->fetch_result($result, 0, "ref_id");
357 $owner_uid = $this->dbh
->fetch_result($result, 0, "owner_uid");
359 $article = format_article($id, false, true, $owner_uid);
361 print_r($article['content']);
364 print "Article not found.";
370 $feed = $this->dbh
->escape_string($_REQUEST["id"]);
371 $key = $this->dbh
->escape_string($_REQUEST["key"]);
372 $is_cat = sql_bool_to_bool($_REQUEST["is_cat"]);
373 $limit = (int)$this->dbh
->escape_string($_REQUEST["limit"]);
374 $offset = (int)$this->dbh
->escape_string($_REQUEST["offset"]);
376 $search = $this->dbh
->escape_string($_REQUEST["q"]);
377 $search_mode = $this->dbh
->escape_string($_REQUEST["smode"]);
378 $view_mode = $this->dbh
->escape_string($_REQUEST["view-mode"]);
379 $order = $this->dbh
->escape_string($_REQUEST["order"]);
380 $start_ts = $this->dbh
->escape_string($_REQUEST["ts"]);
382 $format = $this->dbh
->escape_string($_REQUEST['format']);
383 $orig_guid = sql_bool_to_bool($_REQUEST["orig_guid"]);
385 if (!$format) $format = 'atom';
387 if (SINGLE_USER_MODE
) {
388 authenticate_user("admin", null);
394 $result = $this->dbh
->query("SELECT owner_uid FROM
395 ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'");
397 if ($this->dbh
->num_rows($result) == 1)
398 $owner_id = $this->dbh
->fetch_result($result, 0, "owner_uid");
402 $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit,
403 $offset, $search, $search_mode, $view_mode, $format, $order, $orig_guid, $start_ts);
405 header('HTTP/1.1 403 Forbidden');
409 function updateTask() {
410 PluginHost
::getInstance()->run_hooks(PluginHost
::HOOK_UPDATE_TASK
, "hook_update_task", false);
413 function housekeepingTask() {
414 PluginHost
::getInstance()->run_hooks(PluginHost
::HOOK_HOUSE_KEEPING
, "hook_house_keeping", false);
417 function globalUpdateFeeds() {
418 RPC
::updaterandomfeed_real($this->dbh
);
420 PluginHost
::getInstance()->run_hooks(PluginHost
::HOOK_UPDATE_TASK
, "hook_update_task", false);
423 function sharepopup() {
424 if (SINGLE_USER_MODE
) {
428 header('Content-Type: text/html; charset=utf-8');
429 print "<html><head><title>Tiny Tiny RSS</title>
430 <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">
431 <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">";
433 echo stylesheet_tag("css/utility.css");
434 echo stylesheet_tag("css/dijit.css");
435 echo javascript_tag("lib/prototype.js");
436 echo javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,controls");
437 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
438 </head><body id='sharepopup'>";
440 $action = $_REQUEST["action"];
442 if ($_SESSION["uid"]) {
444 if ($action == 'share') {
446 $title = $this->dbh
->escape_string(strip_tags($_REQUEST["title"]));
447 $url = $this->dbh
->escape_string(strip_tags($_REQUEST["url"]));
448 $content = $this->dbh
->escape_string(strip_tags($_REQUEST["content"]));
449 $labels = $this->dbh
->escape_string(strip_tags($_REQUEST["labels"]));
451 Article
::create_published_article($title, $url, $content, $labels,
454 print "<script type='text/javascript'>";
455 print "window.close();";
459 $title = htmlspecialchars($_REQUEST["title"]);
460 $url = htmlspecialchars($_REQUEST["url"]);
464 <table height
='100%' width
='100%'><tr
><td colspan
='2'>
465 <h1
><?php
echo __("Share with Tiny Tiny RSS") ?
></h1
>
468 <form id
='share_form' name
='share_form'>
470 <input type
="hidden" name
="op" value
="sharepopup">
471 <input type
="hidden" name
="action" value
="share">
473 <tr
><td align
='right'><?php
echo __("Title:") ?
></td
>
474 <td width
='80%'><input name
='title' value
="<?php echo $title ?>"></td
></tr
>
475 <tr
><td align
='right'><?php
echo __("URL:") ?
></td
>
476 <td
><input name
='url' value
="<?php echo $url ?>"></td
></tr
>
477 <tr
><td align
='right'><?php
echo __("Content:") ?
></td
>
478 <td
><input name
='content' value
=""></td
></tr
>
479 <tr
><td align
='right'><?php
echo __("Labels:") ?
></td
>
480 <td
><input name
='labels' id
="labels_value"
481 placeholder
='Alpha, Beta, Gamma' value
="">
485 <div
class="autocomplete" id
="labels_choices"
486 style
="display : block"></div
></td
></tr
>
488 <script type
='text/javascript'>document
.forms
[0].title
.focus();</script
>
490 <script type
='text/javascript'>
491 new Ajax
.Autocompleter('labels_value', 'labels_choices',
492 "backend.php?op=rpc&method=completeLabels",
493 { tokens
: ',', paramName
: "search" });
497 <div style
='float : right' class='insensitive-small'>
498 <?php
echo __("Shared article will appear in the Published feed.") ?
>
500 <button type
="submit"><?php
echo __('Share') ?
></button
>
501 <button onclick
="return window.close()"><?php
echo __('Cancel') ?
></button
>
513 $return = urlencode($_SERVER["REQUEST_URI"])
516 <form action
="public.php?return=<?php echo $return ?>"
517 method
="POST" id
="loginForm" name
="loginForm">
519 <input type
="hidden" name
="op" value
="login">
521 <table height
='100%' width
='100%'><tr
><td colspan
='2'>
522 <h1
><?php
echo __("Not logged in") ?
></h1
></td
></tr
>
524 <tr
><td align
="right"><?php
echo __("Login:") ?
></td
>
525 <td align
="right"><input name
="login"
526 value
="<?php echo $_SESSION["fake_login
"] ?>"></td
></tr
>
527 <tr
><td align
="right"><?php
echo __("Password:") ?
></td
>
528 <td align
="right"><input type
="password" name
="password"
529 value
="<?php echo $_SESSION["fake_password
"] ?>"></td
></tr
>
531 <button type
="submit">
532 <?php
echo __('Log in') ?
></button
>
534 <button onclick
="return window.close()">
535 <?php
echo __('Cancel') ?
></button
>
545 if (!SINGLE_USER_MODE
) {
547 $login = $this->dbh
->escape_string($_POST["login"]);
548 $password = $_POST["password"];
549 $remember_me = $_POST["remember_me"];
552 session_set_cookie_params(SESSION_COOKIE_LIFETIME
);
554 session_set_cookie_params(0);
559 if (authenticate_user($login, $password)) {
560 $_POST["password"] = "";
562 if (get_schema_version() >= 120) {
563 $_SESSION["language"] = get_pref("USER_LANGUAGE", $_SESSION["uid"]);
566 $_SESSION["ref_schema_version"] = get_schema_version(true);
567 $_SESSION["bw_limit"] = !!$_POST["bw_limit"];
569 if ($_POST["profile"]) {
571 $profile = $this->dbh
->escape_string($_POST["profile"]);
573 $result = $this->dbh
->query("SELECT id FROM ttrss_settings_profiles
574 WHERE id = '$profile' AND owner_uid = " . $_SESSION["uid"]);
576 if ($this->dbh
->num_rows($result) != 0) {
577 $_SESSION["profile"] = $profile;
581 $_SESSION["login_error_msg"] = __("Incorrect username or password");
582 user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING
);
585 if ($_REQUEST['return']) {
586 header("Location: " . $_REQUEST['return']);
588 header("Location: " . SELF_URL_PATH
);
593 /* function subtest() {
594 header("Content-type: text/plain; charset=utf-8");
596 $url = $_REQUEST["url"];
601 print_r(get_feeds_from_html($url, fetch_file_contents($url)));
605 function subscribe() {
606 if (SINGLE_USER_MODE
) {
610 if ($_SESSION["uid"]) {
612 $feed_url = $this->dbh
->escape_string(trim($_REQUEST["feed_url"]));
614 header('Content-Type: text/html; charset=utf-8');
617 <title>Tiny Tiny RSS</title>
618 <link rel=\"stylesheet\" type=\"text/css\" href=\"css/utility.css\">
619 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
620 <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">
621 <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">
625 <img class=\"floatingLogo\" src=\"images/logo_small.png\"
626 alt=\"Tiny Tiny RSS\"/>
627 <h1>".__("Subscribe to feed...")."</h1><div class='content'>";
629 $rc = subscribe_to_feed($feed_url);
631 switch ($rc['code']) {
633 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
636 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
639 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
642 print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
645 print_notice(__("Multiple feed URLs found."));
646 $feed_urls = $rc["feeds"];
649 print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
655 print "<form action=\"public.php\">";
656 print "<input type=\"hidden\" name=\"op\" value=\"subscribe\">";
658 print "<select name=\"feed_url\">";
660 foreach ($feed_urls as $url => $name) {
661 $url = htmlspecialchars($url);
662 $name = htmlspecialchars($name);
664 print "<option value=\"$url\">$name</option>";
667 print "<input type=\"submit\" value=\"".__("Subscribe to selected feed").
673 $tp_uri = get_self_url_prefix() . "/prefs.php";
674 $tt_uri = get_self_url_prefix();
676 if ($rc['code'] <= 2){
677 $result = $this->dbh
->query("SELECT id FROM ttrss_feeds WHERE
678 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
680 $feed_id = $this->dbh
->fetch_result($result, 0, "id");
687 print "<form method=\"GET\" style='display: inline'
689 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
690 <input type=\"hidden\" name=\"method\" value=\"editFeed\">
691 <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
692 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
696 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
697 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
700 print "</div></body></html>";
708 header("Content-Type: text/plain");
709 print error_json(13);
712 function forgotpass() {
715 @$hash = $_REQUEST["hash"];
717 header('Content-Type: text/html; charset=utf-8');
718 print "<html><head><title>Tiny Tiny RSS</title>
719 <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">
720 <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">";
722 echo stylesheet_tag("css/utility.css");
723 echo javascript_tag("lib/prototype.js");
725 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
726 </head><body id='forgotpass'>";
728 print '<div class="floatingLogo"><img src="images/logo_small.png"></div>';
729 print "<h1>".__("Password recovery")."</h1>";
730 print "<div class='content'>";
732 @$method = $_POST['method'];
735 $login = $_REQUEST["login"];
738 $result = $this->dbh
->query("SELECT id, resetpass_token FROM ttrss_users
739 WHERE login = '$login'");
741 if ($this->dbh
->num_rows($result) != 0) {
742 $id = $this->dbh
->fetch_result($result, 0, "id");
743 $resetpass_token_full = $this->dbh
->fetch_result($result, 0, "resetpass_token");
744 list($timestamp, $resetpass_token) = explode(":", $resetpass_token_full);
746 if ($timestamp && $resetpass_token &&
747 $timestamp >= time() - 15*60*60 &&
748 $resetpass_token == $hash) {
750 $result = $this->dbh
->query("UPDATE ttrss_users SET resetpass_token = NULL
753 Pref_Users
::resetUserPassword($id, true);
755 print "<p>"."Completed."."</p>";
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_error("Some of the information provided is missing or incorrect.");
767 print "<form method=\"GET\" action=\"index.php\">
768 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
771 } else if (!$method) {
772 print_notice(__("You will need to provide valid account name and email. A password reset link will be sent to your email address."));
774 print "<form method='POST' action='public.php'>";
775 print "<input type='hidden' name='method' value='do'>";
776 print "<input type='hidden' name='op' value='forgotpass'>";
779 print "<label>".__("Login:")."</label>";
780 print "<input type='text' name='login' value='' required>";
784 print "<label>".__("Email:")."</label>";
785 print "<input type='email' name='email' value='' required>";
789 print "<label>".__("How much is two plus two:")."</label>";
790 print "<input type='text' name='test' value='' required>";
794 print "<button type='submit'>".__("Reset password")."</button>";
797 } else if ($method == 'do') {
799 $login = $this->dbh
->escape_string($_POST["login"]);
800 $email = $this->dbh
->escape_string($_POST["email"]);
801 $test = $this->dbh
->escape_string($_POST["test"]);
803 if (($test != 4 && $test != 'four') ||
!$email ||
!$login) {
804 print_error(__('Some of the required form parameters are missing or incorrect.'));
806 print "<form method=\"GET\" action=\"public.php\">
807 <input type=\"hidden\" name=\"op\" value=\"forgotpass\">
808 <input type=\"submit\" value=\"".__("Go back")."\">
813 print_notice("Password reset instructions are being sent to your email address.");
815 $result = $this->dbh
->query("SELECT id FROM ttrss_users
816 WHERE login = '$login' AND email = '$email'");
818 if ($this->dbh
->num_rows($result) != 0) {
819 $id = $this->dbh
->fetch_result($result, 0, "id");
822 $resetpass_token = sha1(get_random_bytes(128));
823 $resetpass_link = get_self_url_prefix() . "/public.php?op=forgotpass&hash=" . $resetpass_token .
824 "&login=" . urlencode($login);
826 require_once 'classes/ttrssmailer.php';
827 require_once "lib/MiniTemplator.class.php";
829 $tpl = new MiniTemplator
;
831 $tpl->readTemplateFromFile("templates/resetpass_link_template.txt");
833 $tpl->setVariable('LOGIN', $login);
834 $tpl->setVariable('RESETPASS_LINK', $resetpass_link);
836 $tpl->addBlock('message');
840 $tpl->generateOutputToString($message);
842 $mail = new ttrssMailer();
844 $rc = $mail->quickMail($email, $login,
845 __("[tt-rss] Password reset request"),
848 if (!$rc) print_error($mail->ErrorInfo
);
850 $resetpass_token_full = $this->dbh
->escape_string(time() . ":" . $resetpass_token);
852 $result = $this->dbh
->query("UPDATE ttrss_users
853 SET resetpass_token = '$resetpass_token_full'
854 WHERE login = '$login' AND email = '$email'");
856 //Pref_Users::resetUserPassword($id, false);
860 print "<p>"."Completed."."</p>";
862 print_error("User ID not found.");
865 print "<form method=\"GET\" action=\"index.php\">
866 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
870 print_error(__("Sorry, login and email combination not found."));
872 print "<form method=\"GET\" action=\"public.php\">
873 <input type=\"hidden\" name=\"op\" value=\"forgotpass\">
874 <input type=\"submit\" value=\"".__("Go back")."\">
888 function dbupdate() {
891 if (!SINGLE_USER_MODE
&& $_SESSION["access_level"] < 10) {
892 $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script.");
899 <title
>Database Updater
</title
>
900 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8"/>
901 <link rel
="stylesheet" type
="text/css" href
="css/utility.css"/>
902 <link rel
=\"shortcut icon\" type
=\"image
/png\" href
=\"images
/favicon
.png\"
>
903 <link rel
=\"icon\" type
=\"image
/png\" sizes
=\"72x72\" href
=\"images
/favicon
-72px
.png\"
>
905 <style type
="text/css">
906 span
.ok
{ color
: #009000; font-weight : bold; }
907 span
.err
{ color
: #ff0000; font-weight : bold; }
910 <script type
='text/javascript'>
911 function confirmOP() {
912 return confirm("Update the database?");
916 <div
class="floatingLogo"><img src
="images/logo_small.png"></div
>
918 <h1
><?php
echo __("Database Updater") ?
></h1
>
920 <div
class="content">
923 @$op = $_REQUEST["subop"];
924 $updater = new DbUpdater(Db
::get(), DB_TYPE
, SCHEMA_VERSION
);
926 if ($op == "performupdate") {
927 if ($updater->isUpdateRequired()) {
929 print "<h2>Performing updates</h2>";
931 print "<h3>Updating to schema version " . SCHEMA_VERSION
. "</h3>";
935 for ($i = $updater->getSchemaVersion() +
1; $i <= SCHEMA_VERSION
; $i++
) {
936 print "<li>Performing update up to version $i...";
938 $result = $updater->performUpdateTo($i);
941 print "<span class='err'>FAILED!</span></li></ul>";
943 print_warning("One of the updates failed. Either retry the process or perform updates manually.");
944 print "<p><form method=\"GET\" action=\"index.php\">
945 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
950 print "<span class='ok'>OK!</span></li>";
956 print_notice("Your Tiny Tiny RSS database is now updated to the latest version.");
958 print "<p><form method=\"GET\" action=\"index.php\">
959 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
963 print "<h2>Your database is up to date.</h2>";
965 print "<p><form method=\"GET\" action=\"index.php\">
966 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
970 if ($updater->isUpdateRequired()) {
972 print "<h2>Database update required</h2>";
975 printf("Your Tiny Tiny RSS database needs update to the latest version: %d to %d.",
976 $updater->getSchemaVersion(), SCHEMA_VERSION
);
979 print_warning("Please backup your database before proceeding.");
981 print "<form method='POST'>
982 <input type='hidden' name='subop' value='performupdate'>
983 <input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'>
988 print_notice("Tiny Tiny RSS database is up to date.");
990 print "<p><form method=\"GET\" action=\"index.php\">
991 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
1004 function cached_image() {
1005 @$hash = basename($_GET['hash']);
1009 $filename = CACHE_DIR
. '/images/' . $hash . '.png';
1011 if (file_exists($filename)) {
1012 /* See if we can use X-Sendfile */
1014 if (function_exists('apache_get_modules') &&
1015 array_search('mod_xsendfile', apache_get_modules()))
1019 header("X-Sendfile: $filename");
1020 header("Content-type: application/octet-stream");
1021 header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
1023 header("Content-type: image/png");
1024 $stamp = gmdate("D, d M Y H:i:s", filemtime($filename)). " GMT";
1025 header("Last-Modified: $stamp", true);
1026 readfile($filename);
1029 header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
1030 echo "File not found.";
1035 private function make_article_tag_uri($id, $timestamp) {
1037 $timestamp = date("Y-m-d", strtotime($timestamp));
1039 return "tag:" . parse_url(get_self_url_prefix(), PHP_URL_HOST
) . ",$timestamp:/$id";