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

nudge.php 3.62 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 45 46 47
/**
 * Nudge a user action class.
 *
 * @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/
 */
48 49
class NudgeAction extends Action
{
Robin Millette's avatar
Robin Millette committed
50 51 52 53 54 55 56
     /**
     * Class handler.
     * 
     * @param array $args array of arguments
     *
     * @return nothing
     */
57 58
    function handle($args)
    {
59
        parent::handle($args);
csarven's avatar
csarven committed
60

61
        if (!common_logged_in()) {
62
            $this->clientError(_('Not logged in.'));
63 64
            return;
        }
csarven's avatar
csarven committed
65

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

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

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

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

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

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