]>
git.wh0rd.org - tt-rss.git/blob - classes/handler/public.php
ec0c0fc60f379f180897b60dca09470a2cf1a243
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";
41 "owner_uid" => $owner_uid,
44 "view_mode" => $view_mode,
45 "cat_view" => $is_cat,
47 "override_order" => $date_sort_field,
48 "include_children" => true,
49 "ignore_vfeed_group" => true,
51 "start_ts" => $start_ts
54 $qfh_ret = Feeds
::queryFeedHeadlines($params);
56 $result = $qfh_ret[0];
58 if ($this->dbh
->num_rows($result) != 0) {
60 $ts = strtotime($this->dbh
->fetch_result($result, 0, $date_check_field));
62 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) &&
63 strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $ts) {
64 header('HTTP/1.0 304 Not Modified');
68 $last_modified = gmdate("D, d M Y H:i:s", $ts) . " GMT";
69 header("Last-Modified: $last_modified", true);
73 "owner_uid" => $owner_uid,
76 "view_mode" => $view_mode,
77 "cat_view" => $is_cat,
79 "override_order" => $date_sort_field,
80 "include_children" => true,
81 "ignore_vfeed_group" => true,
83 "start_ts" => $start_ts
86 $qfh_ret = Feeds
::queryFeedHeadlines($params);
88 $result = $qfh_ret[0];
89 $feed_title = htmlspecialchars($qfh_ret[1]);
90 $feed_site_url = $qfh_ret[2];
91 /* $last_error = $qfh_ret[3]; */
93 $feed_self_url = get_self_url_prefix() .
94 "/public.php?op=rss&id=$feed&key=" .
95 get_feed_access_key($feed, false, $owner_uid);
97 if (!$feed_site_url) $feed_site_url = get_self_url_prefix();
99 if ($format == 'atom') {
100 $tpl = new MiniTemplator
;
102 $tpl->readTemplateFromFile("templates/generated_feed.txt");
104 $tpl->setVariable('FEED_TITLE', $feed_title, true);
105 $tpl->setVariable('VERSION', VERSION
, true);
106 $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
108 if (PUBSUBHUBBUB_HUB
&& $feed == -2) {
109 $tpl->setVariable('HUB_URL', htmlspecialchars(PUBSUBHUBBUB_HUB
), true);
110 $tpl->addBlock('feed_hub');
113 $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
114 while ($line = $this->dbh
->fetch_assoc($result)) {
116 $line["content_preview"] = sanitize(truncate_string(strip_tags($line["content"]), 100, '...'));
118 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_QUERY_HEADLINES
) as $p) {
119 $line = $p->hook_query_headlines($line);
122 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_ARTICLE_EXPORT_FEED
) as $p) {
123 $line = $p->hook_article_export_feed($line, $feed, $is_cat);
126 $tpl->setVariable('ARTICLE_ID',
127 htmlspecialchars($orig_guid ?
$line['link'] :
128 $this->make_article_tag_uri($line['id'], $line['date_entered'])), true);
129 $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
130 $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
131 $tpl->setVariable('ARTICLE_EXCERPT', $line["content_preview"], true);
133 $content = sanitize($line["content"], false, $owner_uid,
134 $feed_site_url, false, $line["id"]);
137 $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" .
139 $tpl->setVariable('ARTICLE_NOTE', htmlspecialchars($line['note']), true);
142 $tpl->setVariable('ARTICLE_CONTENT', $content, true);
144 $tpl->setVariable('ARTICLE_UPDATED_ATOM',
145 date('c', strtotime($line["updated"])), true);
146 $tpl->setVariable('ARTICLE_UPDATED_RFC822',
147 date(DATE_RFC822
, strtotime($line["updated"])), true);
149 $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true);
151 $tpl->setVariable('ARTICLE_SOURCE_LINK', htmlspecialchars($line['site_url'] ?
$line["site_url"] : get_self_url_prefix()), true);
152 $tpl->setVariable('ARTICLE_SOURCE_TITLE', htmlspecialchars($line['feed_title'] ?
$line['feed_title'] : $feed_title), true);
154 $tags = Article
::get_article_tags($line["id"], $owner_uid);
156 foreach ($tags as $tag) {
157 $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true);
158 $tpl->addBlock('category');
161 $enclosures = Article
::get_article_enclosures($line["id"]);
163 foreach ($enclosures as $e) {
164 $type = htmlspecialchars($e['content_type']);
165 $url = htmlspecialchars($e['content_url']);
166 $length = $e['duration'] ?
$e['duration'] : 1;
168 $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
169 $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
170 $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
172 $tpl->addBlock('enclosure');
175 $tpl->addBlock('entry');
180 $tpl->addBlock('feed');
181 $tpl->generateOutputToString($tmp);
183 if (@!$_REQUEST["noxml"]) {
184 header("Content-Type: text/xml; charset=utf-8");
186 header("Content-Type: text/plain; charset=utf-8");
190 } else if ($format == 'json') {
194 $feed['title'] = $feed_title;
195 $feed['version'] = VERSION
;
196 $feed['feed_url'] = $feed_self_url;
198 if (PUBSUBHUBBUB_HUB
&& $feed == -2) {
199 $feed['hub_url'] = PUBSUBHUBBUB_HUB
;
202 $feed['self_url'] = get_self_url_prefix();
204 $feed['articles'] = array();
206 while ($line = $this->dbh
->fetch_assoc($result)) {
208 $line["content_preview"] = sanitize(truncate_string(strip_tags($line["content_preview"]), 100, '...'));
210 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_QUERY_HEADLINES
) as $p) {
211 $line = $p->hook_query_headlines($line, 100);
214 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_ARTICLE_EXPORT_FEED
) as $p) {
215 $line = $p->hook_article_export_feed($line, $feed, $is_cat);
220 $article['id'] = $line['link'];
221 $article['link'] = $line['link'];
222 $article['title'] = $line['title'];
223 $article['excerpt'] = $line["content_preview"];
224 $article['content'] = sanitize($line["content"], false, $owner_uid, $feed_site_url, false, $line["id"]);
225 $article['updated'] = date('c', strtotime($line["updated"]));
227 if ($line['note']) $article['note'] = $line['note'];
228 if ($article['author']) $article['author'] = $line['author'];
230 $tags = get_article_tags($line["id"], $owner_uid);
232 if (count($tags) > 0) {
233 $article['tags'] = array();
235 foreach ($tags as $tag) {
236 array_push($article['tags'], $tag);
240 $enclosures = Article
::get_article_enclosures($line["id"]);
242 if (count($enclosures) > 0) {
243 $article['enclosures'] = array();
245 foreach ($enclosures as $e) {
246 $type = $e['content_type'];
247 $url = $e['content_url'];
248 $length = $e['duration'];
250 array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length));
254 array_push($feed['articles'], $article);
257 header("Content-Type: text/json; charset=utf-8");
258 print json_encode($feed);
261 header("Content-Type: text/plain; charset=utf-8");
262 print json_encode(array("error" => array("message" => "Unknown format")));
266 function getUnread() {
267 $login = $this->dbh
->escape_string($_REQUEST["login"]);
268 $fresh = $_REQUEST["fresh"] == "1";
270 $result = $this->dbh
->query("SELECT id FROM ttrss_users WHERE login = '$login'");
272 if ($this->dbh
->num_rows($result) == 1) {
273 $uid = $this->dbh
->fetch_result($result, 0, "id");
275 print Feeds
::getGlobalUnread($uid);
279 print Feeds
::getFeedArticles(-3, false, true, $uid);
283 print "-1;User not found";
288 function getProfiles() {
289 $login = $this->dbh
->escape_string($_REQUEST["login"]);
291 $result = $this->dbh
->query("SELECT ttrss_settings_profiles.* FROM ttrss_settings_profiles,ttrss_users
292 WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = '$login' ORDER BY title");
294 print "<select dojoType='dijit.form.Select' style='width : 220px; margin : 0px' name='profile'>";
296 print "<option value='0'>" . __("Default profile") . "</option>";
298 while ($line = $this->dbh
->fetch_assoc($result)) {
300 $title = $line["title"];
302 print "<option value='$id'>$title</option>";
309 $mode = $this->dbh
->escape_string($_REQUEST['hub_mode']);
310 if (!$mode) $mode = $this->dbh
->escape_string($_REQUEST['hub.mode']);
312 $feed_id = (int) $this->dbh
->escape_string($_REQUEST['id']);
313 $feed_url = $this->dbh
->escape_string($_REQUEST['hub_topic']);
315 if (!$feed_url) $feed_url = $this->dbh
->escape_string($_REQUEST['hub.topic']);
317 if (!PUBSUBHUBBUB_ENABLED
) {
318 header('HTTP/1.0 404 Not Found');
319 echo "404 Not found (Disabled by server)";
323 // TODO: implement hub_verifytoken checking
324 // TODO: store requested rel=self or whatever for verification
325 // (may be different from stored feed url) e.g. http://url/ or http://url
327 $result = $this->dbh
->query("SELECT feed_url FROM ttrss_feeds
328 WHERE id = '$feed_id'");
330 if ($this->dbh
->num_rows($result) != 0) {
332 $check_feed_url = $this->dbh
->fetch_result($result, 0, "feed_url");
334 // ignore url checking for the time being
335 if ($check_feed_url && (true ||
$check_feed_url == $feed_url ||
!$feed_url)) {
336 if ($mode == "subscribe") {
338 $this->dbh
->query("UPDATE ttrss_feeds SET pubsub_state = 2
339 WHERE id = '$feed_id'");
341 print $_REQUEST['hub_challenge'];
344 } else if ($mode == "unsubscribe") {
346 $this->dbh
->query("UPDATE ttrss_feeds SET pubsub_state = 0
347 WHERE id = '$feed_id'");
349 print $_REQUEST['hub_challenge'];
354 // Received update ping, schedule feed update.
355 //update_rss_feed($feed_id, true, true);
357 $this->dbh
->query("UPDATE ttrss_feeds SET
358 last_update_started = '1970-01-01',
359 last_updated = '1970-01-01' WHERE id = '$feed_id'");
363 header('HTTP/1.0 404 Not Found');
364 echo "404 Not found (URL check failed)";
367 header('HTTP/1.0 404 Not Found');
368 echo "404 Not found (Feed not found)";
375 header("Location: index.php");
379 $uuid = $this->dbh
->escape_string($_REQUEST["key"]);
381 $result = $this->dbh
->query("SELECT ref_id, owner_uid FROM ttrss_user_entries WHERE
384 if ($this->dbh
->num_rows($result) != 0) {
385 header("Content-Type: text/html");
387 $id = $this->dbh
->fetch_result($result, 0, "ref_id");
388 $owner_uid = $this->dbh
->fetch_result($result, 0, "owner_uid");
390 $article = Article
::format_article($id, false, true, $owner_uid);
392 print_r($article['content']);
395 print "Article not found.";
401 $feed = $this->dbh
->escape_string($_REQUEST["id"]);
402 $key = $this->dbh
->escape_string($_REQUEST["key"]);
403 $is_cat = sql_bool_to_bool($_REQUEST["is_cat"]);
404 $limit = (int)$this->dbh
->escape_string($_REQUEST["limit"]);
405 $offset = (int)$this->dbh
->escape_string($_REQUEST["offset"]);
407 $search = $this->dbh
->escape_string($_REQUEST["q"]);
408 $view_mode = $this->dbh
->escape_string($_REQUEST["view-mode"]);
409 $order = $this->dbh
->escape_string($_REQUEST["order"]);
410 $start_ts = $this->dbh
->escape_string($_REQUEST["ts"]);
412 $format = $this->dbh
->escape_string($_REQUEST['format']);
413 $orig_guid = sql_bool_to_bool($_REQUEST["orig_guid"]);
415 if (!$format) $format = 'atom';
417 if (SINGLE_USER_MODE
) {
418 authenticate_user("admin", null);
424 $result = $this->dbh
->query("SELECT owner_uid FROM
425 ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'");
427 if ($this->dbh
->num_rows($result) == 1)
428 $owner_id = $this->dbh
->fetch_result($result, 0, "owner_uid");
432 $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit,
433 $offset, $search, $view_mode, $format, $order, $orig_guid, $start_ts);
435 header('HTTP/1.1 403 Forbidden');
439 function updateTask() {
440 PluginHost
::getInstance()->run_hooks(PluginHost
::HOOK_UPDATE_TASK
, "hook_update_task", false);
443 function housekeepingTask() {
444 PluginHost
::getInstance()->run_hooks(PluginHost
::HOOK_HOUSE_KEEPING
, "hook_house_keeping", false);
447 function globalUpdateFeeds() {
448 RPC
::updaterandomfeed_real($this->dbh
);
450 PluginHost
::getInstance()->run_hooks(PluginHost
::HOOK_UPDATE_TASK
, "hook_update_task", false);
453 function sharepopup() {
454 if (SINGLE_USER_MODE
) {
458 header('Content-Type: text/html; charset=utf-8');
459 print "<html><head><title>Tiny Tiny RSS</title>
460 <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">
461 <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">";
463 echo stylesheet_tag("css/utility.css");
464 echo stylesheet_tag("css/dijit.css");
465 echo javascript_tag("lib/prototype.js");
466 echo javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,controls");
467 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
468 </head><body id='sharepopup'>";
470 $action = $_REQUEST["action"];
472 if ($_SESSION["uid"]) {
474 if ($action == 'share') {
476 $title = $this->dbh
->escape_string(strip_tags($_REQUEST["title"]));
477 $url = $this->dbh
->escape_string(strip_tags($_REQUEST["url"]));
478 $content = $this->dbh
->escape_string(strip_tags($_REQUEST["content"]));
479 $labels = $this->dbh
->escape_string(strip_tags($_REQUEST["labels"]));
481 Article
::create_published_article($title, $url, $content, $labels,
484 print "<script type='text/javascript'>";
485 print "window.close();";
489 $title = htmlspecialchars($_REQUEST["title"]);
490 $url = htmlspecialchars($_REQUEST["url"]);
494 <table height
='100%' width
='100%'><tr
><td colspan
='2'>
495 <h1
><?php
echo __("Share with Tiny Tiny RSS") ?
></h1
>
498 <form id
='share_form' name
='share_form'>
500 <input type
="hidden" name
="op" value
="sharepopup">
501 <input type
="hidden" name
="action" value
="share">
503 <tr
><td align
='right'><?php
echo __("Title:") ?
></td
>
504 <td width
='80%'><input name
='title' value
="<?php echo $title ?>"></td
></tr
>
505 <tr
><td align
='right'><?php
echo __("URL:") ?
></td
>
506 <td
><input name
='url' value
="<?php echo $url ?>"></td
></tr
>
507 <tr
><td align
='right'><?php
echo __("Content:") ?
></td
>
508 <td
><input name
='content' value
=""></td
></tr
>
509 <tr
><td align
='right'><?php
echo __("Labels:") ?
></td
>
510 <td
><input name
='labels' id
="labels_value"
511 placeholder
='Alpha, Beta, Gamma' value
="">
515 <div
class="autocomplete" id
="labels_choices"
516 style
="display : block"></div
></td
></tr
>
518 <script type
='text/javascript'>document
.forms
[0].title
.focus();</script
>
520 <script type
='text/javascript'>
521 new Ajax
.Autocompleter('labels_value', 'labels_choices',
522 "backend.php?op=rpc&method=completeLabels",
523 { tokens
: ',', paramName
: "search" });
527 <div style
='float : right' class='insensitive-small'>
528 <?php
echo __("Shared article will appear in the Published feed.") ?
>
530 <button type
="submit"><?php
echo __('Share') ?
></button
>
531 <button onclick
="return window.close()"><?php
echo __('Cancel') ?
></button
>
543 $return = urlencode($_SERVER["REQUEST_URI"])
546 <form action
="public.php?return=<?php echo $return ?>"
547 method
="POST" id
="loginForm" name
="loginForm">
549 <input type
="hidden" name
="op" value
="login">
551 <table height
='100%' width
='100%'><tr
><td colspan
='2'>
552 <h1
><?php
echo __("Not logged in") ?
></h1
></td
></tr
>
554 <tr
><td align
="right"><?php
echo __("Login:") ?
></td
>
555 <td align
="right"><input name
="login"
556 value
="<?php echo $_SESSION["fake_login
"] ?>"></td
></tr
>
557 <tr
><td align
="right"><?php
echo __("Password:") ?
></td
>
558 <td align
="right"><input type
="password" name
="password"
559 value
="<?php echo $_SESSION["fake_password
"] ?>"></td
></tr
>
561 <button type
="submit">
562 <?php
echo __('Log in') ?
></button
>
564 <button onclick
="return window.close()">
565 <?php
echo __('Cancel') ?
></button
>
575 if (!SINGLE_USER_MODE
) {
577 $login = $this->dbh
->escape_string($_POST["login"]);
578 $password = $_POST["password"];
579 $remember_me = $_POST["remember_me"];
582 session_set_cookie_params(SESSION_COOKIE_LIFETIME
);
584 session_set_cookie_params(0);
589 if (authenticate_user($login, $password)) {
590 $_POST["password"] = "";
592 if (get_schema_version() >= 120) {
593 $_SESSION["language"] = get_pref("USER_LANGUAGE", $_SESSION["uid"]);
596 $_SESSION["ref_schema_version"] = get_schema_version(true);
597 $_SESSION["bw_limit"] = !!$_POST["bw_limit"];
599 if ($_POST["profile"]) {
601 $profile = $this->dbh
->escape_string($_POST["profile"]);
603 $result = $this->dbh
->query("SELECT id FROM ttrss_settings_profiles
604 WHERE id = '$profile' AND owner_uid = " . $_SESSION["uid"]);
606 if ($this->dbh
->num_rows($result) != 0) {
607 $_SESSION["profile"] = $profile;
611 $_SESSION["login_error_msg"] = __("Incorrect username or password");
612 user_error("Failed login attempt for $login from {$_SERVER['REMOTE_ADDR']}", E_USER_WARNING
);
615 if ($_REQUEST['return']) {
616 header("Location: " . $_REQUEST['return']);
618 header("Location: " . SELF_URL_PATH
);
623 /* function subtest() {
624 header("Content-type: text/plain; charset=utf-8");
626 $url = $_REQUEST["url"];
631 print_r(get_feeds_from_html($url, fetch_file_contents($url)));
635 function subscribe() {
636 if (SINGLE_USER_MODE
) {
640 if ($_SESSION["uid"]) {
642 $feed_url = $this->dbh
->escape_string(trim($_REQUEST["feed_url"]));
644 header('Content-Type: text/html; charset=utf-8');
647 <title>Tiny Tiny RSS</title>
648 <link rel=\"stylesheet\" type=\"text/css\" href=\"css/utility.css\">
649 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
650 <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">
651 <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">
655 <img class=\"floatingLogo\" src=\"images/logo_small.png\"
656 alt=\"Tiny Tiny RSS\"/>
657 <h1>".__("Subscribe to feed...")."</h1><div class='content'>";
659 $rc = Feeds
::subscribe_to_feed($feed_url);
661 switch ($rc['code']) {
663 print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
666 print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
669 print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
672 print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
675 print_notice(__("Multiple feed URLs found."));
676 $feed_urls = $rc["feeds"];
679 print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
685 print "<form action=\"public.php\">";
686 print "<input type=\"hidden\" name=\"op\" value=\"subscribe\">";
688 print "<select name=\"feed_url\">";
690 foreach ($feed_urls as $url => $name) {
691 $url = htmlspecialchars($url);
692 $name = htmlspecialchars($name);
694 print "<option value=\"$url\">$name</option>";
697 print "<input type=\"submit\" value=\"".__("Subscribe to selected feed").
703 $tp_uri = get_self_url_prefix() . "/prefs.php";
704 $tt_uri = get_self_url_prefix();
706 if ($rc['code'] <= 2){
707 $result = $this->dbh
->query("SELECT id FROM ttrss_feeds WHERE
708 feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
710 $feed_id = $this->dbh
->fetch_result($result, 0, "id");
717 print "<form method=\"GET\" style='display: inline'
719 <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
720 <input type=\"hidden\" name=\"method\" value=\"editFeed\">
721 <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
722 <input type=\"submit\" value=\"".__("Edit subscription options")."\">
726 print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
727 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
730 print "</div></body></html>";
738 header("Content-Type: text/plain");
739 print error_json(13);
742 function forgotpass() {
745 @$hash = $_REQUEST["hash"];
747 header('Content-Type: text/html; charset=utf-8');
748 print "<html><head><title>Tiny Tiny RSS</title>
749 <link rel=\"shortcut icon\" type=\"image/png\" href=\"images/favicon.png\">
750 <link rel=\"icon\" type=\"image/png\" sizes=\"72x72\" href=\"images/favicon-72px.png\">";
752 echo stylesheet_tag("css/utility.css");
753 echo javascript_tag("lib/prototype.js");
755 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
756 </head><body id='forgotpass'>";
758 print '<div class="floatingLogo"><img src="images/logo_small.png"></div>';
759 print "<h1>".__("Password recovery")."</h1>";
760 print "<div class='content'>";
762 @$method = $_POST['method'];
765 $login = $_REQUEST["login"];
768 $result = $this->dbh
->query("SELECT id, resetpass_token FROM ttrss_users
769 WHERE login = '$login'");
771 if ($this->dbh
->num_rows($result) != 0) {
772 $id = $this->dbh
->fetch_result($result, 0, "id");
773 $resetpass_token_full = $this->dbh
->fetch_result($result, 0, "resetpass_token");
774 list($timestamp, $resetpass_token) = explode(":", $resetpass_token_full);
776 if ($timestamp && $resetpass_token &&
777 $timestamp >= time() - 15*60*60 &&
778 $resetpass_token == $hash) {
780 $result = $this->dbh
->query("UPDATE ttrss_users SET resetpass_token = NULL
783 Pref_Users
::resetUserPassword($id, true);
785 print "<p>"."Completed."."</p>";
788 print_error("Some of the information provided is missing or incorrect.");
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 "<form method=\"GET\" action=\"index.php\">
798 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
801 } else if (!$method) {
802 print_notice(__("You will need to provide valid account name and email. A password reset link will be sent to your email address."));
804 print "<form method='POST' action='public.php'>";
805 print "<input type='hidden' name='method' value='do'>";
806 print "<input type='hidden' name='op' value='forgotpass'>";
809 print "<label>".__("Login:")."</label>";
810 print "<input type='text' name='login' value='' required>";
814 print "<label>".__("Email:")."</label>";
815 print "<input type='email' name='email' value='' required>";
819 print "<label>".__("How much is two plus two:")."</label>";
820 print "<input type='text' name='test' value='' required>";
824 print "<button type='submit'>".__("Reset password")."</button>";
827 } else if ($method == 'do') {
829 $login = $this->dbh
->escape_string($_POST["login"]);
830 $email = $this->dbh
->escape_string($_POST["email"]);
831 $test = $this->dbh
->escape_string($_POST["test"]);
833 if (($test != 4 && $test != 'four') ||
!$email ||
!$login) {
834 print_error(__('Some of the required form parameters are missing or incorrect.'));
836 print "<form method=\"GET\" action=\"public.php\">
837 <input type=\"hidden\" name=\"op\" value=\"forgotpass\">
838 <input type=\"submit\" value=\"".__("Go back")."\">
843 print_notice("Password reset instructions are being sent to your email address.");
845 $result = $this->dbh
->query("SELECT id FROM ttrss_users
846 WHERE login = '$login' AND email = '$email'");
848 if ($this->dbh
->num_rows($result) != 0) {
849 $id = $this->dbh
->fetch_result($result, 0, "id");
852 $resetpass_token = sha1(get_random_bytes(128));
853 $resetpass_link = get_self_url_prefix() . "/public.php?op=forgotpass&hash=" . $resetpass_token .
854 "&login=" . urlencode($login);
856 require_once 'classes/ttrssmailer.php';
857 require_once "lib/MiniTemplator.class.php";
859 $tpl = new MiniTemplator
;
861 $tpl->readTemplateFromFile("templates/resetpass_link_template.txt");
863 $tpl->setVariable('LOGIN', $login);
864 $tpl->setVariable('RESETPASS_LINK', $resetpass_link);
866 $tpl->addBlock('message');
870 $tpl->generateOutputToString($message);
872 $mail = new ttrssMailer();
874 $rc = $mail->quickMail($email, $login,
875 __("[tt-rss] Password reset request"),
878 if (!$rc) print_error($mail->ErrorInfo
);
880 $resetpass_token_full = $this->dbh
->escape_string(time() . ":" . $resetpass_token);
882 $result = $this->dbh
->query("UPDATE ttrss_users
883 SET resetpass_token = '$resetpass_token_full'
884 WHERE login = '$login' AND email = '$email'");
886 //Pref_Users::resetUserPassword($id, false);
890 print "<p>"."Completed."."</p>";
892 print_error("User ID not found.");
895 print "<form method=\"GET\" action=\"index.php\">
896 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
900 print_error(__("Sorry, login and email combination not found."));
902 print "<form method=\"GET\" action=\"public.php\">
903 <input type=\"hidden\" name=\"op\" value=\"forgotpass\">
904 <input type=\"submit\" value=\"".__("Go back")."\">
918 function dbupdate() {
921 if (!SINGLE_USER_MODE
&& $_SESSION["access_level"] < 10) {
922 $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script.");
929 <title
>Database Updater
</title
>
930 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8"/>
931 <link rel
="stylesheet" type
="text/css" href
="css/utility.css"/>
932 <link rel
=\"shortcut icon\" type
=\"image
/png\" href
=\"images
/favicon
.png\"
>
933 <link rel
=\"icon\" type
=\"image
/png\" sizes
=\"72x72\" href
=\"images
/favicon
-72px
.png\"
>
935 <style type
="text/css">
936 span
.ok
{ color
: #009000; font-weight : bold; }
937 span
.err
{ color
: #ff0000; font-weight : bold; }
940 <script type
='text/javascript'>
941 function confirmOP() {
942 return confirm("Update the database?");
946 <div
class="floatingLogo"><img src
="images/logo_small.png"></div
>
948 <h1
><?php
echo __("Database Updater") ?
></h1
>
950 <div
class="content">
953 @$op = $_REQUEST["subop"];
954 $updater = new DbUpdater(Db
::get(), DB_TYPE
, SCHEMA_VERSION
);
956 if ($op == "performupdate") {
957 if ($updater->isUpdateRequired()) {
959 print "<h2>Performing updates</h2>";
961 print "<h3>Updating to schema version " . SCHEMA_VERSION
. "</h3>";
965 for ($i = $updater->getSchemaVersion() +
1; $i <= SCHEMA_VERSION
; $i++
) {
966 print "<li>Performing update up to version $i...";
968 $result = $updater->performUpdateTo($i, true);
971 print "<span class='err'>FAILED!</span></li></ul>";
973 print_warning("One of the updates failed. Either retry the process or perform updates manually.");
974 print "<p><form method=\"GET\" action=\"index.php\">
975 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
980 print "<span class='ok'>OK!</span></li>";
986 print_notice("Your Tiny Tiny RSS database is now updated to the latest version.");
988 print "<p><form method=\"GET\" action=\"index.php\">
989 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
993 print "<h2>Your database is up to date.</h2>";
995 print "<p><form method=\"GET\" action=\"index.php\">
996 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
1000 if ($updater->isUpdateRequired()) {
1002 print "<h2>Database update required</h2>";
1004 print_notice("<h4>".
1005 sprintf("Your Tiny Tiny RSS database needs update to the latest version: %d to %d.",
1006 $updater->getSchemaVersion(), SCHEMA_VERSION
).
1009 print_warning("Please backup your database before proceeding.");
1011 print "<form method='POST'>
1012 <input type='hidden' name='subop' value='performupdate'>
1013 <input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'>
1018 print_notice("Tiny Tiny RSS database is up to date.");
1020 print "<p><form method=\"GET\" action=\"index.php\">
1021 <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
1034 function cached_url() {
1035 @$hash = basename($_GET['hash']);
1037 // we don't need an extension to find the file, hash is a complete URL
1038 $hash = preg_replace("/\.[^\.]*$/", "", $hash);
1042 $filename = CACHE_DIR
. '/images/' . $hash;
1044 if (file_exists($filename)) {
1045 header("Content-Disposition: inline; filename=\"$hash\"");
1046 $mimetype = mime_content_type($filename);
1048 /* See if we can use X-Sendfile */
1050 if (function_exists('apache_get_modules') &&
1051 array_search('mod_xsendfile', apache_get_modules()))
1055 header("X-Sendfile: $filename");
1056 header("Content-type: $mimetype");
1057 header('Content-Disposition: inline; filename="' . basename($filename) . '"');
1059 header("Content-type: $mimetype");
1060 $stamp = gmdate("D, d M Y H:i:s", filemtime($filename)). " GMT";
1061 header("Last-Modified: $stamp", true);
1062 readfile($filename);
1065 header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
1066 echo "File not found.";
1071 private function make_article_tag_uri($id, $timestamp) {
1073 $timestamp = date("Y-m-d", strtotime($timestamp));
1075 return "tag:" . parse_url(get_self_url_prefix(), PHP_URL_HOST
) . ",$timestamp:/$id";
1078 // this should be used very carefully because this endpoint is exposed to unauthenticated users
1079 // plugin data is not loaded because there's no user context and owner_uid/session may or may not be available
1080 // in general, don't do anything user-related in here and do not modify $_SESSION
1081 public function pluginhandler() {
1082 $host = new PluginHost();
1084 $plugin = basename($_REQUEST["plugin"]);
1085 $method = $_REQUEST["pmethod"];
1087 $host->load($plugin, PluginHost
::KIND_USER
, 0);
1090 $pclass = $host->get_plugin($plugin);
1093 if (method_exists($pclass, $method)) {
1094 if ($pclass->is_public_method($method)) {
1097 header("Content-Type: text/json");
1098 print error_json(6);
1101 header("Content-Type: text/json");
1102 print error_json(13);
1105 header("Content-Type: text/json");
1106 print error_json(14);