| @@ -2,8 +2,9 @@ | ||
| 2 | 2 | namespace Activitypub\Integration; |
| 3 | 3 | |
| 4 | 4 | use function Activitypub\get_total_users; |
| 5 | 5 | use function Activitypub\get_active_users; |
| 6 | +use function Activitypub\get_rest_url_by_path; | |
| 6 | 7 | |
| 7 | 8 | /** |
| 8 | 9 | * Compatibility with the NodeInfo plugin |
| 9 | 10 | * |
| @@ -13,10 +14,12 @@ | ||
| 13 | 14 | /** |
| 14 | 15 | * Initialize the class, registering WordPress hooks |
| 15 | 16 | */ |
| 16 | 17 | public static function init() { |
| 17 | - \add_filter( 'nodeinfo_data', array( self::class, 'add_nodeinfo_discovery' ), 10, 2 ); | |
| 18 | - \add_filter( 'nodeinfo2_data', array( self::class, 'add_nodeinfo2_discovery' ), 10 ); | |
| 18 | + \add_filter( 'nodeinfo_data', array( self::class, 'add_nodeinfo_data' ), 10, 2 ); | |
| 19 | + \add_filter( 'nodeinfo2_data', array( self::class, 'add_nodeinfo2_data' ), 10 ); | |
| 20 | + | |
| 21 | + \add_filter( 'wellknown_nodeinfo_data', array( self::class, 'add_wellknown_nodeinfo_data' ), 10, 2 ); | |
| 19 | 22 | } |
| 20 | 23 | |
| 21 | 24 | /** |
| 22 | 25 | * Extend NodeInfo data |
| @@ -25,9 +28,9 @@ | ||
| 25 | 28 | * @param string The NodeInfo Version |
| 26 | 29 | * |
| 27 | 30 | * @return array The extended array |
| 28 | 31 | */ |
| 29 | - public static function add_nodeinfo_discovery( $nodeinfo, $version ) { | |
| 32 | + public static function add_nodeinfo_data( $nodeinfo, $version ) { | |
| 30 | 33 | if ( $version >= '2.0' ) { |
| 31 | 34 | $nodeinfo['protocols'][] = 'activitypub'; |
| 32 | 35 | } else { |
| 33 | 36 | $nodeinfo['protocols']['inbound'][] = 'activitypub'; |
| @@ -49,9 +52,9 @@ | ||
| 49 | 52 | * @param array $nodeinfo NodeInfo2 data |
| 50 | 53 | * |
| 51 | 54 | * @return array The extended array |
| 52 | 55 | */ |
| 53 | - public static function add_nodeinfo2_discovery( $nodeinfo ) { | |
| 56 | + public static function add_nodeinfo2_data( $nodeinfo ) { | |
| 54 | 57 | $nodeinfo['protocols'][] = 'activitypub'; |
| 55 | 58 | |
| 56 | 59 | $nodeinfo['usage']['users'] = array( |
| 57 | 60 | 'total' => get_total_users(), |
| @@ -59,6 +62,22 @@ | ||
| 59 | 62 | 'activeHalfyear' => get_active_users( '6 month ago' ), |
| 60 | 63 | ); |
| 61 | 64 | |
| 62 | 65 | return $nodeinfo; |
| 66 | + } | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * Extend the well-known nodeinfo data | |
| 70 | + * | |
| 71 | + * @param array $data The well-known nodeinfo data | |
| 72 | + * | |
| 73 | + * @return array The extended array | |
| 74 | + */ | |
| 75 | + public static function add_wellknown_nodeinfo_data( $data ) { | |
| 76 | + $data['links'][] = array( | |
| 77 | + 'rel' => 'https://www.w3.org/ns/activitystreams#Application', | |
| 78 | + 'href' => get_rest_url_by_path( 'application' ), | |
| 79 | + ); | |
| 80 | + | |
| 81 | + return $data; | |
| 63 | 82 | } |
| 64 | 83 | } |