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') && !defined('LACONICA')) { exit(1); }
27 require_once INSTALLDIR . '/lib/peopletaglist.php';
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 OStatusPeopletagAction 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->isPeopletag()) {
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 $this->elementStart('form', array('method' => 'post',
62 'id' => 'form_ostatus_sub',
63 'class' => 'form_settings',
64 'action' => $this->selfLink()));
66 $this->hidden('token', common_session_token());
68 $this->elementStart('fieldset', array('id' => 'settings_feeds'));
70 $this->elementStart('ul', 'form_data');
71 $this->elementStart('li');
72 $this->input('profile',
73 // TRANS: Field label.
74 _m('Subscribe to list'),
76 // TRANS: Field title.
77 _m("Address of the OStatus list, like http://example.net/user/all/tag."));
78 $this->elementEnd('li');
79 $this->elementEnd('ul');
81 // TRANS: Button text to continue joining a remote list.
82 $this->submit('validate', _m('BUTTON','Continue'));
84 $this->elementEnd('fieldset');
86 $this->elementEnd('form');
90 * Show a preview for a remote peopletag's profile
91 * @return boolean true if we're ok to try joining
95 $oprofile = $this->oprofile;
96 $ptag = $oprofile->localPeopletag();
98 $cur = common_current_user();
99 if ($ptag->hasSubscriber($cur->id)) {
100 $this->element('div', array('class' => 'error'),
101 // TRANS: Error text displayed when trying to subscribe to a list already a subscriber to.
102 _m('You are already subscribed to this list.'));
108 $this->showEntity($ptag);
112 function showEntity($ptag)
114 $this->elementStart('div', 'peopletag');
115 $widget = new PeopletagListItem($ptag, common_current_user(), $this);
116 $widget->showCreator();
118 $widget->showDescription();
119 $this->elementEnd('div');
123 * Redirect on successful remote people tag subscription
127 $cur = common_current_user();
128 $url = common_local_url('peopletagsubscriptions', array('nickname' => $cur->nickname));
129 common_redirect($url, 303);
133 * Attempt to finalize subscription.
134 * validateFeed must have been run first.
136 * Calls showForm on failure or success on success.
140 $user = common_current_user();
141 $ptag = $this->oprofile->localPeopletag();
142 if ($ptag->hasSubscriber($user->id)) {
143 // TRANS: OStatus remote group subscription dialog error.
144 $this->showForm(_m('Already subscribed!'));
149 Profile_tag_subscription::add($ptag, $user);
151 } catch (Exception $e) {
152 $this->showForm($e->getMessage());
159 * @return string Title of the page
164 // TRANS: Page title for OStatus remote list subscription form
165 return _m('Confirm subscription to remote list');
169 * Instructions for use
171 * @return instructions for use
174 function getInstructions()
176 // TRANS: Instructions for OStatus list subscription form.
177 return _m('You can subscribe to lists from other supported sites. Paste the list\'s URI below:');
182 return common_local_url('ostatuspeopletag');