]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/AnonymousFave/anondisfavor.php
- Lookup anon profiles by ID (safer because they are guranteed to be unique) and...
[quix0rs-gnu-social.git] / plugins / AnonymousFave / anondisfavor.php
1 <?php
2
3 /**
4  * Anonymous disfavor action
5  *
6  * PHP version 5
7  *
8  * @category Action
9  * @package  StatusNet
10  * @author   Zach Copley <zach@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) 2010, 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')) {
32     exit(1);
33 }
34
35 /**
36  * Anonymous disfavor class
37  *
38  * @category Action
39  * @package  StatusNet
40  * @author   Zach Copley <zach@status.net>
41  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
42  * @link     http://status.net/
43  */
44 class AnonDisfavorAction extends RedirectingAction
45 {
46     /**
47      * Class handler.
48      *
49      * @param array $args query arguments
50      *
51      * @return void
52      */
53     function handle($args)
54     {
55         parent::handle($args);
56
57         $profile = AnonymousFavePlugin::getAnonProfile();
58
59         if (empty($profile) || $_SERVER['REQUEST_METHOD'] != 'POST') {
60             $this->clientError(
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             $this->clientError(_m('There was a problem with your session token. Try again, please.'));
72             return;
73         }
74
75         $fave            = new Fave();
76         $fave->user_id   = $profile->id;
77         $fave->notice_id = $notice->id;
78
79         if (!$fave->find(true)) {
80             $this->clientError(_m('This notice is not a favorite!'));
81             return;
82         }
83
84         $result = $fave->delete();
85
86         if (!$result) {
87             common_log_db_error($fave, 'DELETE', __FILE__);
88             $this->serverError(_m('Could not delete favorite.'));
89             return;
90         }
91
92         $profile->blowFavesCache();
93
94         if ($this->boolean('ajax')) {
95             $this->startHTML('text/xml;charset=utf-8');
96             $this->elementStart('head');
97             $this->element('title', null, _m('Add to favorites'));
98             $this->elementEnd('head');
99             $this->elementStart('body');
100             $favor = new AnonFavorForm($this, $notice);
101             $favor->show();
102             $this->elementEnd('body');
103             $this->elementEnd('html');
104         } else {
105             $this->returnToPrevious();
106         }
107     }
108
109     /**
110      * If returnto not set, return to the public stream.
111      *
112      * @return string URL
113      */
114     function defaultReturnTo()
115     {
116         $returnto = common_get_returnto();
117         if (empty($returnto)) {
118             return common_local_url('public');
119         } else {
120             return $returnto;
121         }
122     }
123 }
124