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