]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OStatus/actions/ostatusgroup.php
OStatusSub should use inherent attributes
[quix0rs-gnu-social.git] / plugins / OStatus / actions / ostatusgroup.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2009-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 Brion Vibber <brion@status.net>
23  */
24
25 if (!defined('STATUSNET')) {
26     exit(1);
27 }
28
29 /**
30  * Key UI methods:
31  *
32  *  showInputForm() - form asking for a remote profile account or URL
33  *                    We end up back here on errors
34  *
35  *  showPreviewForm() - surrounding form for preview-and-confirm
36  *    preview() - display profile for a remote group
37  *
38  *  success() - redirects to groups page on join
39  */
40 class OStatusGroupAction extends OStatusSubAction
41 {
42     protected $profile_uri; // provided acct: or URI of remote entity
43     protected $oprofile; // Ostatus_profile of remote entity, if valid
44
45
46     function validateRemoteProfile()
47     {
48         if (!$this->oprofile->isGroup()) {
49             // Send us to the user subscription form for conf
50             $target = common_local_url('ostatussub', array(), array('profile' => $this->profile_uri));
51             common_redirect($target, 303);
52         }
53     }
54
55     /**
56      * Show the initial form, when we haven't yet been given a valid
57      * remote profile.
58      */
59     function showInputForm()
60     {
61         $this->elementStart('form', array('method' => 'post',
62                                           'id' => 'form_ostatus_sub',
63                                           'class' => 'form_settings',
64                                           'action' => $this->selfLink()));
65
66         $this->hidden('token', common_session_token());
67
68         $this->elementStart('fieldset', array('id' => 'settings_feeds'));
69
70         $this->elementStart('ul', 'form_data');
71         $this->elementStart('li');
72         $this->input('profile',
73                      // TRANS: Field label.
74                      _m('Join group'),
75                      $this->profile_uri,
76                      // TRANS: Tooltip for field label "Join group". Do not translate the "example.net"
77                      // TRANS: domain name in the URL, as it is an official standard domain name for examples.
78                      _m("OStatus group's address, like http://example.net/group/nickname."));
79         $this->elementEnd('li');
80         $this->elementEnd('ul');
81
82         // TRANS: Button text.
83         $this->submit('validate', _m('BUTTON','Continue'));
84
85         $this->elementEnd('fieldset');
86
87         $this->elementEnd('form');
88     }
89
90     /**
91      * Show a preview for a remote group's profile
92      * @return boolean true if we're ok to try joining
93      */
94     function preview()
95     {
96         $group = $this->oprofile->localGroup();
97
98         if ($this->scoped->isMember($group)) {
99             $this->element('div', array('class' => 'error'),
100                            // TRANS: Error text displayed when trying to join a remote group the user is already a member of.
101                            _m('You are already a member of this group.'));
102             $ok = false;
103         } else {
104             $ok = true;
105         }
106
107         $this->showEntity($group,
108                           $group->homeUrl(),
109                           $group->homepage_logo,
110                           $group->description);
111         return $ok;
112     }
113
114     /**
115      * Redirect on successful remote group join
116      */
117     function success()
118     {
119         $url = common_local_url('usergroups', array('nickname' => $this->scoped->getNickname()));
120         common_redirect($url, 303);
121     }
122
123     /**
124      * Attempt to finalize subscription.
125      * validateFeed must have been run first.
126      *
127      * Calls showForm on failure or success on success.
128      */
129     function saveFeed()
130     {
131         $group = $this->oprofile->localGroup();
132         if ($this->scoped->isMember($group)) {
133             // TRANS: OStatus remote group subscription dialog error.
134             $this->showForm(_m('Already a member!'));
135             return;
136         }
137
138         try {
139             $this->scoped->joinGroup($group);
140         } catch (Exception $e) {
141             common_log(LOG_ERR, "Exception on remote group join: " . $e->getMessage());
142             common_log(LOG_ERR, $e->getTraceAsString());
143             // TRANS: OStatus remote group subscription dialog error.
144             $this->showForm(_m('Remote group join failed!'));
145             return;
146         }
147
148         $this->success();
149     }
150
151     /**
152      * Title of the page
153      *
154      * @return string Title of the page
155      */
156     function title()
157     {
158         // TRANS: Page title for OStatus remote group join form
159         return _m('Confirm joining remote group');
160     }
161
162     /**
163      * Instructions for use
164      *
165      * @return instructions for use
166      */
167     function getInstructions()
168     {
169         // TRANS: Form instructions.
170         return _m('You can subscribe to groups from other supported sites. Paste the group\'s profile URI below:');
171     }
172
173     function selfLink()
174     {
175         return common_local_url('ostatusgroup');
176     }
177 }