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 $profile = AnonymousFavePlugin::getAnonProfile();
59 if (empty($profile) || $_SERVER['REQUEST_METHOD'] != 'POST') {
61 _m('Could not favor notice! Please make sure your browser has cookies enabled.')
66 $id = $this->trimmed('notice');
67 $notice = Notice::staticGet($id);
68 $token = $this->trimmed('token-' . $notice->id);
70 if (empty($token) || $token != common_session_token()) {
71 $this->clientError(_m('There was a problem with your session token. Try again, please.'));
76 if ($profile->hasFave($notice)) {
77 $this->clientError(_m('This notice is already a favorite!'));
80 $fave = Fave::addNew($profile, $notice);
83 $this->serverError(_m('Could not create favorite.'));
87 $profile->blowFavesCache();
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);
97 $this->elementEnd('body');
98 $this->elementEnd('html');
100 $this->returnToPrevious();
105 * If returnto not set, return to the public stream.
109 function defaultReturnTo()
111 $returnto = common_get_returnto();
112 if (empty($returnto)) {
113 return common_local_url('public');