From cc454c2a378e1a6e155606a3d8a17907ef3fc352 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sun, 25 Mar 2018 14:16:43 -0600 Subject: [PATCH] Add base plugin and the beginning of the actor method --- ActivityPubPlugin.php | 53 ++++++++++++++++++++++++++++++++++++ actions/activitypubactor.php | 53 ++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 ActivityPubPlugin.php create mode 100644 actions/activitypubactor.php diff --git a/ActivityPubPlugin.php b/ActivityPubPlugin.php new file mode 100644 index 0000000..313d017 --- /dev/null +++ b/ActivityPubPlugin.php @@ -0,0 +1,53 @@ +. + * + * @category Plugin + * @package GNUsocial + * @author Daniel Supernault + * @copyright 2014 Free Software Foundation http://fsf.org + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link https://www.gnu.org/software/social/ + */ + +if (!defined('GNUSOCIAL')) { exit(1); } + +class ActivityPubPlugin extends Plugin +{ + + public function onRouterInitialized(URLMapper $m) + { + $m->connect('api/statuses/user_timeline/:id.ap', + ['action' => 'activitypubactor'], + ['id' => '[0-9]+']); + } + + public function onPluginVersion(array &$versions) + { + $versions[] = [ 'name' => 'ActivityPub', + 'version' => GNUSOCIAL_VERSION, + 'author' => 'Daniel Supernault', + 'homepage' => 'https://www.gnu.org/software/social/', + 'rawdescription' => + // Todo: Translation + 'Adds ActivityPub Support']; + return true; + } +} diff --git a/actions/activitypubactor.php b/actions/activitypubactor.php new file mode 100644 index 0000000..19aa7c3 --- /dev/null +++ b/actions/activitypubactor.php @@ -0,0 +1,53 @@ +. + * + * @category Plugin + * @package GNUsocial + * @author Daniel Supernault + * @copyright 2015 Free Software Foundaction, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link https://gnu.io/social + */ + +if (!defined('GNUSOCIAL')) { exit(1); } + +class ActivityPubActorAction extends ManagedAction +{ + protected $needLogin = false; + protected $canPost = true; + + protected $user = false; + + protected function handle() + { + $this->user = User::getByID($this->trimmed('id')); + + $res = [ + '@context' => ["https://www.w3.org/ns/activitystreams"], + 'id' => $this->user->uri, + 'type' => 'Person' + + ]; + + header('Content-Type: application/json'); + echo json_encode($res, JSON_PRETTY_PRINT); + } +}