| @@ -1,7 +1,11 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Activitypub\Integration; |
| 3 | 3 | |
| 4 | +use function Activitypub\get_total_users; | |
| 5 | +use function Activitypub\get_active_users; | |
| 6 | +use function Activitypub\get_rest_url_by_path; | |
| 7 | + | |
| 4 | 8 | /** |
| 5 | 9 | * Compatibility with the NodeInfo plugin |
| 6 | 10 | * |
| 7 | 11 | * @see https://wordpress.org/plugins/nodeinfo/ |
| @@ -10,10 +14,12 @@ | ||
| 10 | 14 | /** |
| 11 | 15 | * Initialize the class, registering WordPress hooks |
| 12 | 16 | */ |
| 13 | 17 | public static function init() { |
| 14 | - \add_filter( 'nodeinfo_data', array( self::class, 'add_nodeinfo_discovery' ), 10, 2 ); | |
| 15 | - \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 ); | |
| 16 | 22 | } |
| 17 | 23 | |
| 18 | 24 | /** |
| 19 | 25 | * Extend NodeInfo data |
| @@ -22,9 +28,9 @@ | ||
| 22 | 28 | * @param string The NodeInfo Version |
| 23 | 29 | * |
| 24 | 30 | * @return array The extended array |
| 25 | 31 | */ |
| 26 | - public static function add_nodeinfo_discovery( $nodeinfo, $version ) { | |
| 32 | + public static function add_nodeinfo_data( $nodeinfo, $version ) { | |
| 27 | 33 | if ( $version >= '2.0' ) { |
| 28 | 34 | $nodeinfo['protocols'][] = 'activitypub'; |
| 29 | 35 | } else { |
| 30 | 36 | $nodeinfo['protocols']['inbound'][] = 'activitypub'; |
| @@ -30,8 +36,14 @@ | ||
| 30 | 36 | $nodeinfo['protocols']['inbound'][] = 'activitypub'; |
| 31 | 37 | $nodeinfo['protocols']['outbound'][] = 'activitypub'; |
| 32 | 38 | } |
| 33 | 39 | |
| 40 | + $nodeinfo['usage']['users'] = array( | |
| 41 | + 'total' => get_total_users(), | |
| 42 | + 'activeMonth' => get_active_users( '1 month ago' ), | |
| 43 | + 'activeHalfyear' => get_active_users( '6 month ago' ), | |
| 44 | + ); | |
| 45 | + | |
| 34 | 46 | return $nodeinfo; |
| 35 | 47 | } |
| 36 | 48 | |
| 37 | 49 | /** |
| @@ -40,10 +52,32 @@ | ||
| 40 | 52 | * @param array $nodeinfo NodeInfo2 data |
| 41 | 53 | * |
| 42 | 54 | * @return array The extended array |
| 43 | 55 | */ |
| 44 | - public static function add_nodeinfo2_discovery( $nodeinfo ) { | |
| 56 | + public static function add_nodeinfo2_data( $nodeinfo ) { | |
| 45 | 57 | $nodeinfo['protocols'][] = 'activitypub'; |
| 46 | 58 | |
| 59 | + $nodeinfo['usage']['users'] = array( | |
| 60 | + 'total' => get_total_users(), | |
| 61 | + 'activeMonth' => get_active_users( '1 month ago' ), | |
| 62 | + 'activeHalfyear' => get_active_users( '6 month ago' ), | |
| 63 | + ); | |
| 64 | + | |
| 47 | 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; | |
| 48 | 82 | } |
| 49 | 83 | } |