summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/OStatus/OStatusPlugin.php60
-rw-r--r--plugins/OStatus/actions/salmon.php49
-rw-r--r--plugins/OStatus/actions/webfinger.php7
-rw-r--r--plugins/OStatus/lib/Salmon.php64
-rw-r--r--plugins/OStatus/lib/Webfinger.php4
5 files changed, 181 insertions, 3 deletions
diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php
index ce33344d2..60a4e3827 100644
--- a/plugins/OStatus/OStatusPlugin.php
+++ b/plugins/OStatus/OStatusPlugin.php
@@ -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',
@@ -65,7 +66,8 @@ class OStatusPlugin extends Plugin
array('action' => 'ostatussub'));
$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,11 +118,15 @@ 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;
}
-
+
/**
* Add the feed settings page to the Connect Settings menu
*
@@ -180,8 +191,51 @@ class OStatusPlugin extends Plugin
$output->elementEnd('li');
}
}
-
+ /**
+ * 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() {
// warning: the autoincrement doesn't seem to set.
diff --git a/plugins/OStatus/actions/salmon.php b/plugins/OStatus/actions/salmon.php
new file mode 100644
index 000000000..012869cf7
--- /dev/null
+++ b/plugins/OStatus/actions/salmon.php
@@ -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
+
+ }
+}
diff --git a/plugins/OStatus/actions/webfinger.php b/plugins/OStatus/actions/webfinger.php
index ec2dddd53..75ba16638 100644
--- a/plugins/OStatus/actions/webfinger.php
+++ b/plugins/OStatus/actions/webfinger.php
@@ -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',
diff --git a/plugins/OStatus/lib/Salmon.php b/plugins/OStatus/lib/Salmon.php
new file mode 100644
index 000000000..8c77222a6
--- /dev/null
+++ b/plugins/OStatus/lib/Salmon.php
@@ -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)
+ {
+
+
+ }
+}
diff --git a/plugins/OStatus/lib/Webfinger.php b/plugins/OStatus/lib/Webfinger.php
index 7ab6b421b..417d54904 100644
--- a/plugins/OStatus/lib/Webfinger.php
+++ b/plugins/OStatus/lib/Webfinger.php
@@ -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)