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');
23 require_once INSTALLDIR.'/lib/disfavorform.php';
25 class FavorAction extends Action
28 function handle($args)
30 parent::handle($args);
32 if (!common_logged_in()) {
33 $this->clientError(_('Not logged in.'));
37 $user = common_current_user();
39 if ($_SERVER['REQUEST_METHOD'] != 'POST') {
40 common_redirect(common_local_url('showfavorites', array('nickname' => $user->nickname)));
44 $id = $this->trimmed('notice');
46 $notice = Notice::staticGet($id);
50 $token = $this->trimmed('token-'.$notice->id);
51 if (!$token || $token != common_session_token()) {
52 $this->clientError(_("There was a problem with your session token. Try again, please."));
56 if ($user->hasFave($notice)) {
57 $this->clientError(_('This notice is already a favorite!'));
61 $fave = Fave::addNew($user, $notice);
64 $this->serverError(_('Could not create favorite.'));
68 $this->notify($fave, $notice, $user);
69 $user->blowFavesCache();
71 if ($this->boolean('ajax')) {
72 $this->startHTML('text/xml;charset=utf-8', true);
73 $this->elementStart('head');
74 $this->element('title', null, _('Disfavor favorite'));
75 $this->elementEnd('head');
76 $this->elementStart('body');
77 $disfavor = new DisFavorForm($this, $notice);
79 $this->elementEnd('body');
80 $this->elementEnd('html');
82 common_redirect(common_local_url('showfavorites',
83 array('nickname' => $user->nickname)));
87 function notify($fave, $notice, $user)
89 $other = User::staticGet('id', $notice->profile_id);
90 if ($other && $other->id != $user->id) {
91 if ($other->email && $other->emailnotifyfav) {
92 mail_notify_fave($other, $user, $notice);