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

nudge.php 3.79 KB
Newer Older
csarven's avatar
csarven committed
1
<?php
Robin Millette's avatar
Robin Millette committed
2 3 4 5 6 7 8 9 10 11 12 13 14

/**
 * User by ID action class.
 *
 * PHP version 5
 *
 * @category Action
 * @package  Laconica
 * @author   Evan Prodromou <evan@controlyourself.ca>
 * @author   Robin Millette <millette@controlyourself.ca>
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
 * @link     http://laconi.ca/
 *
csarven's avatar
csarven committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 * Laconica - a distributed open-source microblogging tool
 * Copyright (C) 2008, Controlez-Vous, Inc.
 *
 * 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/>.
 */

Robin Millette's avatar
Robin Millette committed
32 33 34
if (!defined('LACONICA')) {
    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 42 43 44
/**
 * Nudge a user action class.
 *
 * @category Action
 * @package  Laconica
 * @author   Evan Prodromou <evan@controlyourself.ca>
 * @author   Robin Millette <millette@controlyourself.ca>
45
 * @author   Sarven Capadisli <csarven@controlyourself.ca>
Robin Millette's avatar
Robin Millette committed
46 47 48
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
 * @link     http://laconi.ca/
 */
49 50
class NudgeAction extends Action
{
Robin Millette's avatar
Robin Millette committed
51 52 53 54 55 56 57
     /**
     * Class handler.
     * 
     * @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
            $this->clientError(_('Not logged in.'));
64 65
            return;
        }
csarven's avatar
csarven committed
66

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

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

Robin Millette's avatar
Robin Millette committed
76
        // CSRF protection
77 78 79
        $token = $this->trimmed('token');
        
        if (!$token || $token != common_session_token()) {
80
            $this->clientError(_('There was a problem with your session token. Try again, please.'));
81 82
            return;
        }
millette's avatar
millette committed
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.'));
millette's avatar
millette committed
86 87 88
            return;
        }

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

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

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

    function isReadOnly()
    {
        return true;
    }
csarven's avatar
csarven committed
130
}
131