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 | includes/rest/class-nodeinfo-controller.php +20 -196 9.2.05.7.0 View file →
@@ -7,8 +7,10 @@
7 7
8 8 namespace Activitypub\Rest;
9 9
10 10 use function Activitypub\get_masked_wp_version;
11 +use function Activitypub\get_total_users;
12 +use function Activitypub\get_active_users;
11 13 use function Activitypub\get_rest_url_by_path;
12 14
13 15 /**
14 16 * ActivityPub NodeInfo Controller.
@@ -51,9 +53,9 @@
51 53 \register_rest_route(
52 54 $this->namespace,
53 55 '/' . $this->rest_base . '/(?P<version>\d\.\d)',
54 56 array(
55 - 'args' => array(
57 + 'args' => array(
56 58 'version' => array(
57 59 'description' => 'The version of the NodeInfo schema.',
58 60 'type' => 'string',
59 61 'required' => true,
@@ -63,9 +65,8 @@
63 65 'methods' => \WP_REST_Server::READABLE,
64 66 'callback' => array( $this, 'get_item' ),
65 67 'permission_callback' => '__return_true',
66 68 ),
67 - 'schema' => array( $this, 'get_item_schema' ),
68 69 )
69 70 );
70 71 }
71 72
@@ -92,16 +93,8 @@
92 93 'rel' => 'https://nodeinfo.diaspora.software/ns/schema/2.0',
93 94 'href' => get_rest_url_by_path( '/nodeinfo/2.0' ),
94 95 ),
95 96 array(
96 - 'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.1',
97 - 'href' => get_rest_url_by_path( '/nodeinfo/2.1' ),
98 - ),
99 - array(
100 - 'rel' => 'https://nodeinfo.diaspora.software/ns/schema/2.1',
101 - 'href' => get_rest_url_by_path( '/nodeinfo/2.1' ),
102 - ),
103 - array(
104 97 'rel' => 'https://www.w3.org/ns/activitystreams#Application',
105 98 'href' => get_rest_url_by_path( 'application' ),
106 99 ),
107 100 ),
@@ -127,10 +120,9 @@
127 120 \do_action( 'activitypub_rest_nodeinfo_pre', $version );
128 121
129 122 switch ( $version ) {
130 123 case '2.0':
131 - case '2.1':
132 - $response = $this->get_version_2_X( $version );
124 + $response = $this->get_version_2_0();
133 125 break;
134 126
135 127 default:
136 128 $response = new \WP_Error( 'activitypub_rest_nodeinfo_invalid_version', 'Unsupported NodeInfo version.', array( 'status' => 405 ) );
@@ -142,25 +134,33 @@
142 134
143 135 /**
144 136 * Get the NodeInfo 2.0 data.
145 137 *
146 - * @param string $version The NodeInfo version.
147 - *
148 - * @return array The NodeInfo data.
138 + * @return array
149 139 */
150 - public function get_version_2_X( $version ) {
140 + public function get_version_2_0() {
151 141 $posts = \wp_count_posts();
152 142 $comments = \wp_count_comments();
153 143
154 - $nodeinfo = array(
155 - 'version' => $version,
144 + return array(
145 + 'version' => '2.0',
156 146 'software' => array(
157 147 'name' => 'wordpress',
158 148 'version' => get_masked_wp_version(),
159 149 ),
160 - 'openRegistrations' => (bool) \get_option( 'users_can_register' ),
150 + 'protocols' => array( 'activitypub' ),
151 + 'services' => array(
152 + 'inbound' => array(),
153 + 'outbound' => array(),
154 + ),
155 + 'openRegistrations' => (bool) get_option( 'users_can_register' ),
161 156 'usage' => array(
162 - 'localPosts' => (int) $posts->publish,
157 + 'users' => array(
158 + 'total' => get_total_users(),
159 + 'activeHalfyear' => get_active_users( 6 ),
160 + 'activeMonth' => get_active_users(),
161 + ),
162 + 'localPosts' => $posts->publish,
163 163 'localComments' => $comments->approved,
164 164 ),
165 165 'metadata' => array(
166 166 'nodeName' => \get_bloginfo( 'name' ),
@@ -165,184 +165,8 @@
165 165 'metadata' => array(
166 166 'nodeName' => \get_bloginfo( 'name' ),
167 167 'nodeDescription' => \get_bloginfo( 'description' ),
168 168 'nodeIcon' => \get_site_icon_url(),
169 - ),
170 - );
171 -
172 - /**
173 - * Filter the NodeInfo data.
174 - *
175 - * @param array $nodeinfo The NodeInfo data.
176 - * @param string $version The NodeInfo version.
177 - */
178 - return \apply_filters( 'nodeinfo_data', $nodeinfo, $version );
179 - }
180 -
181 - /**
182 - * Retrieves the NodeInfo schema, conforming to JSON Schema.
183 - *
184 - * @return array NodeInfo schema data.
185 - */
186 - public function get_item_schema() {
187 - return array(
188 - '$schema' => 'http://json-schema.org/draft-04/schema#',
189 - 'title' => 'nodeinfo',
190 - 'type' => 'object',
191 - 'properties' => array(
192 - 'version' => array(
193 - 'description' => 'The version of the NodeInfo schema.',
194 - 'type' => 'string',
195 - 'enum' => array( '2.0', '2.1' ),
196 - ),
197 - 'software' => array(
198 - 'description' => 'Information about the software.',
199 - 'type' => 'object',
200 - 'properties' => array(
201 - 'name' => array(
202 - 'description' => 'The canonical name of this server software.',
203 - 'type' => 'string',
204 - ),
205 - 'version' => array(
206 - 'description' => 'The version of this server software.',
207 - 'type' => 'string',
208 - ),
209 - 'homepage' => array(
210 - 'description' => 'The url of the homepage of this server software.',
211 - 'type' => 'string',
212 - 'format' => 'uri',
213 - ),
214 - 'repository' => array(
215 - 'description' => 'The url of the source code repository of this server software.',
216 - 'type' => 'string',
217 - 'format' => 'uri',
218 - ),
219 - ),
220 - ),
221 - 'protocols' => array(
222 - 'description' => 'The protocols supported on this server.',
223 - 'type' => 'array',
224 - 'items' => array(
225 - 'type' => 'string',
226 - 'enum' => array(
227 - 'activitypub',
228 - 'buddycloud',
229 - 'dfrn',
230 - 'diaspora',
231 - 'libertree',
232 - 'ostatus',
233 - 'pumpio',
234 - 'tent',
235 - 'xmpp',
236 - 'zot',
237 - ),
238 - ),
239 - ),
240 - 'services' => array(
241 - 'description' => 'The third party sites this server can connect to via their application API.',
242 - 'type' => 'object',
243 - 'properties' => array(
244 - 'inbound' => array(
245 - 'description' => 'The third party sites this server can retrieve messages from for combined display with regular traffic.',
246 - 'type' => 'array',
247 - 'items' => array(
248 - 'type' => 'string',
249 - 'enum' => array(
250 - 'atom1.0',
251 - 'gnusocial',
252 - 'imap',
253 - 'pnut',
254 - 'pop3',
255 - 'pumpio',
256 - 'rss2.0',
257 - 'twitter',
258 - ),
259 - ),
260 - ),
261 - 'outbound' => array(
262 - 'description' => 'The third party sites this server can publish messages to on the behalf of a user.',
263 - 'type' => 'array',
264 - 'items' => array(
265 - 'type' => 'string',
266 - 'enum' => array(
267 - 'atom1.0',
268 - 'blogger',
269 - 'buddycloud',
270 - 'diaspora',
271 - 'dreamwidth',
272 - 'drupal',
273 - 'facebook',
274 - 'friendica',
275 - 'gnusocial',
276 - 'google',
277 - 'insanejournal',
278 - 'libertree',
279 - 'linkedin',
280 - 'livejournal',
281 - 'mediagoblin',
282 - 'myspace',
283 - 'pinterest',
284 - 'pnut',
285 - 'posterous',
286 - 'pumpio',
287 - 'redmatrix',
288 - 'rss2.0',
289 - 'smtp',
290 - 'tent',
291 - 'tumblr',
292 - 'twitter',
293 - 'wordpress',
294 - 'xmpp',
295 - ),
296 - ),
297 - ),
298 - ),
299 - ),
300 - 'openRegistrations' => array(
301 - 'description' => 'Whether this server allows open self-registration.',
302 - 'type' => 'boolean',
303 - ),
304 - 'usage' => array(
305 - 'description' => 'Usage statistics for this server.',
306 - 'type' => 'object',
307 - 'properties' => array(
308 - 'users' => array(
309 - 'description' => 'Statistics about the users of this server.',
310 - 'type' => 'object',
311 - 'properties' => array(
312 - 'total' => array(
313 - 'description' => 'The total amount of on this server registered users.',
314 - 'type' => 'integer',
315 - 'minimum' => 0,
316 - ),
317 - 'activeMonth' => array(
318 - 'description' => 'The amount of users that signed in at least once in the last 30 days.',
319 - 'type' => 'integer',
320 - 'minimum' => 0,
321 - ),
322 - 'activeHalfyear' => array(
323 - 'description' => 'The amount of users that signed in at least once in the last 180 days.',
324 - 'type' => 'integer',
325 - 'minimum' => 0,
326 - ),
327 - ),
328 - ),
329 - 'localPosts' => array(
330 - 'description' => 'The amount of posts that were made by users that are registered on this server.',
331 - 'type' => 'integer',
332 - 'minimum' => 0,
333 - ),
334 - 'localComments' => array(
335 - 'description' => 'The amount of comments that were made by users that are registered on this server.',
336 - 'type' => 'integer',
337 - 'minimum' => 0,
338 - ),
339 - ),
340 - ),
341 - 'metadata' => array(
342 - 'description' => 'Free form key value pairs for software specific values.',
343 - 'type' => 'object',
344 - ),
345 169 ),
346 170 );
347 171 }
348 172 }