2018-09-27 22:28:49 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2018-09-30 22:51:22 +02:00
|
|
|
* ActivityPub Inbox Class
|
2018-09-27 22:28:49 +02:00
|
|
|
*
|
|
|
|
* @author Matthias Pfefferle
|
|
|
|
*/
|
|
|
|
class Activitypub_Inbox {
|
|
|
|
/**
|
|
|
|
* Register routes
|
|
|
|
*/
|
|
|
|
public static function register_routes() {
|
|
|
|
register_rest_route(
|
|
|
|
'activitypub/1.0', '/inbox', array(
|
|
|
|
array(
|
|
|
|
'methods' => WP_REST_Server::EDITABLE,
|
2018-09-30 22:51:22 +02:00
|
|
|
'callback' => array( 'Activitypub_Inbox', 'shared_inbox' ),
|
2018-09-27 22:28:49 +02:00
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
register_rest_route(
|
|
|
|
'activitypub/1.0', '/users/(?P<id>\d+)/inbox', array(
|
|
|
|
array(
|
|
|
|
'methods' => WP_REST_Server::EDITABLE,
|
2018-09-30 22:51:22 +02:00
|
|
|
'callback' => array( 'Activitypub_Inbox', 'user_inbox' ),
|
2018-09-27 22:28:49 +02:00
|
|
|
'args' => self::request_parameters(),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-09-30 22:51:22 +02:00
|
|
|
public static function user_inbox( $request ) {
|
2018-09-27 22:28:49 +02:00
|
|
|
$author_id = $request->get_param( 'id' );
|
|
|
|
$author = get_user_by( 'ID', $author_id );
|
|
|
|
|
|
|
|
$data = json_decode( $request->get_body(), true );
|
|
|
|
|
2018-09-30 22:51:22 +02:00
|
|
|
do_action( 'activitypub_inbox', $data );
|
|
|
|
|
2018-09-27 22:28:49 +02:00
|
|
|
if ( ! is_array( $data ) || ! array_key_exists( 'type', $data ) ) {
|
|
|
|
return new WP_Error( 'rest_invalid_data', __( 'Invalid payload', 'activitypub' ), array( 'status' => 422 ) );
|
|
|
|
}
|
|
|
|
|
2018-09-30 22:51:22 +02:00
|
|
|
return new WP_REST_Response();
|
2018-09-27 22:28:49 +02:00
|
|
|
}
|
|
|
|
|
2018-09-30 22:51:22 +02:00
|
|
|
/**
|
|
|
|
* The shared inbox
|
|
|
|
*
|
|
|
|
* @param [type] $request [description]
|
|
|
|
*
|
|
|
|
* @return WP_Error not yet implemented
|
|
|
|
*/
|
|
|
|
public static function shared_inbox( $request ) {
|
2018-09-27 22:28:49 +02:00
|
|
|
// Create the response object
|
|
|
|
return new WP_Error( 'rest_not_implemented', __( 'This method is not yet implemented', 'activitypub' ), array( 'status' => 501 ) );
|
|
|
|
}
|
|
|
|
|
2018-09-30 22:51:22 +02:00
|
|
|
/**
|
|
|
|
* The supported parameters
|
|
|
|
*
|
|
|
|
* @return array list of parameters
|
|
|
|
*/
|
2018-09-27 22:28:49 +02:00
|
|
|
public static function request_parameters() {
|
|
|
|
$params = array();
|
|
|
|
|
|
|
|
$params['page'] = array(
|
|
|
|
'type' => 'integer',
|
|
|
|
);
|
|
|
|
|
|
|
|
$params['id'] = array(
|
|
|
|
'required' => true,
|
|
|
|
'type' => 'integer',
|
|
|
|
);
|
|
|
|
|
|
|
|
return $params;
|
|
|
|
}
|
|
|
|
}
|