]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Webmention frontend
authorStephen Paul Weber <singpolyma@singpolyma.net>
Thu, 22 Oct 2015 17:18:20 +0000 (17:18 +0000)
committerStephen Paul Weber <singpolyma@singpolyma.net>
Thu, 12 Nov 2015 19:06:15 +0000 (19:06 +0000)
plugins/Linkback/LinkbackPlugin.php
plugins/Linkback/actions/webmention.php [new file with mode: 0644]

index e3519dac9ee9c7eada8e30654a07bbeee9b3faa5..2aeb8ea016f57d5f5a648145abc3fa97322df934 100644 (file)
@@ -32,6 +32,7 @@ if (!defined('STATUSNET')) {
 }
 
 require_once('Auth/Yadis/Yadis.php');
+require_once(__DIR__ . '/lib/util.php');
 
 define('LINKBACKPLUGIN_VERSION', '0.1');
 
@@ -306,6 +307,12 @@ class LinkbackPlugin extends Plugin
         }
     }
 
+
+    public function onRouterInitialized(URLMapper $m)
+    {
+        $m->connect('main/linkback/webmention', array('action' => 'webmention'));
+    }
+
     public function version()
     {
         return LINKBACKPLUGIN_VERSION;
diff --git a/plugins/Linkback/actions/webmention.php b/plugins/Linkback/actions/webmention.php
new file mode 100644 (file)
index 0000000..30bc42c
--- /dev/null
@@ -0,0 +1,73 @@
+<?php
+/*
+ * 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/>.
+ */
+
+if (!defined('STATUSNET')) {
+    exit(1);
+}
+
+class WebmentionAction extends Action
+{
+    protected function handle()
+    {
+        GNUsocial::setApi(true); // Minimize error messages to aid in debugging
+        parent::handle();
+        if ($this->isPost()) {
+            return $this->handlePost();
+        }
+
+        return false;
+    }
+
+    function handlePost()
+    {
+        $source = $this->arg('source');
+        $target = $this->arg('target');
+
+        header('Content-Type: text/plain; charset=utf-8');
+
+        if(!$source) {
+            echo _m('"source" is missing')."\n";
+            throw new ServerException(_m('"source" is missing'), 400);
+        }
+
+        if(!$target) {
+            echo _m('"target" is missing')."\n";
+            throw new ServerException(_m('"target" is missing'), 400);
+        }
+
+        $response = linkback_get_source($source, $target);
+        if(!$response) {
+            echo _m('Source does not link to target.')."\n";
+            throw new ServerException(_m('Source does not link to target.'), 400);
+        }
+
+        $notice = linkback_get_target($target);
+        if(!$notice) {
+            echo _m('Target not found')."\n";
+            throw new ServerException(_m('Target not found'), 404);
+        }
+
+        $url = linkback_save($source, $target, $response, $notice);
+        if(!$url) {
+            echo _m('An error occured while saving.')."\n";
+            throw new ServerException(_m('An error occured while saving.'), 500);
+        }
+
+        echo $url."\n";
+
+        return true;
+    }
+}