]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/cancelsubscription.php
Merge remote branch 'gitorious/1.0.x' into 1.0.x
[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             $this->clientError(_('Not logged in.'));
57             return;
58         }
59
60         $user = common_current_user();
61
62         if ($_SERVER['REQUEST_METHOD'] != 'POST') {
63             common_redirect(common_local_url('subscriptions',
64                                              array('nickname' => $user->nickname)));
65             return;
66         }
67
68         /* Use a session token for CSRF protection. */
69
70         $token = $this->trimmed('token');
71
72         if (!$token || $token != common_session_token()) {
73             $this->clientError(_('There was a problem with your session token. ' .
74                                  'Try again, please.'));
75             return;
76         }
77
78         $other_id = $this->arg('unsubscribeto');
79
80         if (!$other_id) {
81             $this->clientError(_('No profile ID in request.'));
82             return;
83         }
84
85         $other = Profile::staticGet('id', $other_id);
86
87         if (!$other) {
88             $this->clientError(_('No profile with that ID.'));
89             return;
90         }
91
92         $this->request = Subscription_queue::pkeyGet(array('subscriber' => $user->id,
93                                                            'subscribed' => $other->id));
94
95         if (empty($this->request)) {
96             // TRANS: Client error displayed when trying to approve a non-existing group join request.
97             // TRANS: %s is a user nickname.
98             $this->clientError(sprintf(_('%s is not in the moderation queue for this group.'), $this->profile->nickname), 403);
99         }
100
101         $this->request->abort();
102
103         if ($this->boolean('ajax')) {
104             $this->startHTML('text/xml;charset=utf-8');
105             $this->elementStart('head');
106             $this->element('title', null, _('Unsubscribed'));
107             $this->elementEnd('head');
108             $this->elementStart('body');
109             $subscribe = new SubscribeForm($this, $other);
110             $subscribe->show();
111             $this->elementEnd('body');
112             $this->elementEnd('html');
113         } else {
114             common_redirect(common_local_url('subscriptions',
115                                              array('nickname' => $user->nickname)),
116                             303);
117         }
118     }
119 }