Updated plugin as per the doc

This commit is contained in:
Diogo Cordeiro 2018-04-29 13:43:18 +01:00
parent 8efcc5742d
commit 2889b1ba7e
4 changed files with 93 additions and 21 deletions

View File

@ -22,6 +22,7 @@
* @category Plugin
* @package GNUsocial
* @author Daniel Supernault <danielsupernault@gmail.com>
* @author Diogo Cordeiro <diogo@fc.up.pt>
* @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/
@ -34,16 +35,16 @@ class ActivityPubPlugin extends Plugin
public function onRouterInitialized(URLMapper $m)
{
$m->connect('api/statuses/user_timeline/:id.ap',
['action' => 'activitypubactor'],
['id' => '[0-9]+']);
$m->connect(':nickname/profile.json',
['action' => 'apActorProfile'],
['nickname' => Nickname::DISPLAY_FMT]);
}
public function onPluginVersion(array &$versions)
{
$versions[] = [ 'name' => 'ActivityPub',
'version' => GNUSOCIAL_VERSION,
'author' => 'Daniel Supernault',
'author' => 'Daniel Supernault, Diogo Cordeiro',
'homepage' => 'https://www.gnu.org/software/social/',
'rawdescription' =>
// Todo: Translation

View File

@ -1,3 +1,2 @@
# ActivityPub GNU/Social Plugin
Warning: This is still a work in progress, not every ActivityPub property is fully implemented yet.
Warning: This is still a work in progress, not every ActivityPub property is fully implemented yet.

View File

@ -22,6 +22,7 @@
* @category Plugin
* @package GNUsocial
* @author Daniel Supernault <danielsupernault@gmail.com>
* @author Diogo Cordeiro <diogo@fc.up.pt>
* @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
@ -29,18 +30,23 @@
if (!defined('GNUSOCIAL')) { exit(1); }
class ActivityPubActorAction extends ManagedAction
class apActorProfileAction extends ManagedAction
{
protected $needLogin = false;
protected $canPost = true;
protected function handle()
{
$user = User::getByID($this->trimmed('id'));
$profile = $user->getProfile();
$url = $profile->profileurl;
$nickname = $this->trimmed('nickname');
try {
$user = User::getByNickname($nickname);
$profile = $user->getProfile();
$url = $profile->profileurl;
} catch (Exception $e) {
throw new \Exception('Invalid username');
}
$avatar = $profile->avatarUrl(AVATAR_PROFILE_SIZE);
$avatar_url = $profile->avatarUrl(AVATAR_PROFILE_SIZE);
$res = [
'@context' => [
@ -49,27 +55,29 @@ class ActivityPubActorAction extends ManagedAction
"@language" => "en"
]
],
'id' => $url,
'id' => $user->getID(),
'type' => 'Person',
'following' => "{$url}/subscriptions",
'username' => $user->nickname,
'inbox' => "{$url}/inbox.json",
'outbox' => "{$url}/outbox.json",
'acct' => null, // TODO: Equals `username` for local users, includes `@domain` for remote ones
'display_name' => $profile->fullname,
'followers' => "{$url}/subscribers",
'inbox' => null,
'outbox' => null,
'liked' => "{$url}/favorites",
'preferredUsername' => $user->nickname,
'name' => $user->nickname,
'following' => "{$url}/subscriptions",
'liked' => "{$url}/liked.json",
'liked_count' => Fave::countByProfile ($profile),
'summary' => $profile->bio,
'url' => $url,
'icon' => [
'avatar' => [
'type' => 'Image',
'width' => 96,
'height' => 96,
'url' => $avatar
'url' => $avatar_url
]
];
header('Content-Type: application/json');
echo json_encode($res, JSON_PRETTY_PRINT);
echo json_encode($res, isset($_GET["pretty"]) ? JSON_PRETTY_PRINT : null);
}
}

View File

@ -0,0 +1,64 @@
<?php
/**
* GNU social - a federating social network
*
* Todo: Description
*
* PHP version 5
*
* LICENCE: 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/>.
*
* @category Plugin
* @package GNUsocial
* @author Daniel Supernault <danielsupernault@gmail.com>
* @author Diogo Cordeiro <diogo@fc.up.pt>
* @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 Activitypub_notice extends Managed_DataObject
{
public static function noticeToObject($notice)
{
// todo: fix timestamp formats
$item = [
'id' => $notice->getUrl(),
// TODO: handle other types
'type' => 'Notice',
'actor' => $notice->getProfile()->getUrl(),
'published' => $notice->created,
'to' => [
// TODO: handle proper scope
'https://www.w3.org/ns/activitystreams#Public'
],
'cc' => [
// TODO: add cc's
"{$notice->getProfile()->getUrl()}/subscribers",
],
'content' => $notice->getContent(),
'rendered' => $notice->getRendered(),
'url' => $notice->getUrl(),
'reply_to' => empty($notice->reply_to) ? null : Notice::getById($notice->reply_to)->getUrl(),
'is_local' => $notice->is_local,
'conversation' => $notice->conversation,
'attachment' => [],
'tag' => []
];
return $item;
}
}