Skip to content

Commit aeb5169

Browse files
committed
added MAUs
1 parent 0671872 commit aeb5169

File tree

9 files changed

+111
-65
lines changed

9 files changed

+111
-65
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
**Tags:** nodeinfo, fediverse, ostatus, diaspora, activitypub
66
**Requires at least:** 4.9
77
**Tested up to:** 6.3
8-
**Stable tag:** 2.1.1
8+
**Stable tag:** 2.2.0
99
**Requires PHP:** 5.6
1010
**License:** MIT
1111
**License URI:** https://opensource.org/licenses/MIT
@@ -24,6 +24,10 @@ This plugin provides a barebone JSON file with basic "node"-informations. The fi
2424

2525
Project and support maintained on github at [pfefferle/wordpress-nodeinfo](https://github.com/pfefferle/wordpress-nodeinfo).
2626

27+
### 2.2.0 ###
28+
29+
* add MAUs
30+
2731
### 2.1.1 ###
2832

2933
* load plugin on init, to keep up with changes on the ActivityPub side

includes/class-nodeinfo-endpoint.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public static function register_routes() {
1313
'/discovery',
1414
array(
1515
array(
16-
'methods' => WP_REST_Server::READABLE,
17-
'callback' => array( 'Nodeinfo_Endpoint', 'render_discovery' ),
16+
'methods' => WP_REST_Server::READABLE,
17+
'callback' => array( 'Nodeinfo_Endpoint', 'render_discovery' ),
1818
'permission_callback' => '__return_true',
1919
),
2020
)
@@ -25,15 +25,15 @@ public static function register_routes() {
2525
'/(?P<version>[\.\d]+)',
2626
array(
2727
array(
28-
'methods' => WP_REST_Server::READABLE,
29-
'callback' => array( 'Nodeinfo_Endpoint', 'render_nodeinfo' ),
28+
'methods' => WP_REST_Server::READABLE,
29+
'callback' => array( 'Nodeinfo_Endpoint', 'render_nodeinfo' ),
3030
'permission_callback' => '__return_true',
31-
'args' => array(
31+
'args' => array(
3232
'version' => array(
33-
'required' => true,
34-
'type' => 'string',
33+
'required' => true,
34+
'type' => 'string',
3535
'description' => __( 'The version of the NodeInfo scheme', 'nodeinfo' ),
36-
'enum' => array(
36+
'enum' => array(
3737
'1.0',
3838
'1.1',
3939
'2.0',
@@ -50,15 +50,15 @@ public static function register_routes() {
5050
'/(?P<version>[\.\d]+)',
5151
array(
5252
array(
53-
'methods' => WP_REST_Server::READABLE,
54-
'callback' => array( 'Nodeinfo_Endpoint', 'render_nodeinfo2' ),
53+
'methods' => WP_REST_Server::READABLE,
54+
'callback' => array( 'Nodeinfo_Endpoint', 'render_nodeinfo2' ),
5555
'permission_callback' => '__return_true',
56-
'args' => array(
56+
'args' => array(
5757
'version' => array(
58-
'required' => true,
59-
'type' => 'string',
58+
'required' => true,
59+
'type' => 'string',
6060
'description' => __( 'The version of the NodeInfo2 scheme', 'nodeinfo' ),
61-
'enum' => array(
61+
'enum' => array(
6262
'1.0',
6363
),
6464
),
@@ -75,22 +75,22 @@ public static function register_routes() {
7575
* @return WP_REST_Response the response object
7676
*/
7777
public static function render_discovery( WP_REST_Request $request ) {
78-
$discovery = array();
78+
$discovery = array();
7979
$discovery['links'] = array(
8080
array(
81-
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.1',
81+
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.1',
8282
'href' => get_rest_url( null, '/nodeinfo/2.1' ),
8383
),
8484
array(
85-
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.0',
85+
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.0',
8686
'href' => get_rest_url( null, '/nodeinfo/2.0' ),
8787
),
8888
array(
89-
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.1',
89+
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.1',
9090
'href' => get_rest_url( null, '/nodeinfo/1.1' ),
9191
),
9292
array(
93-
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.0',
93+
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.0',
9494
'href' => get_rest_url( null, '/nodeinfo/1.0' ),
9595
),
9696
);
@@ -111,7 +111,7 @@ public static function render_discovery( WP_REST_Request $request ) {
111111
* @return WP_REST_Response the response object
112112
*/
113113
public static function render_nodeinfo( WP_REST_Request $request ) {
114-
require_once( 'class-nodeinfo.php' );
114+
require_once 'class-nodeinfo.php';
115115

116116
$nodeinfo = new Nodeinfo( $request->get_param( 'version' ) );
117117

@@ -126,7 +126,7 @@ public static function render_nodeinfo( WP_REST_Request $request ) {
126126
* @return WP_REST_Response the response object
127127
*/
128128
public static function render_nodeinfo2( WP_REST_Request $request ) {
129-
require_once( 'class-nodeinfo2.php' );
129+
require_once 'class-nodeinfo2.php';
130130

131131
$nodeinfo2 = new Nodeinfo2( $request->get_param( 'version' ) );
132132

@@ -142,22 +142,22 @@ public static function render_nodeinfo2( WP_REST_Request $request ) {
142142
*/
143143
public static function render_jrd( $jrd ) {
144144
$jrd['links'][] = array(
145-
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.1',
145+
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.1',
146146
'href' => get_rest_url( null, '/nodeinfo/2.1' ),
147147
);
148148

149149
$jrd['links'][] = array(
150-
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.0',
150+
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.0',
151151
'href' => get_rest_url( null, '/nodeinfo/2.0' ),
152152
);
153153

154154
$jrd['links'][] = array(
155-
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.1',
155+
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.1',
156156
'href' => get_rest_url( null, '/nodeinfo/1.1' ),
157157
);
158158

159159
$jrd['links'][] = array(
160-
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.0',
160+
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.0',
161161
'href' => get_rest_url( null, '/nodeinfo/1.0' ),
162162
);
163163

includes/class-nodeinfo.php

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
* @link https://github.com/jhass/nodeinfo
66
*/
77
class Nodeinfo {
8-
public $version = '2.0';
9-
public $software = array();
10-
public $usage = array();
8+
public $version = '2.0';
9+
public $software = array();
10+
public $usage = array();
1111
public $openRegistrations = false; // phpcs:ignore
12-
public $services = array(
13-
'inbound' => array(),
12+
public $services = array(
13+
'inbound' => array(),
1414
'outbound' => array(),
1515
);
16-
public $protocols = array();
17-
public $metadata = array();
16+
public $protocols = array();
17+
public $metadata = array();
1818

1919
public function __construct( $version = '2.0' ) {
2020
if ( in_array( $version, array( '1.0', '1.1', '2.0', '2.1' ), true ) ) {
@@ -32,6 +32,7 @@ public function __construct( $version = '2.0' ) {
3232
public function generate_usage() {
3333
$users = get_users(
3434
array(
35+
'fields' => 'ID',
3536
'capability__in' => array( 'publish_posts' ),
3637
)
3738
);
@@ -42,16 +43,18 @@ public function generate_usage() {
4243
$users = 1;
4344
}
4445

45-
$posts = wp_count_posts();
46+
$posts = wp_count_posts();
4647
$comments = wp_count_comments();
4748

4849
$this->usage = apply_filters(
4950
'nodeinfo_data_usage',
5051
array(
51-
'users' => array(
52-
'total' => $users,
52+
'users' => array(
53+
'total' => $users,
54+
'activeMonth' => nodeinfo_get_active_users( '1 month ago' ),
55+
'activeHalfyear' => nodeinfo_get_active_users( '6 month ago' ),
5356
),
54-
'localPosts' => (int) $posts->publish,
57+
'localPosts' => (int) $posts->publish,
5558
'localComments' => (int) $comments->approved,
5659
),
5760
$this->version
@@ -60,7 +63,7 @@ public function generate_usage() {
6063

6164
public function generate_software() {
6265
$software = array(
63-
'name' => 'wordpress',
66+
'name' => 'wordpress',
6467
'version' => get_bloginfo( 'version' ),
6568
);
6669

@@ -81,7 +84,7 @@ public function generate_protocols() {
8184
if ( version_compare( $this->version, '2.0', '>=' ) ) {
8285
$protocols = array();
8386
} else {
84-
$protocols['inbound'] = array( 'smtp' );
87+
$protocols['inbound'] = array( 'smtp' );
8588
$protocols['outbound'] = array( 'smtp' );
8689
}
8790

@@ -92,7 +95,7 @@ public function generate_services() {
9295
$services = $this->services;
9396

9497
if ( version_compare( $this->version, '2.0', '>=' ) ) {
95-
$services['inbound'] = array( 'atom1.0', 'rss2.0', 'pop3' );
98+
$services['inbound'] = array( 'atom1.0', 'rss2.0', 'pop3' );
9699
$services['outbound'] = array( 'atom1.0', 'rss2.0', 'wordpress', 'smtp' );
97100
} else {
98101
$services['outbound'] = array( 'smtp' );
@@ -107,8 +110,8 @@ public function generate_metadata() {
107110
$metadata['email'] = get_option( 'admin_email' );
108111

109112
$metadata['generator'] = array(
110-
'name' => 'NodeInfo WordPress-Plugin',
111-
'version' => nodeinfo_version(),
113+
'name' => 'NodeInfo WordPress-Plugin',
114+
'version' => nodeinfo_version(),
112115
'repository' => 'https://github.com/pfefferle/wordpress-nodeinfo/',
113116
);
114117

includes/class-nodeinfo2.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
* @link https://github.com/jaywink/nodeinfo2
66
*/
77
class Nodeinfo2 {
8-
public $version = '1.0';
9-
public $server = array();
10-
public $usage = array();
8+
public $version = '1.0';
9+
public $server = array();
10+
public $usage = array();
1111
public $openRegistrations = false; // phpcs:ignore
12-
public $services = array(
13-
'inbound' => array(),
12+
public $services = array(
13+
'inbound' => array(),
1414
'outbound' => array(),
1515
);
16-
public $protocols = array();
17-
public $metadata = array();
16+
public $protocols = array();
17+
public $metadata = array();
1818

1919
public function __construct( $version = '1.0' ) {
2020
if ( in_array( $version, array( '1.0' ), true ) ) {
@@ -42,16 +42,18 @@ public function generate_usage() {
4242
$users = 1;
4343
}
4444

45-
$posts = wp_count_posts();
45+
$posts = wp_count_posts();
4646
$comments = wp_count_comments();
4747

4848
$this->usage = apply_filters(
4949
'nodeinfo2_data_usage',
5050
array(
51-
'users' => array(
52-
'total' => $users,
51+
'users' => array(
52+
'total' => $users,
53+
'activeMonth' => nodeinfo_get_active_users( '1 month ago' ),
54+
'activeHalfyear' => nodeinfo_get_active_users( '6 month ago' ),
5355
),
54-
'localPosts' => (int) $posts->publish,
56+
'localPosts' => (int) $posts->publish,
5557
'localComments' => (int) $comments->approved,
5658
),
5759
$this->version
@@ -62,10 +64,10 @@ public function generate_server() {
6264
$this->server = apply_filters(
6365
'nodeinfo2_data_server',
6466
array(
65-
'baseUrl' => home_url( '/' ),
66-
'name' => get_bloginfo( 'name' ),
67+
'baseUrl' => home_url( '/' ),
68+
'name' => get_bloginfo( 'name' ),
6769
'software' => 'wordpress',
68-
'version' => get_bloginfo( 'version' ),
70+
'version' => get_bloginfo( 'version' ),
6971
),
7072
$this->version
7173
);
@@ -78,7 +80,7 @@ public function generate_protocols() {
7880
public function generate_services() {
7981
$services = $this->services;
8082

81-
$services['inbound'] = array( 'atom1.0', 'rss2.0', 'wordpress', 'pop3' );
83+
$services['inbound'] = array( 'atom1.0', 'rss2.0', 'wordpress', 'pop3' );
8284
$services['outbound'] = array( 'atom1.0', 'rss2.0', 'wordpress', 'smtp' );
8385

8486
$this->services = apply_filters( 'nodeinfo2_data_services', $services, $this->version );

includes/functions.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
function nodeinfo_get_active_users( $duration = '1 month ago' ) {
3+
// get all distinct authors that have published a post in the last 30 days
4+
$posts = get_posts(
5+
array(
6+
'post_type' => 'post',
7+
'post_status' => 'publish',
8+
'orderby' => 'post_count',
9+
'order' => 'DESC',
10+
'posts_per_page' => 4,
11+
'date_query' => array(
12+
array(
13+
'after' => $duration,
14+
),
15+
),
16+
)
17+
);
18+
19+
if ( ! $posts ) {
20+
return 0;
21+
}
22+
23+
// get all distinct ID from $posts
24+
return count(
25+
array_unique(
26+
wp_list_pluck(
27+
$posts,
28+
'post_author'
29+
)
30+
)
31+
);
32+
}

languages/nodeinfo.pot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# This file is distributed under the MIT.
33
msgid ""
44
msgstr ""
5-
"Project-Id-Version: NodeInfo 2.1.1\n"
5+
"Project-Id-Version: NodeInfo 2.2.0\n"
66
"Report-Msgid-Bugs-To: "
77
"https://wordpress.org/support/plugin/wordpress-nodeinfo\n"
8-
"POT-Creation-Date: 2023-07-31 13:02:06+00:00\n"
8+
"POT-Creation-Date: 2023-10-16 15:44:17+00:00\n"
99
"MIME-Version: 1.0\n"
1010
"Content-Type: text/plain; charset=utf-8\n"
1111
"Content-Transfer-Encoding: 8bit\n"

nodeinfo.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: NodeInfo
44
* Plugin URI: https://github.com/pfefferle/wordpress-nodeinfo/
55
* Description: NodeInfo is an effort to create a standardized way of exposing metadata about a server running one of the distributed social networks.
6-
* Version: 2.1.1
6+
* Version: 2.2.0
77
* Author: Matthias Pfefferle
88
* Author URI: https://notiz.blog/
99
* License: MIT
@@ -16,7 +16,8 @@
1616
* Initialize plugin
1717
*/
1818
function nodeinfo_init() {
19-
require_once dirname( __FILE__ ) . '/includes/class-nodeinfo-endpoint.php';
19+
require_once __DIR__ . '/includes/class-nodeinfo-endpoint.php';
20+
require_once __DIR__ . '/includes/functions.php';
2021

2122
// Configure the REST API route
2223
add_action( 'rest_api_init', array( 'Nodeinfo_Endpoint', 'register_routes' ) );

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
},
2121
"homepage": "https://github.com/pfefferle/wordpress-nodeinfo#readme",
2222
"devDependencies": {
23-
"grunt": "^1.0.3",
24-
"grunt-wp-i18n": "^1.0.2",
25-
"grunt-wp-readme-to-markdown": "^2.0.1"
23+
"grunt": "^1.6.1",
24+
"grunt-wp-i18n": "^1.0.3",
25+
"grunt-wp-readme-to-markdown": "^2.1.0"
2626
}
2727
}

0 commit comments

Comments
 (0)