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.'));
61 $user = common_current_user();
63 if ($_SERVER['REQUEST_METHOD'] != 'POST') {
64 common_redirect(common_local_url('subscriptions',
65 array('nickname' => $user->nickname)));
69 /* Use a session token for CSRF protection. */
71 $token = $this->trimmed('token');
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.'));
80 $other_id = $this->arg('unsubscribeto');
83 // TRANS: Client error displayed when trying to leave a group without specifying an ID.
84 $this->clientError(_('No profile ID in request.'));
88 $other = Profile::staticGet('id', $other_id);
91 // TRANS: Client error displayed when trying to leave a non-existing group.
92 $this->clientError(_('No profile with that ID.'));
96 $this->request = Subscription_queue::pkeyGet(array('subscriber' => $user->id,
97 'subscribed' => $other->id));
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);
105 $this->request->abort();
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);
116 $this->elementEnd('body');
117 $this->elementEnd('html');
119 common_redirect(common_local_url('subscriptions',
120 array('nickname' => $user->nickname)),