Flesh out user actor profile

This commit is contained in:
Jeremy Dormitzer 2018-08-22 08:33:06 -04:00
parent 9233f7bc92
commit b07ffb9a7c
2 changed files with 16 additions and 11 deletions

View File

@ -1,17 +1,22 @@
<?php
namespace actors;
function author_to_user( $user ) {
function user_to_actor( $user ) {
$handle = get_the_author_meta( 'user_nicename', $user->get('ID'));
$actor = array(
"@context" => array( "https://www.w3.org/ns/activitystreams" ),
"type" => "Person",
"id" => get_rest_url( null, sprintf( '/activitypub/v1/user/%s', $handle ) ),
"following" => "TODO", // link to following JSON
"followers" => "TODO", // link to followers JSON
"liked" => "TODO", // link to liked JSON
"inbox" => "TODO", // link to inbox JSON
"outbox" => "TODO", // link to outbox JSON
"id" => get_rest_url( null, sprintf( '/activitypub/v1/actor/%s', $handle ) ),
"following" => get_rest_url(
null, sprintf( '/activitypub/v1/actor/%s/following', $handle ) ),
"followers" => get_rest_url(
null, sprintf( '/activitypub/v1/actor/%s/followers', $handle ) ),
"liked" => get_rest_url(
null, sprintf( '/activitypub/v1/actor/%s/liked', $handle ) ),
"inbox" => get_rest_url(
null, sprintf( '/activitypub/v1/actor/%s/inbox', $handle ) ),
"outbox" => get_rest_url(
null, sprintf( '/activitypub/v1/actor/%s/outbox', $handle ) ),
"preferredUsername" => $handle,
"name" => get_the_author_meta( 'display_name', $user->get('ID') ),
"summary" => get_the_author_meta( 'description', $user->get('ID') ),

View File

@ -3,16 +3,16 @@ namespace api;
require_once plugin_dir_path( __FILE__ ) . '/actors.php';
function get_user( $data ) {
function get_user_actor( $data ) {
$handle = $data["handle"];
$id = get_user_by( 'slug', $handle );
return \actors\author_to_user( $id );
return \actors\user_to_actor( $id );
}
function register_routes() {
register_rest_route( 'activitypub/v1', '/user/(?P<handle>[a-zA-Z0-9-]+)', array(
register_rest_route( 'activitypub/v1', '/actor/(?P<handle>[a-zA-Z0-9-]+)', array(
'methods' => 'GET',
'callback' => __NAMESPACE__ . '\get_user',
'callback' => __NAMESPACE__ . '\get_user_actor',
) );
}
?>