3 * Anonymous disfavor 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('STATUSNET')) {
35 * Anonymous disfavor class
39 * @author Zach Copley <zach@status.net>
40 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
41 * @link http://status.net/
43 class AnonDisfavorAction extends RedirectingAction
48 * @param array $args query arguments
52 function handle($args)
54 parent::handle($args);
56 $profile = AnonymousFavePlugin::getAnonProfile();
58 if (empty($profile) || $_SERVER['REQUEST_METHOD'] != 'POST') {
60 // TRANS: Client error.
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 // TRANS: Client error.
72 $this->clientError(_m('There was a problem with your session token. Try again, please.'));
77 $fave->user_id = $profile->id;
78 $fave->notice_id = $notice->id;
80 if (!$fave->find(true)) {
81 // TRANS: Client error.
82 $this->clientError(_m('This notice is not a favorite!'));
86 $result = $fave->delete();
89 common_log_db_error($fave, 'DELETE', __FILE__);
90 // TRANS: Server error.
91 $this->serverError(_m('Could not delete favorite.'));
95 $profile->blowFavesCache();
97 if ($this->boolean('ajax')) {
98 $this->startHTML('text/xml;charset=utf-8');
99 $this->elementStart('head');
101 $this->element('title', null, _m('Add to favorites'));
102 $this->elementEnd('head');
103 $this->elementStart('body');
104 $favor = new AnonFavorForm($this, $notice);
106 $this->elementEnd('body');
107 $this->elementEnd('html');
109 $this->returnToPrevious();
114 * If returnto not set, return to the public stream.
118 function defaultReturnTo()
120 $returnto = common_get_returnto();
121 if (empty($returnto)) {
122 return common_local_url('public');