public.php 29 KB

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