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