PluginProbe
ActivityPub / 5.7.0
ActivityPub v5.7.0
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
← All changes | integration/class-nodeinfo.php +42 -17 1.2.05.7.0 View file →
@@ -1,33 +1,42 @@
1 1 <?php
2 +/**
3 + * NodeInfo integration file.
4 + *
5 + * @package Activitypub
6 + */
7 +
2 8 namespace Activitypub\Integration;
3 9
4 10 use function Activitypub\get_total_users;
5 11 use function Activitypub\get_active_users;
12 +use function Activitypub\get_rest_url_by_path;
6 13
7 14 /**
8 - * Compatibility with the NodeInfo plugin
15 + * Compatibility with the NodeInfo plugin.
9 16 *
10 17 * @see https://wordpress.org/plugins/nodeinfo/
11 18 */
12 19 class Nodeinfo {
13 20 /**
14 - * Initialize the class, registering WordPress hooks
21 + * Initialize the class, registering WordPress hooks.
15 22 */
16 23 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 );
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' ) );
19 28 }
20 29
21 30 /**
22 - * Extend NodeInfo data
31 + * Extend NodeInfo data.
23 32 *
24 - * @param array $nodeinfo NodeInfo data
25 - * @param string The NodeInfo Version
33 + * @param array $nodeinfo NodeInfo data.
34 + * @param string $version The NodeInfo Version.
26 35 *
27 - * @return array The extended array
36 + * @return array The extended array.
28 37 */
29 - public static function add_nodeinfo_discovery( $nodeinfo, $version ) {
38 + public static function add_nodeinfo_data( $nodeinfo, $version ) {
30 39 if ( $version >= '2.0' ) {
31 40 $nodeinfo['protocols'][] = 'activitypub';
32 41 } else {
33 42 $nodeinfo['protocols']['inbound'][] = 'activitypub';
@@ -35,10 +44,10 @@
35 44 }
36 45
37 46 $nodeinfo['usage']['users'] = array(
38 47 'total' => get_total_users(),
39 - 'activeMonth' => get_active_users( '1 month ago' ),
40 - 'activeHalfyear' => get_active_users( '6 month ago' ),
48 + 'activeMonth' => get_active_users(),
49 + 'activeHalfyear' => get_active_users( 6 ),
41 50 );
42 51
43 52 return $nodeinfo;
44 53 }
@@ -43,22 +52,38 @@
43 52 return $nodeinfo;
44 53 }
45 54
46 55 /**
47 - * Extend NodeInfo2 data
56 + * Extend NodeInfo2 data.
48 57 *
49 - * @param array $nodeinfo NodeInfo2 data
58 + * @param array $nodeinfo NodeInfo2 data.
50 59 *
51 - * @return array The extended array
60 + * @return array The extended array.
52 61 */
53 - public static function add_nodeinfo2_discovery( $nodeinfo ) {
62 + public static function add_nodeinfo2_data( $nodeinfo ) {
54 63 $nodeinfo['protocols'][] = 'activitypub';
55 64
56 65 $nodeinfo['usage']['users'] = array(
57 66 'total' => get_total_users(),
58 - 'activeMonth' => get_active_users( '1 month ago' ),
59 - 'activeHalfyear' => get_active_users( '6 month ago' ),
67 + 'activeMonth' => get_active_users(),
68 + 'activeHalfyear' => get_active_users( 6 ),
60 69 );
61 70
62 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;
63 88 }
64 89 }