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-28 23:26:18 +00:00
|
|
|
require_once plugin_dir_path( __FILE__ ) . '/objects.php';
|
2018-08-29 20:43:15 +00:00
|
|
|
require_once plugin_dir_path( __FILE__ ) . '/activities.php';
|
2018-08-21 13:17:07 +00:00
|
|
|
|
2018-08-29 20:43:15 +00:00
|
|
|
function get_actor( $request ) {
|
2018-08-29 20:47:56 +00:00
|
|
|
$actor = $request['actor'];
|
2018-08-29 20:43:15 +00:00
|
|
|
$user = get_user_by( 'slug', $actor );
|
|
|
|
return \actors\get_actor( $user );
|
2018-08-21 13:17:07 +00:00
|
|
|
}
|
|
|
|
|
2018-08-23 02:39:59 +00:00
|
|
|
function post_to_outbox( $request ) {
|
2018-08-29 20:47:56 +00:00
|
|
|
$actor = $request['actor'];
|
2018-08-23 02:39:59 +00:00
|
|
|
$activity = json_decode( $request->get_body() );
|
2018-08-29 20:43:15 +00:00
|
|
|
return \outbox\handle_activity( $actor, $activity );
|
2018-08-23 02:39:59 +00:00
|
|
|
}
|
|
|
|
|
2018-08-28 23:26:18 +00:00
|
|
|
function get_object( $request ) {
|
|
|
|
$id = $request['id'];
|
|
|
|
return \objects\get_object( $id );
|
|
|
|
}
|
|
|
|
|
2018-08-29 20:43:15 +00:00
|
|
|
function get_activity( $request ) {
|
|
|
|
$id = $request['id'];
|
|
|
|
return \activities\get_activity( $id );
|
|
|
|
}
|
|
|
|
|
2018-08-21 21:52:56 +00:00
|
|
|
function register_routes() {
|
2018-08-29 20:47:56 +00:00
|
|
|
register_rest_route( 'activitypub/v1', '/actor/(?P<actor>[a-zA-Z0-9-]+)', array(
|
2018-08-21 13:17:07 +00:00
|
|
|
'methods' => 'GET',
|
2018-08-29 20:43:15 +00:00
|
|
|
'callback' => __NAMESPACE__ . '\get_actor',
|
2018-08-21 13:17:07 +00:00
|
|
|
) );
|
2018-08-29 20:47:56 +00:00
|
|
|
register_rest_route( 'activitypub/v1', '/actor/(?P<actor>[a-zA-Z0-9-]+)/outbox', array(
|
2018-08-23 02:39:59 +00:00
|
|
|
'methods' => 'POST',
|
|
|
|
'callback' => __NAMESPACE__ . '\post_to_outbox',
|
|
|
|
) );
|
2018-08-28 23:26:18 +00:00
|
|
|
register_rest_route( 'activitypub/v1', '/object/(?P<id>[0-9]+)', array(
|
|
|
|
'methods' => 'GET',
|
|
|
|
'callback' => __NAMESPACE__ . '\get_object',
|
|
|
|
) );
|
2018-08-29 20:43:15 +00:00
|
|
|
register_rest_route( 'activitypub/v1', '/activity/(?P<id>[0-9]+)', array(
|
|
|
|
'methods' => 'GET',
|
|
|
|
'callback' => __NAMESPACE__ . '\get_activity',
|
|
|
|
) );
|
2018-08-21 21:52:56 +00:00
|
|
|
}
|
2018-08-21 13:17:07 +00:00
|
|
|
?>
|