PluginProbe
ActivityPub / 4.7.1
ActivityPub v4.7.1
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
activitypub / integration / class-nodeinfo.php

class-nodeinfo.php in ActivityPub 4.7.1, at integration/class-nodeinfo.php

90 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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