10 * @author Evan Prodromou <evan@controlyourself.ca>
11 * @author Robin Millette <millette@controlyourself.ca>
12 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
13 * @link http://laconi.ca/
17 * Laconica - a distributed open-source microblogging tool
18 * Copyright (C) 2008, Controlez-Vous, Inc.
20 * This program is free software: you can redistribute it and/or modify
21 * it under the terms of the GNU Affero General Public License as published by
22 * the Free Software Foundation, either version 3 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU Affero General Public License for more details.
30 * You should have received a copy of the GNU Affero General Public License
31 * along with this program. If not, see <http://www.gnu.org/licenses/>.
34 if (!defined('LACONICA')) {
38 require_once INSTALLDIR.'/lib/mail.php';
39 require_once INSTALLDIR.'/lib/disfavorform.php';
46 * @author Evan Prodromou <evan@controlyourself.ca>
47 * @author Robin Millette <millette@controlyourself.ca>
48 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
49 * @link http://laconi.ca/
51 class FavorAction extends Action
56 * @param array $args query arguments
60 function handle($args)
62 parent::handle($args);
63 if (!common_logged_in()) {
64 $this->clientError(_('Not logged in.'));
67 $user = common_current_user();
68 if ($_SERVER['REQUEST_METHOD'] != 'POST') {
69 common_redirect(common_local_url('showfavorites',
70 array('nickname' => $user->nickname)));
73 $id = $this->trimmed('notice');
74 $notice = Notice::staticGet($id);
75 $token = $this->trimmed('token-'.$notice->id);
76 if (!$token || $token != common_session_token()) {
77 $this->clientError(_("There was a problem with your session token. Try again, please."));
80 if ($user->hasFave($notice)) {
81 $this->clientError(_('This notice is already a favorite!'));
84 $fave = Fave::addNew($user, $notice);
86 $this->serverError(_('Could not create favorite.'));
89 $this->notify($notice, $user);
90 $user->blowFavesCache();
91 if ($this->boolean('ajax')) {
92 $this->startHTML('text/xml;charset=utf-8');
93 $this->elementStart('head');
94 $this->element('title', null, _('Disfavor favorite'));
95 $this->elementEnd('head');
96 $this->elementStart('body');
97 $disfavor = new DisFavorForm($this, $notice);
99 $this->elementEnd('body');
100 $this->elementEnd('html');
102 common_redirect(common_local_url('showfavorites',
103 array('nickname' => $user->nickname)),
109 * Notifies a user when his notice is favorited.
111 * @param class $notice favorited notice
112 * @param class $user user declaring a favorite
116 function notify($notice, $user)
118 $other = User::staticGet('id', $notice->profile_id);
119 if ($other && $other->id != $user->id) {
120 if ($other->email && $other->emailnotifyfav) {
121 mail_notify_fave($other, $user, $notice);
124 // XXX: notify by SMS