]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/cancelsubscription.php
590fde9f2ef309c5192a8a073b23637aec7466af
[quix0rs-gnu-social.git] / actions / cancelsubscription.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Leave a group
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Group
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @copyright 2008-2009 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 /**
35  * Leave a group
36  *
37  * This is the action for leaving a group. It works more or less like the subscribe action
38  * for users.
39  *
40  * @category Group
41  * @package  StatusNet
42  * @author   Evan Prodromou <evan@status.net>
43  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44  * @link     http://status.net/
45  */
46 class CancelsubscriptionAction extends Action
47 {
48
49     function handle($args)
50     {
51         parent::handle($args);
52         if ($this->boolean('ajax')) {
53             StatusNet::setApi(true);
54         }
55         if (!common_logged_in()) {
56             // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
57             $this->clientError(_('Not logged in.'));
58             return;
59         }
60
61         $user = common_current_user();
62
63         if ($_SERVER['REQUEST_METHOD'] != 'POST') {
64             common_redirect(common_local_url('subscriptions',
65                                              array('nickname' => $user->nickname)));
66             return;
67         }
68
69         /* Use a session token for CSRF protection. */
70
71         $token = $this->trimmed('token');
72
73         if (!$token || $token != common_session_token()) {
74             // TRANS: Client error displayed when the session token does not match or is not given.
75             $this->clientError(_('There was a problem with your session token. ' .
76                                  'Try again, please.'));
77             return;
78         }
79
80         $other_id = $this->arg('unsubscribeto');
81
82         if (!$other_id) {
83             // TRANS: Client error displayed when trying to leave a group without specifying an ID.
84             $this->clientError(_('No profile ID in request.'));
85             return;
86         }
87
88         $other = Profile::getKV('id', $other_id);
89
90         if (!$other) {
91             // TRANS: Client error displayed when trying to leave a non-existing group.
92             $this->clientError(_('No profile with that ID.'));
93             return;
94         }
95
96         $this->request = Subscription_queue::pkeyGet(array('subscriber' => $user->id,
97                                                            'subscribed' => $other->id));
98
99         if (empty($this->request)) {
100             // TRANS: Client error displayed when trying to approve a non-existing group join request.
101             // TRANS: %s is a user nickname.
102             $this->clientError(sprintf(_('%s is not in the moderation queue for this group.'), $this->profile->nickname), 403);
103         }
104
105         $this->request->abort();
106
107         if ($this->boolean('ajax')) {
108             $this->startHTML('text/xml;charset=utf-8');
109             $this->elementStart('head');
110             // TRANS: Title after unsubscribing from a group.
111             $this->element('title', null, _m('TITLE','Unsubscribed'));
112             $this->elementEnd('head');
113             $this->elementStart('body');
114             $subscribe = new SubscribeForm($this, $other);
115             $subscribe->show();
116             $this->elementEnd('body');
117             $this->endHTML();
118         } else {
119             common_redirect(common_local_url('subscriptions',
120                                              array('nickname' => $user->nickname)),
121                             303);
122         }
123     }
124 }