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/mail.php';
36 require_once INSTALLDIR.'/lib/disfavorform.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 FavorAction extends Action
53 * @param array $args query arguments
57 function handle($args)
59 parent::handle($args);
60 if (!common_logged_in()) {
61 // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
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.'));
79 if ($user->hasFave($notice)) {
80 // TRANS: Client error displayed when trying to mark a notice as favorite that already is a favorite.
81 $this->clientError(_('This notice is already a favorite!'));
84 $fave = Fave::addNew($user->getProfile(), $notice);
86 // TRANS: Server error displayed when trying to mark a notice as favorite fails in the database.
87 $this->serverError(_('Could not create favorite.'));
90 $this->notify($notice, $user);
91 $user->blowFavesCache();
92 if ($this->boolean('ajax')) {
93 $this->startHTML('text/xml;charset=utf-8');
94 $this->elementStart('head');
95 // TRANS: Page title for page on which favorite notices can be unfavourited.
96 $this->element('title', null, _('Disfavor favorite.'));
97 $this->elementEnd('head');
98 $this->elementStart('body');
99 $disfavor = new DisFavorForm($this, $notice);
101 $this->elementEnd('body');
102 $this->elementEnd('html');
104 common_redirect(common_local_url('showfavorites',
105 array('nickname' => $user->nickname)),
111 * Notifies a user when their notice is favorited.
113 * @param class $notice favorited notice
114 * @param class $user user declaring a favorite
118 function notify($notice, $user)
120 $other = User::staticGet('id', $notice->profile_id);
121 if ($other && $other->id != $user->id) {
122 if ($other->email && $other->emailnotifyfav) {
123 mail_notify_fave($other, $user, $notice);
126 // XXX: notify by SMS