]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/disfavor.php
Merge branch '0.7.x' into 0.8.x
[quix0rs-gnu-social.git] / actions / disfavor.php
1 <?php
2
3 /**
4  * Disfavor action.
5  *
6  * PHP version 5
7  *
8  * @category Action
9  * @package  Laconica
10  * @author   Evan Prodromou <evan@controlyourself.ca>
11  * @author   Robin Millette <millette@controlyourself.ca>
12  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
13  * @link     http://laconi.ca/
14  *
15  * Laconica - a distributed open-source microblogging tool
16  * Copyright (C) 2008, 2009, Control Yourself, 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('LACONICA')) {
33     exit(1);
34 }
35
36 require_once INSTALLDIR.'/lib/favorform.php';
37
38 /**
39  * Disfavor class.
40  *
41  * @category Action
42  * @package  Laconica
43  * @author   Evan Prodromou <evan@controlyourself.ca>
44  * @author   Robin Millette <millette@controlyourself.ca>
45  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
46  * @link     http://laconi.ca/
47  */
48 class DisfavorAction extends Action
49 {
50     /**
51      * Class handler.
52      *
53      * @param array $args query arguments
54      *
55      * @return void
56      */
57     function handle($args)
58     {
59         parent::handle($args);
60         if (!common_logged_in()) {
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             $this->clientError(_("There was a problem with your session token. Try again, please."));
75             return;
76         }
77         $fave            = new Fave();
78         $fave->user_id   = $user->id;
79         $fave->notice_id = $notice->id;
80         if (!$fave->find(true)) {
81             $this->clientError(_('This notice is not a favorite!'));
82             return;
83         }
84         $result = $fave->delete();
85         if (!$result) {
86             common_log_db_error($fave, 'DELETE', __FILE__);
87             $this->serverError(_('Could not delete favorite.'));
88             return;
89         }
90         $user->blowFavesCache();
91         if ($this->boolean('ajax')) {
92             $this->startHTML('text/xml;charset=utf-8');
93             $this->elementStart('head');
94             $this->element('title', null, _('Add to favorites'));
95             $this->elementEnd('head');
96             $this->elementStart('body');
97             $favor = new FavorForm($this, $notice);
98             $favor->show();
99             $this->elementEnd('body');
100             $this->elementEnd('html');
101         } else {
102             common_redirect(common_local_url('showfavorites',
103                                              array('nickname' => $user->nickname)),
104                             303);
105         }
106     }
107 }
108