]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/favor.php
Update translator documentation.
[quix0rs-gnu-social.git] / actions / favor.php
1 <?php
2 /**
3  * Favor action.
4  *
5  * PHP version 5
6  *
7  * @category Action
8  * @package  StatusNet
9  * @author   Evan Prodromou <evan@status.net>
10  * @author   Robin Millette <millette@status.net>
11  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
12  * @link     http://status.net/
13  *
14  * StatusNet - the distributed open-source microblogging tool
15  * Copyright (C) 2008, 2009, StatusNet, Inc.
16  *
17  * This program is free software: you can redistribute it and/or modify
18  * it under the terms of the GNU Affero General Public License as published by
19  * the Free Software Foundation, either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU Affero General Public License for more details.
26  *
27  * You should have received a copy of the GNU Affero General Public License
28  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
29  */
30
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/mail.php';
36 require_once INSTALLDIR.'/lib/disfavorform.php';
37
38 /**
39  * Favor class.
40  *
41  * @category Action
42  * @package  StatusNet
43  * @author   Evan Prodromou <evan@status.net>
44  * @author   Robin Millette <millette@status.net>
45  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
46  * @link     http://status.net/
47  */
48 class FavorAction extends Action
49 {
50     /**
51      * Class handler.
52      *
53      * @param array $args query arguments
54      *
55      * @return void
56      */
57     function handle($args)
58     {
59         parent::handle($args);
60         if (!common_logged_in()) {
61             // TRANS: Client error displayed when trying to mark a notice as favorite without being logged in.
62             $this->clientError(_('Not logged in.'));
63             return;
64         }
65         $user = common_current_user();
66         if ($_SERVER['REQUEST_METHOD'] != 'POST') {
67             common_redirect(common_local_url('showfavorites',
68                 array('nickname' => $user->nickname)));
69             return;
70         }
71         $id     = $this->trimmed('notice');
72         $notice = Notice::staticGet($id);
73         $token  = $this->trimmed('token-'.$notice->id);
74         if (!$token || $token != common_session_token()) {
75             // TRANS: Client error displayed when the session token does not match or is not given.
76             $this->clientError(_('There was a problem with your session token. Try again, please.'));
77             return;
78         }
79         if ($user->hasFave($notice)) {
80             // TRANS: Client error displayed when trying to mark a notice as favorite that already is a favorite.
81             $this->clientError(_('This notice is already a favorite!'));
82             return;
83         }
84         $fave = Fave::addNew($user->getProfile(), $notice);
85         if (!$fave) {
86             // TRANS: Server error displayed when trying to mark a notice as favorite fails in the database.
87             $this->serverError(_('Could not create favorite.'));
88             return;
89         }
90         $this->notify($notice, $user);
91         $user->blowFavesCache();
92         if ($this->boolean('ajax')) {
93             $this->startHTML('text/xml;charset=utf-8');
94             $this->elementStart('head');
95             // TRANS: Page title for page on which favorite notices can be unfavourited.
96             $this->element('title', null, _('Disfavor favorite.'));
97             $this->elementEnd('head');
98             $this->elementStart('body');
99             $disfavor = new DisFavorForm($this, $notice);
100             $disfavor->show();
101             $this->elementEnd('body');
102             $this->elementEnd('html');
103         } else {
104             common_redirect(common_local_url('showfavorites',
105                                              array('nickname' => $user->nickname)),
106                             303);
107         }
108     }
109
110     /**
111      * Notifies a user when their notice is favorited.
112      *
113      * @param class $notice favorited notice
114      * @param class $user   user declaring a favorite
115      *
116      * @return void
117      */
118     function notify($notice, $user)
119     {
120         $other = User::staticGet('id', $notice->profile_id);
121         if ($other && $other->id != $user->id) {
122             if ($other->email && $other->emailnotifyfav) {
123                 mail_notify_fave($other, $user, $notice);
124             }
125             // XXX: notify by IM
126             // XXX: notify by SMS
127         }
128     }
129 }