]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/favor.php
Repeated and Favorited CSS/mf2 fixes
[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     protected $needPost = true;
50
51     protected function handlePost()
52     {
53         $id     = $this->trimmed('notice');
54         $notice = Notice::getKV($id);
55         if (!($notice instanceof Notice)) {
56             $this->serverError(_('Notice not found'));
57         }
58         if ($this->scoped->hasFave($notice)) {
59             // TRANS: Client error displayed when trying to mark a notice as favorite that already is a favorite.
60             $this->clientError(_('This notice is already a favorite!'));
61         }
62         $fave = Fave::addNew($this->scoped, $notice);
63         if (!$fave) {
64             // TRANS: Server error displayed when trying to mark a notice as favorite fails in the database.
65             $this->serverError(_('Could not create favorite.'));
66         }
67         $this->notify($notice, $this->scoped->getUser());
68         $this->scoped->blowFavesCache();
69         if (StatusNet::isAjax()) {
70             $this->startHTML('text/xml;charset=utf-8');
71             $this->elementStart('head');
72             // TRANS: Page title for page on which favorite notices can be unfavourited.
73             $this->element('title', null, _('Disfavor favorite.'));
74             $this->elementEnd('head');
75             $this->elementStart('body');
76             $disfavor = new DisFavorForm($this, $notice);
77             $disfavor->show();
78             $this->elementEnd('body');
79             $this->endHTML();
80             exit;
81         }
82         common_redirect(common_local_url('showfavorites',
83                                          array('nickname' => $this->scoped->nickname)),
84                             303);
85     }
86
87     /**
88      * Notifies a user when their notice is favorited.
89      *
90      * @param class $notice favorited notice
91      * @param class $user   user declaring a favorite
92      *
93      * @return void
94      */
95     function notify($notice, $user)
96     {
97         $other = User::getKV('id', $notice->profile_id);
98         if ($other && $other->id != $user->id) {
99             if ($other->email && $other->emailnotifyfav) {
100                 mail_notify_fave($other, $user, $notice);
101             }
102             // XXX: notify by IM
103             // XXX: notify by SMS
104         }
105     }
106 }