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 // TRANS: Client error displayed when trying to remove a favorite while not logged in.
62 $this->clientError(_('Not logged in.'));
65 $user = common_current_user();
66 if ($_SERVER['REQUEST_METHOD'] != 'POST') {
67 common_redirect(common_local_url('showfavorites',
68 array('nickname' => $user->nickname)));
71 $id = $this->trimmed('notice');
72 $notice = Notice::staticGet($id);
73 $token = $this->trimmed('token-'.$notice->id);
74 if (!$token || $token != common_session_token()) {
75 // TRANS: Client error displayed when the session token does not match or is not given.
76 $this->clientError(_('There was a problem with your session token. Try again, please.'));
80 $fave->user_id = $user->id;
81 $fave->notice_id = $notice->id;
82 if (!$fave->find(true)) {
83 // TRANS: Client error displayed when trying to remove favorite status for a notice that is not a favorite.
84 $this->clientError(_('This notice is not a favorite!'));
87 $result = $fave->delete();
89 common_log_db_error($fave, 'DELETE', __FILE__);
90 // TRANS: Server error displayed when removing a favorite from the database fails.
91 $this->serverError(_('Could not delete favorite.'));
94 $user->blowFavesCache();
95 if ($this->boolean('ajax')) {
96 $this->startHTML('text/xml;charset=utf-8');
97 $this->elementStart('head');
98 // TRANS: Title for page on which favorites can be added.
99 $this->element('title', null, _('Add to favorites'));
100 $this->elementEnd('head');
101 $this->elementStart('body');
102 $favor = new FavorForm($this, $notice);
104 $this->elementEnd('body');
105 $this->elementEnd('html');
107 common_redirect(common_local_url('showfavorites',
108 array('nickname' => $user->nickname)),