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: Client error displayed when trying to mark a notice as favorite without being 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 $this->clientError(_('There was a problem with your session token. Try again, please.'));
78 if ($user->hasFave($notice)) {
79 // TRANS: Client error displayed when trying to mark a notice as favorite that already is a favorite.
80 $this->clientError(_('This notice is already a favorite!'));
83 $fave = Fave::addNew($user->getProfile(), $notice);
85 // TRANS: Server error displayed when trying to mark a notice as favorite fails in the database.
86 $this->serverError(_('Could not create favorite.'));
89 $this->notify($notice, $user);
90 $user->blowFavesCache();
91 if ($this->boolean('ajax')) {
92 $this->startHTML('text/xml;charset=utf-8');
93 $this->elementStart('head');
94 // TRANS: Page title for page on which favorite notices can be unfavourited.
95 $this->element('title', null, _('Disfavor favorite.'));
96 $this->elementEnd('head');
97 $this->elementStart('body');
98 $disfavor = new DisFavorForm($this, $notice);
100 $this->elementEnd('body');
101 $this->elementEnd('html');
103 common_redirect(common_local_url('showfavorites',
104 array('nickname' => $user->nickname)),
110 * Notifies a user when their notice is favorited.
112 * @param class $notice favorited notice
113 * @param class $user user declaring a favorite
117 function notify($notice, $user)
119 $other = User::staticGet('id', $notice->profile_id);
120 if ($other && $other->id != $user->id) {
121 if ($other->email && $other->emailnotifyfav) {
122 mail_notify_fave($other, $user, $notice);
125 // XXX: notify by SMS