Skip to content

Commit 80ec65a

Browse files
committed
simplified WebFinger code
1 parent d6095d0 commit 80ec65a

File tree

2 files changed

+36
-43
lines changed

2 files changed

+36
-43
lines changed

includes/rest/class-webfinger.php

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
use WP_Error;
55
use WP_REST_Response;
6-
use Activitypub\Collection\Users as User_Collection;
76

87
/**
98
* ActivityPub WebFinger REST-Class
@@ -103,43 +102,7 @@ public static function request_parameters() {
103102
*
104103
* @return array the WebFinger profile.
105104
*/
106-
public static function get_profile( $resource ) {
107-
$user = User_Collection::get_by_resource( $resource );
108-
109-
if ( \is_wp_error( $user ) ) {
110-
return $user;
111-
}
112-
113-
$aliases = array(
114-
$user->get_url(),
115-
$user->get_alternate_url(),
116-
);
117-
118-
$aliases = array_unique( $aliases );
119-
120-
$profile = array(
121-
'subject' => sprintf( 'acct:%s', $user->get_webfinger() ),
122-
'aliases' => array_values( array_unique( $aliases ) ),
123-
'links' => array(
124-
array(
125-
'rel' => 'self',
126-
'type' => 'application/activity+json',
127-
'href' => $user->get_url(),
128-
),
129-
array(
130-
'rel' => 'http://webfinger.net/rel/profile-page',
131-
'type' => 'text/html',
132-
'href' => $user->get_url(),
133-
),
134-
),
135-
);
136-
137-
if ( 'Person' !== $user->get_type() ) {
138-
$profile['links'][0]['properties'] = array(
139-
'https://www.w3.org/ns/activitystreams#type' => $user->get_type(),
140-
);
141-
}
142-
143-
return $profile;
105+
public static function get_profile( $resource ) { // phpcs:ignore
106+
return apply_filters( 'webfinger_data', array(), $resource );
144107
}
145108
}

integration/class-webfinger.php

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,42 @@ public static function add_user_discovery( $array, $resource, $user ) {
5858
* @return array the jrd array
5959
*/
6060
public static function add_pseudo_user_discovery( $array, $resource ) {
61-
$user = Webfinger_Rest::get_profile( $resource );
61+
$user = User_Collection::get_by_resource( $resource );
6262

63-
if ( ! $user || is_wp_error( $user ) ) {
64-
return $array;
63+
if ( \is_wp_error( $user ) ) {
64+
return $user;
65+
}
66+
67+
$aliases = array(
68+
$user->get_url(),
69+
$user->get_alternate_url(),
70+
);
71+
72+
$aliases = array_unique( $aliases );
73+
74+
$profile = array(
75+
'subject' => sprintf( 'acct:%s', $user->get_webfinger() ),
76+
'aliases' => array_values( array_unique( $aliases ) ),
77+
'links' => array(
78+
array(
79+
'rel' => 'self',
80+
'type' => 'application/activity+json',
81+
'href' => $user->get_url(),
82+
),
83+
array(
84+
'rel' => 'http://webfinger.net/rel/profile-page',
85+
'type' => 'text/html',
86+
'href' => $user->get_url(),
87+
),
88+
),
89+
);
90+
91+
if ( 'Person' !== $user->get_type() ) {
92+
$profile['links'][0]['properties'] = array(
93+
'https://www.w3.org/ns/activitystreams#type' => $user->get_type(),
94+
);
6595
}
6696

67-
return $user;
97+
return $profile;
6898
}
6999
}

0 commit comments

Comments
 (0)