]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OStatus/actions/ostatuspeopletag.php
People tags -> Lists (only UI changes, for experimentation)
[quix0rs-gnu-social.git] / plugins / OStatus / actions / ostatuspeopletag.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') && !defined('LACONICA')) { exit(1); }
26
27 require_once INSTALLDIR . '/lib/peopletaglist.php';
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 OStatusPeopletagAction 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->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);
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                      _m('Subscribe to people tag'),
74                      $this->profile_uri,
75                      _m("Address of the OStatus people tag, like http://example.net/user/all/tag"));
76         $this->elementEnd('li');
77         $this->elementEnd('ul');
78
79         $this->submit('validate', _m('Continue'));
80
81         $this->elementEnd('fieldset');
82
83         $this->elementEnd('form');
84     }
85
86     /**
87      * Show a preview for a remote peopletag's profile
88      * @return boolean true if we're ok to try joining
89      */
90     function preview()
91     {
92         $oprofile = $this->oprofile;
93         $ptag = $oprofile->localPeopletag();
94
95         $cur = common_current_user();
96         if ($ptag->hasSubscriber($cur->id)) {
97             $this->element('div', array('class' => 'error'),
98                            _m('You are already subscribed to this people tag.'));
99             $ok = false;
100         } else {
101             $ok = true;
102         }
103
104         $this->showEntity($ptag);
105         return $ok;
106     }
107
108     function showEntity($ptag)
109     {
110         $this->elementStart('div', 'peopletag');
111         $widget = new PeopletagListItem($ptag, common_current_user(), $this);
112         $widget->showCreator();
113         $widget->showTag();
114         $widget->showDescription();
115         $this->elementEnd('div');
116     }
117
118     /**
119      * Redirect on successful remote people tag subscription
120      */
121     function success()
122     {
123         $cur = common_current_user();
124         $url = common_local_url('peopletagsubscriptions', array('nickname' => $cur->nickname));
125         common_redirect($url, 303);
126     }
127
128     /**
129      * Attempt to finalize subscription.
130      * validateFeed must have been run first.
131      *
132      * Calls showForm on failure or success on success.
133      */
134     function saveFeed()
135     {
136         $user = common_current_user();
137         $ptag = $this->oprofile->localPeopletag();
138         if ($ptag->hasSubscriber($user->id)) {
139             // TRANS: OStatus remote group subscription dialog error.
140             $this->showForm(_m('Already subscribed!'));
141             return;
142         }
143
144         try {
145             Profile_tag_subscription::add($ptag, $user);
146             $this->success();
147         } catch (Exception $e) {
148             $this->showForm($e->getMessage());
149         }
150     }
151
152     /**
153      * Title of the page
154      *
155      * @return string Title of the page
156      */
157
158     function title()
159     {
160         // TRANS: Page title for OStatus remote people tag subscription form
161         return _m('Confirm subscription to remote people tag');
162     }
163
164     /**
165      * Instructions for use
166      *
167      * @return instructions for use
168      */
169
170     function getInstructions()
171     {
172         return _m('You can subscribe to lists from other supported sites. Paste the lists\'s URI below:');
173     }
174
175     function selfLink()
176     {
177         return common_local_url('ostatuspeopletag');
178     }
179 }