public.php 28 KB

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