4 * Anonymous disfavor 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 disfavor 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 AnonDisfavorAction extends RedirectingAction
49 * @param array $args query arguments
53 function handle($args)
55 parent::handle($args);
57 $anon = $_SESSION['anon_nickname'];
59 $profile = Profile::staticGet('nickname', $anon);
61 if (empty($profile)) {
63 "AnonDisFavorAction - Anon user tried to disfave a notice but doesn't have a profile."
67 if (empty($profile) || $_SERVER['REQUEST_METHOD'] != 'POST') {
69 _m('Could not disfavor notice! Please make sure your browser has cookies enabled.')
74 $id = $this->trimmed('notice');
75 $notice = Notice::staticGet($id);
76 $token = $this->trimmed('token-' . $notice->id);
78 if (!$token || $token != common_session_token()) {
79 $this->clientError(_m('There was a problem with your session token. Try again, please.'));
84 $fave->user_id = $profile->id;
85 $fave->notice_id = $notice->id;
87 if (!$fave->find(true)) {
88 $this->clientError(_m('This notice is not a favorite!'));
92 $result = $fave->delete();
95 common_log_db_error($fave, 'DELETE', __FILE__);
96 $this->serverError(_m('Could not delete favorite.'));
100 $profile->blowFavesCache();
102 if ($this->boolean('ajax')) {
103 $this->startHTML('text/xml;charset=utf-8');
104 $this->elementStart('head');
105 $this->element('title', null, _m('Add to favorites'));
106 $this->elementEnd('head');
107 $this->elementStart('body');
108 $favor = new AnonFavorForm($this, $notice);
110 $this->elementEnd('body');
111 $this->elementEnd('html');
113 $this->returnToPrevious();
118 * If returnto not set, return to the public stream.
122 function defaultReturnTo()
124 $returnto = common_get_returnto();
125 if (empty($returnto)) {
126 return common_local_url('public');