]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/AnonymousFave/actions/anondisfavor.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / plugins / AnonymousFave / actions / 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('GNUSOCIAL')) { exit(1); }
31
32 /**
33  * Anonymous disfavor class
34  *
35  * @category Action
36  * @package  StatusNet
37  * @author   Zach Copley <zach@status.net>
38  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
39  * @link     http://status.net/
40  */
41 class AnonDisfavorAction extends RedirectingAction
42 {
43     /**
44      * Class handler.
45      *
46      * @param array $args query arguments
47      *
48      * @return void
49      */
50     function handle($args)
51     {
52         parent::handle($args);
53
54         $profile = AnonymousFavePlugin::getAnonProfile();
55
56         if (empty($profile) || $_SERVER['REQUEST_METHOD'] != 'POST') {
57             $this->clientError(
58                 // TRANS: Client error.
59                 _m('Could not disfavor notice! Please make sure your browser has cookies enabled.')
60             );
61         }
62
63         $id     = $this->trimmed('notice');
64         $notice = Notice::getKV($id);
65         $token  = $this->checkSessionToken();
66
67         $fave            = new Fave();
68         $fave->user_id   = $profile->id;
69         $fave->notice_id = $notice->id;
70
71         if (!$fave->find(true)) {
72             throw new NoResultException($fave);
73         }
74
75         $result = $fave->delete();
76
77         if (!$result) {
78             common_log_db_error($fave, 'DELETE', __FILE__);
79             // TRANS: Server error.
80             $this->serverError(_m('Could not delete favorite.'));
81         }
82
83         Fave::blowCacheForProfileId($profile->id);
84
85         if ($this->boolean('ajax')) {
86             $this->startHTML('text/xml;charset=utf-8');
87             $this->elementStart('head');
88             // TRANS: Title.
89             $this->element('title', null, _m('Add to favorites'));
90             $this->elementEnd('head');
91             $this->elementStart('body');
92             $favor = new AnonFavorForm($this, $notice);
93             $favor->show();
94             $this->elementEnd('body');
95             $this->endHTML();
96         } else {
97             $this->returnToPrevious();
98         }
99     }
100
101     /**
102      * If returnto not set, return to the public stream.
103      *
104      * @return string URL
105      */
106     function defaultReturnTo()
107     {
108         $returnto = common_get_returnto();
109         if (empty($returnto)) {
110             return common_local_url('public');
111         } else {
112             return $returnto;
113         }
114     }
115 }