]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OStatus/actions/ostatustag.php
b94dec12ebffa14e0cd0d20e943d2939356aaeca
[quix0rs-gnu-social.git] / plugins / OStatus / actions / ostatustag.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2010, StatusNet, Inc.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 /**
21  * @package OStatusPlugin
22  * @maintainer James Walker <james@status.net>
23  */
24
25 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
26
27
28 class OStatusTagAction extends OStatusInitAction
29 {
30     var $nickname;
31     var $profile;
32     var $err;
33
34     function prepare($args)
35     {
36         parent::prepare($args);
37
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!'));
41             return false;
42         }
43
44         $this->nickname = $this->trimmed('nickname');
45
46         // Webfinger or profile URL of the remote user
47         $this->profile = $this->trimmed('profile');
48
49         return true;
50     }
51
52     function showContent()
53     {
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',
59                                           'method' => 'post',
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());
65
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');
83     }
84
85     function connectWebfinger($acct)
86     {
87         $target_profile = $this->targetProfile();
88
89         $disco = new Discovery;
90         $result = $disco->lookup($acct);
91         if (!$result) {
92             // TRANS: Client error displayed when remote profile could not be looked up.
93             $this->clientError(_m('Could not look up OStatus account profile.'));
94         }
95
96         foreach ($result->links as $link) {
97             if ($link['rel'] == 'http://ostatus.org/schema/1.0/tag') {
98                 // We found a URL - let's redirect!
99                 $url = Discovery::applyTemplate($link['template'], $target_profile);
100                 common_log(LOG_INFO, "Sending remote subscriber $acct to $url");
101                 common_redirect($url, 303);
102             }
103
104         }
105         // TRANS: Client error displayed when remote profile address could not be confirmed.
106         $this->clientError(_m('Could not confirm remote profile address.'));
107     }
108
109     function connectProfile($subscriber_profile)
110     {
111         $target_profile = $this->targetProfile();
112
113         // @fixme hack hack! We should look up the remote sub URL from XRDS
114         $suburl = preg_replace('!^(.*)/(.*?)$!', '$1/main/tagprofile', $subscriber_profile);
115         $suburl .= '?uri=' . urlencode($target_profile);
116
117         common_log(LOG_INFO, "Sending remote subscriber $subscriber_profile to $suburl");
118         common_redirect($suburl, 303);
119     }
120
121     function title()
122     {
123       // TRANS: Title for an OStatus list.
124       return _m('OStatus list');  
125     }
126 }