]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/AnonymousFave/anondisfavor.php
* L10/i18n review.
[quix0rs-gnu-social.git] / plugins / AnonymousFave / anondisfavor.php
1 <?php
2 /**
3  * Anonymous disfavor action
4  *
5  * PHP version 5
6  *
7  * @category Action
8  * @package  StatusNet
9  * @author   Zach Copley <zach@status.net>
10  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11  * @link     http://status.net/
12  *
13  * StatusNet - the distributed open-source microblogging tool
14  * Copyright (C) 2010, StatusNet, Inc.
15  *
16  * This program is free software: you can redistribute it and/or modify
17  * it under the terms of the GNU Affero General Public License as published by
18  * the Free Software Foundation, either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU Affero General Public License for more details.
25  *
26  * You should have received a copy of the GNU Affero General Public License
27  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 /**
35  * Anonymous disfavor class
36  *
37  * @category Action
38  * @package  StatusNet
39  * @author   Zach Copley <zach@status.net>
40  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
41  * @link     http://status.net/
42  */
43 class AnonDisfavorAction extends RedirectingAction
44 {
45     /**
46      * Class handler.
47      *
48      * @param array $args query arguments
49      *
50      * @return void
51      */
52     function handle($args)
53     {
54         parent::handle($args);
55
56         $profile = AnonymousFavePlugin::getAnonProfile();
57
58         if (empty($profile) || $_SERVER['REQUEST_METHOD'] != 'POST') {
59             $this->clientError(
60                 // TRANS: Client error.
61                 _m('Could not disfavor notice! Please make sure your browser has cookies enabled.')
62             );
63             return;
64         }
65
66         $id     = $this->trimmed('notice');
67         $notice = Notice::staticGet($id);
68         $token  = $this->trimmed('token-' . $notice->id);
69
70         if (!$token || $token != common_session_token()) {
71             // TRANS: Client error.
72             $this->clientError(_m('There was a problem with your session token. Try again, please.'));
73             return;
74         }
75
76         $fave            = new Fave();
77         $fave->user_id   = $profile->id;
78         $fave->notice_id = $notice->id;
79
80         if (!$fave->find(true)) {
81             // TRANS: Client error.
82             $this->clientError(_m('This notice is not a favorite!'));
83             return;
84         }
85
86         $result = $fave->delete();
87
88         if (!$result) {
89             common_log_db_error($fave, 'DELETE', __FILE__);
90             // TRANS: Server error.
91             $this->serverError(_m('Could not delete favorite.'));
92             return;
93         }
94
95         $profile->blowFavesCache();
96
97         if ($this->boolean('ajax')) {
98             $this->startHTML('text/xml;charset=utf-8');
99             $this->elementStart('head');
100             // TRANS: Title.
101             $this->element('title', null, _m('Add to favorites'));
102             $this->elementEnd('head');
103             $this->elementStart('body');
104             $favor = new AnonFavorForm($this, $notice);
105             $favor->show();
106             $this->elementEnd('body');
107             $this->elementEnd('html');
108         } else {
109             $this->returnToPrevious();
110         }
111     }
112
113     /**
114      * If returnto not set, return to the public stream.
115      *
116      * @return string URL
117      */
118     function defaultReturnTo()
119     {
120         $returnto = common_get_returnto();
121         if (empty($returnto)) {
122             return common_local_url('public');
123         } else {
124             return $returnto;
125         }
126     }
127 }