We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

disfavor.php 3.45 KB
Newer Older
1
<?php
Robin Millette's avatar
Robin Millette committed
2 3 4 5 6 7 8 9 10 11 12 13 14

/**
 * Disfavor action.
 *
 * PHP version 5
 *
 * @category Action
 * @package  Laconica
 * @author   Evan Prodromou <evan@controlyourself.ca>
 * @author   Robin Millette <millette@controlyourself.ca>
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
 * @link     http://laconi.ca/
 *
15
 * Laconica - a distributed open-source microblogging tool
16
 * Copyright (C) 2008, 2009, Control Yourself, Inc.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 *
 * 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/>.
 */

Robin Millette's avatar
Robin Millette committed
32 33 34
if (!defined('LACONICA')) {
    exit(1);
}
35

sarven's avatar
sarven committed
36 37
require_once INSTALLDIR.'/lib/favorform.php';

Robin Millette's avatar
Robin Millette committed
38 39 40 41 42 43 44 45 46 47
/**
 * Disfavor class.
 *
 * @category Action
 * @package  Laconica
 * @author   Evan Prodromou <evan@controlyourself.ca>
 * @author   Robin Millette <millette@controlyourself.ca>
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
 * @link     http://laconi.ca/
 */
48 49
class DisfavorAction extends Action
{
Robin Millette's avatar
Robin Millette committed
50 51
    /**
     * Class handler.
52
     *
Robin Millette's avatar
Robin Millette committed
53 54 55 56
     * @param array $args query arguments
     *
     * @return void
     */
57 58
    function handle($args)
    {
59 60
        parent::handle($args);
        if (!common_logged_in()) {
61
            $this->clientError(_('Not logged in.'));
62 63 64 65
            return;
        }
        $user = common_current_user();
        if ($_SERVER['REQUEST_METHOD'] != 'POST') {
Robin Millette's avatar
Robin Millette committed
66 67
            common_redirect(common_local_url('showfavorites',
                array('nickname' => $user->nickname)));
68 69
            return;
        }
Robin Millette's avatar
Robin Millette committed
70
        $id     = $this->trimmed('notice');
71
        $notice = Notice::staticGet($id);
Robin Millette's avatar
Robin Millette committed
72
        $token  = $this->trimmed('token-'.$notice->id);
73
        if (!$token || $token != common_session_token()) {
74
            $this->clientError(_("There was a problem with your session token. Try again, please."));
75 76
            return;
        }
Robin Millette's avatar
Robin Millette committed
77 78
        $fave            = new Fave();
        $fave->user_id   = $this->id;
79 80
        $fave->notice_id = $notice->id;
        if (!$fave->find(true)) {
81
            $this->clientError(_('This notice is not a favorite!'));
82 83 84 85 86
            return;
        }
        $result = $fave->delete();
        if (!$result) {
            common_log_db_error($fave, 'DELETE', __FILE__);
87
            $this->serverError(_('Could not delete favorite.'));
88 89 90 91
            return;
        }
        $user->blowFavesCache();
        if ($this->boolean('ajax')) {
92
            $this->startHTML('text/xml;charset=utf-8');
93 94 95 96
            $this->elementStart('head');
            $this->element('title', null, _('Add to favorites'));
            $this->elementEnd('head');
            $this->elementStart('body');
sarven's avatar
sarven committed
97 98
            $favor = new FavorForm($this, $notice);
            $favor->show();
99 100
            $this->elementEnd('body');
            $this->elementEnd('html');
101 102
        } else {
            common_redirect(common_local_url('showfavorites',
103 104
                                             array('nickname' => $user->nickname)),
                            303);
105 106
        }
    }
107
}
Robin Millette's avatar
Robin Millette committed
108