9 * @author Evan Prodromou <evan@status.net>
10 * @author Robin Millette <millette@status.net>
11 * @author Mikael Nordfeldth <mmn@hethane.se>
12 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
13 * @link http://www.gnu.org/software/social/
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('GNUSOCIAL')) { exit(1); }
34 require_once INSTALLDIR.'/lib/mail.php';
41 * @author Evan Prodromou <evan@status.net>
42 * @author Robin Millette <millette@status.net>
43 * @author Mikael Nordfeldth <mmn@hethane.se>
44 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
45 * @link http://www.gnu.org/software/social/
47 class FavorAction extends FormAction
49 protected $needPost = true;
51 protected function handlePost()
53 $id = $this->trimmed('notice');
54 $notice = Notice::getKV($id);
55 if (!($notice instanceof Notice)) {
56 $this->serverError(_('Notice not found'));
58 if ($this->scoped->hasFave($notice)) {
59 // TRANS: Client error displayed when trying to mark a notice as favorite that already is a favorite.
60 $this->clientError(_('This notice is already a favorite!'));
62 $fave = Fave::addNew($this->scoped, $notice);
64 // TRANS: Server error displayed when trying to mark a notice as favorite fails in the database.
65 $this->serverError(_('Could not create favorite.'));
67 $this->notify($notice, $this->scoped->getUser());
68 $this->scoped->blowFavesCache();
69 if (StatusNet::isAjax()) {
70 $this->startHTML('text/xml;charset=utf-8');
71 $this->elementStart('head');
72 // TRANS: Page title for page on which favorite notices can be unfavourited.
73 $this->element('title', null, _('Disfavor favorite.'));
74 $this->elementEnd('head');
75 $this->elementStart('body');
76 $disfavor = new DisFavorForm($this, $notice);
78 $this->elementEnd('body');
82 common_redirect(common_local_url('showfavorites',
83 array('nickname' => $this->scoped->nickname)),
88 * Notifies a user when their notice is favorited.
90 * @param class $notice favorited notice
91 * @param class $user user declaring a favorite
95 function notify($notice, $user)
97 $other = User::getKV('id', $notice->profile_id);
98 if ($other && $other->id != $user->id) {
99 if ($other->email && $other->emailnotifyfav) {
100 mail_notify_fave($other, $user, $notice);
103 // XXX: notify by SMS