Skip to content

Commit

Permalink
Fix compatibility with WebFinger and NodeInfo plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
pfefferle committed Oct 11, 2023
1 parent 12b6750 commit fd6cb84
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 79 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
**Tags:** OStatus, fediverse, activitypub, activitystream
**Requires at least:** 4.7
**Tested up to:** 6.3
**Stable tag:** 1.0.4
**Stable tag:** 1.0.5
**Requires PHP:** 5.6
**License:** MIT
**License URI:** http://opensource.org/licenses/MIT
Expand Down Expand Up @@ -105,6 +105,10 @@ Where 'blog' is the path to the subdirectory at which your blog resides.

Project maintained on GitHub at [automattic/wordpress-activitypub](https://github.com/automattic/wordpress-activitypub).

### 1.0.5 ###

* Fixed: compatibility with WebFinger and NodeInfo plugin

### 1.0.4 ###

* Fixed: Constants were not loaded early enough, resulting in a race condition
Expand Down
8 changes: 7 additions & 1 deletion activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: ActivityPub
* Plugin URI: https://github.com/pfefferle/wordpress-activitypub/
* Description: The ActivityPub protocol is a decentralized social networking protocol based upon the ActivityStreams 2.0 data format.
* Version: 1.0.4
* Version: 1.0.5
* Author: Matthias Pfefferle & Automattic
* Author URI: https://automattic.com/
* License: MIT
Expand Down Expand Up @@ -82,6 +82,12 @@ function plugin_init() {
require_once $debug_file;
Debug::init();
}

require_once __DIR__ . '/integration/class-webfinger.php';
Integration\Webfinger::init();

require_once __DIR__ . '/integration/class-nodeinfo.php';
Integration\Nodeinfo::init();
}
\add_action( 'plugins_loaded', __NAMESPACE__ . '\plugin_init' );

Expand Down
35 changes: 0 additions & 35 deletions includes/rest/class-nodeinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ class Nodeinfo {
*/
public static function init() {
self::register_routes();

\add_filter( 'nodeinfo_data', array( self::class, 'add_nodeinfo_discovery' ), 10, 2 );
\add_filter( 'nodeinfo2_data', array( self::class, 'add_nodeinfo2_discovery' ), 10 );
}

/**
Expand Down Expand Up @@ -194,36 +191,4 @@ public static function discovery( $request ) {

return new \WP_REST_Response( $discovery, 200 );
}

/**
* Extend NodeInfo data
*
* @param array $nodeinfo NodeInfo data
* @param string The NodeInfo Version
*
* @return array The extended array
*/
public static function add_nodeinfo_discovery( $nodeinfo, $version ) {
if ( '2.0' === $version ) {
$nodeinfo['protocols'][] = 'activitypub';
} else {
$nodeinfo['protocols']['inbound'][] = 'activitypub';
$nodeinfo['protocols']['outbound'][] = 'activitypub';
}

return $nodeinfo;
}

/**
* Extend NodeInfo2 data
*
* @param array $nodeinfo NodeInfo2 data
*
* @return array The extended array
*/
public static function add_nodeinfo2_discovery( $nodeinfo ) {
$nodeinfo['protocols'][] = 'activitypub';

return $nodeinfo;
}
}
41 changes: 0 additions & 41 deletions includes/rest/class-webfinger.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ class Webfinger {
*/
public static function init() {
self::register_routes();

\add_filter( 'webfinger_user_data', array( self::class, 'add_user_discovery' ), 10, 3 );
\add_filter( 'webfinger_data', array( self::class, 'add_pseudo_user_discovery' ), 99, 2 );
}

/**
Expand Down Expand Up @@ -81,44 +78,6 @@ public static function request_parameters() {
return $params;
}

/**
* Add WebFinger discovery links
*
* @param array $array the jrd array
* @param string $resource the WebFinger resource
* @param WP_User $user the WordPress user
*
* @return array the jrd array
*/
public static function add_user_discovery( $array, $resource, $user ) {
$user = User_Collection::get_by_id( $user->ID );

$array['links'][] = array(
'rel' => 'self',
'type' => 'application/activity+json',
'href' => $user->get_url(),
);

return $array;
}

/**
* Add WebFinger discovery links
*
* @param array $array the jrd array
* @param string $resource the WebFinger resource
* @param WP_User $user the WordPress user
*
* @return array the jrd array
*/
public static function add_pseudo_user_discovery( $array, $resource ) {
if ( $array ) {
return $array;
}

return self::get_profile( $resource );
}

/**
* Get the WebFinger profile.
*
Expand Down
8 changes: 8 additions & 0 deletions integration/class-buddypress.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
<?php
namespace Activitypub\Integration;

/**
* Compatibility with the BuddyPress plugin
*
* @see https://buddypress.org/
*/
class Buddypress {
/**
* Initialize the class, registering WordPress hooks
*/
public static function init() {
\add_filter( 'activitypub_json_author_array', array( self::class, 'add_user_metadata' ), 11, 2 );
}
Expand Down
49 changes: 49 additions & 0 deletions integration/class-nodeinfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
namespace Activitypub\Integration;

/**
* Compatibility with the NodeInfo plugin
*
* @see https://wordpress.org/plugins/nodeinfo/
*/
class Nodeinfo {
/**
* Initialize the class, registering WordPress hooks
*/
public static function init() {
\add_filter( 'nodeinfo_data', array( self::class, 'add_nodeinfo_discovery' ), 10, 2 );
\add_filter( 'nodeinfo2_data', array( self::class, 'add_nodeinfo2_discovery' ), 10 );
}

/**
* Extend NodeInfo data
*
* @param array $nodeinfo NodeInfo data
* @param string The NodeInfo Version
*
* @return array The extended array
*/
public static function add_nodeinfo_discovery( $nodeinfo, $version ) {
if ( $version >= '2.0' ) {
$nodeinfo['protocols'][] = 'activitypub';
} else {
$nodeinfo['protocols']['inbound'][] = 'activitypub';
$nodeinfo['protocols']['outbound'][] = 'activitypub';
}

return $nodeinfo;
}

/**
* Extend NodeInfo2 data
*
* @param array $nodeinfo NodeInfo2 data
*
* @return array The extended array
*/
public static function add_nodeinfo2_discovery( $nodeinfo ) {
$nodeinfo['protocols'][] = 'activitypub';

return $nodeinfo;
}
}
57 changes: 57 additions & 0 deletions integration/class-webfinger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
namespace Activitypub\Integration;

use Activitypub\Collection\Users as User_Collection;

/**
* Compatibility with the WebFinger plugin
*
* @see https://wordpress.org/plugins/webfinger/
*/
class Webfinger {
/**
* Initialize the class, registering WordPress hooks
*/
public static function init() {
\add_filter( 'webfinger_user_data', array( self::class, 'add_user_discovery' ), 10, 3 );
\add_filter( 'webfinger_data', array( self::class, 'add_pseudo_user_discovery' ), 99, 2 );
}

/**
* Add WebFinger discovery links
*
* @param array $array the jrd array
* @param string $resource the WebFinger resource
* @param WP_User $user the WordPress user
*
* @return array the jrd array
*/
public static function add_user_discovery( $array, $resource, $user ) {
$user = User_Collection::get_by_id( $user->ID );

$array['links'][] = array(
'rel' => 'self',
'type' => 'application/activity+json',
'href' => $user->get_url(),
);

return $array;
}

/**
* Add WebFinger discovery links
*
* @param array $array the jrd array
* @param string $resource the WebFinger resource
* @param WP_User $user the WordPress user
*
* @return array the jrd array
*/
public static function add_pseudo_user_discovery( $array, $resource ) {
if ( $array ) {
return $array;
}

return self::get_profile( $resource );
}
}
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: automattic, pfefferle, mediaformat, mattwiebe, akirk, jeherve, nur
Tags: OStatus, fediverse, activitypub, activitystream
Requires at least: 4.7
Tested up to: 6.3
Stable tag: 1.0.4
Stable tag: 1.0.5
Requires PHP: 5.6
License: MIT
License URI: http://opensource.org/licenses/MIT
Expand Down Expand Up @@ -105,6 +105,10 @@ Where 'blog' is the path to the subdirectory at which your blog resides.

Project maintained on GitHub at [automattic/wordpress-activitypub](https://github.com/automattic/wordpress-activitypub).

= 1.0.5 =

* Fixed: compatibility with WebFinger and NodeInfo plugin

= 1.0.4 =

* Fixed: Constants were not loaded early enough, resulting in a race condition
Expand Down

0 comments on commit fd6cb84

Please sign in to comment.