3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('LACONICA')) { exit(1); }
22 require_once(INSTALLDIR.'/lib/mail.php');
24 class FavorAction extends Action
27 function handle($args)
29 parent::handle($args);
31 if (!common_logged_in()) {
32 $this->clientError(_('Not logged in.'));
36 $user = common_current_user();
38 if ($_SERVER['REQUEST_METHOD'] != 'POST') {
39 common_redirect(common_local_url('showfavorites', array('nickname' => $user->nickname)));
43 $id = $this->trimmed('notice');
45 $notice = Notice::staticGet($id);
49 $token = $this->trimmed('token-'.$notice->id);
50 if (!$token || $token != common_session_token()) {
51 $this->clientError(_("There was a problem with your session token. Try again, please."));
55 if ($user->hasFave($notice)) {
56 $this->clientError(_('This notice is already a favorite!'));
60 $fave = Fave::addNew($user, $notice);
63 $this->serverError(_('Could not create favorite.'));
67 $this->notify($fave, $notice, $user);
68 $user->blowFavesCache();
70 if ($this->boolean('ajax')) {
71 $this->startHTML('text/xml;charset=utf-8', true);
72 $this->elementStart('head');
73 $this->element('title', null, _('Disfavor favorite'));
74 $this->elementEnd('head');
75 $this->elementStart('body');
76 common_disfavor_form($notice);
77 $this->elementEnd('body');
78 $this->elementEnd('html');
80 common_redirect(common_local_url('showfavorites',
81 array('nickname' => $user->nickname)));
85 function notify($fave, $notice, $user)
87 $other = User::staticGet('id', $notice->profile_id);
88 if ($other && $other->id != $user->id) {
89 if ($other->email && $other->emailnotifyfav) {
90 mail_notify_fave($other, $user, $notice);