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); }
39 * @author Evan Prodromou <evan@status.net>
40 * @author Robin Millette <millette@status.net>
41 * @author Mikael Nordfeldth <mmn@hethane.se>
42 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
43 * @link http://www.gnu.org/software/social/
45 class FavorAction extends FormAction
47 protected $needPost = true;
49 protected $object = null;
51 protected function prepare(array $args=array())
53 parent::prepare($args);
55 $this->target = Notice::getKV($this->trimmed('notice'));
56 if (!$this->target instanceof Notice) {
57 throw new ServerException(_m('No such notice.'));
59 if (!$this->target->inScope($this->scoped)) {
60 // TRANS: Client error displayed when trying to reply to a notice a the target has no access to.
61 // TRANS: %1$s is a user nickname, %2$d is a notice ID (number).
62 throw new ClientException(sprintf(_m('%1$s has no right to reply to notice %2$d.'), $this->scoped->getNickname(), $this->target->id), 403);
68 protected function handlePost()
72 if (Fave::existsForProfile($this->target, $this->scoped)) {
73 // TRANS: Client error displayed when trying to mark a notice as favorite that already is a favorite.
74 throw new AlreadyFulfilledException(_('You have already favorited this!'));
77 $fave = Fave::addNew($this->scoped, $this->target);
80 $this->serverError(_('Could not create favorite.'));
83 $this->notify($fave, $this->target, $this->scoped);
84 Fave::blowCacheForProfileId($this->scoped->id);
86 return _('Favorited the notice');
89 protected function showContent()
91 if ($this->target instanceof Notice) {
92 $disfavor = new DisfavorForm($this, $this->target);
98 * Notify the author of the favorite that the user likes their notice
100 * @param Favorite $fave the favorite in question
101 * @param Notice $notice the notice that's been faved
102 * @param User $user the user doing the favoriting
106 function notify($fave, $notice, $user)
108 $other = User::getKV('id', $notice->profile_id);
109 if ($other && $other->id != $user->id && !empty($other->email)) {
110 require_once INSTALLDIR.'/lib/mail.php';
112 mail_notify_fave($other, $user->getProfile(), $notice);
114 // XXX: notify by SMS