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