| 1 |
<?php |
| 2 |
namespace Activitypub\Integration; |
| 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 |
|
| 8 |
/** |
| 9 |
* Compatibility with the NodeInfo plugin |
| 10 |
* |
| 11 |
* @see https://wordpress.org/plugins/nodeinfo/ |
| 12 |
*/ |
| 13 |
class Nodeinfo { |
| 14 |
/** |
| 15 |
* Initialize the class, registering WordPress hooks |
| 16 |
*/ |
| 17 |
public static function init() { |
| 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 ); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Extend NodeInfo data |
| 26 |
* |
| 27 |
* @param array $nodeinfo NodeInfo data |
| 28 |
* @param string The NodeInfo Version |
| 29 |
* |
| 30 |
* @return array The extended array |
| 31 |
*/ |
| 32 |
public static function add_nodeinfo_data( $nodeinfo, $version ) { |
| 33 |
if ( $version >= '2.0' ) { |
| 34 |
$nodeinfo['protocols'][] = 'activitypub'; |
| 35 |
} else { |
| 36 |
$nodeinfo['protocols']['inbound'][] = 'activitypub'; |
| 37 |
$nodeinfo['protocols']['outbound'][] = 'activitypub'; |
| 38 |
} |
| 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 |
|
| 46 |
return $nodeinfo; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Extend NodeInfo2 data |
| 51 |
* |
| 52 |
* @param array $nodeinfo NodeInfo2 data |
| 53 |
* |
| 54 |
* @return array The extended array |
| 55 |
*/ |
| 56 |
public static function add_nodeinfo2_data( $nodeinfo ) { |
| 57 |
$nodeinfo['protocols'][] = 'activitypub'; |
| 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 |
|
| 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; |
| 82 |
} |
| 83 |
} |
| 84 |
|