We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

nudge.php 4.11 KB
Newer Older
csarven's avatar
csarven committed
1
<?php
Robin Millette's avatar
Robin Millette committed
2 3 4 5 6 7 8

/**
 * User by ID action class.
 *
 * PHP version 5
 *
 * @category Action
9
 * @package  StatusNet
10 11
 * @author   Evan Prodromou <evan@status.net>
 * @author   Robin Millette <millette@status.net>
Robin Millette's avatar
Robin Millette committed
12
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
13
 * @link     http://status.net/
Robin Millette's avatar
Robin Millette committed
14
 *
15
 * StatusNet - the distributed open-source microblogging tool
16
 * Copyright (C) 2008, 2009, StatusNet, Inc.
csarven's avatar
csarven committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

32
if (!defined('STATUSNET') && !defined('LACONICA')) {
Robin Millette's avatar
Robin Millette committed
33 34
    exit(1);
}
csarven's avatar
csarven committed
35

Robin Millette's avatar
Robin Millette committed
36
require_once INSTALLDIR.'/lib/mail.php';
csarven's avatar
csarven committed
37

Robin Millette's avatar
Robin Millette committed
38 39 40 41
/**
 * Nudge a user action class.
 *
 * @category Action
42
 * @package  StatusNet
43 44 45
 * @author   Evan Prodromou <evan@status.net>
 * @author   Robin Millette <millette@status.net>
 * @author   Sarven Capadisli <csarven@status.net>
Robin Millette's avatar
Robin Millette committed
46
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
47
 * @link     http://status.net/
Robin Millette's avatar
Robin Millette committed
48
 */
49 50
class NudgeAction extends Action
{
Robin Millette's avatar
Robin Millette committed
51 52
     /**
     * Class handler.
53
     *
Robin Millette's avatar
Robin Millette committed
54 55 56 57
     * @param array $args array of arguments
     *
     * @return nothing
     */
58 59
    function handle($args)
    {
60
        parent::handle($args);
csarven's avatar
csarven committed
61

62
        if (!common_logged_in()) {
63
            // TRANS: Client error displayed trying to nudge a user without being logged in.
64
            $this->clientError(_('Not logged in.'));
65 66
            return;
        }
csarven's avatar
csarven committed
67

Robin Millette's avatar
Robin Millette committed
68
        $user  = common_current_user();
69
        $other = User::staticGet('nickname', $this->arg('nickname'));
millette's avatar
millette committed
70

71
        if ($_SERVER['REQUEST_METHOD'] != 'POST') {
Robin Millette's avatar
Robin Millette committed
72 73
            common_redirect(common_local_url('showstream',
                array('nickname' => $other->nickname)));
74 75
            return;
        }
millette's avatar
millette committed
76

Robin Millette's avatar
Robin Millette committed
77
        // CSRF protection
78
        $token = $this->trimmed('token');
79

80
        if (!$token || $token != common_session_token()) {
81
            $this->clientError(_('There was a problem with your session token. Try again, please.'));
82 83
            return;
        }
millette's avatar
millette committed
84 85

        if (!$other->email || !$other->emailnotifynudge) {
86
            // TRANS: Client error displayed trying to nudge a user that cannot be nudged.
Siebrand Mazeland's avatar
Siebrand Mazeland committed
87
            $this->clientError(_('This user doesn\'t allow nudges or hasn\'t confirmed or set their email address yet.'));
millette's avatar
millette committed
88 89 90
            return;
        }

91
        $this->notify($user, $other);
csarven's avatar
csarven committed
92

93
        if ($this->boolean('ajax')) {
94
            $this->startHTML('text/xml;charset=utf-8');
95
            $this->elementStart('head');
96
            // TRANS: Page title after sending a nudge.
97 98 99
            $this->element('title', null, _('Nudge sent'));
            $this->elementEnd('head');
            $this->elementStart('body');
100
            // TRANS: Confirmation text after sending a nudge.
101
            $this->element('p', array('id' => 'nudge_response'), _('Nudge sent!'));
102 103
            $this->elementEnd('body');
            $this->elementEnd('html');
104
        } else {
105
            // display a confirmation to the user
106
            common_redirect(common_local_url('showstream',
107 108
                                             array('nickname' => $other->nickname)),
                            303);
109 110
        }
    }
csarven's avatar
csarven committed
111

Robin Millette's avatar
Robin Millette committed
112 113 114 115 116 117 118 119
     /**
     * Do the actual notification
     *
     * @param class $user  nudger
     * @param class $other nudgee
     *
     * @return nothing
     */
120 121
    function notify($user, $other)
    {
122 123 124 125
        if ($other->id != $user->id) {
            if ($other->email && $other->emailnotifynudge) {
                mail_notify_nudge($user, $other);
            }
Robin Millette's avatar
Robin Millette committed
126 127
            // XXX: notify by IM
            // XXX: notify by SMS
128 129
        }
    }
Robin Millette's avatar
Robin Millette committed
130

131
    function isReadOnly($args)
Robin Millette's avatar
Robin Millette committed
132 133 134
    {
        return true;
    }
csarven's avatar
csarven committed
135
}