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 / includes / rest / class-webfinger.php

class-webfinger.php in ActivityPub 3.2.4, at includes/rest/class-webfinger.php

109 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Activitypub\Rest;
3
4 use WP_Error;
5 use WP_REST_Response;
6
7 /**
8 * ActivityPub WebFinger REST-Class
9 *
10 * @author Matthias Pfefferle
11 *
12 * @see https://webfinger.net/
13 */
14 class Webfinger {
15 /**
16 * Initialize the class, registering WordPress hooks.
17 *
18 * @return void
19 */
20 public static function init() {
21 self::register_routes();
22 }
23
24 /**
25 * Register routes.
26 *
27 * @return void
28 */
29 public static function register_routes() {
30 \register_rest_route(
31 ACTIVITYPUB_REST_NAMESPACE,
32 '/webfinger',
33 array(
34 array(
35 'methods' => \WP_REST_Server::READABLE,
36 'callback' => array( self::class, 'webfinger' ),
37 'args' => self::request_parameters(),
38 'permission_callback' => '__return_true',
39 ),
40 )
41 );
42 }
43
44 /**
45 * WebFinger endpoint.
46 *
47 * @param WP_REST_Request $request The request object.
48 *
49 * @return WP_REST_Response The response object.
50 */
51 public static function webfinger( $request ) {
52 /*
53 * Action triggerd prior to the ActivityPub profile being created and sent to the client
54 */
55 \do_action( 'activitypub_rest_webfinger_pre' );
56
57 $code = 200;
58
59 $resource = $request->get_param( 'resource' );
60 $response = self::get_profile( $resource );
61
62 if ( \is_wp_error( $response ) ) {
63 $code = 400;
64 $error_data = $response->get_error_data();
65
66 if ( isset( $error_data['status'] ) ) {
67 $code = $error_data['status'];
68 }
69 }
70
71 return new WP_REST_Response(
72 $response,
73 $code,
74 array(
75 'Access-Control-Allow-Origin' => '*',
76 'Content-Type' => 'application/jrd+json; charset=' . get_option( 'blog_charset' ),
77 )
78 );
79 }
80
81 /**
82 * The supported parameters
83 *
84 * @return array list of parameters
85 */
86 public static function request_parameters() {
87 $params = array();
88
89 $params['resource'] = array(
90 'required' => true,
91 'type' => 'string',
92 'pattern' => '^(acct:)|^(https?://)(.+)$',
93 );
94
95 return $params;
96 }
97
98 /**
99 * Get the WebFinger profile.
100 *
101 * @param string $resource the WebFinger resource.
102 *
103 * @return array the WebFinger profile.
104 */
105 public static function get_profile( $resource ) { // phpcs:ignore
106 return apply_filters( 'webfinger_data', array(), $resource );
107 }
108 }
109