3 * Anonyous favor action
9 * @author Zach Copley <zach@status.net>
10 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11 * @link http://status.net/
13 * StatusNet - the distributed open-source microblogging tool
14 * Copyright (C) 2010, StatusNet, Inc.
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.
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.
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/>.
30 if (!defined('GNUSOCIAL')) { exit(1); }
33 * Anonymous favor class
37 * @author Zach Copley <zach@status.net>
38 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
39 * @link http://status.net/
41 class AnonFavorAction extends RedirectingAction
46 * @param array $args query arguments
50 function handle(array $args=array())
52 parent::handle($args);
54 $profile = AnonymousFavePlugin::getAnonProfile();
56 if (empty($profile) || $_SERVER['REQUEST_METHOD'] != 'POST') {
57 // TRANS: Client error.
58 $this->clientError(_m('Could not favor notice! Please make sure your browser has cookies enabled.'));
61 $id = $this->trimmed('notice');
62 $notice = Notice::getKV($id);
63 $token = $this->checkSessionToken();
65 if (Fave::existsForProfile($notice, $profile)) {
66 // TRANS: Client error.
67 throw new AlreadyFulfilledException(_m('This notice is already a favorite!'));
71 $stored = Fave::addNew($profile, $notice);
73 if ($this->boolean('ajax')) {
74 $this->startHTML('text/xml;charset=utf-8');
75 $this->elementStart('head');
77 $this->element('title', null, _m('Disfavor favorite'));
78 $this->elementEnd('head');
79 $this->elementStart('body');
80 $disfavor = new AnonDisFavorForm($this, $notice);
82 $this->elementEnd('body');
85 $this->returnToPrevious();
90 * If returnto not set, return to the public stream.
94 function defaultReturnTo()
96 $returnto = common_get_returnto();
97 if (empty($returnto)) {
98 return common_local_url('public');