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