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 // We overload this because success should redirect
50 public function showForm($msg=null, $success=false)
53 common_redirect(common_local_url('showfavorites',
54 array('nickname' => $user->nickname)), 303);
57 parent::showForm($msg, $success);
60 protected function handlePost()
62 $id = $this->trimmed('notice');
63 $notice = Notice::getKV($id);
64 if (!($notice instanceof Notice)) {
65 $this->serverError(_('Notice not found'));
67 if ($this->scoped->hasFave($notice)) {
68 // TRANS: Client error displayed when trying to mark a notice as favorite that already is a favorite.
69 $this->clientError(_('This notice is already a favorite!'));
71 $fave = Fave::addNew($this->scoped, $notice);
73 // TRANS: Server error displayed when trying to mark a notice as favorite fails in the database.
74 $this->serverError(_('Could not create favorite.'));
76 $this->notify($notice, $this->scoped->getUser());
77 $this->scoped->blowFavesCache();
78 if (StatusNet::isAjax()) {
79 $this->startHTML('text/xml;charset=utf-8');
80 $this->elementStart('head');
81 // TRANS: Page title for page on which favorite notices can be unfavourited.
82 $this->element('title', null, _('Disfavor favorite.'));
83 $this->elementEnd('head');
84 $this->elementStart('body');
85 $disfavor = new DisFavorForm($this, $notice);
87 $this->elementEnd('body');
91 common_redirect(common_local_url('showfavorites',
92 array('nickname' => $this->scoped->nickname)),
97 * Notifies a user when their notice is favorited.
99 * @param class $notice favorited notice
100 * @param class $user user declaring a favorite
104 function notify($notice, $user)
106 $other = User::getKV('id', $notice->profile_id);
107 if ($other && $other->id != $user->id) {
108 if ($other->email && $other->emailnotifyfav) {
109 mail_notify_fave($other, $user, $notice);
112 // XXX: notify by SMS