Fix WebFinger endpoint
This commit is contained in:
parent
57bc4214b7
commit
e0d767ed98
1 changed files with 27 additions and 11 deletions
|
@ -14,7 +14,9 @@ use Activitypub\Collection\Users as User_Collection;
|
||||||
*/
|
*/
|
||||||
class Webfinger {
|
class Webfinger {
|
||||||
/**
|
/**
|
||||||
* Initialize the class, registering WordPress hooks
|
* Initialize the class, registering WordPress hooks.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function init() {
|
public static function init() {
|
||||||
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
||||||
|
@ -23,7 +25,9 @@ class Webfinger {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register routes
|
* Register routes.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function register_routes() {
|
public static function register_routes() {
|
||||||
\register_rest_route(
|
\register_rest_route(
|
||||||
|
@ -41,10 +45,11 @@ class Webfinger {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render JRD file
|
* WebFinger endpoint.
|
||||||
*
|
*
|
||||||
* @param WP_REST_Request $request
|
* @param WP_REST_Request $request The request object.
|
||||||
* @return WP_REST_Response
|
*
|
||||||
|
* @return WP_REST_Response The response object.
|
||||||
*/
|
*/
|
||||||
public static function webfinger( $request ) {
|
public static function webfinger( $request ) {
|
||||||
$resource = $request->get_param( 'resource' );
|
$resource = $request->get_param( 'resource' );
|
||||||
|
@ -76,12 +81,16 @@ class Webfinger {
|
||||||
* @param array $array the jrd array
|
* @param array $array the jrd array
|
||||||
* @param string $resource the WebFinger resource
|
* @param string $resource the WebFinger resource
|
||||||
* @param WP_User $user the WordPress user
|
* @param WP_User $user the WordPress user
|
||||||
|
*
|
||||||
|
* @return array the jrd array
|
||||||
*/
|
*/
|
||||||
public static function add_user_discovery( $array, $resource, $user ) {
|
public static function add_user_discovery( $array, $resource, $user ) {
|
||||||
|
$user = User_Collection::get_by_id( $user->ID );
|
||||||
|
|
||||||
$array['links'][] = array(
|
$array['links'][] = array(
|
||||||
'rel' => 'self',
|
'rel' => 'self',
|
||||||
'type' => 'application/activity+json',
|
'type' => 'application/activity+json',
|
||||||
'href' => \get_author_posts_url( $user->ID ),
|
'href' => $user->get_url(),
|
||||||
);
|
);
|
||||||
|
|
||||||
return $array;
|
return $array;
|
||||||
|
@ -93,17 +102,24 @@ class Webfinger {
|
||||||
* @param array $array the jrd array
|
* @param array $array the jrd array
|
||||||
* @param string $resource the WebFinger resource
|
* @param string $resource the WebFinger resource
|
||||||
* @param WP_User $user the WordPress user
|
* @param WP_User $user the WordPress user
|
||||||
|
*
|
||||||
|
* @return array the jrd array
|
||||||
*/
|
*/
|
||||||
public static function add_pseudo_user_discovery( $array, $resource ) {
|
public static function add_pseudo_user_discovery( $array, $resource ) {
|
||||||
if ( ! $array ) {
|
if ( $array ) {
|
||||||
$array = array();
|
return $array;
|
||||||
}
|
}
|
||||||
|
|
||||||
$profile = self::get_profile( $resource );
|
return self::get_profile( $resource );
|
||||||
|
|
||||||
return array_merge( $array, $profile );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the WebFinger profile.
|
||||||
|
*
|
||||||
|
* @param string $resource the WebFinger resource.
|
||||||
|
*
|
||||||
|
* @return array the WebFinger profile.
|
||||||
|
*/
|
||||||
public static function get_profile( $resource ) {
|
public static function get_profile( $resource ) {
|
||||||
$user = User_Collection::get_by_resource( $resource );
|
$user = User_Collection::get_by_resource( $resource );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue