10 * @author Evan Prodromou <evan@status.net>
11 * @author Robin Millette <millette@status.net>
12 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
13 * @link http://status.net/
15 * StatusNet - the distributed open-source microblogging tool
16 * Copyright (C) 2008, 2009, StatusNet, Inc.
18 * This program is free software: you can redistribute it and/or modify
19 * it under the terms of the GNU Affero General Public License as published by
20 * the Free Software Foundation, either version 3 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU Affero General Public License for more details.
28 * You should have received a copy of the GNU Affero General Public License
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32 if (!defined('STATUSNET') && !defined('LACONICA')) {
36 require_once INSTALLDIR.'/lib/favorform.php';
43 * @author Evan Prodromou <evan@status.net>
44 * @author Robin Millette <millette@status.net>
45 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
46 * @link http://status.net/
48 class DisfavorAction extends Action
53 * @param array $args query arguments
57 function handle($args)
59 parent::handle($args);
60 if (!common_logged_in()) {
61 $this->clientError(_('Not logged in.'));
64 $user = common_current_user();
65 if ($_SERVER['REQUEST_METHOD'] != 'POST') {
66 common_redirect(common_local_url('showfavorites',
67 array('nickname' => $user->nickname)));
70 $id = $this->trimmed('notice');
71 $notice = Notice::staticGet($id);
72 $token = $this->trimmed('token-'.$notice->id);
73 if (!$token || $token != common_session_token()) {
74 $this->clientError(_("There was a problem with your session token. Try again, please."));
78 $fave->user_id = $user->id;
79 $fave->notice_id = $notice->id;
80 if (!$fave->find(true)) {
81 $this->clientError(_('This notice is not a favorite!'));
84 $result = $fave->delete();
86 common_log_db_error($fave, 'DELETE', __FILE__);
87 $this->serverError(_('Could not delete favorite.'));
90 $user->blowFavesCache();
91 if ($this->boolean('ajax')) {
92 $this->startHTML('text/xml;charset=utf-8');
93 $this->elementStart('head');
94 $this->element('title', null, _('Add to favorites'));
95 $this->elementEnd('head');
96 $this->elementStart('body');
97 $favor = new FavorForm($this, $notice);
99 $this->elementEnd('body');
100 $this->elementEnd('html');
102 common_redirect(common_local_url('showfavorites',
103 array('nickname' => $user->nickname)),