3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2009-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 Brion Vibber <brion@status.net>
25 if (!defined('STATUSNET')) {
32 * showInputForm() - form asking for a remote profile account or URL
33 * We end up back here on errors
35 * showPreviewForm() - surrounding form for preview-and-confirm
36 * preview() - display profile for a remote group
38 * success() - redirects to groups page on join
40 class OStatusGroupAction extends OStatusSubAction
42 protected $profile_uri; // provided acct: or URI of remote entity
43 protected $oprofile; // Ostatus_profile of remote entity, if valid
46 function validateRemoteProfile()
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);
56 * Show the initial form, when we haven't yet been given a valid
59 function showInputForm()
61 $user = common_current_user();
63 $profile = $user->getProfile();
65 $this->elementStart('form', array('method' => 'post',
66 'id' => 'form_ostatus_sub',
67 'class' => 'form_settings',
68 'action' => $this->selfLink()));
70 $this->hidden('token', common_session_token());
72 $this->elementStart('fieldset', array('id' => 'settings_feeds'));
74 $this->elementStart('ul', 'form_data');
75 $this->elementStart('li');
76 $this->input('profile',
77 // TRANS: Field label.
80 // TRANS: Tooltip for field label "Join group".
81 _m("OStatus group's address, like http://example.net/group/nickname."));
82 $this->elementEnd('li');
83 $this->elementEnd('ul');
85 // TRANS: Button text.
86 $this->submit('validate', _m('BUTTON','Continue'));
88 $this->elementEnd('fieldset');
90 $this->elementEnd('form');
94 * Show a preview for a remote group's profile
95 * @return boolean true if we're ok to try joining
99 $oprofile = $this->oprofile;
100 $group = $oprofile->localGroup();
102 $cur = common_current_user();
103 if ($cur->isMember($group)) {
104 $this->element('div', array('class' => 'error'),
105 _m("You are already a member of this group."));
111 $this->showEntity($group,
113 $group->homepage_logo,
114 $group->description);
119 * Redirect on successful remote group join
123 $cur = common_current_user();
124 $url = common_local_url('usergroups', array('nickname' => $cur->nickname));
125 common_redirect($url, 303);
129 * Attempt to finalize subscription.
130 * validateFeed must have been run first.
132 * Calls showForm on failure or success on success.
136 $user = common_current_user();
137 $group = $this->oprofile->localGroup();
138 if ($user->isMember($group)) {
139 // TRANS: OStatus remote group subscription dialog error.
140 $this->showForm(_m('Already a member!'));
144 if (Event::handle('StartJoinGroup', array($group, $user))) {
145 $ok = Group_member::join($this->oprofile->group_id, $user->id);
147 Event::handle('EndJoinGroup', array($group, $user));
150 // TRANS: OStatus remote group subscription dialog error.
151 $this->showForm(_m('Remote group join failed!'));
154 // TRANS: OStatus remote group subscription dialog error.
155 $this->showForm(_m('Remote group join aborted!'));
162 * @return string Title of the page
166 // TRANS: Page title for OStatus remote group join form
167 return _m('Confirm joining remote group');
171 * Instructions for use
173 * @return instructions for use
175 function getInstructions()
177 // TRANS: Instructions.
178 return _m('You can subscribe to groups from other supported sites. Paste the group\'s profile URI below:');
183 return common_local_url('ostatusgroup');