forked from GNUsocial/gnu-social
Merge branch 'testing' of git@gitorious.org:statusnet/mainline into testing
This commit is contained in:
commit
5509f923ea
@ -53,6 +53,7 @@ class OStatusPlugin extends Plugin
|
||||
*/
|
||||
function onRouterInitialized($m)
|
||||
{
|
||||
// Discovery actions
|
||||
$m->connect('.well-known/host-meta',
|
||||
array('action' => 'hostmeta'));
|
||||
$m->connect('main/webfinger',
|
||||
@ -66,6 +67,7 @@ class OStatusPlugin extends Plugin
|
||||
$m->connect('main/ostatussub',
|
||||
array('action' => 'ostatussub'), array('feed' => '[A-Za-z0-9\.\/\:]+'));
|
||||
|
||||
// PuSH actions
|
||||
$m->connect('main/push/hub', array('action' => 'pushhub'));
|
||||
|
||||
$m->connect('main/push/callback/:feed',
|
||||
@ -73,6 +75,11 @@ class OStatusPlugin extends Plugin
|
||||
array('feed' => '[0-9]+'));
|
||||
$m->connect('settings/feedsub',
|
||||
array('action' => 'feedsubsettings'));
|
||||
|
||||
// Salmon endpoint
|
||||
$m->connect('salmon/user/:id',
|
||||
array('action' => 'salmon'),
|
||||
array('id' => '[0-9]+'));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -111,6 +118,10 @@ class OStatusPlugin extends Plugin
|
||||
// Updates will be handled for our internal PuSH hub.
|
||||
$action->element('link', array('rel' => 'hub',
|
||||
'href' => common_local_url('pushhub')));
|
||||
|
||||
// Also, we'll add in the salmon link
|
||||
$action->element('link', array('rel' => 'salmon',
|
||||
'href' => common_local_url('salmon')));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@ -181,6 +192,49 @@ class OStatusPlugin extends Plugin
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we've got some Salmon stuff to send
|
||||
*/
|
||||
function onEndNoticeSave($notice)
|
||||
{
|
||||
$count = preg_match_all('/(\w+\.)*\w+@(\w+\.)*\w+(\w+\-\w+)*\.\w+/', $notice->content, $matches);
|
||||
if ($count) {
|
||||
foreach ($matches[0] as $webfinger) {
|
||||
// Check to see if we've got an actual webfinger
|
||||
$w = new Webfinger;
|
||||
|
||||
$endpoint_uri = '';
|
||||
|
||||
$result = $w->lookup($webfinger);
|
||||
if (empty($result)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($result->links as $link) {
|
||||
if ($link['rel'] == 'salmon') {
|
||||
$endpoint_uri = $link['href'];
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($endpoint_uri)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$profile = $notice->getProfile();
|
||||
|
||||
$acct = $profile->nickname .'@'. common_config('site', 'server');
|
||||
|
||||
$xml = '<?xml version="1.0" encoding="UTF-8" ?>';
|
||||
$xml .= $notice->asAtomEntry();
|
||||
// TODO : need to set author/uri to webfinger acct. more cleanly
|
||||
$xml = preg_replace('/<uri>([^<])*<\/uri>/i', '<uri>acct:'.$acct.'</uri>', $xml);
|
||||
|
||||
|
||||
$salmon = new Salmon();
|
||||
$salmon->post($endpoint_uri, $xml);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function onCheckSchema() {
|
||||
|
49
plugins/OStatus/actions/salmon.php
Normal file
49
plugins/OStatus/actions/salmon.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/*
|
||||
* StatusNet - the distributed open-source microblogging tool
|
||||
* Copyright (C) 2010, StatusNet, 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @package OStatusPlugin
|
||||
* @author James Walker <james@status.net>
|
||||
*/
|
||||
|
||||
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
|
||||
|
||||
class SalmonAction extends Action
|
||||
{
|
||||
|
||||
function handle()
|
||||
{
|
||||
parent::handle();
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
$this->handlePost();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function handlePost()
|
||||
{
|
||||
$user_id = $this->arg('id');
|
||||
common_log(LOG_DEBUG, 'Salmon: incoming post for user: '. $user_id);
|
||||
|
||||
$xml = file_get_contents('php://input');
|
||||
|
||||
// TODO : Insert new $xml -> notice code
|
||||
|
||||
}
|
||||
}
|
@ -58,6 +58,13 @@ class WebfingerAction extends Action
|
||||
$xrd->links[] = array('rel' => 'http://webfinger.net/rel/profile-page',
|
||||
'type' => 'text/html',
|
||||
'href' => common_profile_url($nick));
|
||||
|
||||
$salmon_url = common_local_url('salmon',
|
||||
array('id' => $this->user->id));
|
||||
|
||||
$xrd->links[] = array('rel' => 'salmon',
|
||||
'href' => $salmon_url);
|
||||
|
||||
// TODO - finalize where the redirect should go on the publisher
|
||||
$url = common_local_url('ostatussub') . '?feed={uri}';
|
||||
$xrd->links[] = array('rel' => 'http://ostatus.org/schema/1.0/subscribe',
|
||||
|
64
plugins/OStatus/lib/Salmon.php
Normal file
64
plugins/OStatus/lib/Salmon.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?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
|
||||
{
|
||||
public function post($endpoint_uri, $xml)
|
||||
{
|
||||
if (empty($endpoint_uri)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$headers = array('Content-type: application/atom+xml');
|
||||
|
||||
try {
|
||||
$client = new HTTPClient();
|
||||
$client->setBody($xml);
|
||||
$response = $client->post($endpoint_uri, $headers);
|
||||
} catch (HTTP_Request2_Exception $e) {
|
||||
return false;
|
||||
}
|
||||
if ($response->getStatus() != 200) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function createMagicEnv($text, $userid)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function verifyMagicEnv($env)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -76,6 +76,10 @@ class Webfinger
|
||||
{
|
||||
$url = 'http://'. $domain .'/.well-known/host-meta';
|
||||
$content = $this->fetchURL($url);
|
||||
if (empty($content)) {
|
||||
common_log(LOG_DEBUG, 'Error fetching host-meta');
|
||||
return false;
|
||||
}
|
||||
$result = XRD::parse($content);
|
||||
|
||||
// Ensure that the host == domain (spec may include signing later)
|
||||
|
Loading…
Reference in New Issue
Block a user