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: Client error displayed when trying to leave a group while not logged in.
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 $this->clientError(_('There was a problem with your session token. ' .
75 'Try again, please.'));
79 $other_id = $this->arg('unsubscribeto');
82 // TRANS: Client error displayed when trying to leave a group without specifying an ID.
83 $this->clientError(_('No profile ID in request.'));
87 $other = Profile::staticGet('id', $other_id);
90 // TRANS: Client error displayed when trying to leave a non-existing group.
91 $this->clientError(_('No profile with that ID.'));
95 $this->request = Subscription_queue::pkeyGet(array('subscriber' => $user->id,
96 'subscribed' => $other->id));
98 if (empty($this->request)) {
99 // TRANS: Client error displayed when trying to approve a non-existing group join request.
100 // TRANS: %s is a user nickname.
101 $this->clientError(sprintf(_('%s is not in the moderation queue for this group.'), $this->profile->nickname), 403);
104 $this->request->abort();
106 if ($this->boolean('ajax')) {
107 $this->startHTML('text/xml;charset=utf-8');
108 $this->elementStart('head');
109 // TRANS: Title after unsubscribing from a group.
110 $this->element('title', null, _m('TITLE','Unsubscribed'));
111 $this->elementEnd('head');
112 $this->elementStart('body');
113 $subscribe = new SubscribeForm($this, $other);
115 $this->elementEnd('body');
116 $this->elementEnd('html');
118 common_redirect(common_local_url('subscriptions',
119 array('nickname' => $user->nickname)),