]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Favorite/actions/disfavor.php
b39453b5aa7f83f31b9beb557e2dff6835f26dcd
[quix0rs-gnu-social.git] / plugins / Favorite / actions / disfavor.php
1 <?php
2 /**
3  * Disfavor action.
4  *
5  * PHP version 5
6  *
7  * @category Action
8  * @package  GNUsocial
9  * @author   Evan Prodromou <evan@status.net>
10  * @author   Robin Millette <millette@status.net>
11  * @author   Mikael Nordfeldth <mmn@hethane.se>
12  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
13  * @link     http://www.gnu.org/software/social/
14  *
15  * StatusNet - the distributed open-source microblogging tool
16  * Copyright (C) 2008, 2009, StatusNet, Inc.
17  *
18  * This program is free software: you can redistribute it and/or modify
19  * it under the terms of the GNU Affero General Public License as published by
20  * the Free Software Foundation, either version 3 of the License, or
21  * (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  * GNU Affero General Public License for more details.
27  *
28  * You should have received a copy of the GNU Affero General Public License
29  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
30  */
31
32 if (!defined('GNUSOCIAL')) { exit(1); }
33
34 /**
35  * DisfavorAction class.
36  *
37  * @category Action
38  * @package  GNUsocial
39  * @author   Evan Prodromou <evan@status.net>
40  * @author   Robin Millette <millette@status.net>
41  * @author   Mikael Nordfeldth <mmn@hethane.se>
42  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
43  * @link     http://www.gnu.org/software/social/
44  */
45 class DisfavorAction extends FormAction
46 {
47     public function showForm($msg=null, $success=false)
48     {
49         if ($success) {
50             common_redirect(common_local_url('showfavorites',
51                 array('nickname' => $this->scoped->nickname)), 303);
52         }
53         parent::showForm($msg, $success);
54     }
55
56     protected function handlePost()
57     {
58         $id     = $this->trimmed('notice');
59         $notice = Notice::getKV($id);
60         if (!$notice instanceof Notice) {
61             $this->serverError(_('Notice not found'));
62         }
63
64         $fave            = new Fave();
65         $fave->user_id   = $this->scoped->id;
66         $fave->notice_id = $notice->id;
67         if (!$fave->find(true)) {
68             throw new NoResultException($fave);
69         }
70         $result = $fave->delete();
71         if (!$result) {
72             common_log_db_error($fave, 'DELETE', __FILE__);
73             // TRANS: Server error displayed when removing a favorite from the database fails.
74             $this->serverError(_('Could not delete favorite.'));
75         }
76         Fave::blowCacheForProfileId($this->scoped->id);
77         if (GNUsocial::isAjax()) {
78             $this->startHTML('text/xml;charset=utf-8');
79             $this->elementStart('head');
80             // TRANS: Title for page on which favorites can be added.
81             $this->element('title', null, _('Add to favorites'));
82             $this->elementEnd('head');
83             $this->elementStart('body');
84             $favor = new FavorForm($this, $notice);
85             $favor->show();
86             $this->elementEnd('body');
87             $this->endHTML();
88             exit;
89         }
90     }
91 }