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 $profile = AnonymousFavePlugin::getAnonProfile();
59 if (empty($profile) || $_SERVER['REQUEST_METHOD'] != 'POST') {
61 _m('Could not disfavor 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 (!$token || $token != common_session_token()) {
71 $this->clientError(_m('There was a problem with your session token. Try again, please.'));
76 $fave->user_id = $profile->id;
77 $fave->notice_id = $notice->id;
79 if (!$fave->find(true)) {
80 $this->clientError(_m('This notice is not a favorite!'));
84 $result = $fave->delete();
87 common_log_db_error($fave, 'DELETE', __FILE__);
88 $this->serverError(_m('Could not delete favorite.'));
92 $profile->blowFavesCache();
94 if ($this->boolean('ajax')) {
95 $this->startHTML('text/xml;charset=utf-8');
96 $this->elementStart('head');
97 $this->element('title', null, _m('Add to favorites'));
98 $this->elementEnd('head');
99 $this->elementStart('body');
100 $favor = new AnonFavorForm($this, $notice);
102 $this->elementEnd('body');
103 $this->elementEnd('html');
105 $this->returnToPrevious();
110 * If returnto not set, return to the public stream.
114 function defaultReturnTo()
116 $returnto = common_get_returnto();
117 if (empty($returnto)) {
118 return common_local_url('public');