]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/nudge.php
Merge branch 'master' of ../trunk
[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  Laconica
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/
14  *
15  * Laconica - a distributed open-source microblogging tool
16  * Copyright (C) 2008, Controlez-Vous, 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('LACONICA')) {
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  Laconica
43  * @author   Evan Prodromou <evan@controlyourself.ca>
44  * @author   Robin Millette <millette@controlyourself.ca>
45  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
46  * @link     http://laconi.ca/
47  */
48 class NudgeAction extends Action
49 {
50      /**
51      * Class handler.
52      * 
53      * @param array $args array of arguments
54      *
55      * @return nothing
56      */
57     function handle($args)
58     {
59         parent::handle($args);
60
61         if (!common_logged_in()) {
62             $this->clientError(_('Not logged in.'));
63             return;
64         }
65
66         $user  = common_current_user();
67         $other = User::staticGet('nickname', $this->arg('nickname'));
68
69         if ($_SERVER['REQUEST_METHOD'] != 'POST') {
70             common_redirect(common_local_url('showstream',
71                 array('nickname' => $other->nickname)));
72             return;
73         }
74
75         // CSRF protection
76         $token = $this->trimmed('token');
77         
78         if (!$token || $token != common_session_token()) {
79             $this->clientError(_('There was a problem with your session token. Try again, please.'));
80             return;
81         }
82
83         if (!$other->email || !$other->emailnotifynudge) {
84             $this->clientError(_('This user doesn\'t allow nudges or hasn\'t confirmed or set his email yet.'));
85             return;
86         }
87
88         $this->notify($user, $other);
89
90         if ($this->boolean('ajax')) {
91             $this->startHTML('text/xml;charset=utf-8', true);
92             $this->elementStart('head');
93             $this->element('title', null, _('Nudge sent'));
94             $this->elementEnd('head');
95             $this->elementStart('body');
96             common_nudge_response();
97             $this->elementEnd('body');
98             $this->elementEnd('html');
99         } else {
100             // display a confirmation to the user
101             common_redirect(common_local_url('showstream',
102                                              array('nickname' => $other->nickname)));
103         }
104     }
105
106      /**
107      * Do the actual notification
108      *
109      * @param class $user  nudger
110      * @param class $other nudgee
111      *
112      * @return nothing
113      */
114     function notify($user, $other)
115     {
116         if ($other->id != $user->id) {
117             if ($other->email && $other->emailnotifynudge) {
118                 mail_notify_nudge($user, $other);
119             }
120             // XXX: notify by IM
121             // XXX: notify by SMS
122         }
123     }
124 }
125