pterotype/inc/api.php

30 lines
887 B
PHP
Raw Normal View History

2018-08-21 13:17:07 +00:00
<?php
2018-08-21 21:52:56 +00:00
namespace api;
require_once plugin_dir_path( __FILE__ ) . '/actors.php';
2018-08-23 02:39:59 +00:00
require_once plugin_dir_path( __FILE__ ) . '/outbox.php';
2018-08-21 13:17:07 +00:00
2018-08-23 02:39:59 +00:00
function get_user_actor( $request ) {
$handle = $request['handle'];
2018-08-21 13:17:07 +00:00
$id = get_user_by( 'slug', $handle );
2018-08-22 12:33:06 +00:00
return \actors\user_to_actor( $id );
2018-08-21 13:17:07 +00:00
}
2018-08-23 02:39:59 +00:00
function post_to_outbox( $request ) {
$handle = $request['handle'] ;
$activity = json_decode( $request->get_body() );
return \outbox\persist_activity( $handle, $activity );
2018-08-23 02:39:59 +00:00
}
2018-08-21 21:52:56 +00:00
function register_routes() {
2018-08-22 12:33:06 +00:00
register_rest_route( 'activitypub/v1', '/actor/(?P<handle>[a-zA-Z0-9-]+)', array(
2018-08-21 13:17:07 +00:00
'methods' => 'GET',
2018-08-22 12:33:06 +00:00
'callback' => __NAMESPACE__ . '\get_user_actor',
2018-08-21 13:17:07 +00:00
) );
2018-08-23 02:39:59 +00:00
register_rest_route( 'activitypub/v1', '/actor/(?P<handle>[a-zA-Z0-9-]+)/outbox', array(
'methods' => 'POST',
'callback' => __NAMESPACE__ . '\post_to_outbox',
) );
2018-08-21 21:52:56 +00:00
}
2018-08-21 13:17:07 +00:00
?>