diff --git a/activitypub.php b/activitypub.php index 045ee39..a989088 100644 --- a/activitypub.php +++ b/activitypub.php @@ -19,9 +19,13 @@ function activitypub_init() { require_once dirname( __FILE__ ) . '/includes/functions.php'; require_once dirname( __FILE__ ) . '/includes/class-activitypub.php'; - add_filter( 'template_include', array( 'Activity_Pub', 'render_profile' ), 99 ); - add_action( 'webfinger_user_data', array( 'Activity_Pub', 'add_webfinger_discovery' ), 10, 3 ); - add_filter( 'query_vars', array( 'Activity_Pub', 'add_query_vars' ) ); - add_action( 'init', array( 'Activity_Pub', 'add_rewrite_endpoint' ) ); + add_filter( 'template_include', array( 'Activitypub', 'render_profile' ), 99 ); + add_action( 'webfinger_user_data', array( 'Activitypub', 'add_webfinger_discovery' ), 10, 3 ); + add_filter( 'query_vars', array( 'Activitypub', 'add_query_vars' ) ); + add_action( 'init', array( 'Activitypub', 'add_rewrite_endpoint' ) ); + + require_once dirname( __FILE__ ) . '/includes/class-activitypub-outbox.php'; + // Configure the REST API route + add_action( 'rest_api_init', array( 'Activitypub_Outbox', 'register_routes' ) ); } add_action( 'plugins_loaded', 'activitypub_init' ); diff --git a/includes/class-activitypub-outbox.php b/includes/class-activitypub-outbox.php new file mode 100644 index 0000000..5dd7ea2 --- /dev/null +++ b/includes/class-activitypub-outbox.php @@ -0,0 +1,34 @@ + WP_REST_Server::READABLE, + 'callback' => array( 'Activitypub_Outbox', 'get' ), + ), + ) + ); + } + + public static function get( $request ) { + $outbox = new stdClass(); + + $outbox->{'@context'} = array( + 'https://www.w3.org/ns/activitystreams', + 'https://w3id.org/security/v1', + ); + + //var_dump($request->get_param('page')); + + return new WP_REST_Response( $outbox, 200 ); + } +} diff --git a/includes/class-activitypub.php b/includes/class-activitypub.php index 421bb7d..48beae9 100644 --- a/includes/class-activitypub.php +++ b/includes/class-activitypub.php @@ -1,6 +1,6 @@ id = get_author_posts_url( $author_id ); $json->type = 'Person'; $json->name = get_the_author_meta( 'display_name', $author_id ); $json->summary = get_the_author_meta( 'description', $author_id ); -$json->preferredUsername = get_the_author(); +$json->preferredUsername = get_the_author(); // phpcs:ignore $json->url = get_author_posts_url( $author_id ); $json->icon = array( 'type' => 'Image', @@ -32,7 +32,10 @@ if ( has_header_image() ) { ); } +$json->outbox = get_rest_url( null, '/activitypub/1.0/outbox' ); + if ( method_exists( 'Magic_Sig', 'get_public_key' ) ) { + // phpcs:ignore $json->publicKey = array( 'id' => get_author_posts_url( $author_id ) . '#key', 'owner' => get_author_posts_url( $author_id ), @@ -53,7 +56,7 @@ do_action( 'activitypub_profile_pre' ); $options = 0; // JSON_PRETTY_PRINT added in PHP 5.4 if ( get_query_var( 'pretty' ) ) { - $options |= JSON_PRETTY_PRINT; + $options |= JSON_PRETTY_PRINT; // phpcs:ignore } /*