]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/favor.php
Using GNUSOCIAL_VERSION instead of STATUSNET_VERSION
[quix0rs-gnu-social.git] / actions / favor.php
1 <?php
2 /**
3  * Favor action.
4  *
5  * PHP version 5
6  *
7  * @category Action
8  * @package  GNUsocial
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/
14  *
15  * StatusNet - the distributed open-source microblogging tool
16  * Copyright (C) 2008, 2009, StatusNet, Inc.
17  *
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.
22  *
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.
27  *
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/>.
30  */
31
32 if (!defined('GNUSOCIAL')) { exit(1); }
33
34 require_once INSTALLDIR.'/lib/mail.php';
35
36 /**
37  * FavorAction class.
38  *
39  * @category Action
40  * @package  GNUsocial
41  * @author   Evan Prodromou <evan@status.net>
42  * @author   Robin Millette <millette@status.net>
43  * @author   Mikael Nordfeldth <mmn@hethane.se>
44  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
45  * @link     http://www.gnu.org/software/social/
46  */
47 class FavorAction extends FormAction
48 {
49     // We overload this because success should redirect
50     public function showForm($msg=null, $success=false)
51     {
52         if ($success) {
53             common_redirect(common_local_url('showfavorites',
54                 array('nickname' => $user->nickname)), 303);
55         }
56
57         parent::showForm($msg, $success);
58     }
59
60     protected function handlePost()
61     {
62         $id     = $this->trimmed('notice');
63         $notice = Notice::getKV($id);
64         if (!($notice instanceof Notice)) {
65             $this->serverError(_('Notice not found'));
66         }
67         if ($this->scoped->hasFave($notice)) {
68             // TRANS: Client error displayed when trying to mark a notice as favorite that already is a favorite.
69             $this->clientError(_('This notice is already a favorite!'));
70         }
71         $fave = Fave::addNew($this->scoped, $notice);
72         if (!$fave) {
73             // TRANS: Server error displayed when trying to mark a notice as favorite fails in the database.
74             $this->serverError(_('Could not create favorite.'));
75         }
76         $this->notify($notice, $this->scoped->getUser());
77         $this->scoped->blowFavesCache();
78         if (StatusNet::isAjax()) {
79             $this->startHTML('text/xml;charset=utf-8');
80             $this->elementStart('head');
81             // TRANS: Page title for page on which favorite notices can be unfavourited.
82             $this->element('title', null, _('Disfavor favorite.'));
83             $this->elementEnd('head');
84             $this->elementStart('body');
85             $disfavor = new DisFavorForm($this, $notice);
86             $disfavor->show();
87             $this->elementEnd('body');
88             $this->endHTML();
89             exit;
90         }
91         common_redirect(common_local_url('showfavorites',
92                                          array('nickname' => $this->scoped->nickname)),
93                             303);
94     }
95
96     /**
97      * Notifies a user when their notice is favorited.
98      *
99      * @param class $notice favorited notice
100      * @param class $user   user declaring a favorite
101      *
102      * @return void
103      */
104     function notify($notice, $user)
105     {
106         $other = User::getKV('id', $notice->profile_id);
107         if ($other && $other->id != $user->id) {
108             if ($other->email && $other->emailnotifyfav) {
109                 mail_notify_fave($other, $user, $notice);
110             }
111             // XXX: notify by IM
112             // XXX: notify by SMS
113         }
114     }
115 }