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
activitypub / integration / class-webfinger.php

class-webfinger.php in ActivityPub 3.2.4, at integration/class-webfinger.php

111 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Activitypub\Integration;
3
4 use Activitypub\Rest\Webfinger as Webfinger_Rest;
5 use Activitypub\Collection\Users as User_Collection;
6
7 use function Activitypub\get_rest_url_by_path;
8
9 /**
10 * Compatibility with the WebFinger plugin
11 *
12 * @see https://wordpress.org/plugins/webfinger/
13 */
14 class Webfinger {
15 /**
16 * Initialize the class, registering WordPress hooks
17 */
18 public static function init() {
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 );
21 }
22
23 /**
24 * Add WebFinger discovery links
25 *
26 * @param array $array the jrd array
27 * @param string $resource the WebFinger resource
28 * @param WP_User $user the WordPress user
29 *
30 * @return array the jrd array
31 */
32 public static function add_user_discovery( $array, $resource, $user ) {
33 $user = User_Collection::get_by_id( $user->ID );
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
44 $array['links'][] = array(
45 'rel' => 'self',
46 'type' => 'application/activity+json',
47 'href' => $user->get_url(),
48 );
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
55 return $array;
56 }
57
58 /**
59 * Add WebFinger discovery links
60 *
61 * @param array $array the jrd array
62 * @param string $resource the WebFinger resource
63 * @param WP_User $user the WordPress user
64 *
65 * @return array the jrd array
66 */
67 public static function add_pseudo_user_discovery( $array, $resource ) {
68 $user = User_Collection::get_by_resource( $resource );
69
70 if ( \is_wp_error( $user ) ) {
71 return $user;
72 }
73
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;
109 }
110 }
111