10 * @author Evan Prodromou <evan@status.net>
11 * @author Robin Millette <millette@status.net>
12 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
13 * @link http://status.net/
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('STATUSNET') && !defined('LACONICA')) {
36 require_once INSTALLDIR.'/lib/mail.php';
37 require_once INSTALLDIR.'/lib/disfavorform.php';
44 * @author Evan Prodromou <evan@status.net>
45 * @author Robin Millette <millette@status.net>
46 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
47 * @link http://status.net/
49 class FavorAction extends Action
54 * @param array $args query arguments
58 function handle($args)
60 parent::handle($args);
61 if (!common_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 $this->clientError(_('This notice is already a favorite!'));
82 $fave = Fave::addNew($user->getProfile(), $notice);
84 $this->serverError(_('Could not create favorite.'));
87 $this->notify($notice, $user);
88 $user->blowFavesCache();
89 if ($this->boolean('ajax')) {
90 $this->startHTML('text/xml;charset=utf-8');
91 $this->elementStart('head');
92 $this->element('title', null, _('Disfavor favorite'));
93 $this->elementEnd('head');
94 $this->elementStart('body');
95 $disfavor = new DisFavorForm($this, $notice);
97 $this->elementEnd('body');
98 $this->elementEnd('html');
100 common_redirect(common_local_url('showfavorites',
101 array('nickname' => $user->nickname)),
107 * Notifies a user when their notice is favorited.
109 * @param class $notice favorited notice
110 * @param class $user user declaring a favorite
114 function notify($notice, $user)
116 $other = User::staticGet('id', $notice->profile_id);
117 if ($other && $other->id != $user->id) {
118 if ($other->email && $other->emailnotifyfav) {
119 mail_notify_fave($other, $user, $notice);
122 // XXX: notify by SMS