3 * StatusNet, the distributed open-source microblogging tool
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.
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.
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/>.
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/
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
37 * This is the action for leaving a group. It works more or less like the subscribe action
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/
46 class CancelsubscriptionAction extends Action
49 function handle($args)
51 parent::handle($args);
52 if ($this->boolean('ajax')) {
53 StatusNet::setApi(true);
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.'));
60 $user = common_current_user();
62 if ($_SERVER['REQUEST_METHOD'] != 'POST') {
63 common_redirect(common_local_url('subscriptions',
64 array('nickname' => $user->nickname)));
67 /* Use a session token for CSRF protection. */
69 $token = $this->trimmed('token');
71 if (!$token || $token != common_session_token()) {
72 // TRANS: Client error displayed when the session token does not match or is not given.
73 $this->clientError(_('There was a problem with your session token. ' .
74 'Try again, please.'));
77 $other_id = $this->arg('unsubscribeto');
80 // TRANS: Client error displayed when trying to leave a group without specifying an ID.
81 $this->clientError(_('No profile ID in request.'));
84 $other = Profile::getKV('id', $other_id);
87 // TRANS: Client error displayed when trying to leave a non-existing group.
88 $this->clientError(_('No profile with that ID.'));
91 $this->request = Subscription_queue::pkeyGet(array('subscriber' => $user->id,
92 'subscribed' => $other->id));
94 if (empty($this->request)) {
95 // TRANS: Client error displayed when trying to approve a non-existing group join request.
96 // TRANS: %s is a user nickname.
97 $this->clientError(sprintf(_('%s is not in the moderation queue for this group.'), $this->profile->nickname), 403);
100 $this->request->abort();
102 if ($this->boolean('ajax')) {
103 $this->startHTML('text/xml;charset=utf-8');
104 $this->elementStart('head');
105 // TRANS: Title after unsubscribing from a group.
106 $this->element('title', null, _m('TITLE','Unsubscribed'));
107 $this->elementEnd('head');
108 $this->elementStart('body');
109 $subscribe = new SubscribeForm($this, $other);
111 $this->elementEnd('body');
114 common_redirect(common_local_url('subscriptions',
115 array('nickname' => $user->nickname)),