9 * @author Evan Prodromou <evan@status.net>
10 * @author Robin Millette <millette@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) 2008, 2009, 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') && !defined('LACONICA')) {
35 require_once INSTALLDIR.'/lib/favorform.php';
42 * @author Evan Prodromou <evan@status.net>
43 * @author Robin Millette <millette@status.net>
44 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
45 * @link http://status.net/
47 class DisfavorAction extends Action
52 * @param array $args query arguments
56 function handle($args)
58 parent::handle($args);
59 if (!common_logged_in()) {
60 // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
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 // TRANS: Client error displayed when the session token does not match or is not given.
75 $this->clientError(_('There was a problem with your session token. Try again, please.'));
79 $fave->user_id = $user->id;
80 $fave->notice_id = $notice->id;
81 if (!$fave->find(true)) {
82 // TRANS: Client error displayed when trying to remove favorite status for a notice that is not a favorite.
83 $this->clientError(_('This notice is not a favorite!'));
86 $result = $fave->delete();
88 common_log_db_error($fave, 'DELETE', __FILE__);
89 // TRANS: Server error displayed when removing a favorite from the database fails.
90 $this->serverError(_('Could not delete favorite.'));
93 $user->blowFavesCache();
94 if ($this->boolean('ajax')) {
95 $this->startHTML('text/xml;charset=utf-8');
96 $this->elementStart('head');
97 // TRANS: Title for page on which favorites can be added.
98 $this->element('title', null, _('Add to favorites'));
99 $this->elementEnd('head');
100 $this->elementStart('body');
101 $favor = new FavorForm($this, $notice);
103 $this->elementEnd('body');
104 $this->elementEnd('html');
106 common_redirect(common_local_url('showfavorites',
107 array('nickname' => $user->nickname)),