public.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957
  1. <?php
  2. class Handler_Public extends Handler {
  3. private function generate_syndicated_feed($owner_uid, $feed, $is_cat,
  4. $limit, $offset, $search, $search_mode,
  5. $view_mode = false, $format = 'atom', $order = false) {
  6. require_once "lib/MiniTemplator.class.php";
  7. $note_style = "background-color : #fff7d5;
  8. border-width : 1px; ".
  9. "padding : 5px; border-style : dashed; border-color : #e7d796;".
  10. "margin-bottom : 1em; color : #9a8c59;";
  11. if (!$limit) $limit = 60;
  12. $date_sort_field = "date_entered DESC, updated DESC";
  13. if ($feed == -2)
  14. $date_sort_field = "last_published DESC";
  15. else if ($feed == -1)
  16. $date_sort_field = "last_marked DESC";
  17. switch ($order) {
  18. case "title":
  19. $date_sort_field = "ttrss_entries.title";
  20. break;
  21. case "date_reverse":
  22. $date_sort_field = "date_entered, updated";
  23. break;
  24. case "feed_dates":
  25. $date_sort_field = "updated DESC";
  26. break;
  27. }
  28. $qfh_ret = queryFeedHeadlines($feed,
  29. 1, $view_mode, $is_cat, $search, $search_mode,
  30. $date_sort_field, $offset, $owner_uid,
  31. false, 0, false, true);
  32. $result = $qfh_ret[0];
  33. if ($this->dbh->num_rows($result) != 0) {
  34. $ts = strtotime($this->dbh->fetch_result($result, 0, "date_entered"));
  35. if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) &&
  36. strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $ts) {
  37. header('HTTP/1.0 304 Not Modified');
  38. return;
  39. }
  40. $last_modified = gmdate("D, d M Y H:i:s", $ts) . " GMT";
  41. header("Last-Modified: $last_modified", true);
  42. }
  43. $qfh_ret = queryFeedHeadlines($feed,
  44. $limit, $view_mode, $is_cat, $search, $search_mode,
  45. $date_sort_field, $offset, $owner_uid,
  46. false, 0, false, true);
  47. $result = $qfh_ret[0];
  48. $feed_title = htmlspecialchars($qfh_ret[1]);
  49. $feed_site_url = $qfh_ret[2];
  50. $last_error = $qfh_ret[3];
  51. $feed_self_url = get_self_url_prefix() .
  52. "/public.php?op=rss&id=-2&key=" .
  53. get_feed_access_key(-2, false, $owner_uid);
  54. if (!$feed_site_url) $feed_site_url = get_self_url_prefix();
  55. if ($format == 'atom') {
  56. $tpl = new MiniTemplator;
  57. $tpl->readTemplateFromFile("templates/generated_feed.txt");
  58. $tpl->setVariable('FEED_TITLE', $feed_title, true);
  59. $tpl->setVariable('VERSION', VERSION, true);
  60. $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
  61. if (PUBSUBHUBBUB_HUB && $feed == -2) {
  62. $tpl->setVariable('HUB_URL', htmlspecialchars(PUBSUBHUBBUB_HUB), true);
  63. $tpl->addBlock('feed_hub');
  64. }
  65. $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
  66. while ($line = $this->dbh->fetch_assoc($result)) {
  67. $tpl->setVariable('ARTICLE_ID', htmlspecialchars($line['link']), true);
  68. $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
  69. $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
  70. $tpl->setVariable('ARTICLE_EXCERPT',
  71. truncate_string(strip_tags($line["content_preview"]), 100, '...'), true);
  72. $content = sanitize($line["content_preview"], false, $owner_uid);
  73. if ($line['note']) {
  74. $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" .
  75. $content;
  76. $tpl->setVariable('ARTICLE_NOTE', htmlspecialchars($line['note']), true);
  77. }
  78. $tpl->setVariable('ARTICLE_CONTENT', $content, true);
  79. $tpl->setVariable('ARTICLE_UPDATED_ATOM',
  80. date('c', strtotime($line["updated"])), true);
  81. $tpl->setVariable('ARTICLE_UPDATED_RFC822',
  82. date(DATE_RFC822, strtotime($line["updated"])), true);
  83. $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true);
  84. $tags = get_article_tags($line["id"], $owner_uid);
  85. foreach ($tags as $tag) {
  86. $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true);
  87. $tpl->addBlock('category');
  88. }
  89. $enclosures = get_article_enclosures($line["id"]);
  90. foreach ($enclosures as $e) {
  91. $type = htmlspecialchars($e['content_type']);
  92. $url = htmlspecialchars($e['content_url']);
  93. $length = $e['duration'];
  94. $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
  95. $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
  96. $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
  97. $tpl->addBlock('enclosure');
  98. }
  99. $tpl->addBlock('entry');
  100. }
  101. $tmp = "";
  102. $tpl->addBlock('feed');
  103. $tpl->generateOutputToString($tmp);
  104. if (@!$_REQUEST["noxml"]) {
  105. header("Content-Type: text/xml; charset=utf-8");
  106. } else {
  107. header("Content-Type: text/plain; charset=utf-8");
  108. }
  109. print $tmp;
  110. } else if ($format == 'json') {
  111. $feed = array();
  112. $feed['title'] = $feed_title;
  113. $feed['version'] = VERSION;
  114. $feed['feed_url'] = $feed_self_url;
  115. if (PUBSUBHUBBUB_HUB && $feed == -2) {
  116. $feed['hub_url'] = PUBSUBHUBBUB_HUB;
  117. }
  118. $feed['self_url'] = get_self_url_prefix();
  119. $feed['articles'] = array();
  120. while ($line = $this->dbh->fetch_assoc($result)) {
  121. $article = array();
  122. $article['id'] = $line['link'];
  123. $article['link'] = $line['link'];
  124. $article['title'] = $line['title'];
  125. $article['excerpt'] = truncate_string(strip_tags($line["content_preview"]), 100, '...');
  126. $article['content'] = sanitize($line["content_preview"], false, $owner_uid);
  127. $article['updated'] = date('c', strtotime($line["updated"]));
  128. if ($line['note']) $article['note'] = $line['note'];
  129. if ($article['author']) $article['author'] = $line['author'];
  130. $tags = get_article_tags($line["id"], $owner_uid);
  131. if (count($tags) > 0) {
  132. $article['tags'] = array();
  133. foreach ($tags as $tag) {
  134. array_push($article['tags'], $tag);
  135. }
  136. }
  137. $enclosures = get_article_enclosures($line["id"]);
  138. if (count($enclosures) > 0) {
  139. $article['enclosures'] = array();
  140. foreach ($enclosures as $e) {
  141. $type = $e['content_type'];
  142. $url = $e['content_url'];
  143. $length = $e['duration'];
  144. array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length));
  145. }
  146. }
  147. array_push($feed['articles'], $article);
  148. }
  149. header("Content-Type: text/json; charset=utf-8");
  150. print json_encode($feed);
  151. } else {
  152. header("Content-Type: text/plain; charset=utf-8");
  153. print json_encode(array("error" => array("message" => "Unknown format")));
  154. }
  155. }
  156. function getUnread() {
  157. $login = $this->dbh->escape_string($_REQUEST["login"]);
  158. $fresh = $_REQUEST["fresh"] == "1";
  159. $result = $this->dbh->query("SELECT id FROM ttrss_users WHERE login = '$login'");
  160. if ($this->dbh->num_rows($result) == 1) {
  161. $uid = $this->dbh->fetch_result($result, 0, "id");
  162. print getGlobalUnread($uid);
  163. if ($fresh) {
  164. print ";";
  165. print getFeedArticles(-3, false, true, $uid);
  166. }
  167. } else {
  168. print "-1;User not found";
  169. }
  170. }
  171. function getProfiles() {
  172. $login = $this->dbh->escape_string($_REQUEST["login"]);
  173. $result = $this->dbh->query("SELECT ttrss_settings_profiles.* FROM ttrss_settings_profiles,ttrss_users
  174. WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = '$login' ORDER BY title");
  175. print "<select dojoType='dijit.form.Select' style='width : 220px; margin : 0px' name='profile'>";
  176. print "<option value='0'>" . __("Default profile") . "</option>";
  177. while ($line = $this->dbh->fetch_assoc($result)) {
  178. $id = $line["id"];
  179. $title = $line["title"];
  180. print "<option value='$id'>$title</option>";
  181. }
  182. print "</select>";
  183. }
  184. function pubsub() {
  185. $mode = $this->dbh->escape_string($_REQUEST['hub_mode']);
  186. $feed_id = (int) $this->dbh->escape_string($_REQUEST['id']);
  187. $feed_url = $this->dbh->escape_string($_REQUEST['hub_topic']);
  188. if (!PUBSUBHUBBUB_ENABLED) {
  189. header('HTTP/1.0 404 Not Found');
  190. echo "404 Not found";
  191. return;
  192. }
  193. // TODO: implement hub_verifytoken checking
  194. $result = $this->dbh->query("SELECT feed_url FROM ttrss_feeds
  195. WHERE id = '$feed_id'");
  196. if ($this->dbh->num_rows($result) != 0) {
  197. $check_feed_url = $this->dbh->fetch_result($result, 0, "feed_url");
  198. if ($check_feed_url && ($check_feed_url == $feed_url || !$feed_url)) {
  199. if ($mode == "subscribe") {
  200. $this->dbh->query("UPDATE ttrss_feeds SET pubsub_state = 2
  201. WHERE id = '$feed_id'");
  202. print $_REQUEST['hub_challenge'];
  203. return;
  204. } else if ($mode == "unsubscribe") {
  205. $this->dbh->query("UPDATE ttrss_feeds SET pubsub_state = 0
  206. WHERE id = '$feed_id'");
  207. print $_REQUEST['hub_challenge'];
  208. return;
  209. } else if (!$mode) {
  210. // Received update ping, schedule feed update.
  211. //update_rss_feed($feed_id, true, true);
  212. $this->dbh->query("UPDATE ttrss_feeds SET
  213. last_update_started = '1970-01-01',
  214. last_updated = '1970-01-01' WHERE id = '$feed_id'");
  215. }
  216. } else {
  217. header('HTTP/1.0 404 Not Found');
  218. echo "404 Not found";
  219. }
  220. } else {
  221. header('HTTP/1.0 404 Not Found');
  222. echo "404 Not found";
  223. }
  224. }
  225. function logout() {
  226. logout_user();
  227. header("Location: index.php");
  228. }
  229. function share() {
  230. $uuid = $this->dbh->escape_string($_REQUEST["key"]);
  231. $result = $this->dbh->query("SELECT ref_id, owner_uid FROM ttrss_user_entries WHERE
  232. uuid = '$uuid'");
  233. if ($this->dbh->num_rows($result) != 0) {
  234. header("Content-Type: text/html");
  235. $id = $this->dbh->fetch_result($result, 0, "ref_id");
  236. $owner_uid = $this->dbh->fetch_result($result, 0, "owner_uid");
  237. $article = format_article($id, false, true, $owner_uid);
  238. print_r($article['content']);
  239. } else {
  240. print "Article not found.";
  241. }
  242. }
  243. function rss() {
  244. $feed = $this->dbh->escape_string($_REQUEST["id"]);
  245. $key = $this->dbh->escape_string($_REQUEST["key"]);
  246. $is_cat = $_REQUEST["is_cat"] != false;
  247. $limit = (int)$this->dbh->escape_string($_REQUEST["limit"]);
  248. $offset = (int)$this->dbh->escape_string($_REQUEST["offset"]);
  249. $search = $this->dbh->escape_string($_REQUEST["q"]);
  250. $search_mode = $this->dbh->escape_string($_REQUEST["smode"]);
  251. $view_mode = $this->dbh->escape_string($_REQUEST["view-mode"]);
  252. $order = $this->dbh->escape_string($_REQUEST["order"]);
  253. $format = $this->dbh->escape_string($_REQUEST['format']);
  254. if (!$format) $format = 'atom';
  255. if (SINGLE_USER_MODE) {
  256. authenticate_user("admin", null);
  257. }
  258. $owner_id = false;
  259. if ($key) {
  260. $result = $this->dbh->query("SELECT owner_uid FROM
  261. ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'");
  262. if ($this->dbh->num_rows($result) == 1)
  263. $owner_id = $this->dbh->fetch_result($result, 0, "owner_uid");
  264. }
  265. if ($owner_id) {
  266. $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit,
  267. $offset, $search, $search_mode, $view_mode, $format, $order);
  268. } else {
  269. header('HTTP/1.1 403 Forbidden');
  270. }
  271. }
  272. function globalUpdateFeeds() {
  273. include "rssfuncs.php";
  274. // Update all feeds needing a update.
  275. update_daemon_common(0, true, false);
  276. housekeeping_common(false);
  277. PluginHost::getInstance()->run_hooks(PluginHost::HOOK_UPDATE_TASK, "hook_update_task", $op);
  278. }
  279. function sharepopup() {
  280. if (SINGLE_USER_MODE) {
  281. login_sequence();
  282. }
  283. header('Content-Type: text/html; charset=utf-8');
  284. print "<html><head><title>Tiny Tiny RSS</title>";
  285. stylesheet_tag("css/utility.css");
  286. javascript_tag("lib/prototype.js");
  287. javascript_tag("lib/scriptaculous/scriptaculous.js?load=effects,dragdrop,controls");
  288. print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
  289. </head><body id='sharepopup'>";
  290. $action = $_REQUEST["action"];
  291. if ($_SESSION["uid"]) {
  292. if ($action == 'share') {
  293. $title = $this->dbh->escape_string(strip_tags($_REQUEST["title"]));
  294. $url = $this->dbh->escape_string(strip_tags($_REQUEST["url"]));
  295. $content = $this->dbh->escape_string(strip_tags($_REQUEST["content"]));
  296. $labels = $this->dbh->escape_string(strip_tags($_REQUEST["labels"]));
  297. Article::create_published_article($title, $url, $content, $labels,
  298. $_SESSION["uid"]);
  299. print "<script type='text/javascript'>";
  300. print "window.close();";
  301. print "</script>";
  302. } else {
  303. $title = htmlspecialchars($_REQUEST["title"]);
  304. $url = htmlspecialchars($_REQUEST["url"]);
  305. ?>
  306. <table height='100%' width='100%'><tr><td colspan='2'>
  307. <h1><?php echo __("Share with Tiny Tiny RSS") ?></h1>
  308. </td></tr>
  309. <form id='share_form' name='share_form'>
  310. <input type="hidden" name="op" value="sharepopup">
  311. <input type="hidden" name="action" value="share">
  312. <tr><td align='right'><?php echo __("Title:") ?></td>
  313. <td width='80%'><input name='title' value="<?php echo $title ?>"></td></tr>
  314. <tr><td align='right'><?php echo __("URL:") ?></td>
  315. <td><input name='url' value="<?php echo $url ?>"></td></tr>
  316. <tr><td align='right'><?php echo __("Content:") ?></td>
  317. <td><input name='content' value=""></td></tr>
  318. <tr><td align='right'><?php echo __("Labels:") ?></td>
  319. <td><input name='labels' id="labels_value"
  320. placeholder='Alpha, Beta, Gamma' value="">
  321. </td></tr>
  322. <tr><td>
  323. <div class="autocomplete" id="labels_choices"
  324. style="display : block"></div></td></tr>
  325. <script type='text/javascript'>document.forms[0].title.focus();</script>
  326. <script type='text/javascript'>
  327. new Ajax.Autocompleter('labels_value', 'labels_choices',
  328. "backend.php?op=rpc&method=completeLabels",
  329. { tokens: ',', paramName: "search" });
  330. </script>
  331. <tr><td colspan='2'>
  332. <div style='float : right' class='insensitive-small'>
  333. <?php echo __("Shared article will appear in the Published feed.") ?>
  334. </div>
  335. <button type="submit"><?php echo __('Share') ?></button>
  336. <button onclick="return window.close()"><?php echo __('Cancel') ?></button>
  337. </div>
  338. </form>
  339. </td></tr></table>
  340. </body></html>
  341. <?php
  342. }
  343. } else {
  344. $return = urlencode($_SERVER["REQUEST_URI"])
  345. ?>
  346. <form action="public.php?return=<?php echo $return ?>"
  347. method="POST" id="loginForm" name="loginForm">
  348. <input type="hidden" name="op" value="login">
  349. <table height='100%' width='100%'><tr><td colspan='2'>
  350. <h1><?php echo __("Not logged in") ?></h1></td></tr>
  351. <tr><td align="right"><?php echo __("Login:") ?></td>
  352. <td align="right"><input name="login"
  353. value="<?php echo $_SESSION["fake_login"] ?>"></td></tr>
  354. <tr><td align="right"><?php echo __("Password:") ?></td>
  355. <td align="right"><input type="password" name="password"
  356. value="<?php echo $_SESSION["fake_password"] ?>"></td></tr>
  357. <tr><td colspan='2'>
  358. <button type="submit">
  359. <?php echo __('Log in') ?></button>
  360. <button onclick="return window.close()">
  361. <?php echo __('Cancel') ?></button>
  362. </td></tr>
  363. </table>
  364. </form>
  365. <?php
  366. }
  367. }
  368. function login() {
  369. if (!SINGLE_USER_MODE) {
  370. $login = $this->dbh->escape_string($_POST["login"]);
  371. $password = $_POST["password"];
  372. $remember_me = $_POST["remember_me"];
  373. if ($remember_me) {
  374. session_set_cookie_params(SESSION_COOKIE_LIFETIME);
  375. } else {
  376. session_set_cookie_params(0);
  377. }
  378. @session_start();
  379. if (authenticate_user($login, $password)) {
  380. $_POST["password"] = "";
  381. if (get_schema_version() >= 120) {
  382. $_SESSION["language"] = get_pref("USER_LANGUAGE", $_SESSION["uid"]);
  383. }
  384. $_SESSION["ref_schema_version"] = get_schema_version(true);
  385. $_SESSION["bw_limit"] = !!$_POST["bw_limit"];
  386. if ($_POST["profile"]) {
  387. $profile = $this->dbh->escape_string($_POST["profile"]);
  388. $result = $this->dbh->query("SELECT id FROM ttrss_settings_profiles
  389. WHERE id = '$profile' AND owner_uid = " . $_SESSION["uid"]);
  390. if ($this->dbh->num_rows($result) != 0) {
  391. $_SESSION["profile"] = $profile;
  392. }
  393. }
  394. } else {
  395. $_SESSION["login_error_msg"] = __("Incorrect username or password");
  396. }
  397. if ($_REQUEST['return']) {
  398. header("Location: " . $_REQUEST['return']);
  399. } else {
  400. header("Location: " . SELF_URL_PATH);
  401. }
  402. }
  403. }
  404. function subscribe() {
  405. if (SINGLE_USER_MODE) {
  406. login_sequence();
  407. }
  408. if ($_SESSION["uid"]) {
  409. $feed_url = $this->dbh->escape_string(trim($_REQUEST["feed_url"]));
  410. header('Content-Type: text/html; charset=utf-8');
  411. print "<html>
  412. <head>
  413. <title>Tiny Tiny RSS</title>
  414. <link rel=\"stylesheet\" type=\"text/css\" href=\"css/utility.css\">
  415. <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
  416. </head>
  417. <body>
  418. <img class=\"floatingLogo\" src=\"images/logo_small.png\"
  419. alt=\"Tiny Tiny RSS\"/>
  420. <h1>".__("Subscribe to feed...")."</h1><div class='content'>";
  421. $rc = subscribe_to_feed($feed_url);
  422. switch ($rc['code']) {
  423. case 0:
  424. print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
  425. break;
  426. case 1:
  427. print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
  428. break;
  429. case 2:
  430. print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
  431. break;
  432. case 3:
  433. print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
  434. break;
  435. case 4:
  436. print_notice(__("Multiple feed URLs found."));
  437. $feed_urls = $rc["feeds"];
  438. break;
  439. case 5:
  440. print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
  441. break;
  442. }
  443. if ($feed_urls) {
  444. print "<form action=\"public.php\">";
  445. print "<input type=\"hidden\" name=\"op\" value=\"subscribe\">";
  446. print "<select name=\"feed_url\">";
  447. foreach ($feed_urls as $url => $name) {
  448. $url = htmlspecialchars($url);
  449. $name = htmlspecialchars($name);
  450. print "<option value=\"$url\">$name</option>";
  451. }
  452. print "<input type=\"submit\" value=\"".__("Subscribe to selected feed").
  453. "\">";
  454. print "</form>";
  455. }
  456. $tp_uri = get_self_url_prefix() . "/prefs.php";
  457. $tt_uri = get_self_url_prefix();
  458. if ($rc['code'] <= 2){
  459. $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE
  460. feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
  461. $feed_id = $this->dbh->fetch_result($result, 0, "id");
  462. } else {
  463. $feed_id = 0;
  464. }
  465. print "<p>";
  466. if ($feed_id) {
  467. print "<form method=\"GET\" style='display: inline'
  468. action=\"$tp_uri\">
  469. <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
  470. <input type=\"hidden\" name=\"method\" value=\"editFeed\">
  471. <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
  472. <input type=\"submit\" value=\"".__("Edit subscription options")."\">
  473. </form>";
  474. }
  475. print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
  476. <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
  477. </form></p>";
  478. print "</div></body></html>";
  479. } else {
  480. render_login_form();
  481. }
  482. }
  483. function subscribe2() {
  484. $feed_url = $this->dbh->escape_string(trim($_REQUEST["feed_url"]));
  485. $cat_id = $this->dbh->escape_string($_REQUEST["cat_id"]);
  486. $from = $this->dbh->escape_string($_REQUEST["from"]);
  487. $feed_urls = array();
  488. /* only read authentication information from POST */
  489. $auth_login = $this->dbh->escape_string(trim($_POST["auth_login"]));
  490. $auth_pass = $this->dbh->escape_string(trim($_POST["auth_pass"]));
  491. $rc = subscribe_to_feed($feed_url, $cat_id, $auth_login, $auth_pass);
  492. switch ($rc) {
  493. case 1:
  494. print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
  495. break;
  496. case 2:
  497. print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
  498. break;
  499. case 3:
  500. print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
  501. break;
  502. case 0:
  503. print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
  504. break;
  505. case 4:
  506. print_notice(__("Multiple feed URLs found."));
  507. $contents = @fetch_file_contents($url, false, $auth_login, $auth_pass);
  508. if (is_html($contents)) {
  509. $feed_urls = get_feeds_from_html($url, $contents);
  510. }
  511. break;
  512. case 5:
  513. print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
  514. break;
  515. }
  516. if ($feed_urls) {
  517. print "<form action=\"backend.php\">";
  518. print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
  519. print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
  520. print "<input type=\"hidden\" name=\"method\" value=\"add\">";
  521. print "<select name=\"feed_url\">";
  522. foreach ($feed_urls as $url => $name) {
  523. $url = htmlspecialchars($url);
  524. $name = htmlspecialchars($name);
  525. print "<option value=\"$url\">$name</option>";
  526. }
  527. print "<input type=\"submit\" value=\"".__("Subscribe to selected feed")."\">";
  528. print "</form>";
  529. }
  530. $tp_uri = get_self_url_prefix() . "/prefs.php";
  531. $tt_uri = get_self_url_prefix();
  532. if ($rc <= 2){
  533. $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE
  534. feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
  535. $feed_id = $this->dbh->fetch_result($result, 0, "id");
  536. } else {
  537. $feed_id = 0;
  538. }
  539. print "<p>";
  540. if ($feed_id) {
  541. print "<form method=\"GET\" style='display: inline'
  542. action=\"$tp_uri\">
  543. <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
  544. <input type=\"hidden\" name=\"method\" value=\"editFeed\">
  545. <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
  546. <input type=\"submit\" value=\"".__("Edit subscription options")."\">
  547. </form>";
  548. }
  549. print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
  550. <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
  551. </form></p>";
  552. print "</body></html>";
  553. }
  554. function index() {
  555. header("Content-Type: text/plain");
  556. print json_encode(array("error" => array("code" => 7)));
  557. }
  558. function forgotpass() {
  559. startup_gettext();
  560. header('Content-Type: text/html; charset=utf-8');
  561. print "<html><head><title>Tiny Tiny RSS</title>";
  562. stylesheet_tag("css/utility.css");
  563. javascript_tag("lib/prototype.js");
  564. print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
  565. </head><body id='forgotpass'>";
  566. print '<div class="floatingLogo"><img src="images/logo_small.png"></div>';
  567. print "<h1>".__("Password recovery")."</h1>";
  568. print "<div class='content'>";
  569. @$method = $_POST['method'];
  570. if (!$method) {
  571. print_notice(__("You will need to provide valid account name and email. New password will be sent on your email address."));
  572. print "<form method='POST' action='public.php'>";
  573. print "<input type='hidden' name='method' value='do'>";
  574. print "<input type='hidden' name='op' value='forgotpass'>";
  575. print "<fieldset>";
  576. print "<label>".__("Login:")."</label>";
  577. print "<input type='text' name='login' value='' required>";
  578. print "</fieldset>";
  579. print "<fieldset>";
  580. print "<label>".__("Email:")."</label>";
  581. print "<input type='email' name='email' value='' required>";
  582. print "</fieldset>";
  583. print "<fieldset>";
  584. print "<label>".__("How much is two plus two:")."</label>";
  585. print "<input type='text' name='test' value='' required>";
  586. print "</fieldset>";
  587. print "<p/>";
  588. print "<button type='submit'>".__("Reset password")."</button>";
  589. print "</form>";
  590. } else if ($method == 'do') {
  591. $login = $this->dbh->escape_string($_POST["login"]);
  592. $email = $this->dbh->escape_string($_POST["email"]);
  593. $test = $this->dbh->escape_string($_POST["test"]);
  594. if (($test != 4 && $test != 'four') || !$email || !$login) {
  595. print_error(__('Some of the required form parameters are missing or incorrect.'));
  596. print "<form method=\"GET\" action=\"public.php\">
  597. <input type=\"hidden\" name=\"op\" value=\"forgotpass\">
  598. <input type=\"submit\" value=\"".__("Go back")."\">
  599. </form>";
  600. } else {
  601. $result = $this->dbh->query("SELECT id FROM ttrss_users
  602. WHERE login = '$login' AND email = '$email'");
  603. if ($this->dbh->num_rows($result) != 0) {
  604. $id = $this->dbh->fetch_result($result, 0, "id");
  605. Pref_Users::resetUserPassword($id, false);
  606. print "<p>";
  607. print "<p>"."Completed."."</p>";
  608. print "<form method=\"GET\" action=\"index.php\">
  609. <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
  610. </form>";
  611. } else {
  612. print_error(__("Sorry, login and email combination not found."));
  613. print "<form method=\"GET\" action=\"public.php\">
  614. <input type=\"hidden\" name=\"op\" value=\"forgotpass\">
  615. <input type=\"submit\" value=\"".__("Go back")."\">
  616. </form>";
  617. }
  618. }
  619. }
  620. print "</div>";
  621. print "</body>";
  622. print "</html>";
  623. }
  624. function dbupdate() {
  625. startup_gettext();
  626. if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) {
  627. $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script.");
  628. render_login_form();
  629. exit;
  630. }
  631. ?><html>
  632. <head>
  633. <title>Database Updater</title>
  634. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  635. <link rel="stylesheet" type="text/css" href="css/utility.css"/>
  636. </head>
  637. <style type="text/css">
  638. span.ok { color : #009000; font-weight : bold; }
  639. span.err { color : #ff0000; font-weight : bold; }
  640. </style>
  641. <body>
  642. <script type='text/javascript'>
  643. function confirmOP() {
  644. return confirm("Update the database?");
  645. }
  646. </script>
  647. <div class="floatingLogo"><img src="images/logo_small.png"></div>
  648. <h1><?php echo __("Database Updater") ?></h1>
  649. <div class="content">
  650. <?php
  651. @$op = $_REQUEST["subop"];
  652. $updater = new DbUpdater(Db::get(), DB_TYPE, SCHEMA_VERSION);
  653. if ($op == "performupdate") {
  654. if ($updater->isUpdateRequired()) {
  655. print "<h2>Performing updates</h2>";
  656. print "<h3>Updating to schema version " . SCHEMA_VERSION . "</h3>";
  657. print "<ul>";
  658. for ($i = $updater->getSchemaVersion() + 1; $i <= SCHEMA_VERSION; $i++) {
  659. print "<li>Performing update up to version $i...";
  660. $result = $updater->performUpdateTo($i);
  661. if (!$result) {
  662. print "<span class='err'>FAILED!</span></li></ul>";
  663. print_warning("One of the updates failed. Either retry the process or perform updates manually.");
  664. print "<p><form method=\"GET\" action=\"index.php\">
  665. <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
  666. </form>";
  667. break;
  668. } else {
  669. print "<span class='ok'>OK!</span></li>";
  670. }
  671. }
  672. print "</ul>";
  673. print_notice("Your Tiny Tiny RSS database is now updated to the latest version.");
  674. print "<p><form method=\"GET\" action=\"index.php\">
  675. <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
  676. </form>";
  677. } else {
  678. print "<h2>Your database is up to date.</h2>";
  679. print "<p><form method=\"GET\" action=\"index.php\">
  680. <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
  681. </form>";
  682. }
  683. } else {
  684. if ($updater->isUpdateRequired()) {
  685. print "<h2>Database update required</h2>";
  686. print "<h3>";
  687. printf("Your Tiny Tiny RSS database needs update to the latest version: %d to %d.",
  688. $updater->getSchemaVersion(), SCHEMA_VERSION);
  689. print "</h3>";
  690. print_warning("Please backup your database before proceeding.");
  691. print "<form method='POST'>
  692. <input type='hidden' name='subop' value='performupdate'>
  693. <input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'>
  694. </form>";
  695. } else {
  696. print_notice("Tiny Tiny RSS database is up to date.");
  697. print "<p><form method=\"GET\" action=\"index.php\">
  698. <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
  699. </form>";
  700. }
  701. }
  702. ?>
  703. </div>
  704. </body>
  705. </html>
  706. <?php
  707. }
  708. }
  709. ?>