public.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  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. stylesheet_tag("utility.css");
  274. javascript_tag("lib/prototype.js");
  275. 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 colspan='2'>
  346. <button type="submit">
  347. <?php echo __('Log in') ?></button>
  348. <button onclick="return window.close()">
  349. <?php echo __('Cancel') ?></button>
  350. </td></tr>
  351. </table>
  352. </form>
  353. <?php
  354. }
  355. }
  356. function login() {
  357. if (!SINGLE_USER_MODE) {
  358. $login = $this->dbh->escape_string($_POST["login"]);
  359. $password = $_POST["password"];
  360. $remember_me = $_POST["remember_me"];
  361. if ($remember_me) {
  362. session_set_cookie_params(SESSION_COOKIE_LIFETIME);
  363. } else {
  364. session_set_cookie_params(0);
  365. }
  366. @session_start();
  367. if (authenticate_user($login, $password)) {
  368. $_POST["password"] = "";
  369. if (get_schema_version() >= 120) {
  370. $_SESSION["language"] = get_pref("USER_LANGUAGE", $_SESSION["uid"]);
  371. }
  372. $_SESSION["ref_schema_version"] = get_schema_version(true);
  373. $_SESSION["bw_limit"] = !!$_POST["bw_limit"];
  374. if ($_POST["profile"]) {
  375. $profile = $this->dbh->escape_string($_POST["profile"]);
  376. $result = $this->dbh->query("SELECT id FROM ttrss_settings_profiles
  377. WHERE id = '$profile' AND owner_uid = " . $_SESSION["uid"]);
  378. if ($this->dbh->num_rows($result) != 0) {
  379. $_SESSION["profile"] = $profile;
  380. }
  381. }
  382. } else {
  383. $_SESSION["login_error_msg"] = __("Incorrect username or password");
  384. }
  385. if ($_REQUEST['return']) {
  386. header("Location: " . $_REQUEST['return']);
  387. } else {
  388. header("Location: " . SELF_URL_PATH);
  389. }
  390. }
  391. }
  392. function subscribe() {
  393. if (SINGLE_USER_MODE) {
  394. login_sequence();
  395. }
  396. if ($_SESSION["uid"]) {
  397. $feed_url = $this->dbh->escape_string(trim($_REQUEST["feed_url"]));
  398. header('Content-Type: text/html; charset=utf-8');
  399. print "<html>
  400. <head>
  401. <title>Tiny Tiny RSS</title>
  402. <link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
  403. <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
  404. </head>
  405. <body>
  406. <img class=\"floatingLogo\" src=\"images/logo_small.png\"
  407. alt=\"Tiny Tiny RSS\"/>
  408. <h1>".__("Subscribe to feed...")."</h1><div class='content'>";
  409. $rc = subscribe_to_feed($feed_url);
  410. switch ($rc['code']) {
  411. case 0:
  412. print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
  413. break;
  414. case 1:
  415. print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
  416. break;
  417. case 2:
  418. print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
  419. break;
  420. case 3:
  421. print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
  422. break;
  423. case 4:
  424. print_notice(__("Multiple feed URLs found."));
  425. $feed_urls = $rc["feeds"];
  426. break;
  427. case 5:
  428. print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
  429. break;
  430. }
  431. if ($feed_urls) {
  432. print "<form action=\"public.php\">";
  433. print "<input type=\"hidden\" name=\"op\" value=\"subscribe\">";
  434. print "<select name=\"feed_url\">";
  435. foreach ($feed_urls as $url => $name) {
  436. $url = htmlspecialchars($url);
  437. $name = htmlspecialchars($name);
  438. print "<option value=\"$url\">$name</option>";
  439. }
  440. print "<input type=\"submit\" value=\"".__("Subscribe to selected feed").
  441. "\">";
  442. print "</form>";
  443. }
  444. $tp_uri = get_self_url_prefix() . "/prefs.php";
  445. $tt_uri = get_self_url_prefix();
  446. if ($rc['code'] <= 2){
  447. $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE
  448. feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
  449. $feed_id = $this->dbh->fetch_result($result, 0, "id");
  450. } else {
  451. $feed_id = 0;
  452. }
  453. print "<p>";
  454. if ($feed_id) {
  455. print "<form method=\"GET\" style='display: inline'
  456. action=\"$tp_uri\">
  457. <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
  458. <input type=\"hidden\" name=\"method\" value=\"editFeed\">
  459. <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
  460. <input type=\"submit\" value=\"".__("Edit subscription options")."\">
  461. </form>";
  462. }
  463. print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
  464. <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
  465. </form></p>";
  466. print "</div></body></html>";
  467. } else {
  468. render_login_form();
  469. }
  470. }
  471. function subscribe2() {
  472. $feed_url = $this->dbh->escape_string(trim($_REQUEST["feed_url"]));
  473. $cat_id = $this->dbh->escape_string($_REQUEST["cat_id"]);
  474. $from = $this->dbh->escape_string($_REQUEST["from"]);
  475. $feed_urls = array();
  476. /* only read authentication information from POST */
  477. $auth_login = $this->dbh->escape_string(trim($_POST["auth_login"]));
  478. $auth_pass = $this->dbh->escape_string(trim($_POST["auth_pass"]));
  479. $rc = subscribe_to_feed($feed_url, $cat_id, $auth_login, $auth_pass);
  480. switch ($rc) {
  481. case 1:
  482. print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
  483. break;
  484. case 2:
  485. print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
  486. break;
  487. case 3:
  488. print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
  489. break;
  490. case 0:
  491. print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
  492. break;
  493. case 4:
  494. print_notice(__("Multiple feed URLs found."));
  495. $contents = @fetch_file_contents($url, false, $auth_login, $auth_pass);
  496. if (is_html($contents)) {
  497. $feed_urls = get_feeds_from_html($url, $contents);
  498. }
  499. break;
  500. case 5:
  501. print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
  502. break;
  503. }
  504. if ($feed_urls) {
  505. print "<form action=\"backend.php\">";
  506. print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
  507. print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
  508. print "<input type=\"hidden\" name=\"method\" value=\"add\">";
  509. print "<select name=\"feed_url\">";
  510. foreach ($feed_urls as $url => $name) {
  511. $url = htmlspecialchars($url);
  512. $name = htmlspecialchars($name);
  513. print "<option value=\"$url\">$name</option>";
  514. }
  515. print "<input type=\"submit\" value=\"".__("Subscribe to selected feed")."\">";
  516. print "</form>";
  517. }
  518. $tp_uri = get_self_url_prefix() . "/prefs.php";
  519. $tt_uri = get_self_url_prefix();
  520. if ($rc <= 2){
  521. $result = $this->dbh->query("SELECT id FROM ttrss_feeds WHERE
  522. feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
  523. $feed_id = $this->dbh->fetch_result($result, 0, "id");
  524. } else {
  525. $feed_id = 0;
  526. }
  527. print "<p>";
  528. if ($feed_id) {
  529. print "<form method=\"GET\" style='display: inline'
  530. action=\"$tp_uri\">
  531. <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
  532. <input type=\"hidden\" name=\"method\" value=\"editFeed\">
  533. <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
  534. <input type=\"submit\" value=\"".__("Edit subscription options")."\">
  535. </form>";
  536. }
  537. print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
  538. <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
  539. </form></p>";
  540. print "</body></html>";
  541. }
  542. function index() {
  543. header("Content-Type: text/plain");
  544. print json_encode(array("error" => array("code" => 7)));
  545. }
  546. function forgotpass() {
  547. header('Content-Type: text/html; charset=utf-8');
  548. print "<html><head><title>Tiny Tiny RSS</title>";
  549. stylesheet_tag("utility.css");
  550. javascript_tag("lib/prototype.js");
  551. print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
  552. </head><body id='forgotpass'>";
  553. print '<div class="floatingLogo"><img src="images/logo_small.png"></div>';
  554. print "<h1>".__("Password recovery")."</h1>";
  555. print "<div class='content'>";
  556. @$method = $_POST['method'];
  557. if (!$method) {
  558. print_notice(__("You will need to provide valid account name and email. New password will be sent on your email address."));
  559. print "<form method='POST' action='public.php'>";
  560. print "<input type='hidden' name='method' value='do'>";
  561. print "<input type='hidden' name='op' value='forgotpass'>";
  562. print "<fieldset>";
  563. print "<label>".__("Login:")."</label>";
  564. print "<input type='text' name='login' value='' required>";
  565. print "</fieldset>";
  566. print "<fieldset>";
  567. print "<label>".__("Email:")."</label>";
  568. print "<input type='email' name='email' value='' required>";
  569. print "</fieldset>";
  570. print "<fieldset>";
  571. print "<label>".__("How much is two plus two:")."</label>";
  572. print "<input type='text' name='test' value='' required>";
  573. print "</fieldset>";
  574. print "<p/>";
  575. print "<button type='submit'>".__("Reset password")."</button>";
  576. print "</form>";
  577. } else if ($method == 'do') {
  578. $login = $this->dbh->escape_string($_POST["login"]);
  579. $email = $this->dbh->escape_string($_POST["email"]);
  580. $test = $this->dbh->escape_string($_POST["test"]);
  581. if (($test != 4 && $test != 'four') || !$email || !$login) {
  582. print_error(__('Some of the required form parameters are missing or incorrect.'));
  583. print "<form method=\"GET\" action=\"public.php\">
  584. <input type=\"hidden\" name=\"op\" value=\"forgotpass\">
  585. <input type=\"submit\" value=\"".__("Go back")."\">
  586. </form>";
  587. } else {
  588. $result = $this->dbh->query("SELECT id FROM ttrss_users
  589. WHERE login = '$login' AND email = '$email'");
  590. if ($this->dbh->num_rows($result) != 0) {
  591. $id = $this->dbh->fetch_result($result, 0, "id");
  592. Pref_Users::resetUserPassword($id, false);
  593. print "<p>";
  594. print "<p>"."Completed."."</p>";
  595. print "<form method=\"GET\" action=\"index.php\">
  596. <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
  597. </form>";
  598. } else {
  599. print_error(__("Sorry, login and email combination not found."));
  600. print "<form method=\"GET\" action=\"public.php\">
  601. <input type=\"hidden\" name=\"op\" value=\"forgotpass\">
  602. <input type=\"submit\" value=\"".__("Go back")."\">
  603. </form>";
  604. }
  605. }
  606. }
  607. print "</div>";
  608. print "</body>";
  609. print "</html>";
  610. }
  611. function dbupdate() {
  612. if (!SINGLE_USER_MODE && $_SESSION["access_level"] < 10) {
  613. $_SESSION["login_error_msg"] = __("Your access level is insufficient to run this script.");
  614. render_login_form();
  615. exit;
  616. }
  617. ?><html>
  618. <head>
  619. <title>Database Updater</title>
  620. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  621. <link rel="stylesheet" type="text/css" href="utility.css"/>
  622. </head>
  623. <style type="text/css">
  624. span.ok { color : #009000; font-weight : bold; }
  625. span.err { color : #ff0000; font-weight : bold; }
  626. </style>
  627. <body>
  628. <script type='text/javascript'>
  629. function confirmOP() {
  630. return confirm("Update the database?");
  631. }
  632. </script>
  633. <div class="floatingLogo"><img src="images/logo_small.png"></div>
  634. <h1><?php echo __("Database Updater") ?></h1>
  635. <div class="content">
  636. <?php
  637. @$op = $_REQUEST["subop"];
  638. $updater = new DbUpdater(Db::get(), DB_TYPE, SCHEMA_VERSION);
  639. if ($op == "performupdate") {
  640. if ($updater->isUpdateRequired()) {
  641. print "<h2>Performing updates</h2>";
  642. print "<h3>Updating to schema version " . SCHEMA_VERSION . "</h3>";
  643. print "<ul>";
  644. for ($i = $updater->getSchemaVersion() + 1; $i <= SCHEMA_VERSION; $i++) {
  645. print "<li>Performing update up to version $i...";
  646. $result = $updater->performUpdateTo($i);
  647. if (!$result) {
  648. print "<span class='err'>FAILED!</span></li></ul>";
  649. print_warning("One of the updates failed. Either retry the process or perform updates manually.");
  650. print "<p><form method=\"GET\" action=\"index.php\">
  651. <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
  652. </form>";
  653. break;
  654. } else {
  655. print "<span class='ok'>OK!</span></li>";
  656. }
  657. }
  658. print "</ul>";
  659. print_notice("Your Tiny Tiny RSS database is now updated to the latest version.");
  660. print "<p><form method=\"GET\" action=\"index.php\">
  661. <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
  662. </form>";
  663. } else {
  664. print "<h2>Your database is up to date.</h2>";
  665. print "<p><form method=\"GET\" action=\"index.php\">
  666. <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
  667. </form>";
  668. }
  669. } else {
  670. if ($updater->isUpdateRequired()) {
  671. print "<h2>Database update required</h2>";
  672. print "<h3>";
  673. printf("Your Tiny Tiny RSS database needs update to the latest version: %d to %d.",
  674. $updater->getSchemaVersion(), SCHEMA_VERSION);
  675. print "</h3>";
  676. print_warning("Please backup your database before proceeding.");
  677. print "<form method='POST'>
  678. <input type='hidden' name='subop' value='performupdate'>
  679. <input type='submit' onclick='return confirmOP()' value='".__("Perform updates")."'>
  680. </form>";
  681. } else {
  682. print_notice("Tiny Tiny RSS database is up to date.");
  683. print "<p><form method=\"GET\" action=\"index.php\">
  684. <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
  685. </form>";
  686. }
  687. }
  688. ?>
  689. </div>
  690. </body>
  691. </html>
  692. <?php
  693. }
  694. }
  695. ?>