public.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. <?php
  2. class Handler_Public extends Handler {
  3. private function generate_syndicated_feed($owner_uid, $feed, $is_cat,
  4. $limit, $offset, $search, $search_mode,
  5. $view_mode = false, $format = 'atom') {
  6. require_once "lib/MiniTemplator.class.php";
  7. $note_style = "background-color : #fff7d5;
  8. border-width : 1px; ".
  9. "padding : 5px; border-style : dashed; border-color : #e7d796;".
  10. "margin-bottom : 1em; color : #9a8c59;";
  11. if (!$limit) $limit = 100;
  12. if (get_pref($this->link, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) {
  13. $date_sort_field = "updated";
  14. } else {
  15. $date_sort_field = "date_entered";
  16. }
  17. if ($feed == -2)
  18. $date_sort_field = "last_read";
  19. $qfh_ret = queryFeedHeadlines($this->link, $feed,
  20. $limit, $view_mode, $is_cat, $search, $search_mode,
  21. "$date_sort_field DESC", $offset, $owner_uid,
  22. false, 0, false, true);
  23. $result = $qfh_ret[0];
  24. $feed_title = htmlspecialchars($qfh_ret[1]);
  25. $feed_site_url = $qfh_ret[2];
  26. $last_error = $qfh_ret[3];
  27. $feed_self_url = get_self_url_prefix() .
  28. "/public.php?op=rss&id=-2&key=" .
  29. get_feed_access_key($this->link, -2, false, $owner_uid);
  30. if (!$feed_site_url) $feed_site_url = get_self_url_prefix();
  31. if ($format == 'atom') {
  32. $tpl = new MiniTemplator;
  33. $tpl->readTemplateFromFile("templates/generated_feed.txt");
  34. $tpl->setVariable('FEED_TITLE', $feed_title, true);
  35. $tpl->setVariable('VERSION', VERSION, true);
  36. $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
  37. if (PUBSUBHUBBUB_HUB && $feed == -2) {
  38. $tpl->setVariable('HUB_URL', htmlspecialchars(PUBSUBHUBBUB_HUB), true);
  39. $tpl->addBlock('feed_hub');
  40. }
  41. $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
  42. while ($line = db_fetch_assoc($result)) {
  43. $tpl->setVariable('ARTICLE_ID', htmlspecialchars($line['link']), true);
  44. $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
  45. $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
  46. $tpl->setVariable('ARTICLE_EXCERPT',
  47. truncate_string(strip_tags($line["content_preview"]), 100, '...'), true);
  48. $content = sanitize($this->link, $line["content_preview"], false, $owner_uid);
  49. if ($line['note']) {
  50. $content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" .
  51. $content;
  52. }
  53. $tpl->setVariable('ARTICLE_CONTENT', $content, true);
  54. $tpl->setVariable('ARTICLE_UPDATED_ATOM',
  55. date('c', strtotime($line["updated"])), true);
  56. $tpl->setVariable('ARTICLE_UPDATED_RFC822',
  57. date(DATE_RFC822, strtotime($line["updated"])), true);
  58. $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true);
  59. $tags = get_article_tags($this->link, $line["id"], $owner_uid);
  60. foreach ($tags as $tag) {
  61. $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true);
  62. $tpl->addBlock('category');
  63. }
  64. $enclosures = get_article_enclosures($this->link, $line["id"]);
  65. foreach ($enclosures as $e) {
  66. $type = htmlspecialchars($e['content_type']);
  67. $url = htmlspecialchars($e['content_url']);
  68. $length = $e['duration'];
  69. $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
  70. $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
  71. $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
  72. $tpl->addBlock('enclosure');
  73. }
  74. $tpl->addBlock('entry');
  75. }
  76. $tmp = "";
  77. $tpl->addBlock('feed');
  78. $tpl->generateOutputToString($tmp);
  79. if (@!$_REQUEST["noxml"]) {
  80. header("Content-Type: text/xml; charset=utf-8");
  81. } else {
  82. header("Content-Type: text/plain; charset=utf-8");
  83. }
  84. print $tmp;
  85. } else if ($format == 'json') {
  86. $feed = array();
  87. $feed['title'] = $feed_title;
  88. $feed['version'] = VERSION;
  89. $feed['feed_url'] = $feed_self_url;
  90. if (PUBSUBHUBBUB_HUB && $feed == -2) {
  91. $feed['hub_url'] = PUBSUBHUBBUB_HUB;
  92. }
  93. $feed['self_url'] = get_self_url_prefix();
  94. $feed['articles'] = array();
  95. while ($line = db_fetch_assoc($result)) {
  96. $article = array();
  97. $article['id'] = $line['link'];
  98. $article['link'] = $line['link'];
  99. $article['title'] = $line['title'];
  100. $article['excerpt'] = truncate_string(strip_tags($line["content_preview"]), 100, '...');
  101. $article['content'] = sanitize($this->link, $line["content_preview"], false, $owner_uid);
  102. $article['updated'] = date('c', strtotime($line["updated"]));
  103. if ($line['note']) $article['note'] = $line['note'];
  104. if ($article['author']) $article['author'] = $line['author'];
  105. $tags = get_article_tags($this->link, $line["id"], $owner_uid);
  106. if (count($tags) > 0) {
  107. $article['tags'] = array();
  108. foreach ($tags as $tag) {
  109. array_push($article['tags'], $tag);
  110. }
  111. }
  112. $enclosures = get_article_enclosures($this->link, $line["id"]);
  113. if (count($enclosures) > 0) {
  114. $article['enclosures'] = array();
  115. foreach ($enclosures as $e) {
  116. $type = $e['content_type'];
  117. $url = $e['content_url'];
  118. $length = $e['duration'];
  119. array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length));
  120. }
  121. }
  122. array_push($feed['articles'], $article);
  123. }
  124. header("Content-Type: text/json; charset=utf-8");
  125. print json_encode($feed);
  126. } else {
  127. header("Content-Type: text/plain; charset=utf-8");
  128. print json_encode(array("error" => array("message" => "Unknown format")));
  129. }
  130. }
  131. function getUnread() {
  132. $login = db_escape_string($this->link, $_REQUEST["login"]);
  133. $fresh = $_REQUEST["fresh"] == "1";
  134. $result = db_query($this->link, "SELECT id FROM ttrss_users WHERE login = '$login'");
  135. if (db_num_rows($result) == 1) {
  136. $uid = db_fetch_result($result, 0, "id");
  137. print getGlobalUnread($this->link, $uid);
  138. if ($fresh) {
  139. print ";";
  140. print getFeedArticles($this->link, -3, false, true, $uid);
  141. }
  142. } else {
  143. print "-1;User not found";
  144. }
  145. }
  146. function getProfiles() {
  147. $login = db_escape_string($this->link, $_REQUEST["login"]);
  148. $result = db_query($this->link, "SELECT * FROM ttrss_settings_profiles,ttrss_users
  149. WHERE ttrss_users.id = ttrss_settings_profiles.owner_uid AND login = '$login' ORDER BY title");
  150. print "<select dojoType='dijit.form.Select' style='width : 220px; margin : 0px' name='profile'>";
  151. print "<option value='0'>" . __("Default profile") . "</option>";
  152. while ($line = db_fetch_assoc($result)) {
  153. $id = $line["id"];
  154. $title = $line["title"];
  155. print "<option value='$id'>$title</option>";
  156. }
  157. print "</select>";
  158. }
  159. function pubsub() {
  160. $mode = db_escape_string($this->link, $_REQUEST['hub_mode']);
  161. $feed_id = (int) db_escape_string($this->link, $_REQUEST['id']);
  162. $feed_url = db_escape_string($this->link, $_REQUEST['hub_topic']);
  163. if (!PUBSUBHUBBUB_ENABLED) {
  164. header('HTTP/1.0 404 Not Found');
  165. echo "404 Not found";
  166. return;
  167. }
  168. // TODO: implement hub_verifytoken checking
  169. $result = db_query($this->link, "SELECT feed_url FROM ttrss_feeds
  170. WHERE id = '$feed_id'");
  171. if (db_num_rows($result) != 0) {
  172. $check_feed_url = db_fetch_result($result, 0, "feed_url");
  173. if ($check_feed_url && ($check_feed_url == $feed_url || !$feed_url)) {
  174. if ($mode == "subscribe") {
  175. db_query($this->link, "UPDATE ttrss_feeds SET pubsub_state = 2
  176. WHERE id = '$feed_id'");
  177. print $_REQUEST['hub_challenge'];
  178. return;
  179. } else if ($mode == "unsubscribe") {
  180. db_query($this->link, "UPDATE ttrss_feeds SET pubsub_state = 0
  181. WHERE id = '$feed_id'");
  182. print $_REQUEST['hub_challenge'];
  183. return;
  184. } else if (!$mode) {
  185. // Received update ping, schedule feed update.
  186. //update_rss_feed($this->link, $feed_id, true, true);
  187. db_query($this->link, "UPDATE ttrss_feeds SET
  188. last_update_started = '1970-01-01',
  189. last_updated = '1970-01-01' WHERE id = '$feed_id'");
  190. }
  191. } else {
  192. header('HTTP/1.0 404 Not Found');
  193. echo "404 Not found";
  194. }
  195. } else {
  196. header('HTTP/1.0 404 Not Found');
  197. echo "404 Not found";
  198. }
  199. }
  200. function logout() {
  201. logout_user();
  202. header("Location: index.php");
  203. }
  204. function share() {
  205. $uuid = db_escape_string($this->link, $_REQUEST["key"]);
  206. $result = db_query($this->link, "SELECT ref_id, owner_uid FROM ttrss_user_entries WHERE
  207. uuid = '$uuid'");
  208. if (db_num_rows($result) != 0) {
  209. header("Content-Type: text/html");
  210. $id = db_fetch_result($result, 0, "ref_id");
  211. $owner_uid = db_fetch_result($result, 0, "owner_uid");
  212. $article = format_article($this->link, $id, false, true, $owner_uid);
  213. print_r($article['content']);
  214. } else {
  215. print "Article not found.";
  216. }
  217. }
  218. function rss() {
  219. $feed = db_escape_string($this->link, $_REQUEST["id"]);
  220. $key = db_escape_string($this->link, $_REQUEST["key"]);
  221. $is_cat = $_REQUEST["is_cat"] != false;
  222. $limit = (int)db_escape_string($this->link, $_REQUEST["limit"]);
  223. $offset = (int)db_escape_string($this->link, $_REQUEST["offset"]);
  224. $search = db_escape_string($this->link, $_REQUEST["q"]);
  225. $search_mode = db_escape_string($this->link, $_REQUEST["smode"]);
  226. $view_mode = db_escape_string($this->link, $_REQUEST["view-mode"]);
  227. $format = db_escape_string($this->link, $_REQUEST['format']);
  228. if (!$format) $format = 'atom';
  229. if (SINGLE_USER_MODE) {
  230. authenticate_user($this->link, "admin", null);
  231. }
  232. $owner_id = false;
  233. if ($key) {
  234. $result = db_query($this->link, "SELECT owner_uid FROM
  235. ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'");
  236. if (db_num_rows($result) == 1)
  237. $owner_id = db_fetch_result($result, 0, "owner_uid");
  238. }
  239. if ($owner_id) {
  240. $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit,
  241. $offset, $search, $search_mode, $view_mode, $format);
  242. } else {
  243. header('HTTP/1.1 403 Forbidden');
  244. }
  245. }
  246. function globalUpdateFeeds() {
  247. include "rssfuncs.php";
  248. // Update all feeds needing a update.
  249. update_daemon_common($this->link, 0, true, false);
  250. }
  251. function sharepopup() {
  252. if (SINGLE_USER_MODE) {
  253. login_sequence($this->link);
  254. }
  255. header('Content-Type: text/html; charset=utf-8');
  256. print "<html>
  257. <head>
  258. <title>Tiny Tiny RSS</title>
  259. <link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
  260. <script type=\"text/javascript\" src=\"lib/prototype.js\"></script>
  261. <script type=\"text/javascript\" src=\"lib/scriptaculous/scriptaculous.js?load=effects,dragdrop,controls\"></script>
  262. <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
  263. </head>
  264. <body id='sharepopup'>";
  265. $action = $_REQUEST["action"];
  266. if ($_SESSION["uid"]) {
  267. if ($action == 'share') {
  268. $title = db_escape_string($this->link, strip_tags($_REQUEST["title"]));
  269. $url = db_escape_string($this->link, strip_tags($_REQUEST["url"]));
  270. $content = db_escape_string($this->link, strip_tags($_REQUEST["content"]));
  271. $labels = db_escape_string($this->link, strip_tags($_REQUEST["labels"]));
  272. Article::create_published_article($this->link, $title, $url, $content, $labels,
  273. $_SESSION["uid"]);
  274. print "<script type='text/javascript'>";
  275. print "window.close();";
  276. print "</script>";
  277. } else {
  278. $title = htmlspecialchars($_REQUEST["title"]);
  279. $url = htmlspecialchars($_REQUEST["url"]);
  280. ?>
  281. <table height='100%' width='100%'><tr><td colspan='2'>
  282. <h1><?php echo __("Share with Tiny Tiny RSS") ?></h1>
  283. </td></tr>
  284. <form id='share_form' name='share_form'>
  285. <input type="hidden" name="op" value="sharepopup">
  286. <input type="hidden" name="action" value="share">
  287. <tr><td align='right'><?php echo __("Title:") ?></td>
  288. <td width='80%'><input name='title' value="<?php echo $title ?>"></td></tr>
  289. <tr><td align='right'><?php echo __("URL:") ?></td>
  290. <td><input name='url' value="<?php echo $url ?>"></td></tr>
  291. <tr><td align='right'><?php echo __("Content:") ?></td>
  292. <td><input name='content' value=""></td></tr>
  293. <tr><td align='right'><?php echo __("Labels:") ?></td>
  294. <td><input name='labels' id="labels_value"
  295. placeholder='Alpha, Beta, Gamma' value="">
  296. </td></tr>
  297. <tr><td>
  298. <div class="autocomplete" id="labels_choices"
  299. style="display : block"></div></td></tr>
  300. <script type='text/javascript'>document.forms[0].title.focus();</script>
  301. <script type='text/javascript'>
  302. new Ajax.Autocompleter('labels_value', 'labels_choices',
  303. "backend.php?op=rpc&method=completeLabels",
  304. { tokens: ',', paramName: "search" });
  305. </script>
  306. <tr><td colspan='2'>
  307. <div style='float : right' class='insensitive-small'>
  308. <?php echo __("Shared article will appear in the Published feed.") ?>
  309. </div>
  310. <button type="submit"><?php echo __('Share') ?></button>
  311. <button onclick="return window.close()"><?php echo __('Cancel') ?></button>
  312. </div>
  313. </form>
  314. </td></tr></table>
  315. </body></html>
  316. <?php
  317. }
  318. } else {
  319. $return = urlencode($_SERVER["REQUEST_URI"])
  320. ?>
  321. <form action="public.php?return=<?php echo $return ?>"
  322. method="POST" id="loginForm" name="loginForm">
  323. <input type="hidden" name="op" value="login">
  324. <table height='100%' width='100%'><tr><td colspan='2'>
  325. <h1><?php echo __("Not logged in") ?></h1></td></tr>
  326. <tr><td align="right"><?php echo __("Login:") ?></td>
  327. <td align="right"><input name="login"
  328. value="<?php echo $_SESSION["fake_login"] ?>"></td></tr>
  329. <tr><td align="right"><?php echo __("Password:") ?></td>
  330. <td align="right"><input type="password" name="password"
  331. value="<?php echo $_SESSION["fake_password"] ?>"></td></tr>
  332. <tr><td align="right"><?php echo __("Language:") ?></td>
  333. <td align="right">
  334. <?php
  335. print_select_hash("language", $_COOKIE["ttrss_lang"], get_translations(),
  336. "style='width : 100%''");
  337. ?>
  338. </td></tr>
  339. <tr><td colspan='2'>
  340. <button type="submit">
  341. <?php echo __('Log in') ?></button>
  342. <button onclick="return window.close()">
  343. <?php echo __('Cancel') ?></button>
  344. </td></tr>
  345. </table>
  346. </form>
  347. <?php
  348. }
  349. }
  350. function login() {
  351. $_SESSION["prefs_cache"] = array();
  352. if (!SINGLE_USER_MODE) {
  353. $login = db_escape_string($this->link, $_POST["login"]);
  354. $password = $_POST["password"];
  355. $remember_me = $_POST["remember_me"];
  356. if (authenticate_user($this->link, $login, $password)) {
  357. $_POST["password"] = "";
  358. $_SESSION["language"] = $_POST["language"];
  359. $_SESSION["ref_schema_version"] = get_schema_version($this->link, true);
  360. $_SESSION["bw_limit"] = !!$_POST["bw_limit"];
  361. if ($_POST["profile"]) {
  362. $profile = db_escape_string($this->link, $_POST["profile"]);
  363. $result = db_query($this->link, "SELECT id FROM ttrss_settings_profiles
  364. WHERE id = '$profile' AND owner_uid = " . $_SESSION["uid"]);
  365. if (db_num_rows($result) != 0) {
  366. $_SESSION["profile"] = $profile;
  367. $_SESSION["prefs_cache"] = array();
  368. }
  369. }
  370. } else {
  371. $_SESSION["login_error_msg"] = __("Incorrect username or password");
  372. }
  373. if ($_REQUEST['return']) {
  374. header("Location: " . $_REQUEST['return']);
  375. } else {
  376. header("Location: " . SELF_URL_PATH);
  377. }
  378. }
  379. }
  380. function subscribe() {
  381. if (SINGLE_USER_MODE) {
  382. login_sequence($this->link);
  383. }
  384. if ($_SESSION["uid"]) {
  385. $feed_url = db_escape_string($this->link, trim($_REQUEST["feed_url"]));
  386. header('Content-Type: text/html; charset=utf-8');
  387. print "<html>
  388. <head>
  389. <title>Tiny Tiny RSS</title>
  390. <link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\">
  391. <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>
  392. </head>
  393. <body>
  394. <img class=\"floatingLogo\" src=\"images/logo_wide.png\"
  395. alt=\"Tiny Tiny RSS\"/>
  396. <h1>".__("Subscribe to feed...")."</h1>";
  397. $rc = subscribe_to_feed($this->link, $feed_url);
  398. switch ($rc['code']) {
  399. case 0:
  400. print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
  401. break;
  402. case 1:
  403. print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
  404. break;
  405. case 2:
  406. print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
  407. break;
  408. case 3:
  409. print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
  410. break;
  411. case 4:
  412. print_notice(__("Multiple feed URLs found."));
  413. $feed_urls = $rc["feeds"];
  414. break;
  415. case 5:
  416. print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
  417. break;
  418. }
  419. if ($feed_urls) {
  420. print "<form action=\"public.php\">";
  421. print "<input type=\"hidden\" name=\"op\" value=\"subscribe\">";
  422. print "<select name=\"feed_url\">";
  423. foreach ($feed_urls as $url => $name) {
  424. $url = htmlspecialchars($url);
  425. $name = htmlspecialchars($name);
  426. print "<option value=\"$url\">$name</option>";
  427. }
  428. print "<input type=\"submit\" value=\"".__("Subscribe to selected feed").
  429. "\">";
  430. print "</form>";
  431. }
  432. $tp_uri = get_self_url_prefix() . "/prefs.php";
  433. $tt_uri = get_self_url_prefix();
  434. if ($rc['code'] <= 2){
  435. $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE
  436. feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
  437. $feed_id = db_fetch_result($result, 0, "id");
  438. } else {
  439. $feed_id = 0;
  440. }
  441. print "<p>";
  442. if ($feed_id) {
  443. print "<form method=\"GET\" style='display: inline'
  444. action=\"$tp_uri\">
  445. <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
  446. <input type=\"hidden\" name=\"method\" value=\"editFeed\">
  447. <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
  448. <input type=\"submit\" value=\"".__("Edit subscription options")."\">
  449. </form>";
  450. }
  451. print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
  452. <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
  453. </form></p>";
  454. print "</body></html>";
  455. } else {
  456. render_login_form($this->link);
  457. }
  458. }
  459. function subscribe2() {
  460. $feed_url = db_escape_string($this->link, trim($_REQUEST["feed_url"]));
  461. $cat_id = db_escape_string($this->link, $_REQUEST["cat_id"]);
  462. $from = db_escape_string($this->link, $_REQUEST["from"]);
  463. /* only read authentication information from POST */
  464. $auth_login = db_escape_string($this->link, trim($_POST["auth_login"]));
  465. $auth_pass = db_escape_string($this->link, trim($_POST["auth_pass"]));
  466. $rc = subscribe_to_feed($this->link, $feed_url, $cat_id, $auth_login, $auth_pass);
  467. switch ($rc) {
  468. case 1:
  469. print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url));
  470. break;
  471. case 2:
  472. print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url));
  473. break;
  474. case 3:
  475. print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url));
  476. break;
  477. case 0:
  478. print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url));
  479. break;
  480. case 4:
  481. print_notice(__("Multiple feed URLs found."));
  482. $feed_urls = get_feeds_from_html($feed_url);
  483. break;
  484. case 5:
  485. print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url));
  486. break;
  487. }
  488. if ($feed_urls) {
  489. print "<form action=\"backend.php\">";
  490. print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">";
  491. print "<input type=\"hidden\" name=\"quiet\" value=\"1\">";
  492. print "<input type=\"hidden\" name=\"method\" value=\"add\">";
  493. print "<select name=\"feed_url\">";
  494. foreach ($feed_urls as $url => $name) {
  495. $url = htmlspecialchars($url);
  496. $name = htmlspecialchars($name);
  497. print "<option value=\"$url\">$name</option>";
  498. }
  499. print "<input type=\"submit\" value=\"".__("Subscribe to selected feed")."\">";
  500. print "</form>";
  501. }
  502. $tp_uri = get_self_url_prefix() . "/prefs.php";
  503. $tt_uri = get_self_url_prefix();
  504. if ($rc <= 2){
  505. $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE
  506. feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]);
  507. $feed_id = db_fetch_result($result, 0, "id");
  508. } else {
  509. $feed_id = 0;
  510. }
  511. print "<p>";
  512. if ($feed_id) {
  513. print "<form method=\"GET\" style='display: inline'
  514. action=\"$tp_uri\">
  515. <input type=\"hidden\" name=\"tab\" value=\"feedConfig\">
  516. <input type=\"hidden\" name=\"method\" value=\"editFeed\">
  517. <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\">
  518. <input type=\"submit\" value=\"".__("Edit subscription options")."\">
  519. </form>";
  520. }
  521. print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\">
  522. <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\">
  523. </form></p>";
  524. print "</body></html>";
  525. }
  526. function index() {
  527. header("Content-Type: text/plain");
  528. print json_encode(array("error" => array("code" => 7)));
  529. }
  530. }
  531. ?>