]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/AnonymousFave/anonfavor.php
58570ced9af7245cece3f5e2e8d0f016128d67ca
[quix0rs-gnu-social.git] / plugins / AnonymousFave / anonfavor.php
1 <?php
2
3 /**
4  * Anonyous favor 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 favor 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 AnonFavorAction 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 favor 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 (empty($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
76         if ($profile->hasFave($notice)) {
77             $this->clientError(_m('This notice is already a favorite!'));
78             return;
79         }
80         $fave = Fave::addNew($profile, $notice);
81
82         if (!$fave) {
83             $this->serverError(_m('Could not create favorite.'));
84             return;
85         }
86
87         $profile->blowFavesCache();
88
89         if ($this->boolean('ajax')) {
90             $this->startHTML('text/xml;charset=utf-8');
91             $this->elementStart('head');
92             $this->element('title', null, _m('Disfavor favorite'));
93             $this->elementEnd('head');
94             $this->elementStart('body');
95             $disfavor = new AnonDisFavorForm($this, $notice);
96             $disfavor->show();
97             $this->elementEnd('body');
98             $this->elementEnd('html');
99         } else {
100             $this->returnToPrevious();
101         }
102     }
103
104     /**
105      * If returnto not set, return to the public stream.
106      *
107      * @return string URL
108      */
109     function defaultReturnTo()
110     {
111         $returnto = common_get_returnto();
112         if (empty($returnto)) {
113             return common_local_url('public');
114         } else {
115             return $returnto;
116         }
117     }
118 }