PluginProbe
ActivityPub / 0.4.3
ActivityPub v0.4.3
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 / includes / class-rest-activitypub-nodeinfo.php

class-rest-activitypub-nodeinfo.php in ActivityPub 0.4.3, at includes/class-rest-activitypub-nodeinfo.php

163 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Rest_Activitypub_Nodeinfo {
4 /**
5 * Register routes
6 */
7 public static function register_routes() {
8 register_rest_route(
9 'activitypub/1.0', '/nodeinfo/discovery', array(
10 array(
11 'methods' => WP_REST_Server::READABLE,
12 'callback' => array( 'Rest_Activitypub_Nodeinfo', 'discovery' ),
13 ),
14 )
15 );
16
17 register_rest_route(
18 'activitypub/1.0', '/nodeinfo', array(
19 array(
20 'methods' => WP_REST_Server::READABLE,
21 'callback' => array( 'Rest_Activitypub_Nodeinfo', 'nodeinfo' ),
22 ),
23 )
24 );
25
26 register_rest_route(
27 'activitypub/1.0', '/nodeinfo2', array(
28 array(
29 'methods' => WP_REST_Server::READABLE,
30 'callback' => array( 'Rest_Activitypub_Nodeinfo', 'nodeinfo2' ),
31 ),
32 )
33 );
34 }
35
36 /**
37 * Render NodeInfo file
38 *
39 * @param WP_REST_Request $request
40 * @return WP_REST_Response
41 */
42 public static function nodeinfo( $request ) {
43 $nodeinfo = array();
44
45 $nodeinfo['version'] = '2.0';
46 $nodeinfo['software'] = array(
47 'name' => 'wordpress',
48 'version' => get_bloginfo( 'version' ),
49 );
50
51 $users = count_users();
52 $posts = wp_count_posts();
53 $comments = wp_count_comments();
54
55 $nodeinfo['usage'] = array(
56 'users' => array(
57 'total' => (int) $users['total_users'],
58 ),
59 'localPosts' => (int) $posts->publish,
60 'localComments' => (int) $comments->approved,
61 );
62
63 $nodeinfo['openRegistrations'] = false;
64 $nodeinfo['protocols'] = array('activitypub');
65
66 $nodeinfo['services'] = array(
67 'inbound' => array(),
68 'outbound' => array(),
69 );
70
71 $nodeinfo['metadata'] = new stdClass;
72
73 return new WP_REST_Response( $nodeinfo, 200 );
74 }
75
76 /**
77 * Render NodeInfo file
78 *
79 * @param WP_REST_Request $request
80 * @return WP_REST_Response
81 */
82 public static function nodeinfo2( $request ) {
83 $nodeinfo = array();
84
85 $nodeinfo['version'] = '1.0';
86 $nodeinfo['software'] = array(
87 'baseUrl' => home_url( '/' ),
88 'name' => get_bloginfo( 'name' ),
89 'software' => 'wordpress',
90 'version' => get_bloginfo( 'version' ),
91 );
92
93 $users = count_users();
94 $posts = wp_count_posts();
95 $comments = wp_count_comments();
96
97 $nodeinfo['usage'] = array(
98 'users' => array(
99 'total' => (int) $users['total_users'],
100 ),
101 'localPosts' => (int) $posts->publish,
102 'localComments' => (int) $comments->approved,
103 );
104
105 $nodeinfo['openRegistrations'] = false;
106 $nodeinfo['protocols'] = array('activitypub');
107
108 $nodeinfo['services'] = array(
109 'inbound' => array(),
110 'outbound' => array(),
111 );
112
113 $nodeinfo['metadata'] = new stdClass;
114
115 return new WP_REST_Response( $nodeinfo, 200 );
116 }
117
118 /**
119 * Render NodeInfo discovery file
120 *
121 * @param WP_REST_Request $request
122 * @return WP_REST_Response
123 */
124 public static function discovery( $request ) {
125 $discovery = array();
126 $discovery['links'] = array(
127 array(
128 'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.0',
129 'href' => get_rest_url( null, 'activitypub/1.0/nodeinfo' ),
130 ),
131 );
132
133 return new WP_REST_Response( $discovery, 200 );
134 }
135
136 /**
137 * Extend NodeInfo data
138 *
139 * @param array $nodeinfo NodeInfo data
140 * @param array updated data
141 */
142 public static function add_nodeinfo_discovery( $nodeinfo, $version ) {
143 if ( '2.0' == $version) {
144 $nodeinfo['protocols'][] = 'activitypub';
145 } else {
146 $nodeinfo['protocols']['inbound'][] = 'activitypub';
147 $nodeinfo['protocols']['outbound'][] = 'activitypub';
148 }
149 return $nodeinfo;
150 }
151
152 /**
153 * Extend NodeInfo2 data
154 *
155 * @param array $nodeinfo NodeInfo2 data
156 * @param array updated data
157 */
158 public static function add_nodeinfo2_discovery( $nodeinfo ) {
159 $nodeinfo['protocols'][] = 'activitypub';
160 return $nodeinfo;
161 }
162 }
163