Skip to content

Commit

Permalink
added MAUs
Browse files Browse the repository at this point in the history
  • Loading branch information
pfefferle committed Oct 16, 2023
1 parent 0671872 commit aeb5169
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 65 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
**Tags:** nodeinfo, fediverse, ostatus, diaspora, activitypub
**Requires at least:** 4.9
**Tested up to:** 6.3
**Stable tag:** 2.1.1
**Stable tag:** 2.2.0
**Requires PHP:** 5.6
**License:** MIT
**License URI:** https://opensource.org/licenses/MIT
Expand All @@ -24,6 +24,10 @@ This plugin provides a barebone JSON file with basic "node"-informations. The fi

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

### 2.2.0 ###

* add MAUs

### 2.1.1 ###

* load plugin on init, to keep up with changes on the ActivityPub side
Expand Down
50 changes: 25 additions & 25 deletions includes/class-nodeinfo-endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public static function register_routes() {
'/discovery',
array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( 'Nodeinfo_Endpoint', 'render_discovery' ),
'methods' => WP_REST_Server::READABLE,
'callback' => array( 'Nodeinfo_Endpoint', 'render_discovery' ),
'permission_callback' => '__return_true',
),
)
Expand All @@ -25,15 +25,15 @@ public static function register_routes() {
'/(?P<version>[\.\d]+)',
array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( 'Nodeinfo_Endpoint', 'render_nodeinfo' ),
'methods' => WP_REST_Server::READABLE,
'callback' => array( 'Nodeinfo_Endpoint', 'render_nodeinfo' ),
'permission_callback' => '__return_true',
'args' => array(
'args' => array(
'version' => array(
'required' => true,
'type' => 'string',
'required' => true,
'type' => 'string',
'description' => __( 'The version of the NodeInfo scheme', 'nodeinfo' ),
'enum' => array(
'enum' => array(
'1.0',
'1.1',
'2.0',
Expand All @@ -50,15 +50,15 @@ public static function register_routes() {
'/(?P<version>[\.\d]+)',
array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( 'Nodeinfo_Endpoint', 'render_nodeinfo2' ),
'methods' => WP_REST_Server::READABLE,
'callback' => array( 'Nodeinfo_Endpoint', 'render_nodeinfo2' ),
'permission_callback' => '__return_true',
'args' => array(
'args' => array(
'version' => array(
'required' => true,
'type' => 'string',
'required' => true,
'type' => 'string',
'description' => __( 'The version of the NodeInfo2 scheme', 'nodeinfo' ),
'enum' => array(
'enum' => array(
'1.0',
),
),
Expand All @@ -75,22 +75,22 @@ public static function register_routes() {
* @return WP_REST_Response the response object
*/
public static function render_discovery( WP_REST_Request $request ) {
$discovery = array();
$discovery = array();
$discovery['links'] = array(
array(
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.1',
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.1',
'href' => get_rest_url( null, '/nodeinfo/2.1' ),
),
array(
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.0',
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.0',
'href' => get_rest_url( null, '/nodeinfo/2.0' ),
),
array(
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.1',
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.1',
'href' => get_rest_url( null, '/nodeinfo/1.1' ),
),
array(
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.0',
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.0',
'href' => get_rest_url( null, '/nodeinfo/1.0' ),
),
);
Expand All @@ -111,7 +111,7 @@ public static function render_discovery( WP_REST_Request $request ) {
* @return WP_REST_Response the response object
*/
public static function render_nodeinfo( WP_REST_Request $request ) {
require_once( 'class-nodeinfo.php' );
require_once 'class-nodeinfo.php';

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

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

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

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

$jrd['links'][] = array(
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.0',
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.0',
'href' => get_rest_url( null, '/nodeinfo/2.0' ),
);

$jrd['links'][] = array(
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.1',
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.1',
'href' => get_rest_url( null, '/nodeinfo/1.1' ),
);

$jrd['links'][] = array(
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.0',
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.0',
'href' => get_rest_url( null, '/nodeinfo/1.0' ),
);

Expand Down
35 changes: 19 additions & 16 deletions includes/class-nodeinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
* @link https://github.com/jhass/nodeinfo
*/
class Nodeinfo {
public $version = '2.0';
public $software = array();
public $usage = array();
public $version = '2.0';
public $software = array();
public $usage = array();
public $openRegistrations = false; // phpcs:ignore
public $services = array(
'inbound' => array(),
public $services = array(
'inbound' => array(),
'outbound' => array(),
);
public $protocols = array();
public $metadata = array();
public $protocols = array();
public $metadata = array();

public function __construct( $version = '2.0' ) {
if ( in_array( $version, array( '1.0', '1.1', '2.0', '2.1' ), true ) ) {
Expand All @@ -32,6 +32,7 @@ public function __construct( $version = '2.0' ) {
public function generate_usage() {
$users = get_users(
array(
'fields' => 'ID',
'capability__in' => array( 'publish_posts' ),
)
);
Expand All @@ -42,16 +43,18 @@ public function generate_usage() {
$users = 1;
}

$posts = wp_count_posts();
$posts = wp_count_posts();
$comments = wp_count_comments();

$this->usage = apply_filters(
'nodeinfo_data_usage',
array(
'users' => array(
'total' => $users,
'users' => array(
'total' => $users,
'activeMonth' => nodeinfo_get_active_users( '1 month ago' ),
'activeHalfyear' => nodeinfo_get_active_users( '6 month ago' ),
),
'localPosts' => (int) $posts->publish,
'localPosts' => (int) $posts->publish,
'localComments' => (int) $comments->approved,
),
$this->version
Expand All @@ -60,7 +63,7 @@ public function generate_usage() {

public function generate_software() {
$software = array(
'name' => 'wordpress',
'name' => 'wordpress',
'version' => get_bloginfo( 'version' ),
);

Expand All @@ -81,7 +84,7 @@ public function generate_protocols() {
if ( version_compare( $this->version, '2.0', '>=' ) ) {
$protocols = array();
} else {
$protocols['inbound'] = array( 'smtp' );
$protocols['inbound'] = array( 'smtp' );
$protocols['outbound'] = array( 'smtp' );
}

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

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

$metadata['generator'] = array(
'name' => 'NodeInfo WordPress-Plugin',
'version' => nodeinfo_version(),
'name' => 'NodeInfo WordPress-Plugin',
'version' => nodeinfo_version(),
'repository' => 'https://github.com/pfefferle/wordpress-nodeinfo/',
);

Expand Down
32 changes: 17 additions & 15 deletions includes/class-nodeinfo2.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
* @link https://github.com/jaywink/nodeinfo2
*/
class Nodeinfo2 {
public $version = '1.0';
public $server = array();
public $usage = array();
public $version = '1.0';
public $server = array();
public $usage = array();
public $openRegistrations = false; // phpcs:ignore
public $services = array(
'inbound' => array(),
public $services = array(
'inbound' => array(),
'outbound' => array(),
);
public $protocols = array();
public $metadata = array();
public $protocols = array();
public $metadata = array();

public function __construct( $version = '1.0' ) {
if ( in_array( $version, array( '1.0' ), true ) ) {
Expand Down Expand Up @@ -42,16 +42,18 @@ public function generate_usage() {
$users = 1;
}

$posts = wp_count_posts();
$posts = wp_count_posts();
$comments = wp_count_comments();

$this->usage = apply_filters(
'nodeinfo2_data_usage',
array(
'users' => array(
'total' => $users,
'users' => array(
'total' => $users,
'activeMonth' => nodeinfo_get_active_users( '1 month ago' ),
'activeHalfyear' => nodeinfo_get_active_users( '6 month ago' ),
),
'localPosts' => (int) $posts->publish,
'localPosts' => (int) $posts->publish,
'localComments' => (int) $comments->approved,
),
$this->version
Expand All @@ -62,10 +64,10 @@ public function generate_server() {
$this->server = apply_filters(
'nodeinfo2_data_server',
array(
'baseUrl' => home_url( '/' ),
'name' => get_bloginfo( 'name' ),
'baseUrl' => home_url( '/' ),
'name' => get_bloginfo( 'name' ),
'software' => 'wordpress',
'version' => get_bloginfo( 'version' ),
'version' => get_bloginfo( 'version' ),
),
$this->version
);
Expand All @@ -78,7 +80,7 @@ public function generate_protocols() {
public function generate_services() {
$services = $this->services;

$services['inbound'] = array( 'atom1.0', 'rss2.0', 'wordpress', 'pop3' );
$services['inbound'] = array( 'atom1.0', 'rss2.0', 'wordpress', 'pop3' );
$services['outbound'] = array( 'atom1.0', 'rss2.0', 'wordpress', 'smtp' );

$this->services = apply_filters( 'nodeinfo2_data_services', $services, $this->version );
Expand Down
32 changes: 32 additions & 0 deletions includes/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
function nodeinfo_get_active_users( $duration = '1 month ago' ) {
// get all distinct authors that have published a post in the last 30 days
$posts = get_posts(
array(
'post_type' => 'post',
'post_status' => 'publish',
'orderby' => 'post_count',
'order' => 'DESC',
'posts_per_page' => 4,
'date_query' => array(
array(
'after' => $duration,
),
),
)
);

if ( ! $posts ) {
return 0;
}

// get all distinct ID from $posts
return count(
array_unique(
wp_list_pluck(
$posts,
'post_author'
)
)
);
}
4 changes: 2 additions & 2 deletions languages/nodeinfo.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# This file is distributed under the MIT.
msgid ""
msgstr ""
"Project-Id-Version: NodeInfo 2.1.1\n"
"Project-Id-Version: NodeInfo 2.2.0\n"
"Report-Msgid-Bugs-To: "
"https://wordpress.org/support/plugin/wordpress-nodeinfo\n"
"POT-Creation-Date: 2023-07-31 13:02:06+00:00\n"
"POT-Creation-Date: 2023-10-16 15:44:17+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
5 changes: 3 additions & 2 deletions nodeinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: NodeInfo
* Plugin URI: https://github.com/pfefferle/wordpress-nodeinfo/
* Description: NodeInfo is an effort to create a standardized way of exposing metadata about a server running one of the distributed social networks.
* Version: 2.1.1
* Version: 2.2.0
* Author: Matthias Pfefferle
* Author URI: https://notiz.blog/
* License: MIT
Expand All @@ -16,7 +16,8 @@
* Initialize plugin
*/
function nodeinfo_init() {
require_once dirname( __FILE__ ) . '/includes/class-nodeinfo-endpoint.php';
require_once __DIR__ . '/includes/class-nodeinfo-endpoint.php';
require_once __DIR__ . '/includes/functions.php';

// Configure the REST API route
add_action( 'rest_api_init', array( 'Nodeinfo_Endpoint', 'register_routes' ) );
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
},
"homepage": "https://github.com/pfefferle/wordpress-nodeinfo#readme",
"devDependencies": {
"grunt": "^1.0.3",
"grunt-wp-i18n": "^1.0.2",
"grunt-wp-readme-to-markdown": "^2.0.1"
"grunt": "^1.6.1",
"grunt-wp-i18n": "^1.0.3",
"grunt-wp-readme-to-markdown": "^2.1.0"
}
}
Loading

0 comments on commit aeb5169

Please sign in to comment.