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

salmon.php 2.42 KB
Newer Older
James Walker's avatar
James Walker committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
<?php
/**
 * StatusNet - the distributed open-source microblogging tool
 * Copyright (C) 2010, StatusNet, Inc.
 *
 * A sample module to show best practices for StatusNet plugins
 *
 * PHP version 5
 *
 * 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/>.
 *
 * @package   StatusNet
 * @author    James Walker <james@status.net>
 * @copyright 2010 StatusNet, Inc.
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
 * @link      http://status.net/
 */
class Salmon
{
31 32
    const REL_SALMON = 'salmon';
    const REL_MENTIONED = 'mentioned';
33

34
    // XXX: these are deprecated
35 36
    const NS_REPLIES = "http://salmon-protocol.org/ns/salmon-replies";
    const NS_MENTIONS = "http://salmon-protocol.org/ns/salmon-mention";
37

38 39 40
    /**
     * Sign and post the given Atom entry as a Salmon message.
     *
41
     * Side effects: may generate a keypair on-demand for the given user,
42
     * which can be very slow on some systems (like those without php5-gmp).
43 44
     *
     * @param string $endpoint_uri
45
     * @param string $xml string representation of payload
46
     * @param User $user local user profile whose keys we sign with
47 48
     * @return boolean success
     */
49
    public static function post($endpoint_uri, $xml, User $user)
James Walker's avatar
James Walker committed
50 51
    {
        if (empty($endpoint_uri)) {
52
            common_debug('No endpoint URI for Salmon post to '.$user->getUri());
53
            return false;
James Walker's avatar
James Walker committed
54 55
        }

56
        try {
57
            $magic_env = MagicEnvelope::signAsUser($xml, $user);
58 59 60 61
        } catch (Exception $e) {
            common_log(LOG_ERR, "Salmon unable to sign: " . $e->getMessage());
            return false;
        }
Siebrand Mazeland's avatar
Siebrand Mazeland committed
62

63
        if (Event::handle('SalmonSlap', array($magic_env))) {
64
            return false;
65
            //throw new ServerException('Could not distribute salmon slap as no plugin completed the event.');
James Walker's avatar
James Walker committed
66 67
        }

68
        return true;
69
    }
James Walker's avatar
James Walker committed
70
}