cancelsubscription.php 2.92 KB
Newer Older
1 2 3 4
<?php
/**
 * StatusNet, the distributed open-source microblogging tool
 *
5
 * Cancel the subscription of a profile
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @category  Group
 * @package   StatusNet
 * @author    Evan Prodromou <evan@status.net>
 * @copyright 2008-2009 StatusNet, Inc.
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link      http://status.net/
 */

30
if (!defined('GNUSOCIAL')) { exit(1); }
31 32

/**
33
 * Cancel the subscription of a profile
34
 *
35
 * @category Subscription
36 37
 * @package  StatusNet
 * @author   Evan Prodromou <evan@status.net>
38
 * @author   Mikael Nordfeldth <mmn@hethane.se>
39 40 41
 * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
 * @link     http://status.net/
 */
42
class CancelsubscriptionAction extends FormAction
43
{
44
    protected $needPost = true;
45

46
    protected function doPreparation()
47
    {
48 49 50 51
        $profile_id = $this->int('unsubscribeto');
        $this->target = Profile::getKV('id', $profile_id);
        if (!$this->target instanceof Profile) {
            throw new NoProfileException($profile_id);
52
        }
53
    }
54

55
    protected function doPost()
56 57 58 59 60 61 62 63 64
    {
        try {
            $request = Subscription_queue::pkeyGet(array('subscriber' => $this->scoped->id,
                                                         'subscribed' => $this->target->id));
            if ($request instanceof Subscription_queue) {
                $request->abort();
            }
        } catch (AlreadyFulfilledException $e) {
            common_debug('Tried to cancel a non-existing pending subscription');
65 66
        }

mmn's avatar
mmn committed
67
        if (GNUsocial::isAjax()) {
68 69
            $this->startHTML('text/xml;charset=utf-8');
            $this->elementStart('head');
Siebrand Mazeland's avatar
Siebrand Mazeland committed
70 71
            // TRANS: Title after unsubscribing from a group.
            $this->element('title', null, _m('TITLE','Unsubscribed'));
72 73
            $this->elementEnd('head');
            $this->elementStart('body');
74
            $subscribe = new SubscribeForm($this, $this->target);
75 76
            $subscribe->show();
            $this->elementEnd('body');
77
            $this->endHTML();
78
            exit();
79
        }
80
        common_redirect(common_local_url('subscriptions', array('nickname' => $this->scoped->getNickname())), 303);
81 82
    }
}