PluginProbe
ActivityPub / 3.2.4
ActivityPub v3.2.4
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 +39 -79 9.2.23.2.4 View file →
@@ -1,14 +1,9 @@
1 1 <?php
2 -/**
3 - * WebFinger integration file.
4 - *
5 - * @package Activitypub
6 - */
7 -
8 2 namespace Activitypub\Integration;
9 3
10 -use Activitypub\Collection\Actors;
4 +use Activitypub\Rest\Webfinger as Webfinger_Rest;
5 +use Activitypub\Collection\Users as User_Collection;
11 6
12 7 use function Activitypub\get_rest_url_by_path;
13 8
14 9 /**
@@ -17,60 +12,61 @@
17 12 * @see https://wordpress.org/plugins/webfinger/
18 13 */
19 14 class Webfinger {
20 15 /**
21 - * Initialize the class, registering WordPress hooks.
16 + * Initialize the class, registering WordPress hooks
22 17 */
23 18 public static function init() {
24 19 \add_filter( 'webfinger_user_data', array( self::class, 'add_user_discovery' ), 1, 3 );
25 20 \add_filter( 'webfinger_data', array( self::class, 'add_pseudo_user_discovery' ), 1, 2 );
26 -
27 - \add_filter( 'webfinger_data', array( self::class, 'add_interaction_links' ), 11 );
28 21 }
29 22
30 23 /**
31 - * Add WebFinger discovery links.
24 + * Add WebFinger discovery links
32 25 *
33 - * @param array $jrd The jrd array.
34 - * @param string $uri The WebFinger resource.
35 - * @param \WP_User $user The WordPress user.
26 + * @param array $array the jrd array
27 + * @param string $resource the WebFinger resource
28 + * @param WP_User $user the WordPress user
36 29 *
37 - * @return array The jrd array.
30 + * @return array the jrd array
38 31 */
39 - public static function add_user_discovery( $jrd, $uri, $user ) {
40 - $user = Actors::get_by_id( $user->ID );
32 + public static function add_user_discovery( $array, $resource, $user ) {
33 + $user = User_Collection::get_by_id( $user->ID );
41 34
42 - if ( ! $user || \is_wp_error( $user ) ) {
43 - return $jrd;
35 + if ( ! $user || is_wp_error( $user ) ) {
36 + return $array;
44 37 }
45 38
46 - $jrd['subject'] = \sprintf( 'acct:%s', $user->get_webfinger() );
39 + $array['subject'] = sprintf( 'acct:%s', $user->get_webfinger() );
47 40
48 - $jrd['aliases'][] = $user->get_id();
49 - $jrd['aliases'][] = $user->get_url();
50 - $jrd['aliases'][] = $user->get_alternate_url();
51 - $jrd['aliases'] = \array_unique( $jrd['aliases'] );
52 - $jrd['aliases'] = \array_values( $jrd['aliases'] );
41 + $array['aliases'][] = $user->get_url();
42 + $array['aliases'][] = $user->get_alternate_url();
53 43
54 - $jrd['links'][] = array(
44 + $array['links'][] = array(
55 45 'rel' => 'self',
56 46 'type' => 'application/activity+json',
57 - 'href' => $user->get_id(),
47 + 'href' => $user->get_url(),
58 48 );
59 49
60 - return $jrd;
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 +
55 + return $array;
61 56 }
62 57
63 58 /**
64 - * Add WebFinger discovery links.
59 + * Add WebFinger discovery links
65 60 *
66 - * @param array $jrd The jrd array.
67 - * @param string $uri The WebFinger resource.
61 + * @param array $array the jrd array
62 + * @param string $resource the WebFinger resource
63 + * @param WP_User $user the WordPress user
68 64 *
69 - * @return array|\WP_Error The jrd array or WP_Error.
65 + * @return array the jrd array
70 66 */
71 - public static function add_pseudo_user_discovery( $jrd, $uri ) {
72 - $user = Actors::get_by_resource( $uri );
67 + public static function add_pseudo_user_discovery( $array, $resource ) {
68 + $user = User_Collection::get_by_resource( $resource );
73 69
74 70 if ( \is_wp_error( $user ) ) {
75 71 return $user;
76 72 }
@@ -75,30 +71,32 @@
75 71 return $user;
76 72 }
77 73
78 74 $aliases = array(
79 - $user->get_id(),
80 75 $user->get_url(),
81 76 $user->get_alternate_url(),
82 77 );
83 78
84 - $aliases = \array_unique( $aliases );
85 - $aliases = \array_values( $aliases );
79 + $aliases = array_unique( $aliases );
86 80
87 81 $profile = array(
88 - 'subject' => \sprintf( 'acct:%s', $user->get_webfinger() ),
89 - 'aliases' => $aliases,
82 + 'subject' => sprintf( 'acct:%s', $user->get_webfinger() ),
83 + 'aliases' => array_values( array_unique( $aliases ) ),
90 84 'links' => array(
91 85 array(
92 86 'rel' => 'self',
93 87 'type' => 'application/activity+json',
94 - 'href' => $user->get_id(),
88 + 'href' => $user->get_url(),
95 89 ),
96 90 array(
97 91 'rel' => 'http://webfinger.net/rel/profile-page',
98 92 'type' => 'text/html',
99 - 'href' => $user->get_id(),
93 + 'href' => $user->get_url(),
100 94 ),
95 + array(
96 + 'rel' => 'http://ostatus.org/schema/1.0/subscribe',
97 + 'template' => get_rest_url_by_path( 'interactions?uri={uri}' ),
98 + ),
101 99 ),
102 100 );
103 101
104 102 if ( 'Person' !== $user->get_type() ) {
@@ -107,44 +105,6 @@
107 105 );
108 106 }
109 107
110 108 return $profile;
111 - }
112 -
113 - /**
114 - * Add interaction links to the WebFinger data.
115 - *
116 - * @see https://codeberg.org/fediverse/fep/src/branch/main/fep/3b86/fep-3b86.md
117 - *
118 - * @param array $jrd The jrd array.
119 - *
120 - * @return array The jrd array.
121 - */
122 - public static function add_interaction_links( $jrd ) {
123 - if ( ! \is_array( $jrd ) ) {
124 - return $jrd;
125 - }
126 -
127 - $jrd['links'][] = array(
128 - 'rel' => 'http://ostatus.org/schema/1.0/subscribe',
129 - 'template' => get_rest_url_by_path( 'interactions?uri={uri}' ),
130 - );
131 -
132 - /*
133 - * Note: The parameter name `{inReplyTo}` is used here for all 'Create' intents,
134 - * not just replies, to maintain compatibility with existing implementations and
135 - * the FEP-3b86 specification. If a more generic parameter name is adopted in the
136 - * future, this should be updated accordingly.
137 - */
138 - $jrd['links'][] = array(
139 - 'rel' => 'https://w3id.org/fep/3b86/Create',
140 - 'template' => get_rest_url_by_path( 'interactions?uri={inReplyTo}&intent=create' ),
141 - );
142 -
143 - $jrd['links'][] = array(
144 - 'rel' => 'https://w3id.org/fep/3b86/Follow',
145 - 'template' => get_rest_url_by_path( 'interactions?uri={object}&intent=follow' ),
146 - );
147 -
148 - return $jrd;
149 109 }
150 110 }