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