PluginProbe
ActivityPub / 3.2.5
ActivityPub v3.2.5
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
← All changes | integration/class-webfinger.php +53 -5 1.3.03.2.5 View file →
@@ -3,8 +3,10 @@
3 3
4 4 use Activitypub\Rest\Webfinger as Webfinger_Rest;
5 5 use Activitypub\Collection\Users as User_Collection;
6 6
7 +use function Activitypub\get_rest_url_by_path;
8 +
7 9 /**
8 10 * Compatibility with the WebFinger plugin
9 11 *
10 12 * @see https://wordpress.org/plugins/webfinger/
@@ -13,10 +15,10 @@
13 15 /**
14 16 * Initialize the class, registering WordPress hooks
15 17 */
16 18 public static function init() {
17 - \add_filter( 'webfinger_user_data', array( self::class, 'add_user_discovery' ), 10, 3 );
18 - \add_filter( 'webfinger_data', array( self::class, 'add_pseudo_user_discovery' ), 99, 2 );
19 + \add_filter( 'webfinger_user_data', array( self::class, 'add_user_discovery' ), 1, 3 );
20 + \add_filter( 'webfinger_data', array( self::class, 'add_pseudo_user_discovery' ), 1, 2 );
19 21 }
20 22
21 23 /**
22 24 * Add WebFinger discovery links
@@ -33,8 +35,13 @@
33 35 if ( ! $user || is_wp_error( $user ) ) {
34 36 return $array;
35 37 }
36 38
39 + $array['subject'] = sprintf( 'acct:%s', $user->get_webfinger() );
40 +
41 + $array['aliases'][] = $user->get_url();
42 + $array['aliases'][] = $user->get_alternate_url();
43 +
37 44 $array['links'][] = array(
38 45 'rel' => 'self',
39 46 'type' => 'application/activity+json',
40 47 'href' => $user->get_url(),
@@ -39,8 +46,13 @@
39 46 'type' => 'application/activity+json',
40 47 'href' => $user->get_url(),
41 48 );
42 49
50 + $array['links'][] = array(
51 + 'rel' => 'http://ostatus.org/schema/1.0/subscribe',
52 + 'template' => get_rest_url_by_path( 'interactions?uri={uri}' ),
53 + );
54 +
43 55 return $array;
44 56 }
45 57
46 58 /**
@@ -52,11 +64,47 @@
52 64 *
53 65 * @return array the jrd array
54 66 */
55 67 public static function add_pseudo_user_discovery( $array, $resource ) {
56 - if ( $array ) {
57 - return $array;
68 + $user = User_Collection::get_by_resource( $resource );
69 +
70 + if ( \is_wp_error( $user ) ) {
71 + return $user;
58 72 }
59 73
60 - return Webfinger_Rest::get_profile( $resource );
74 + $aliases = array(
75 + $user->get_url(),
76 + $user->get_alternate_url(),
77 + );
78 +
79 + $aliases = array_unique( $aliases );
80 +
81 + $profile = array(
82 + 'subject' => sprintf( 'acct:%s', $user->get_webfinger() ),
83 + 'aliases' => array_values( array_unique( $aliases ) ),
84 + 'links' => array(
85 + array(
86 + 'rel' => 'self',
87 + 'type' => 'application/activity+json',
88 + 'href' => $user->get_url(),
89 + ),
90 + array(
91 + 'rel' => 'http://webfinger.net/rel/profile-page',
92 + 'type' => 'text/html',
93 + 'href' => $user->get_url(),
94 + ),
95 + array(
96 + 'rel' => 'http://ostatus.org/schema/1.0/subscribe',
97 + 'template' => get_rest_url_by_path( 'interactions?uri={uri}' ),
98 + ),
99 + ),
100 + );
101 +
102 + if ( 'Person' !== $user->get_type() ) {
103 + $profile['links'][0]['properties'] = array(
104 + 'https://www.w3.org/ns/activitystreams#type' => $user->get_type(),
105 + );
106 + }
107 +
108 + return $profile;
61 109 }
62 110 }