4 * Anonyous favor action
10 * @author Zach Copley <zach@status.net>
11 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
12 * @link http://status.net/
14 * StatusNet - the distributed open-source microblogging tool
15 * Copyright (C) 2010, StatusNet, Inc.
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.
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.
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/>.
31 if (!defined('STATUSNET')) {
36 * Anonymous favor class
40 * @author Zach Copley <zach@status.net>
41 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
42 * @link http://status.net/
44 class AnonFavorAction extends RedirectingAction
49 * @param array $args query arguments
53 function handle($args)
55 parent::handle($args);
57 $anon = $_SESSION['anon_nickname'];
58 $profile = Profile::staticGet('nickname', $anon);
60 if (empty($profile)) {
62 "AnonFavorAction - Anon user tried to fave a notice but doesn't have a profile."
66 if (empty($profile) || $_SERVER['REQUEST_METHOD'] != 'POST') {
68 _m('Could not favor notice! Please make sure your browser has cookies enabled.')
73 $id = $this->trimmed('notice');
74 $notice = Notice::staticGet($id);
75 $token = $this->trimmed('token-' . $notice->id);
77 if (empty($token) || $token != common_session_token()) {
78 $this->clientError(_m('There was a problem with your session token. Try again, please.'));
83 if ($profile->hasFave($notice)) {
84 $this->clientError(_m('This notice is already a favorite!'));
87 $fave = Fave::addNew($profile, $notice);
90 $this->serverError(_m('Could not create favorite.'));
94 $profile->blowFavesCache();
96 if ($this->boolean('ajax')) {
97 $this->startHTML('text/xml;charset=utf-8');
98 $this->elementStart('head');
99 $this->element('title', null, _m('Disfavor favorite'));
100 $this->elementEnd('head');
101 $this->elementStart('body');
102 $disfavor = new AnonDisFavorForm($this, $notice);
104 $this->elementEnd('body');
105 $this->elementEnd('html');
107 $this->returnToPrevious();
112 * If returnto not set, return to the public stream.
116 function defaultReturnTo()
118 $returnto = common_get_returnto();
119 if (empty($returnto)) {
120 return common_local_url('public');