Updated the plugin as per the doc
TODO: Implement query parameters in apactorlikedcollection.php" as per the doc
This commit is contained in:
parent
21abaca924
commit
0938e7809f
@ -22,6 +22,7 @@
|
|||||||
* @category Plugin
|
* @category Plugin
|
||||||
* @package GNUsocial
|
* @package GNUsocial
|
||||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||||
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||||
* @copyright 2014 Free Software Foundation http://fsf.org
|
* @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
|
* @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/
|
* @link https://www.gnu.org/software/social/
|
||||||
@ -34,13 +35,13 @@ class ActivityPubPlugin extends Plugin
|
|||||||
|
|
||||||
public function onRouterInitialized(URLMapper $m)
|
public function onRouterInitialized(URLMapper $m)
|
||||||
{
|
{
|
||||||
$m->connect('api/statuses/user_timeline/:id.ap',
|
$m->connect(':nickname/profile.json',
|
||||||
['action' => 'activitypubactor'],
|
['action' => 'apActorProfile'],
|
||||||
['id' => '[0-9]+']);
|
['nickname' => Nickname::DISPLAY_FMT]);
|
||||||
|
|
||||||
$m->connect('api/user/:id/liked.json',
|
$m->connect(':nickname/liked.json',
|
||||||
['action' => 'likedactor'],
|
['action' => 'apActorLikedCollection'],
|
||||||
['id' => '[0-9]+']);
|
['nickname' => Nickname::DISPLAY_FMT]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onPluginVersion(array &$versions)
|
public function onPluginVersion(array &$versions)
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
*
|
*
|
||||||
* @category Plugin
|
* @category Plugin
|
||||||
* @package GNUsocial
|
* @package GNUsocial
|
||||||
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||||
* @copyright 2015 Free Software Foundaction, Inc.
|
* @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
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||||
@ -29,16 +30,23 @@
|
|||||||
|
|
||||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||||
|
|
||||||
class LikedActorAction extends ManagedAction
|
class apActorLikedCollectionAction extends ManagedAction
|
||||||
{
|
{
|
||||||
protected $needLogin = false;
|
protected $needLogin = false;
|
||||||
protected $canPost = true;
|
protected $canPost = true;
|
||||||
|
|
||||||
protected function handle()
|
protected function handle()
|
||||||
{
|
{
|
||||||
$user = User::getByID($this->trimmed('id'));
|
$nickname = $this->trimmed('nickname');
|
||||||
|
try {
|
||||||
|
$user = User::getByNickname($nickname);
|
||||||
$profile = $user->getProfile();
|
$profile = $user->getProfile();
|
||||||
$url = $profile->profileurl;
|
$url = $profile->profileurl;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
throw new \Exception('Invalid username');
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Implement query parameters as per the doc
|
||||||
|
|
||||||
$total_faves = Fave::countByProfile ($profile);
|
$total_faves = Fave::countByProfile ($profile);
|
||||||
|
|
||||||
@ -64,14 +72,14 @@ class LikedActorAction extends ManagedAction
|
|||||||
|
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
echo json_encode($res, JSON_PRETTY_PRINT);
|
echo json_encode($res, isset($_GET["pretty"]) ? JSON_PRETTY_PRINT : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function pretty_fave ($fave_object)
|
protected function pretty_fave ($fave_object)
|
||||||
{
|
{
|
||||||
$res = array ("uri" => $fave_object->uri,
|
$res = array ("uri" => $fave_object->uri,
|
||||||
"created" => $fave_object->created,
|
"created" => $fave_object->created,
|
||||||
"object" => Notice::getByID($fave_object->notice_id));
|
"object" => Activitypub_notice::noticeToObject(Notice::getByID($fave_object->notice_id)));
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
@ -22,6 +22,7 @@
|
|||||||
* @category Plugin
|
* @category Plugin
|
||||||
* @package GNUsocial
|
* @package GNUsocial
|
||||||
* @author Daniel Supernault <danielsupernault@gmail.com>
|
* @author Daniel Supernault <danielsupernault@gmail.com>
|
||||||
|
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||||
* @copyright 2015 Free Software Foundaction, Inc.
|
* @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
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||||
* @link https://gnu.io/social
|
* @link https://gnu.io/social
|
||||||
@ -29,18 +30,23 @@
|
|||||||
|
|
||||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||||
|
|
||||||
class ActivityPubActorAction extends ManagedAction
|
class apActorProfileAction extends ManagedAction
|
||||||
{
|
{
|
||||||
protected $needLogin = false;
|
protected $needLogin = false;
|
||||||
protected $canPost = true;
|
protected $canPost = true;
|
||||||
|
|
||||||
protected function handle()
|
protected function handle()
|
||||||
{
|
{
|
||||||
$user = User::getByID($this->trimmed('id'));
|
$nickname = $this->trimmed('nickname');
|
||||||
|
try {
|
||||||
|
$user = User::getByNickname($nickname);
|
||||||
$profile = $user->getProfile();
|
$profile = $user->getProfile();
|
||||||
$url = $profile->profileurl;
|
$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 = [
|
$res = [
|
||||||
'@context' => [
|
'@context' => [
|
||||||
@ -49,27 +55,29 @@ class ActivityPubActorAction extends ManagedAction
|
|||||||
"@language" => "en"
|
"@language" => "en"
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
'id' => $url,
|
'id' => $user->getID(),
|
||||||
'type' => 'Person',
|
'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",
|
'followers' => "{$url}/subscribers",
|
||||||
'inbox' => null,
|
'following' => "{$url}/subscriptions",
|
||||||
'outbox' => null,
|
'liked' => "{$url}/liked.json",
|
||||||
'liked' => "{$url}/favorites",
|
'liked_count' => Fave::countByProfile ($profile),
|
||||||
'preferredUsername' => $user->nickname,
|
|
||||||
'name' => $user->nickname,
|
|
||||||
'summary' => $profile->bio,
|
'summary' => $profile->bio,
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
'icon' => [
|
'avatar' => [
|
||||||
'type' => 'Image',
|
'type' => 'Image',
|
||||||
'width' => 96,
|
'width' => 96,
|
||||||
'height' => 96,
|
'height' => 96,
|
||||||
'url' => $avatar
|
'url' => $avatar_url
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
echo json_encode($res, JSON_PRETTY_PRINT);
|
echo json_encode($res, isset($_GET["pretty"]) ? JSON_PRETTY_PRINT : null);
|
||||||
}
|
}
|
||||||
}
|
}
|
64
classes/Activitypub_notice.php
Normal file
64
classes/Activitypub_notice.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user