|
| 1 | +<?php |
| 2 | +namespace Activitypub\Integration; |
| 3 | + |
| 4 | +use Activitypub\Collection\Users as User_Collection; |
| 5 | + |
| 6 | +/** |
| 7 | + * Compatibility with the WebFinger plugin |
| 8 | + * |
| 9 | + * @see https://wordpress.org/plugins/webfinger/ |
| 10 | + */ |
| 11 | +class Webfinger { |
| 12 | + /** |
| 13 | + * Initialize the class, registering WordPress hooks |
| 14 | + */ |
| 15 | + 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 ); |
| 18 | + } |
| 19 | + |
| 20 | + /** |
| 21 | + * Add WebFinger discovery links |
| 22 | + * |
| 23 | + * @param array $array the jrd array |
| 24 | + * @param string $resource the WebFinger resource |
| 25 | + * @param WP_User $user the WordPress user |
| 26 | + * |
| 27 | + * @return array the jrd array |
| 28 | + */ |
| 29 | + public static function add_user_discovery( $array, $resource, $user ) { |
| 30 | + $user = User_Collection::get_by_id( $user->ID ); |
| 31 | + |
| 32 | + $array['links'][] = array( |
| 33 | + 'rel' => 'self', |
| 34 | + 'type' => 'application/activity+json', |
| 35 | + 'href' => $user->get_url(), |
| 36 | + ); |
| 37 | + |
| 38 | + return $array; |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * Add WebFinger discovery links |
| 43 | + * |
| 44 | + * @param array $array the jrd array |
| 45 | + * @param string $resource the WebFinger resource |
| 46 | + * @param WP_User $user the WordPress user |
| 47 | + * |
| 48 | + * @return array the jrd array |
| 49 | + */ |
| 50 | + public static function add_pseudo_user_discovery( $array, $resource ) { |
| 51 | + if ( $array ) { |
| 52 | + return $array; |
| 53 | + } |
| 54 | + |
| 55 | + return self::get_profile( $resource ); |
| 56 | + } |
| 57 | +} |
0 commit comments