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(array $args=array())
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!'));
43 $this->nickname = $this->trimmed('nickname');
45 // Webfinger or profile URL of the remote user
46 $this->profile = $this->trimmed('profile');
51 function showContent()
53 // TRANS: Header for listing a remote object. %s is a remote object's name.
54 $header = sprintf(_m('List %s'), $this->nickname);
55 // TRANS: Button text to list a remote object.
56 $submit = _m('BUTTON','Go');
57 $this->elementStart('form', array('id' => 'form_ostatus_connect',
59 'class' => 'form_settings',
60 'action' => common_local_url('ostatustag')));
61 $this->elementStart('fieldset');
62 $this->element('legend', null, $header);
63 $this->hidden('token', common_session_token());
65 $this->elementStart('ul', 'form_data');
66 $this->elementStart('li', array('id' => 'ostatus_nickname'));
67 // TRANS: Field label.
68 $this->input('nickname', _m('User nickname'), $this->nickname,
69 // TRANS: Field title.
70 _m('Nickname of the user you want to list.'));
71 $this->elementEnd('li');
72 $this->elementStart('li', array('id' => 'ostatus_profile'));
73 // TRANS: Field label.
74 $this->input('profile', _m('Profile Account'), $this->profile,
75 // TRANS: Field title.
76 _m('Your account id (for example user@example.com).'));
77 $this->elementEnd('li');
78 $this->elementEnd('ul');
79 $this->submit('submit', $submit);
80 $this->elementEnd('fieldset');
81 $this->elementEnd('form');
84 function connectWebfinger($acct)
86 $target_profile = $this->targetProfile();
88 $disco = new Discovery;
89 $xrd = $disco->lookup($acct);
91 $link = $xrd->get('http://ostatus.org/schema/1.0/tag');
92 if (!is_null($link)) {
93 // We found a URL - let's redirect!
94 if (!empty($link->template)) {
95 $url = Discovery::applyTemplate($link->template, $target_profile);
99 common_log(LOG_INFO, "Sending remote subscriber $acct to $url");
100 common_redirect($url, 303);
102 // TRANS: Client error displayed when remote profile address could not be confirmed.
103 $this->clientError(_m('Could not confirm remote profile address.'));
106 function connectProfile($subscriber_profile)
108 $target_profile = $this->targetProfile();
110 // @fixme hack hack! We should look up the remote sub URL from XRDS
111 $suburl = preg_replace('!^(.*)/(.*?)$!', '$1/main/tagprofile', $subscriber_profile);
112 $suburl .= '?uri=' . urlencode($target_profile);
114 common_log(LOG_INFO, "Sending remote subscriber $subscriber_profile to $suburl");
115 common_redirect($suburl, 303);
120 // TRANS: Title for an OStatus list.
121 return _m('OStatus list');