updated plugin ActivityPub version 8.3.0
This commit is contained in:
@ -10,8 +10,6 @@ namespace Activitypub\Rest;
|
||||
use Activitypub\Collection\Actors as Actor_Collection;
|
||||
use Activitypub\Webfinger;
|
||||
|
||||
use function Activitypub\is_activitypub_request;
|
||||
|
||||
/**
|
||||
* ActivityPub Actors REST-Class.
|
||||
*
|
||||
@ -20,6 +18,8 @@ use function Activitypub\is_activitypub_request;
|
||||
* @see https://www.w3.org/TR/activitypub/#followers
|
||||
*/
|
||||
class Actors_Controller extends \WP_REST_Controller {
|
||||
use Verification;
|
||||
|
||||
/**
|
||||
* The namespace of this controller's route.
|
||||
*
|
||||
@ -32,7 +32,7 @@ class Actors_Controller extends \WP_REST_Controller {
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $rest_base = '(?:users|actors)\/(?P<user_id>[\w\-\.]+)';
|
||||
protected $rest_base = '(?:users|actors)\/(?P<user_id>[-]?\d+)';
|
||||
|
||||
/**
|
||||
* Register routes.
|
||||
@ -44,16 +44,16 @@ class Actors_Controller extends \WP_REST_Controller {
|
||||
array(
|
||||
'args' => array(
|
||||
'user_id' => array(
|
||||
'description' => 'The ID or username of the actor.',
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
'pattern' => '[\w\-\.]+',
|
||||
'description' => 'The ID of the actor.',
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
'validate_callback' => array( $this, 'validate_user_id' ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( 'Activitypub\Rest\Server', 'verify_signature' ),
|
||||
'permission_callback' => array( $this, 'verify_signature' ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
@ -65,10 +65,10 @@ class Actors_Controller extends \WP_REST_Controller {
|
||||
array(
|
||||
'args' => array(
|
||||
'user_id' => array(
|
||||
'description' => 'The ID or username of the actor.',
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
'pattern' => '[\w\-\.]+',
|
||||
'description' => 'The ID of the actor.',
|
||||
'type' => 'integer',
|
||||
'required' => true,
|
||||
'validate_callback' => array( $this, 'validate_user_id' ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
@ -95,11 +95,7 @@ class Actors_Controller extends \WP_REST_Controller {
|
||||
*/
|
||||
public function get_item( $request ) {
|
||||
$user_id = $request->get_param( 'user_id' );
|
||||
$user = Actor_Collection::get_by_various( $user_id );
|
||||
|
||||
if ( \is_wp_error( $user ) ) {
|
||||
return $user;
|
||||
}
|
||||
$user = Actor_Collection::get_by_id( $user_id );
|
||||
|
||||
/**
|
||||
* Action triggered prior to the ActivityPub profile being created and sent to the client.
|
||||
@ -124,11 +120,7 @@ class Actors_Controller extends \WP_REST_Controller {
|
||||
public function get_remote_follow_item( $request ) {
|
||||
$resource = $request->get_param( 'resource' );
|
||||
$user_id = $request->get_param( 'user_id' );
|
||||
$user = Actor_Collection::get_by_various( $user_id );
|
||||
|
||||
if ( \is_wp_error( $user ) ) {
|
||||
return $user;
|
||||
}
|
||||
$user = Actor_Collection::get_by_id( $user_id );
|
||||
|
||||
$template = Webfinger::get_remote_follow_endpoint( $resource );
|
||||
|
||||
@ -351,9 +343,49 @@ class Actors_Controller extends \WP_REST_Controller {
|
||||
'type' => 'boolean',
|
||||
'readonly' => true,
|
||||
),
|
||||
'generator' => array(
|
||||
'description' => 'The generator of the object.',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'type' => array(
|
||||
'type' => 'string',
|
||||
),
|
||||
'implements' => array(
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'href' => array(
|
||||
'type' => 'string',
|
||||
'format' => 'uri',
|
||||
),
|
||||
'name' => array(
|
||||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'readonly' => true,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return $this->add_additional_fields_schema( $this->schema );
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the user_id parameter.
|
||||
*
|
||||
* @param mixed $user_id The user_id parameter.
|
||||
* @return bool|\WP_Error True if the user_id is valid, WP_Error otherwise.
|
||||
*/
|
||||
public function validate_user_id( $user_id ) {
|
||||
$user = Actor_Collection::get_by_id( $user_id );
|
||||
if ( \is_wp_error( $user ) ) {
|
||||
return $user;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user