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
35 function prepare($args)
37 parent::prepare($args);
39 if (common_logged_in()) {
40 $this->clientError(_m('You can use the local tagging!'));
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 $header = sprintf(_m('Tag %s'), $this->nickname);
56 $this->elementStart('form', array('id' => 'form_ostatus_connect',
58 'class' => 'form_settings',
59 'action' => common_local_url('ostatustag')));
60 $this->elementStart('fieldset');
61 $this->element('legend', null, $header);
62 $this->hidden('token', common_session_token());
64 $this->elementStart('ul', 'form_data');
65 $this->elementStart('li', array('id' => 'ostatus_nickname'));
66 $this->input('nickname', _m('User nickname'), $this->nickname,
67 _m('Nickname of the user you want to tag'));
68 $this->elementEnd('li');
69 $this->elementStart('li', array('id' => 'ostatus_profile'));
70 $this->input('profile', _m('Profile Account'), $this->profile,
71 _m('Your account id (i.e. user@identi.ca)'));
72 $this->elementEnd('li');
73 $this->elementEnd('ul');
74 $this->submit('submit', $submit);
75 $this->elementEnd('fieldset');
76 $this->elementEnd('form');
79 function connectWebfinger($acct)
81 $target_profile = $this->targetProfile();
83 $disco = new Discovery;
84 $result = $disco->lookup($acct);
86 $this->clientError(_m('Could not look up OStatus account profile.'));
89 foreach ($result->links as $link) {
90 if ($link['rel'] == 'http://ostatus.org/schema/1.0/tag') {
91 // We found a URL - let's redirect!
92 $url = Discovery::applyTemplate($link['template'], $target_profile);
93 common_log(LOG_INFO, "Sending remote subscriber $acct to $url");
94 common_redirect($url, 303);
98 $this->clientError(_m('Could not confirm remote profile address.'));
101 function connectProfile($subscriber_profile)
103 $target_profile = $this->targetProfile();
105 // @fixme hack hack! We should look up the remote sub URL from XRDS
106 $suburl = preg_replace('!^(.*)/(.*?)$!', '$1/main/tagprofile', $subscriber_profile);
107 $suburl .= '?uri=' . urlencode($target_profile);
109 common_log(LOG_INFO, "Sending remote subscriber $subscriber_profile to $suburl");
110 common_redirect($suburl, 303);
115 return _m('OStatus list');