3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * @package OStatusPlugin
22 * @maintainer James Walker <james@status.net>
25 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
28 class OStatusInitAction extends Action
35 function prepare($args)
37 parent::prepare($args);
39 if (common_logged_in()) {
40 $this->clientError(_('You can use the local subscription!'));
44 $this->nickname = $this->trimmed('nickname');
45 $this->acct = $this->trimmed('acct');
50 function handle($args)
52 parent::handle($args);
54 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
55 /* Use a session token for CSRF protection. */
56 $token = $this->trimmed('token');
57 if (!$token || $token != common_session_token()) {
58 $this->showForm(_('There was a problem with your session token. '.
59 'Try again, please.'));
62 $this->ostatusConnect();
68 function showForm($err = null)
75 function showContent()
77 $this->elementStart('form', array('id' => 'form_ostatus_connect',
79 'class' => 'form_settings',
80 'action' => common_local_url('ostatusinit')));
81 $this->elementStart('fieldset');
82 $this->element('legend', _('Subscribe to a remote user'));
83 $this->hidden('token', common_session_token());
85 $this->elementStart('ul', 'form_data');
86 $this->elementStart('li');
87 $this->input('nickname', _('User nickname'), $this->nickname,
88 _('Nickname of the user you want to follow'));
89 $this->elementEnd('li');
90 $this->elementStart('li');
91 $this->input('acct', _('Profile Account'), $this->acct,
92 _('Your account id (i.e. user@identi.ca)'));
93 $this->elementEnd('li');
94 $this->elementEnd('ul');
95 $this->submit('submit', _('Subscribe'));
96 $this->elementEnd('fieldset');
97 $this->elementEnd('form');
100 function ostatusConnect()
104 $result = $w->lookup($this->acct);
105 foreach ($result->links as $link) {
106 if ($link['rel'] == 'http://ostatus.org/schema/1.0/subscribe') {
107 // We found a URL - let's redirect!
109 $user = User::staticGet('nickname', $this->nickname);
111 $feed_url = common_local_url('ApiTimelineUser',
112 array('id' => $user->id,
113 'format' => 'atom'));
114 $url = $w->applyTemplate($link['template'], $feed_url);
116 common_redirect($url, 303);
125 return _('OStatus Connect');