public.php 29 KB

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