]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/nudge.php
b699a31441994e705c1219bf9f6df1a72133eabd
[quix0rs-gnu-social.git] / actions / nudge.php
1 <?php
2
3 /**
4  * User by ID action class.
5  *
6  * PHP version 5
7  *
8  * @category Action
9  * @package  StatusNet
10  * @author   Evan Prodromou <evan@status.net>
11  * @author   Robin Millette <millette@status.net>
12  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
13  * @link     http://status.net/
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('STATUSNET')) {
33     exit(1);
34 }
35
36 require_once INSTALLDIR.'/lib/mail.php';
37
38 /**
39  * Nudge a user action class.
40  *
41  * @category Action
42  * @package  StatusNet
43  * @author   Evan Prodromou <evan@status.net>
44  * @author   Robin Millette <millette@status.net>
45  * @author   Sarven Capadisli <csarven@status.net>
46  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
47  * @link     http://status.net/
48  */
49 class NudgeAction extends Action
50 {
51      /**
52      * Class handler.
53      *
54      * @param array $args array of arguments
55      *
56      * @return nothing
57      */
58     function handle($args)
59     {
60         parent::handle($args);
61
62         if (!common_logged_in()) {
63             $this->clientError(_('Not logged in.'));
64             return;
65         }
66
67         $user  = common_current_user();
68         $other = User::staticGet('nickname', $this->arg('nickname'));
69
70         if ($_SERVER['REQUEST_METHOD'] != 'POST') {
71             common_redirect(common_local_url('showstream',
72                 array('nickname' => $other->nickname)));
73             return;
74         }
75
76         // CSRF protection
77         $token = $this->trimmed('token');
78
79         if (!$token || $token != common_session_token()) {
80             $this->clientError(_('There was a problem with your session token. Try again, please.'));
81             return;
82         }
83
84         if (!$other->email || !$other->emailnotifynudge) {
85             $this->clientError(_('This user doesn\'t allow nudges or hasn\'t confirmed or set his email yet.'));
86             return;
87         }
88
89         $this->notify($user, $other);
90
91         if ($this->boolean('ajax')) {
92             $this->startHTML('text/xml;charset=utf-8');
93             $this->elementStart('head');
94             $this->element('title', null, _('Nudge sent'));
95             $this->elementEnd('head');
96             $this->elementStart('body');
97             $this->element('p', array('id' => 'nudge_response'), _('Nudge sent!'));
98             $this->elementEnd('body');
99             $this->elementEnd('html');
100         } else {
101             // display a confirmation to the user
102             common_redirect(common_local_url('showstream',
103                                              array('nickname' => $other->nickname)),
104                             303);
105         }
106     }
107
108      /**
109      * Do the actual notification
110      *
111      * @param class $user  nudger
112      * @param class $other nudgee
113      *
114      * @return nothing
115      */
116     function notify($user, $other)
117     {
118         if ($other->id != $user->id) {
119             if ($other->email && $other->emailnotifynudge) {
120                 mail_notify_nudge($user, $other);
121             }
122             // XXX: notify by IM
123             // XXX: notify by SMS
124         }
125     }
126
127     function isReadOnly($args)
128     {
129         return true;
130     }
131 }
132