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)
71 if ($this->boolean('ajax')) {
72 header('Content-Type: text/xml;charset=utf-8');
73 $this->xw->startDocument('1.0', 'UTF-8');
74 $this->elementStart('html');
75 $this->elementStart('head');
76 $this->element('title', null, _('Subscribe to user'));
77 $this->elementEnd('head');
78 $this->elementStart('body');
80 $this->elementEnd('body');
81 $this->elementEnd('html');
87 function showContent()
89 $this->elementStart('form', array('id' => 'form_ostatus_connect',
91 'class' => 'form_settings',
92 'action' => common_local_url('ostatusinit')));
93 $this->elementStart('fieldset');
94 $this->element('legend', null, sprintf(_('Subscribe to %s'), $this->nickname));
95 $this->hidden('token', common_session_token());
97 $this->elementStart('ul', 'form_data');
98 $this->elementStart('li', array('id' => 'ostatus_nickname'));
99 $this->input('nickname', _('User nickname'), $this->nickname,
100 _('Nickname of the user you want to follow'));
101 $this->elementEnd('li');
102 $this->elementStart('li', array('id' => 'ostatus_profile'));
103 $this->input('acct', _('Profile Account'), $this->acct,
104 _('Your account id (i.e. user@identi.ca)'));
105 $this->elementEnd('li');
106 $this->elementEnd('ul');
107 $this->submit('submit', _('Subscribe'));
108 $this->elementEnd('fieldset');
109 $this->elementEnd('form');
112 function ostatusConnect()
116 $result = $w->lookup($this->acct);
117 foreach ($result->links as $link) {
118 if ($link['rel'] == 'http://ostatus.org/schema/1.0/subscribe') {
119 // We found a URL - let's redirect!
121 $user = User::staticGet('nickname', $this->nickname);
123 $feed_url = common_local_url('ApiTimelineUser',
124 array('id' => $user->id,
125 'format' => 'atom'));
126 $url = $w->applyTemplate($link['template'], $feed_url);
128 common_redirect($url, 303);
137 return _('OStatus Connect');