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 +58 -5 1.0.53.2.5 View file →
@@ -1,9 +1,12 @@
1 1 <?php
2 2 namespace Activitypub\Integration;
3 3
4 +use Activitypub\Rest\Webfinger as Webfinger_Rest;
4 5 use Activitypub\Collection\Users as User_Collection;
5 6
7 +use function Activitypub\get_rest_url_by_path;
8 +
6 9 /**
7 10 * Compatibility with the WebFinger plugin
8 11 *
9 12 * @see https://wordpress.org/plugins/webfinger/
@@ -12,10 +15,10 @@
12 15 /**
13 16 * Initialize the class, registering WordPress hooks
14 17 */
15 18 public static function init() {
16 - \add_filter( 'webfinger_user_data', array( self::class, 'add_user_discovery' ), 10, 3 );
17 - \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 );
18 21 }
19 22
20 23 /**
21 24 * Add WebFinger discovery links
@@ -28,8 +31,17 @@
28 31 */
29 32 public static function add_user_discovery( $array, $resource, $user ) {
30 33 $user = User_Collection::get_by_id( $user->ID );
31 34
35 + if ( ! $user || is_wp_error( $user ) ) {
36 + return $array;
37 + }
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 +
32 44 $array['links'][] = array(
33 45 'rel' => 'self',
34 46 'type' => 'application/activity+json',
35 47 'href' => $user->get_url(),
@@ -34,8 +46,13 @@
34 46 'type' => 'application/activity+json',
35 47 'href' => $user->get_url(),
36 48 );
37 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 +
38 55 return $array;
39 56 }
40 57
41 58 /**
@@ -47,11 +64,47 @@
47 64 *
48 65 * @return array the jrd array
49 66 */
50 67 public static function add_pseudo_user_discovery( $array, $resource ) {
51 - if ( $array ) {
52 - return $array;
68 + $user = User_Collection::get_by_resource( $resource );
69 +
70 + if ( \is_wp_error( $user ) ) {
71 + return $user;
53 72 }
54 73
55 - return self::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;
56 109 }
57 110 }