Initial commit

This commit is contained in:
Jeremy Dormitzer 2018-08-21 09:17:07 -04:00
commit a8837a7290
5 changed files with 56 additions and 0 deletions

11
activitypub.php Normal file
View File

@ -0,0 +1,11 @@
<?php
/*
Plugin Name: ActivityPub
*/
function post_published_activity( $ID, $post ) {
// TODO
$author = $post->post_author;
}
add_action( 'publish_post', 'post_published_activity', 10, 2 );
?>

23
inc/actors.php Normal file
View File

@ -0,0 +1,23 @@
<?php
namespace actors;
function author_to_user( $authorID ) {
$handle = get_the_author_meta( 'user_nicename', $authorID );
$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
"preferredUsername": $handle,
"name": get_the_author_meta( 'display_name', $authorID ),
"summary": get_the_author_meta( 'description', $authorID ),
"icon": get_avatar_url ( $authorID ),
"url": get_the_author_meta( 'user_url', $authorID ),
);
return $actor;
}
?>

16
inc/api.php Normal file
View File

@ -0,0 +1,16 @@
<?php
include 'actors';
function get_user( $data ) {
$handle = $data["handle"];
$id = get_user_by( 'slug', $handle );
return actors\author_to_user( $id );
}
add_action( 'rest_api_init', function () {
register_rest_route( 'activitypub/v1', '/user/(?P<handle>[A-Za-z0-9]+)', array(
'methods' => 'GET',
'callback' => 'get_user',
) );
} );
?>

3
inc/inbox.php Normal file
View File

@ -0,0 +1,3 @@
<?php
?>

3
inc/outbox.php Normal file
View File

@ -0,0 +1,3 @@
<?php
?>