public.php 27 KB

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