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 OStatusTagAction extends OStatusInitAction
34 function prepare($args)
36 parent::prepare($args);
38 if (common_logged_in()) {
39 // TRANS: Client error displayed when trying to list a local object as if it is remote.
40 $this->clientError(_m('You can use the local list functionality!'));
44 $this->nickname = $this->trimmed('nickname');
46 // Webfinger or profile URL of the remote user
47 $this->profile = $this->trimmed('profile');
52 function showContent()
54 // TRANS: Header for listing a remote object. %s is a remote object's name.
55 $header = sprintf(_m('List %s'), $this->nickname);
56 // TRANS: Button text to list a remote object.
57 $submit = _m('BUTTON','Go');
58 $this->elementStart('form', array('id' => 'form_ostatus_connect',
60 'class' => 'form_settings',
61 'action' => common_local_url('ostatustag')));
62 $this->elementStart('fieldset');
63 $this->element('legend', null, $header);
64 $this->hidden('token', common_session_token());
66 $this->elementStart('ul', 'form_data');
67 $this->elementStart('li', array('id' => 'ostatus_nickname'));
68 // TRANS: Field label.
69 $this->input('nickname', _m('User nickname'), $this->nickname,
70 // TRANS: Field title.
71 _m('Nickname of the user you want to list.'));
72 $this->elementEnd('li');
73 $this->elementStart('li', array('id' => 'ostatus_profile'));
74 // TRANS: Field label.
75 $this->input('profile', _m('Profile Account'), $this->profile,
76 // TRANS: Field title.
77 _m('Your account id (for example user@identi.ca).'));
78 $this->elementEnd('li');
79 $this->elementEnd('ul');
80 $this->submit('submit', $submit);
81 $this->elementEnd('fieldset');
82 $this->elementEnd('form');
85 function connectWebfinger($acct)
87 $target_profile = $this->targetProfile();
89 $disco = new Discovery;
90 $xrd = $disco->lookup($acct);
92 $link = $xrd->get('http://ostatus.org/schema/1.0/tag');
93 if (!is_null($link)) {
94 // We found a URL - let's redirect!
95 $url = Discovery::applyTemplate($link->template, $target_profile);
96 common_log(LOG_INFO, "Sending remote subscriber $acct to $url");
97 common_redirect($url, 303);
99 // TRANS: Client error displayed when remote profile address could not be confirmed.
100 $this->clientError(_m('Could not confirm remote profile address.'));
103 function connectProfile($subscriber_profile)
105 $target_profile = $this->targetProfile();
107 // @fixme hack hack! We should look up the remote sub URL from XRDS
108 $suburl = preg_replace('!^(.*)/(.*?)$!', '$1/main/tagprofile', $subscriber_profile);
109 $suburl .= '?uri=' . urlencode($target_profile);
111 common_log(LOG_INFO, "Sending remote subscriber $subscriber_profile to $suburl");
112 common_redirect($suburl, 303);
117 // TRANS: Title for an OStatus list.
118 return _m('OStatus list');