public.php 27 KB

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