2023-10-22 22:20:53 +00:00
|
|
|
<?php
|
2024-10-09 12:44:17 +00:00
|
|
|
/**
|
|
|
|
* NodeInfo integration file.
|
|
|
|
*
|
|
|
|
* @package Activitypub
|
|
|
|
*/
|
|
|
|
|
2023-10-22 22:20:53 +00:00
|
|
|
namespace Activitypub\Integration;
|
|
|
|
|
2023-12-08 23:23:11 +00:00
|
|
|
use function Activitypub\get_total_users;
|
|
|
|
use function Activitypub\get_active_users;
|
2024-02-08 12:31:25 +00:00
|
|
|
use function Activitypub\get_rest_url_by_path;
|
2023-12-08 23:23:11 +00:00
|
|
|
|
2023-10-22 22:20:53 +00:00
|
|
|
/**
|
2024-10-09 12:44:17 +00:00
|
|
|
* Compatibility with the NodeInfo plugin.
|
2023-10-22 22:20:53 +00:00
|
|
|
*
|
|
|
|
* @see https://wordpress.org/plugins/nodeinfo/
|
|
|
|
*/
|
|
|
|
class Nodeinfo {
|
|
|
|
/**
|
2024-10-09 12:44:17 +00:00
|
|
|
* Initialize the class, registering WordPress hooks.
|
2023-10-22 22:20:53 +00:00
|
|
|
*/
|
|
|
|
public static function init() {
|
2024-02-08 12:31:25 +00:00
|
|
|
\add_filter( 'nodeinfo_data', array( self::class, 'add_nodeinfo_data' ), 10, 2 );
|
2024-10-09 12:44:17 +00:00
|
|
|
\add_filter( 'nodeinfo2_data', array( self::class, 'add_nodeinfo2_data' ) );
|
2024-02-08 12:31:25 +00:00
|
|
|
|
|
|
|
\add_filter( 'wellknown_nodeinfo_data', array( self::class, 'add_wellknown_nodeinfo_data' ), 10, 2 );
|
2023-10-22 22:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-10-09 12:44:17 +00:00
|
|
|
* Extend NodeInfo data.
|
2023-10-22 22:20:53 +00:00
|
|
|
*
|
2024-10-09 12:44:17 +00:00
|
|
|
* @param array $nodeinfo NodeInfo data.
|
|
|
|
* @param string $version The NodeInfo Version.
|
2023-10-22 22:20:53 +00:00
|
|
|
*
|
2024-10-09 12:44:17 +00:00
|
|
|
* @return array The extended array.
|
2023-10-22 22:20:53 +00:00
|
|
|
*/
|
2024-02-08 12:31:25 +00:00
|
|
|
public static function add_nodeinfo_data( $nodeinfo, $version ) {
|
2023-10-22 22:20:53 +00:00
|
|
|
if ( $version >= '2.0' ) {
|
|
|
|
$nodeinfo['protocols'][] = 'activitypub';
|
|
|
|
} else {
|
|
|
|
$nodeinfo['protocols']['inbound'][] = 'activitypub';
|
|
|
|
$nodeinfo['protocols']['outbound'][] = 'activitypub';
|
|
|
|
}
|
|
|
|
|
2023-12-08 23:23:11 +00:00
|
|
|
$nodeinfo['usage']['users'] = array(
|
|
|
|
'total' => get_total_users(),
|
|
|
|
'activeMonth' => get_active_users( '1 month ago' ),
|
|
|
|
'activeHalfyear' => get_active_users( '6 month ago' ),
|
|
|
|
);
|
|
|
|
|
2023-10-22 22:20:53 +00:00
|
|
|
return $nodeinfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-10-09 12:44:17 +00:00
|
|
|
* Extend NodeInfo2 data.
|
2023-10-22 22:20:53 +00:00
|
|
|
*
|
2024-10-09 12:44:17 +00:00
|
|
|
* @param array $nodeinfo NodeInfo2 data.
|
2023-10-22 22:20:53 +00:00
|
|
|
*
|
2024-10-09 12:44:17 +00:00
|
|
|
* @return array The extended array.
|
2023-10-22 22:20:53 +00:00
|
|
|
*/
|
2024-02-08 12:31:25 +00:00
|
|
|
public static function add_nodeinfo2_data( $nodeinfo ) {
|
2023-10-22 22:20:53 +00:00
|
|
|
$nodeinfo['protocols'][] = 'activitypub';
|
|
|
|
|
2023-12-08 23:23:11 +00:00
|
|
|
$nodeinfo['usage']['users'] = array(
|
|
|
|
'total' => get_total_users(),
|
|
|
|
'activeMonth' => get_active_users( '1 month ago' ),
|
|
|
|
'activeHalfyear' => get_active_users( '6 month ago' ),
|
|
|
|
);
|
|
|
|
|
2023-10-22 22:20:53 +00:00
|
|
|
return $nodeinfo;
|
|
|
|
}
|
2024-02-08 12:31:25 +00:00
|
|
|
|
|
|
|
/**
|
2024-10-09 12:44:17 +00:00
|
|
|
* Extend the well-known nodeinfo data.
|
2024-02-08 12:31:25 +00:00
|
|
|
*
|
2024-10-09 12:44:17 +00:00
|
|
|
* @param array $data The well-known nodeinfo data.
|
2024-02-08 12:31:25 +00:00
|
|
|
*
|
2024-10-09 12:44:17 +00:00
|
|
|
* @return array The extended array.
|
2024-02-08 12:31:25 +00:00
|
|
|
*/
|
|
|
|
public static function add_wellknown_nodeinfo_data( $data ) {
|
|
|
|
$data['links'][] = array(
|
2024-10-09 12:44:17 +00:00
|
|
|
'rel' => 'https://www.w3.org/ns/activitystreams#Application',
|
2024-02-08 12:31:25 +00:00
|
|
|
'href' => get_rest_url_by_path( 'application' ),
|
|
|
|
);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
2023-10-22 22:20:53 +00:00
|
|
|
}
|