]>
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 //function queryFeedHeadlines($feed,
46 // $limit, $view_mode, $cat_view, $search, $search_mode,
47 // $override_order = false, $offset = 0, $owner_uid = 0,
48 // $filter = false, $since_id = 0, $include_children = false, $ignore_vfeed_group = false, $override_strategy = false, $override_vfeed = false, $start_ts = false, $check_top_id = false) {
51 "owner_uid" => $owner_uid,
54 "view_mode" => $view_mode,
55 "cat_view" => $is_cat,
57 "override_order" => $date_sort_field,
58 "include_children" => true,
59 "ignore_vfeed_group" => true,
61 "start_ts" => $start_ts
64 $qfh_ret = queryFeedHeadlines($params);
66 $result = $qfh_ret[0];
68 if ($this->dbh
->num_rows($result) != 0) {
70 $ts = strtotime($this->dbh
->fetch_result($result, 0, $date_check_field));
72 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) &&
73 strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $ts) {
74 header('HTTP/1.0 304 Not Modified');
78 $last_modified = gmdate("D, d M Y H:i:s", $ts) . " GMT";
79 header("Last-Modified: $last_modified", true);
82 /*$qfh_ret = queryFeedHeadlines($feed,
83 $limit, $view_mode, $is_cat, $search, false,
84 $date_sort_field, $offset, $owner_uid,
85 false, 0, true, true, false, false, $start_ts);*/
88 "owner_uid" => $owner_uid,
91 "view_mode" => $view_mode,
92 "cat_view" => $is_cat,
94 "override_order" => $date_sort_field,
95 "include_children" => true,
96 "ignore_vfeed_group" => true,
98 "start_ts" => $start_ts
101 $qfh_ret = queryFeedHeadlines($params);
103 $result = $qfh_ret[0];
104 $feed_title = htmlspecialchars($qfh_ret[1]);
105 $feed_site_url = $qfh_ret[2];
106 /* $last_error = $qfh_ret[3]; */
108 $feed_self_url = get_self_url_prefix() .
109 "/public.php?op=rss&id=$feed&key=" .
110 get_feed_access_key($feed, false, $owner_uid);
112 if (!$feed_site_url) $feed_site_url = get_self_url_prefix();
114 if ($format == 'atom') {
115 $tpl = new MiniTemplator
;
117 $tpl->readTemplateFromFile("templates/generated_feed.txt");
119 $tpl->setVariable('FEED_TITLE', $feed_title, true);
120 $tpl->setVariable('VERSION', VERSION
, true);
121 $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
123 if (PUBSUBHUBBUB_HUB
&& $feed == -2) {
124 $tpl->setVariable('HUB_URL', htmlspecialchars(PUBSUBHUBBUB_HUB
), true);
125 $tpl->addBlock('feed_hub');
128 $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
129 while ($line = $this->dbh
->fetch_assoc($result)) {
130 $line["content_preview"] = truncate_string(strip_tags($line["content"]), 100, '...');
132 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_QUERY_HEADLINES
) as $p) {
133 $line = $p->hook_query_headlines($line);
136 $tpl->setVariable('ARTICLE_ID',
137 htmlspecialchars($orig_guid ?
$line['link'] :
138 $this->make_article_tag_uri($line['id'], $line['date_entered'])), true);
139 $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
140 $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
141 $tpl->setVariable('ARTICLE_EXCERPT', $line["content_preview"], true);
143 $content = sanitize($line["content"], false, $owner_uid,
147 $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" .
149 $tpl->setVariable('ARTICLE_NOTE', htmlspecialchars($line['note']), true);
152 $tpl->setVariable('ARTICLE_CONTENT', $content, true);
154 $tpl->setVariable('ARTICLE_UPDATED_ATOM',
155 date('c', strtotime($line["updated"])), true);
156 $tpl->setVariable('ARTICLE_UPDATED_RFC822',
157 date(DATE_RFC822
, strtotime($line["updated"])), true);
159 $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true);
161 $tpl->setVariable('ARTICLE_SOURCE_LINK', htmlspecialchars($line['site_url'] ?
$line["site_url"] : get_self_url_prefix()), true);
162 $tpl->setVariable('ARTICLE_SOURCE_TITLE', htmlspecialchars($line['feed_title'] ?
$line['feed_title'] : $feed_title), true);
164 $tags = get_article_tags($line["id"], $owner_uid);
166 foreach ($tags as $tag) {
167 $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true);
168 $tpl->addBlock('category');
171 $enclosures = get_article_enclosures($line["id"]);
173 foreach ($enclosures as $e) {
174 $type = htmlspecialchars($e['content_type']);
175 $url = htmlspecialchars($e['content_url']);
176 $length = $e['duration'] ?
$e['duration'] : 1;
178 $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
179 $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
180 $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
182 $tpl->addBlock('enclosure');
185 $tpl->addBlock('entry');
190 $tpl->addBlock('feed');
191 $tpl->generateOutputToString($tmp);
193 if (@!$_REQUEST["noxml"]) {
194 header("Content-Type: text/xml; charset=utf-8");
196 header("Content-Type: text/plain; charset=utf-8");
200 } else if ($format == 'json') {
204 $feed['title'] = $feed_title;
205 $feed['version'] = VERSION
;
206 $feed['feed_url'] = $feed_self_url;
208 if (PUBSUBHUBBUB_HUB
&& $feed == -2) {
209 $feed['hub_url'] = PUBSUBHUBBUB_HUB
;
212 $feed['self_url'] = get_self_url_prefix();
214 $feed['articles'] = array();
216 while ($line = $this->dbh
->fetch_assoc($result)) {
217 $line["content_preview"] = truncate_string(strip_tags($line["content_preview"]), 100, '...');
218 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_QUERY_HEADLINES
) as $p) {
219 $line = $p->hook_query_headlines($line, 100);
223 $article['id'] = $line['link'];
224 $article['link'] = $line['link'];
225 $article['title'] = $line['title'];
226 $article['excerpt'] = $line["content_preview"];
227 $article['content'] = sanitize($line["content"], false, $owner_uid);
228 $article['updated'] = date('c', strtotime($line["updated"]));
230 if ($line['note']) $article['note'] = $line['note'];
231 if ($article['author']) $article['author'] = $line['author'];
233 $tags = get_article_tags($line["id"], $owner_uid);
235 if (count($tags) > 0) {
236 $article['tags'] = array();
238 foreach ($tags as $tag) {
239 array_push($article['tags'], $tag);
243 $enclosures = get_article_enclosures($line["id"]);
245 if (count($enclosures) > 0) {
246 $article['enclosures'] = array();
248 foreach ($enclosures as $e) {
249 $type = $e['content_type'];
250 $url = $e['content_url'];
251 $length = $e['duration'];
253 array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length));
257 array_push($feed['articles'], $article);
260 header("Content-Type: text/json; charset=utf-8");
261 print json_encode($feed);
264 header("Content-Type: text/plain; charset=utf-8");
265 print json_encode(array("error" => array("message" => "Unknown format")));
269 function getUnread() {
270 $login = $this->dbh
->escape_string($_REQUEST["login"]);
271 $fresh = $_REQUEST["fresh"] == "1";
273 $result = $this->dbh
->query("SELECT id FROM ttrss_users WHERE login = '$login'");
275 if ($this->dbh
->num_rows($result) == 1) {
276 $uid = $this->dbh
->fetch_result($result, 0, "id");
278 print getGlobalUnread($uid);
282 print getFeedArticles(-3, false, true, $uid);
286 print "-1;User not found";
291 function getProfiles() {
292 $login = $this->dbh
->escape_string($_REQUEST["login"]);
294 $result = $this->dbh
->query("SELECT ttrss_settings_profiles.* FROM ttrss_settings_profiles,ttrss_users
295 WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = '$login' ORDER BY title");
297 print "<select dojoType='dijit.form.Select' style='width : 220px; margin : 0px' name='profile'>";
299 print "<option value='0'>" . __("Default profile") . "</option>";
301 while ($line = $this->dbh
->fetch_assoc($result)) {
303 $title = $line["title"];
305 print "<option value='$id'>$title</option>";
312 $mode = $this->dbh
->escape_string($_REQUEST['hub_mode']);
313 if (!$mode) $mode = $this->dbh
->escape_string($_REQUEST['hub.mode']);
315 $feed_id = (int) $this->dbh
->escape_string($_REQUEST['id']);
316 $feed_url = $this->dbh
->escape_string($_REQUEST['hub_topic']);
318 if (!$feed_url) $feed_url = $this->dbh
->escape_string($_REQUEST['hub.topic']);
320 if (!PUBSUBHUBBUB_ENABLED
) {
321 header('HTTP/1.0 404 Not Found');
322 echo "404 Not found (Disabled by server)";
326 // TODO: implement hub_verifytoken checking
327 // TODO: store requested rel=self or whatever for verification
328 // (may be different from stored feed url) e.g. http://url/ or http://url
330 $result = $this->dbh
->query("SELECT feed_url FROM ttrss_feeds
331 WHERE id = '$feed_id'");
333 if ($this->dbh
->num_rows($result) != 0) {
335 $check_feed_url = $this->dbh
->fetch_result($result, 0, "feed_url");
337 // ignore url checking for the time being
338 if ($check_feed_url && (true ||
$check_feed_url == $feed_url ||
!$feed_url)) {
339 if ($mode == "subscribe") {
341 $this->dbh
->query("UPDATE ttrss_feeds SET pubsub_state = 2
342 WHERE id = '$feed_id'");
344 print $_REQUEST['hub_challenge'];
347 } else if ($mode == "unsubscribe") {
349 $this->dbh
->query("UPDATE ttrss_feeds SET pubsub_state = 0
350 WHERE id = '$feed_id'");
352 print $_REQUEST['hub_challenge'];
357 // Received update ping, schedule feed update.
358 //update_rss_feed($feed_id, true, true);
360 $this->dbh
->query("UPDATE ttrss_feeds SET
361 last_update_started = '1970-01-01',
362 last_updated = '1970-01-01' WHERE id = '$feed_id'");
366 header('HTTP/1.0 404 Not Found');
367 echo "404 Not found (URL check failed)";
370 header('HTTP/1.0 404 Not Found');
371 echo "404 Not found (Feed not found)";
378 header("Location: index.php");
382 $uuid = $this->dbh
->escape_string($_REQUEST["key"]);
384 $result = $this->dbh
->query("SELECT ref_id, owner_uid FROM ttrss_user_entries WHERE
387 if ($this->dbh
->num_rows($result) != 0) {
388 header("Content-Type: text/html");
390 $id = $this->dbh
->fetch_result($result, 0, "ref_id");
391 $owner_uid = $this->dbh
->fetch_result($result, 0, "owner_uid");
393 $article = format_article($id, false, true, $owner_uid);
395 print_r($article['content']);
398 print "Article not found.";
404 $feed = $this->dbh
->escape_string($_REQUEST["id"]);
405 $key = $this->dbh
->escape_string($_REQUEST["key"]);
406 $is_cat = sql_bool_to_bool($_REQUEST["is_cat"]);
407 $limit = (int)$this->dbh
->escape_string($_REQUEST["limit"]);
408 $offset = (int)$this->dbh
->escape_string($_REQUEST["offset"]);
410 $search = $this->dbh
->escape_string($_REQUEST["q"]);
411 $view_mode = $this->dbh
->escape_string($_REQUEST["view-mode"]);
412 $order = $this->dbh
->escape_string($_REQUEST["order"]);
413 $start_ts = $this->dbh
->escape_string($_REQUEST["ts"]);
415 $format = $this->dbh
->escape_string($_REQUEST['format']);
416 $orig_guid = sql_bool_to_bool($_REQUEST["orig_guid"]);
418 if (!$format) $format = 'atom';
420 if (SINGLE_USER_MODE
) {
421 authenticate_user("admin", null);
427 $result = $this->dbh
->query("SELECT owner_uid FROM
428 ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'");
430 if ($this->dbh
->num_rows($result) == 1)
431 $owner_id = $this->dbh
->fetch_result($result, 0, "owner_uid");
435 $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit,
436 $offset, $search, $view_mode, $format, $order, $orig_guid, $start_ts);
438 header('HTTP/1.1 403 Forbidden');
442 function updateTask() {
443 PluginHost
::getInstance()->run_hooks(PluginHost
::HOOK_UPDATE_TASK
, "hook_update_task", false);
446 function housekeepingTask() {
447 PluginHost
::getInstance()->run_hooks(PluginHost
::HOOK_HOUSE_KEEPING
, "hook_house_keeping", false);
450 function globalUpdateFeeds() {
451 RPC
::updaterandomfeed_real($this->dbh
);
453 PluginHost
::getInstance()->run_hooks(PluginHost
::HOOK_UPDATE_TASK
, "hook_update_task", false);
456 function sharepopup() {
457 if (SINGLE_USER_MODE
) {
461 header('Content-Type: text/html; charset=utf-8');
462 print "<html><head><title>Tiny Tiny RSS</title>
463 <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">
464 <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">";
466 echo stylesheet_tag("css/utility.css");
467 echo stylesheet_tag("css/dijit.css");
468 echo javascript_tag("lib/prototype.js");
469 echo javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,controls");
470 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
471 </head><body id='sharepopup'>";
473 $action = $_REQUEST["action"];
475 if ($_SESSION["uid"]) {
477 if ($action == 'share') {
479 $title = $this->dbh
->escape_string(strip_tags($_REQUEST["title"]));
480 $url = $this->dbh
->escape_string(strip_tags($_REQUEST["url"]));
481 $content = $this->dbh
->escape_string(strip_tags($_REQUEST["content"]));
482 $labels = $this->dbh
->escape_string(strip_tags($_REQUEST["labels"]));
484 Article
::create_published_article($title, $url, $content, $labels,
487 print "<script type='text/javascript'>";
488 print "window.close();";
492 $title = htmlspecialchars($_REQUEST["title"]);
493 $url = htmlspecialchars($_REQUEST["url"]);
497 <table height
='100%' width
='100%'><tr
><td colspan
='2'>
498 <h1
><?php
echo __("Share with Tiny Tiny RSS") ?
></h1
>
501 <form id
='share_form' name
='share_form'>
503 <input type
="hidden" name
="op" value
="sharepopup">
504 <input type
="hidden" name
="action" value
="share">
506 <tr
><td align
='right'><?php
echo __("Title:") ?
></td
>
507 <td width
='80%'><input name
='title' value
="<?php echo $title ?>"></td
></tr
>
508 <tr
><td align
='right'><?php
echo __("URL:") ?
></td
>
509 <td
><input name
='url' value
="<?php echo $url ?>"></td
></tr
>
510 <tr
><td align
='right'><?php
echo __("Content:") ?
></td
>
511 <td
><input name
='content' value
=""></td
></tr
>
512 <tr
><td align
='right'><?php
echo __("Labels:") ?
></td
>
513 <td
><input name
='labels' id
="labels_value"
514 placeholder
='Alpha, Beta, Gamma' value
="">
518 <div
class="autocomplete" id
="labels_choices"
519 style
="display : block"></div
></td
></tr
>
521 <script type
='text/javascript'>document
.forms
[0].title
.focus();</script
>
523 <script type
='text/javascript'>
524 new Ajax
.Autocompleter('labels_value', 'labels_choices',
525 "backend.php?op=rpc&method=completeLabels",
526 { tokens
: ',', paramName
: "search" });
530 <div style
='float : right' class='insensitive-small'>
531 <?php
echo __("Shared article will appear in the Published feed.") ?
>
533 <button type
="submit"><?php
echo __('Share') ?
></button
>
534 <button onclick
="return window.close()"><?php
echo __('Cancel') ?
></button
>
546 $return = urlencode($_SERVER["REQUEST_URI"])
549 <form action
="public.php?return=<?php echo $return ?>"
550 method
="POST" id
="loginForm" name
="loginForm">
552 <input type
="hidden" name
="op" value
="login">
554 <table height
='100%' width
='100%'><tr
><td colspan
='2'>
555 <h1
><?php
echo __("Not logged in") ?
></h1
></td
></tr
>
557 <tr
><td align
="right"><?php
echo __("Login:") ?
></td
>
558 <td align
="right"><input name
="login"
559 value
="<?php echo $_SESSION["fake_login
"] ?>"></td
></tr
>
560 <tr
><td align
="right"><?php
echo __("Password:") ?
></td
>
561 <td align
="right"><input type
="password" name
="password"
562 value
="<?php echo $_SESSION["fake_password
"] ?>"></td
></tr
>
564 <button type
="submit">
565 <?php
echo __('Log in') ?
></button
>
567 <button onclick
="return window.close()">
568 <?php
echo __('Cancel') ?
></button
>
578 if (!SINGLE_USER_MODE
) {
580 $login = $this->dbh
->escape_string($_POST["login"]);
581 $password = $_POST["password"];
582 $remember_me = $_POST["remember_me"];
585 session_set_cookie_params(SESSION_COOKIE_LIFETIME
);
587 session_set_cookie_params(0);
592 if (authenticate_user($login, $password)) {
593 $_POST["password"] = "";
595 if (get_schema_version() >= 120) {
596 $_SESSION["language"] = get_pref("USER_LANGUAGE", $_SESSION["uid"]);
599 $_SESSION["ref_schema_version"] = get_schema_version(true);
600 $_SESSION["bw_limit"] = !!$_POST["bw_limit"];
602 if ($_POST["profile"]) {
604 $profile = $this->dbh
->escape_string($_POST["profile"]);
606 $result = $this->dbh
->query("SELECT id FROM ttrss_settings_profiles
607 WHERE id = '$profile' AND owner_uid = " . $_SESSION["uid"]);
609 if ($this->dbh
->num_rows($result) != 0) {
610 $_SESSION["profile"] = $profile;
614 $_SESSION["login_error_msg"] = __("Incorrect username or password");
615 user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING
);
618 if ($_REQUEST['return']) {
619 header("Location: " . $_REQUEST['return']);
621 header("Location: " . SELF_URL_PATH
);
626 /* function subtest() {
627 header("Content-type: text/plain; charset=utf-8");
629 $url = $_REQUEST["url"];
634 print_r(get_feeds_from_html($url, fetch_file_contents($url)));
638 function subscribe() {
639 if (SINGLE_USER_MODE
) {
643 if ($_SESSION["uid"]) {
645 $feed_url = $this->dbh
->escape_string(trim($_REQUEST["feed_url"]));
647 header('Content-Type: text/html; charset=utf-8');
650 <title>Tiny Tiny RSS</title>
651 <link rel=\"stylesheet\" type=\"text/css\" href=\"css/utility.css\">
652 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
653 <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">
654 <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">
658 <img class=\"floatingLogo\" src=\"images/logo_small.png\"
659 alt=\"Tiny Tiny RSS\"/>
660 <h1>".__("Subscribe to feed...")."</h1><div class='content'>";
662 $rc = subscribe_to_feed($feed_url);
664 switch ($rc['code']) {
666 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
669 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
672 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
675 print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
678 print_notice(__("Multiple feed URLs found."));
679 $feed_urls = $rc["feeds"];
682 print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
688 print "<form action=\"public.php\">";
689 print "<input type=\"hidden\" name=\"op\" value=\"subscribe\">";
691 print "<select name=\"feed_url\">";
693 foreach ($feed_urls as $url => $name) {
694 $url = htmlspecialchars($url);
695 $name = htmlspecialchars($name);
697 print "<option value=\"$url\">$name</option>";
700 print "<input type=\"submit\" value=\"".__("Subscribe to selected feed").
706 $tp_uri = get_self_url_prefix() . "/prefs.php";
707 $tt_uri = get_self_url_prefix();
709 if ($rc['code'] <= 2){
710 $result = $this->dbh
->query("SELECT id FROM ttrss_feeds WHERE
711 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
713 $feed_id = $this->dbh
->fetch_result($result, 0, "id");
720 print "<form method=\"GET\" style='display: inline'
722 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
723 <input type=\"hidden\" name=\"method\" value=\"editFeed\">
724 <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
725 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
729 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
730 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
733 print "</div></body></html>";
741 header("Content-Type: text/plain");
742 print error_json(13);
745 function forgotpass() {
748 @$hash = $_REQUEST["hash"];
750 header('Content-Type: text/html; charset=utf-8');
751 print "<html><head><title>Tiny Tiny RSS</title>
752 <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">
753 <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">";
755 echo stylesheet_tag("css/utility.css");
756 echo javascript_tag("lib/prototype.js");
758 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
759 </head><body id='forgotpass'>";
761 print '<div class="floatingLogo"><img src="images/logo_small.png"></div>';
762 print "<h1>".__("Password recovery")."</h1>";
763 print "<div class='content'>";
765 @$method = $_POST['method'];
768 $login = $_REQUEST["login"];
771 $result = $this->dbh
->query("SELECT id, resetpass_token FROM ttrss_users
772 WHERE login = '$login'");
774 if ($this->dbh
->num_rows($result) != 0) {
775 $id = $this->dbh
->fetch_result($result, 0, "id");
776 $resetpass_token_full = $this->dbh
->fetch_result($result, 0, "resetpass_token");
777 list($timestamp, $resetpass_token) = explode(":", $resetpass_token_full);
779 if ($timestamp && $resetpass_token &&
780 $timestamp >= time() - 15*60*60 &&
781 $resetpass_token == $hash) {
783 $result = $this->dbh
->query("UPDATE ttrss_users SET resetpass_token = NULL
786 Pref_Users
::resetUserPassword($id, true);
788 print "<p>"."Completed."."</p>";
791 print_error("Some of the information provided is missing or incorrect.");
794 print_error("Some of the information provided is missing or incorrect.");
797 print_error("Some of the information provided is missing or incorrect.");
800 print "<form method=\"GET\" action=\"index.php\">
801 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
804 } else if (!$method) {
805 print_notice(__("You will need to provide valid account name and email. A password reset link will be sent to your email address."));
807 print "<form method='POST' action='public.php'>";
808 print "<input type='hidden' name='method' value='do'>";
809 print "<input type='hidden' name='op' value='forgotpass'>";
812 print "<label>".__("Login:")."</label>";
813 print "<input type='text' name='login' value='' required>";
817 print "<label>".__("Email:")."</label>";
818 print "<input type='email' name='email' value='' required>";
822 print "<label>".__("How much is two plus two:")."</label>";
823 print "<input type='text' name='test' value='' required>";
827 print "<button type='submit'>".__("Reset password")."</button>";
830 } else if ($method == 'do') {
832 $login = $this->dbh
->escape_string($_POST["login"]);
833 $email = $this->dbh
->escape_string($_POST["email"]);
834 $test = $this->dbh
->escape_string($_POST["test"]);
836 if (($test != 4 && $test != 'four') ||
!$email ||
!$login) {
837 print_error(__('Some of the required form parameters are missing or incorrect.'));
839 print "<form method=\"GET\" action=\"public.php\">
840 <input type=\"hidden\" name=\"op\" value=\"forgotpass\">
841 <input type=\"submit\" value=\"".__("Go back")."\">
846 print_notice("Password reset instructions are being sent to your email address.");
848 $result = $this->dbh
->query("SELECT id FROM ttrss_users
849 WHERE login = '$login' AND email = '$email'");
851 if ($this->dbh
->num_rows($result) != 0) {
852 $id = $this->dbh
->fetch_result($result, 0, "id");
855 $resetpass_token = sha1(get_random_bytes(128));
856 $resetpass_link = get_self_url_prefix() . "/public.php?op=forgotpass&hash=" . $resetpass_token .
857 "&login=" . urlencode($login);
859 require_once 'classes/ttrssmailer.php';
860 require_once "lib/MiniTemplator.class.php";
862 $tpl = new MiniTemplator
;
864 $tpl->readTemplateFromFile("templates/resetpass_link_template.txt");
866 $tpl->setVariable('LOGIN', $login);
867 $tpl->setVariable('RESETPASS_LINK', $resetpass_link);
869 $tpl->addBlock('message');
873 $tpl->generateOutputToString($message);
875 $mail = new ttrssMailer();
877 $rc = $mail->quickMail($email, $login,
878 __("[tt-rss] Password reset request"),
881 if (!$rc) print_error($mail->ErrorInfo
);
883 $resetpass_token_full = $this->dbh
->escape_string(time() . ":" . $resetpass_token);
885 $result = $this->dbh
->query("UPDATE ttrss_users
886 SET resetpass_token = '$resetpass_token_full'
887 WHERE login = '$login' AND email = '$email'");
889 //Pref_Users::resetUserPassword($id, false);
893 print "<p>"."Completed."."</p>";
895 print_error("User ID not found.");
898 print "<form method=\"GET\" action=\"index.php\">
899 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
903 print_error(__("Sorry, login and email combination not found."));
905 print "<form method=\"GET\" action=\"public.php\">
906 <input type=\"hidden\" name=\"op\" value=\"forgotpass\">
907 <input type=\"submit\" value=\"".__("Go back")."\">
921 function dbupdate() {
924 if (!SINGLE_USER_MODE
&& $_SESSION["access_level"] < 10) {
925 $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script.");
932 <title
>Database Updater
</title
>
933 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8"/>
934 <link rel
="stylesheet" type
="text/css" href
="css/utility.css"/>
935 <link rel
=\"shortcut icon\" type
=\"image
/png\" href
=\"images
/favicon
.png\"
>
936 <link rel
=\"icon\" type
=\"image
/png\" sizes
=\"72x72\" href
=\"images
/favicon
-72px
.png\"
>
938 <style type
="text/css">
939 span
.ok
{ color
: #009000; font-weight : bold; }
940 span
.err
{ color
: #ff0000; font-weight : bold; }
943 <script type
='text/javascript'>
944 function confirmOP() {
945 return confirm("Update the database?");
949 <div
class="floatingLogo"><img src
="images/logo_small.png"></div
>
951 <h1
><?php
echo __("Database Updater") ?
></h1
>
953 <div
class="content">
956 @$op = $_REQUEST["subop"];
957 $updater = new DbUpdater(Db
::get(), DB_TYPE
, SCHEMA_VERSION
);
959 if ($op == "performupdate") {
960 if ($updater->isUpdateRequired()) {
962 print "<h2>Performing updates</h2>";
964 print "<h3>Updating to schema version " . SCHEMA_VERSION
. "</h3>";
968 for ($i = $updater->getSchemaVersion() +
1; $i <= SCHEMA_VERSION
; $i++
) {
969 print "<li>Performing update up to version $i...";
971 $result = $updater->performUpdateTo($i);
974 print "<span class='err'>FAILED!</span></li></ul>";
976 print_warning("One of the updates failed. Either retry the process or perform updates manually.");
977 print "<p><form method=\"GET\" action=\"index.php\">
978 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
983 print "<span class='ok'>OK!</span></li>";
989 print_notice("Your Tiny Tiny RSS database is now updated to the latest version.");
991 print "<p><form method=\"GET\" action=\"index.php\">
992 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
996 print "<h2>Your database is up to date.</h2>";
998 print "<p><form method=\"GET\" action=\"index.php\">
999 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
1003 if ($updater->isUpdateRequired()) {
1005 print "<h2>Database update required</h2>";
1008 printf("Your Tiny Tiny RSS database needs update to the latest version: %d to %d.",
1009 $updater->getSchemaVersion(), SCHEMA_VERSION
);
1012 print_warning("Please backup your database before proceeding.");
1014 print "<form method='POST'>
1015 <input type='hidden' name='subop' value='performupdate'>
1016 <input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'>
1021 print_notice("Tiny Tiny RSS database is up to date.");
1023 print "<p><form method=\"GET\" action=\"index.php\">
1024 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
1037 function cached_image() {
1038 @$hash = basename($_GET['hash']);
1042 $filename = CACHE_DIR
. '/images/' . $hash . '.png';
1044 if (file_exists($filename)) {
1045 /* See if we can use X-Sendfile */
1047 if (function_exists('apache_get_modules') &&
1048 array_search('mod_xsendfile', apache_get_modules()))
1052 header("X-Sendfile: $filename");
1053 header("Content-type: application/octet-stream");
1054 header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
1056 header("Content-type: image/png");
1057 $stamp = gmdate("D, d M Y H:i:s", filemtime($filename)). " GMT";
1058 header("Last-Modified: $stamp", true);
1059 readfile($filename);
1062 header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
1063 echo "File not found.";
1068 private function make_article_tag_uri($id, $timestamp) {
1070 $timestamp = date("Y-m-d", strtotime($timestamp));
1072 return "tag:" . parse_url(get_self_url_prefix(), PHP_URL_HOST
) . ",$timestamp:/$id";