PluginProbe
ActivityPub / 7.7.0
ActivityPub v7.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 +85 -25 2.1.17.7.0 View file →
@@ -1,58 +1,93 @@
1 1 <?php
2 +/**
3 + * NodeInfo integration file.
4 + *
5 + * @package Activitypub
6 + */
7 +
2 8 namespace Activitypub\Integration;
3 9
4 -use function Activitypub\get_total_users;
10 +use Activitypub\Webfinger;
11 +
5 12 use function Activitypub\get_active_users;
6 13 use function Activitypub\get_rest_url_by_path;
14 +use function Activitypub\get_total_users;
7 15
8 16 /**
9 - * Compatibility with the NodeInfo plugin
17 + * Compatibility with the NodeInfo plugin.
10 18 *
11 19 * @see https://wordpress.org/plugins/nodeinfo/
12 20 */
13 21 class Nodeinfo {
14 22 /**
15 - * Initialize the class, registering WordPress hooks
23 + * Initialize the class, registering WordPress hooks.
16 24 */
17 25 public static function init() {
18 26 \add_filter( 'nodeinfo_data', array( self::class, 'add_nodeinfo_data' ), 10, 2 );
19 - \add_filter( 'nodeinfo2_data', array( self::class, 'add_nodeinfo2_data' ), 10 );
27 + \add_filter( 'nodeinfo2_data', array( self::class, 'add_nodeinfo2_data' ) );
20 28
21 - \add_filter( 'wellknown_nodeinfo_data', array( self::class, 'add_wellknown_nodeinfo_data' ), 10, 2 );
29 + \add_filter( 'wellknown_nodeinfo_data', array( self::class, 'add_wellknown_nodeinfo_data' ) );
22 30 }
23 31
24 32 /**
25 - * Extend NodeInfo data
33 + * Extend NodeInfo data.
26 34 *
27 - * @param array $nodeinfo NodeInfo data
28 - * @param string The NodeInfo Version
35 + * @param array $nodeinfo NodeInfo data.
36 + * @param string $version The NodeInfo Version.
29 37 *
30 - * @return array The extended array
38 + * @return array The extended array.
31 39 */
32 40 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';
41 + $nodeinfo = wp_parse_args(
42 + $nodeinfo,
43 + array(
44 + 'version' => $version,
45 + 'software' => array(),
46 + 'usage' => array(
47 + 'users' => array(
48 + 'total' => 0,
49 + 'activeMonth' => 0,
50 + 'activeHalfyear' => 0,
51 + ),
52 + ),
53 + 'protocols' => array(),
54 + 'services' => array(
55 + 'inbound' => array(),
56 + 'outbound' => array(),
57 + ),
58 + 'metadata' => array(),
59 + )
60 + );
61 +
62 + if ( \version_compare( $version, '2.1', '>=' ) ) {
63 + $nodeinfo['software']['homepage'] = 'https://wordpress.org/plugins/activitypub/';
64 + $nodeinfo['software']['repository'] = 'https://github.com/Automattic/wordpress-activitypub';
38 65 }
39 66
67 + $nodeinfo['protocols'][] = 'activitypub';
68 +
40 69 $nodeinfo['usage']['users'] = array(
41 70 'total' => get_total_users(),
42 - 'activeMonth' => get_active_users( '1 month ago' ),
43 - 'activeHalfyear' => get_active_users( '6 month ago' ),
71 + 'activeMonth' => get_active_users(),
72 + 'activeHalfyear' => get_active_users( 6 ),
44 73 );
45 74
75 + $nodeinfo['metadata']['federation'] = array( 'enabled' => true );
76 + $nodeinfo['metadata']['staffAccounts'] = self::get_staff();
77 +
78 + $nodeinfo['services']['inbound'][] = 'activitypub';
79 + $nodeinfo['services']['outbound'][] = 'activitypub';
80 +
46 81 return $nodeinfo;
47 82 }
48 83
49 84 /**
50 - * Extend NodeInfo2 data
85 + * Extend NodeInfo2 data.
51 86 *
52 - * @param array $nodeinfo NodeInfo2 data
87 + * @param array $nodeinfo NodeInfo2 data.
53 88 *
54 - * @return array The extended array
89 + * @return array The extended array.
55 90 */
56 91 public static function add_nodeinfo2_data( $nodeinfo ) {
57 92 $nodeinfo['protocols'][] = 'activitypub';
58 93
@@ -57,10 +92,10 @@
57 92 $nodeinfo['protocols'][] = 'activitypub';
58 93
59 94 $nodeinfo['usage']['users'] = array(
60 95 'total' => get_total_users(),
61 - 'activeMonth' => get_active_users( '1 month ago' ),
62 - 'activeHalfyear' => get_active_users( '6 month ago' ),
96 + 'activeMonth' => get_active_users(),
97 + 'activeHalfyear' => get_active_users( 6 ),
63 98 );
64 99
65 100 return $nodeinfo;
66 101 }
@@ -65,19 +100,44 @@
65 100 return $nodeinfo;
66 101 }
67 102
68 103 /**
69 - * Extend the well-known nodeinfo data
104 + * Extend the well-known nodeinfo data.
70 105 *
71 - * @param array $data The well-known nodeinfo data
106 + * @param array $data The well-known nodeinfo data.
72 107 *
73 - * @return array The extended array
108 + * @return array The extended array.
74 109 */
75 110 public static function add_wellknown_nodeinfo_data( $data ) {
76 111 $data['links'][] = array(
77 - 'rel' => 'https://www.w3.org/ns/activitystreams#Application',
112 + 'rel' => 'https://www.w3.org/ns/activitystreams#Application',
78 113 'href' => get_rest_url_by_path( 'application' ),
79 114 );
80 115
81 116 return $data;
117 + }
118 +
119 + /**
120 + * Get all staff accounts (admin users with the "activitypub" capability) and return them in WebFinger resource format.
121 + *
122 + * @return array List of staff accounts in WebFinger resource format.
123 + */
124 + private static function get_staff() {
125 + // Get all admin users with the cap activitypub.
126 + $admins = get_users(
127 + array(
128 + 'role' => 'administrator',
129 + 'orderby' => 'ID',
130 + 'order' => 'ASC',
131 + 'cap' => 'activitypub',
132 + 'fields' => array( 'ID' ),
133 + )
134 + );
135 +
136 + return array_map(
137 + function ( $user ) {
138 + return Webfinger::get_user_resource( $user->ID );
139 + },
140 + $admins
141 + );
82 142 }
83 143 }