]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
in progress Salmon responses
authorJames Walker <walkah@walkah.net>
Tue, 9 Feb 2010 20:37:37 +0000 (15:37 -0500)
committerJames Walker <walkah@walkah.net>
Tue, 9 Feb 2010 20:37:37 +0000 (15:37 -0500)
plugins/OStatus/OStatusPlugin.php
plugins/OStatus/actions/salmon.php [new file with mode: 0644]
plugins/OStatus/actions/webfinger.php
plugins/OStatus/lib/Salmon.php [new file with mode: 0644]
plugins/OStatus/lib/Webfinger.php

index ce33344d2c2179af78890215cb70f78f6d5ac2fe..60a4e382737609c33ab603c32b6d477b93e450db 100644 (file)
@@ -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 (file)
index 0000000..012869c
--- /dev/null
@@ -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
+
+    }
+}
index ec2dddd534b4193d60a58d0ec7a3b9f4982a8335..75ba16638ba26f93ed2cfd138c0426caabea7887 100644 (file)
@@ -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 (file)
index 0000000..8c77222
--- /dev/null
@@ -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)
+    {
+
+
+    }
+}
index 7ab6b421bffa940b0df22a2318da3d8f2173e663..417d54904b6d85e251f8fec7459ead5b5b4f353a 100644 (file)
@@ -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)