]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/disfavor.php
Merge activity plugin into mainline
[quix0rs-gnu-social.git] / actions / disfavor.php
1 <?php
2 /**
3  * Disfavor action.
4  *
5  * PHP version 5
6  *
7  * @category Action
8  * @package  StatusNet
9  * @author   Evan Prodromou <evan@status.net>
10  * @author   Robin Millette <millette@status.net>
11  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
12  * @link     http://status.net/
13  *
14  * StatusNet - the distributed open-source microblogging tool
15  * Copyright (C) 2008, 2009, StatusNet, Inc.
16  *
17  * This program is free software: you can redistribute it and/or modify
18  * it under the terms of the GNU Affero General Public License as published by
19  * the Free Software Foundation, either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU Affero General Public License for more details.
26  *
27  * You should have received a copy of the GNU Affero General Public License
28  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
29  */
30
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/favorform.php';
36
37 /**
38  * Disfavor class.
39  *
40  * @category Action
41  * @package  StatusNet
42  * @author   Evan Prodromou <evan@status.net>
43  * @author   Robin Millette <millette@status.net>
44  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
45  * @link     http://status.net/
46  */
47 class DisfavorAction extends Action
48 {
49     /**
50      * Class handler.
51      *
52      * @param array $args query arguments
53      *
54      * @return void
55      */
56     function handle($args)
57     {
58         parent::handle($args);
59         if (!common_logged_in()) {
60             // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
61             $this->clientError(_('Not logged in.'));
62             return;
63         }
64         $user = common_current_user();
65         if ($_SERVER['REQUEST_METHOD'] != 'POST') {
66             common_redirect(common_local_url('showfavorites',
67                 array('nickname' => $user->nickname)));
68             return;
69         }
70         $id     = $this->trimmed('notice');
71         $notice = Notice::staticGet($id);
72         $token  = $this->trimmed('token-'.$notice->id);
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. Try again, please.'));
76             return;
77         }
78         $fave            = new Fave();
79         $fave->user_id   = $user->id;
80         $fave->notice_id = $notice->id;
81         if (!$fave->find(true)) {
82             // TRANS: Client error displayed when trying to remove favorite status for a notice that is not a favorite.
83             $this->clientError(_('This notice is not a favorite!'));
84             return;
85         }
86         $result = $fave->delete();
87         if (!$result) {
88             common_log_db_error($fave, 'DELETE', __FILE__);
89             // TRANS: Server error displayed when removing a favorite from the database fails.
90             $this->serverError(_('Could not delete favorite.'));
91             return;
92         }
93         $user->blowFavesCache();
94         if ($this->boolean('ajax')) {
95             $this->startHTML('text/xml;charset=utf-8');
96             $this->elementStart('head');
97             // TRANS: Title for page on which favorites can be added.
98             $this->element('title', null, _('Add to favorites'));
99             $this->elementEnd('head');
100             $this->elementStart('body');
101             $favor = new FavorForm($this, $notice);
102             $favor->show();
103             $this->elementEnd('body');
104             $this->elementEnd('html');
105         } else {
106             common_redirect(common_local_url('showfavorites',
107                                              array('nickname' => $user->nickname)),
108                             303);
109         }
110     }
111 }