PluginProbe
ActivityPub / 2.6.0
ActivityPub v2.6.0
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 +28 -109 9.2.02.6.0 View file →
@@ -1,17 +1,10 @@
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 -use function Activitypub\get_rest_url_by_path;
13 -
14 7 /**
15 8 * Compatibility with the WebFinger plugin
16 9 *
17 10 * @see https://wordpress.org/plugins/webfinger/
@@ -17,134 +10,60 @@
17 10 * @see https://wordpress.org/plugins/webfinger/
18 11 */
19 12 class Webfinger {
20 13 /**
21 - * Initialize the class, registering WordPress hooks.
14 + * Initialize the class, registering WordPress hooks
22 15 */
23 16 public static function init() {
24 17 \add_filter( 'webfinger_user_data', array( self::class, 'add_user_discovery' ), 1, 3 );
25 18 \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 19 }
29 20
30 21 /**
31 - * Add WebFinger discovery links.
22 + * Add WebFinger discovery links
32 23 *
33 - * @param array $jrd The jrd array.
34 - * @param string $uri The WebFinger resource.
35 - * @param \WP_User $user The WordPress user.
24 + * @param array $array the jrd array
25 + * @param string $resource the WebFinger resource
26 + * @param WP_User $user the WordPress user
36 27 *
37 - * @return array The jrd array.
28 + * @return array the jrd array
38 29 */
39 - public static function add_user_discovery( $jrd, $uri, $user ) {
40 - $user = Actors::get_by_id( $user->ID );
30 + public static function add_user_discovery( $array, $resource, $user ) {
31 + $user = User_Collection::get_by_id( $user->ID );
41 32
42 - if ( ! $user || \is_wp_error( $user ) ) {
43 - return $jrd;
33 + if ( ! $user || is_wp_error( $user ) ) {
34 + return $array;
44 35 }
45 36
46 - $jrd['subject'] = \sprintf( 'acct:%s', $user->get_webfinger() );
37 + $array['subject'] = sprintf( 'acct:%s', $user->get_webfinger() );
47 38
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'] );
39 + $array['aliases'][] = $user->get_url();
40 + $array['aliases'][] = $user->get_alternate_url();
53 41
54 - $jrd['links'][] = array(
42 + $array['links'][] = array(
55 43 'rel' => 'self',
56 44 'type' => 'application/activity+json',
57 - 'href' => $user->get_id(),
45 + 'href' => $user->get_url(),
58 46 );
59 47
60 - return $jrd;
48 + return $array;
61 49 }
62 50
63 51 /**
64 - * Add WebFinger discovery links.
52 + * Add WebFinger discovery links
65 53 *
66 - * @param array $jrd The jrd array.
67 - * @param string $uri The WebFinger resource.
54 + * @param array $array the jrd array
55 + * @param string $resource the WebFinger resource
56 + * @param WP_User $user the WordPress user
68 57 *
69 - * @return array|\WP_Error The jrd array or WP_Error.
58 + * @return array the jrd array
70 59 */
71 - public static function add_pseudo_user_discovery( $jrd, $uri ) {
72 - $user = Actors::get_by_resource( $uri );
60 + public static function add_pseudo_user_discovery( $array, $resource ) {
61 + $user = Webfinger_Rest::get_profile( $resource );
73 62
74 - if ( \is_wp_error( $user ) ) {
75 - return $user;
63 + if ( ! $user || is_wp_error( $user ) ) {
64 + return $array;
76 65 }
77 66
78 - $aliases = array(
79 - $user->get_id(),
80 - $user->get_url(),
81 - $user->get_alternate_url(),
82 - );
83 -
84 - $aliases = \array_unique( $aliases );
85 - $aliases = \array_values( $aliases );
86 -
87 - $profile = array(
88 - 'subject' => \sprintf( 'acct:%s', $user->get_webfinger() ),
89 - 'aliases' => $aliases,
90 - 'links' => array(
91 - array(
92 - 'rel' => 'self',
93 - 'type' => 'application/activity+json',
94 - 'href' => $user->get_id(),
95 - ),
96 - array(
97 - 'rel' => 'http://webfinger.net/rel/profile-page',
98 - 'type' => 'text/html',
99 - 'href' => $user->get_id(),
100 - ),
101 - ),
102 - );
103 -
104 - if ( 'Person' !== $user->get_type() ) {
105 - $profile['links'][0]['properties'] = array(
106 - 'https://www.w3.org/ns/activitystreams#type' => $user->get_type(),
107 - );
108 - }
109 -
110 - 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;
67 + return $user;
149 68 }
150 69 }