updated plugin ActivityPub version 0.13.4

This commit is contained in:
2022-08-19 16:15:51 +00:00
committed by Gitium
parent a3483bf62f
commit b49569de47
14 changed files with 149 additions and 71 deletions

View File

@ -21,7 +21,9 @@ class Followers {
*/
public static function register_routes() {
\register_rest_route(
'activitypub/1.0', '/users/(?P<user_id>\d+)/followers', array(
'activitypub/1.0',
'/users/(?P<user_id>\d+)/followers',
array(
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array( '\Activitypub\Rest\Followers', 'get' ),
@ -44,12 +46,16 @@ class Followers {
$user = \get_user_by( 'ID', $user_id );
if ( ! $user ) {
return new \WP_Error( 'rest_invalid_param', \__( 'User not found', 'activitypub' ), array(
'status' => 404,
'params' => array(
'user_id' => \__( 'User not found', 'activitypub' ),
),
) );
return new \WP_Error(
'rest_invalid_param',
\__( 'User not found', 'activitypub' ),
array(
'status' => 404,
'params' => array(
'user_id' => \__( 'User not found', 'activitypub' ),
),
)
);
}
/*

View File

@ -21,7 +21,9 @@ class Following {
*/
public static function register_routes() {
\register_rest_route(
'activitypub/1.0', '/users/(?P<user_id>\d+)/following', array(
'activitypub/1.0',
'/users/(?P<user_id>\d+)/following',
array(
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array( '\Activitypub\Rest\Following', 'get' ),
@ -44,12 +46,16 @@ class Following {
$user = \get_user_by( 'ID', $user_id );
if ( ! $user ) {
return new \WP_Error( 'rest_invalid_param', \__( 'User not found', 'activitypub' ), array(
'status' => 404,
'params' => array(
'user_id' => \__( 'User not found', 'activitypub' ),
),
) );
return new \WP_Error(
'rest_invalid_param',
\__( 'User not found', 'activitypub' ),
array(
'status' => 404,
'params' => array(
'user_id' => \__( 'User not found', 'activitypub' ),
),
)
);
}
/*

View File

@ -27,7 +27,9 @@ class Inbox {
*/
public static function register_routes() {
\register_rest_route(
'activitypub/1.0', '/inbox', array(
'activitypub/1.0',
'/inbox',
array(
array(
'methods' => \WP_REST_Server::EDITABLE,
'callback' => array( '\Activitypub\Rest\Inbox', 'shared_inbox_post' ),
@ -38,7 +40,9 @@ class Inbox {
);
\register_rest_route(
'activitypub/1.0', '/users/(?P<user_id>\d+)/inbox', array(
'activitypub/1.0',
'/users/(?P<user_id>\d+)/inbox',
array(
array(
'methods' => \WP_REST_Server::EDITABLE,
'callback' => array( '\Activitypub\Rest\Inbox', 'user_inbox_post' ),
@ -161,16 +165,20 @@ class Inbox {
$users = self::extract_recipients( $data );
if ( ! $users ) {
return new \WP_Error( 'rest_invalid_param', \__( 'No recipients found', 'activitypub' ), array(
'status' => 404,
'params' => array(
'to' => \__( 'Please check/validate "to" field', 'activitypub' ),
'bto' => \__( 'Please check/validate "bto" field', 'activitypub' ),
'cc' => \__( 'Please check/validate "cc" field', 'activitypub' ),
'bcc' => \__( 'Please check/validate "bcc" field', 'activitypub' ),
'audience' => \__( 'Please check/validate "audience" field', 'activitypub' ),
),
) );
return new \WP_Error(
'rest_invalid_param',
\__( 'No recipients found', 'activitypub' ),
array(
'status' => 404,
'params' => array(
'to' => \__( 'Please check/validate "to" field', 'activitypub' ),
'bto' => \__( 'Please check/validate "bto" field', 'activitypub' ),
'cc' => \__( 'Please check/validate "cc" field', 'activitypub' ),
'bcc' => \__( 'Please check/validate "bcc" field', 'activitypub' ),
'audience' => \__( 'Please check/validate "audience" field', 'activitypub' ),
),
)
);
}
foreach ( $users as $user ) {

View File

@ -23,7 +23,9 @@ class Nodeinfo {
*/
public static function register_routes() {
\register_rest_route(
'activitypub/1.0', '/nodeinfo/discovery', array(
'activitypub/1.0',
'/nodeinfo/discovery',
array(
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array( '\Activitypub\Rest\Nodeinfo', 'discovery' ),
@ -33,7 +35,9 @@ class Nodeinfo {
);
\register_rest_route(
'activitypub/1.0', '/nodeinfo', array(
'activitypub/1.0',
'/nodeinfo',
array(
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array( '\Activitypub\Rest\Nodeinfo', 'nodeinfo' ),
@ -43,7 +47,9 @@ class Nodeinfo {
);
\register_rest_route(
'activitypub/1.0', '/nodeinfo2', array(
'activitypub/1.0',
'/nodeinfo2',
array(
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array( '\Activitypub\Rest\Nodeinfo', 'nodeinfo2' ),

View File

@ -14,7 +14,9 @@ class Ostatus {
*/
public static function register_routes() {
\register_rest_route(
'activitypub/1.0', '/ostatus/remote-follow', array(
'activitypub/1.0',
'/ostatus/remote-follow',
array(
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array( '\Activitypub\Rest\Ostatus', 'get' ),

View File

@ -21,7 +21,9 @@ class Outbox {
*/
public static function register_routes() {
\register_rest_route(
'activitypub/1.0', '/users/(?P<user_id>\d+)/outbox', array(
'activitypub/1.0',
'/users/(?P<user_id>\d+)/outbox',
array(
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array( '\Activitypub\Rest\Outbox', 'user_outbox_get' ),
@ -43,12 +45,16 @@ class Outbox {
$author = \get_user_by( 'ID', $user_id );
if ( ! $author ) {
return new \WP_Error( 'rest_invalid_param', \__( 'User not found', 'activitypub' ), array(
'status' => 404,
'params' => array(
'user_id' => \__( 'User not found', 'activitypub' ),
),
) );
return new \WP_Error(
'rest_invalid_param',
\__( 'User not found', 'activitypub' ),
array(
'status' => 404,
'params' => array(
'user_id' => \__( 'User not found', 'activitypub' ),
),
)
);
}
$page = $request->get_param( 'page', 0 );
@ -78,12 +84,14 @@ class Outbox {
}
if ( $page ) {
$posts = \get_posts( array(
'posts_per_page' => 10,
'author' => $user_id,
'offset' => ( $page - 1 ) * 10,
'post_type' => 'post',
) );
$posts = \get_posts(
array(
'posts_per_page' => 10,
'author' => $user_id,
'offset' => ( $page - 1 ) * 10,
'post_type' => 'post',
)
);
foreach ( $posts as $post ) {
$activitypub_post = new \Activitypub\Model\Post( $post );

View File

@ -22,7 +22,9 @@ class Webfinger {
*/
public static function register_routes() {
\register_rest_route(
'activitypub/1.0', '/webfinger', array(
'activitypub/1.0',
'/webfinger',
array(
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array( '\Activitypub\Rest\Webfinger', 'webfinger' ),
@ -42,15 +44,16 @@ class Webfinger {
public static function webfinger( $request ) {
$resource = $request->get_param( 'resource' );
$matches = array();
$matched = \preg_match( '/^acct:([^@]+)@(.+)$/', $resource, $matches );
$matched = \str_contains( $resource, '@' );
if ( ! $matched ) {
return new \WP_Error( 'activitypub_unsupported_resource', \__( 'Resource is invalid', 'activitypub' ), array( 'status' => 400 ) );
}
$resource_identifier = $matches[1];
$resource_host = $matches[2];
$resource = \str_replace( 'acct:', '', $resource );
$resource_identifier = \substr( $resource, 0, \strrpos( $resource, '@' ) );
$resource_host = \substr( \strrchr( $resource, '@' ), 1 );
if ( \wp_parse_url( \home_url( '/' ), \PHP_URL_HOST ) !== $resource_host ) {
return new \WP_Error( 'activitypub_wrong_host', \__( 'Resource host does not match blog host', 'activitypub' ), array( 'status' => 404 ) );
@ -95,7 +98,7 @@ class Webfinger {
$params['resource'] = array(
'required' => true,
'type' => 'string',
'pattern' => '^acct:([^@]+)@(.+)$',
'pattern' => '^acct:(.+)@(.+)$',
);
return $params;