From fd6cb84ba3df13049f181e47d74548fcffb16a8e Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Wed, 11 Oct 2023 11:09:37 +0200 Subject: [PATCH] Fix compatibility with WebFinger and NodeInfo plugin --- README.md | 6 +++- activitypub.php | 8 ++++- includes/rest/class-nodeinfo.php | 35 ------------------- includes/rest/class-webfinger.php | 41 ---------------------- integration/class-buddypress.php | 8 +++++ integration/class-nodeinfo.php | 49 ++++++++++++++++++++++++++ integration/class-webfinger.php | 57 +++++++++++++++++++++++++++++++ readme.txt | 6 +++- 8 files changed, 131 insertions(+), 79 deletions(-) create mode 100644 integration/class-nodeinfo.php create mode 100644 integration/class-webfinger.php diff --git a/README.md b/README.md index 210286d..34991a5 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/activitypub.php b/activitypub.php index 808d7ad..3ae2be9 100644 --- a/activitypub.php +++ b/activitypub.php @@ -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 @@ -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' ); diff --git a/includes/rest/class-nodeinfo.php b/includes/rest/class-nodeinfo.php index 8e62874..1f6277a 100644 --- a/includes/rest/class-nodeinfo.php +++ b/includes/rest/class-nodeinfo.php @@ -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 ); } /** @@ -194,36 +191,4 @@ class Nodeinfo { 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; - } } diff --git a/includes/rest/class-webfinger.php b/includes/rest/class-webfinger.php index 315fee1..f69593f 100644 --- a/includes/rest/class-webfinger.php +++ b/includes/rest/class-webfinger.php @@ -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 ); } /** @@ -81,44 +78,6 @@ class Webfinger { 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. * diff --git a/integration/class-buddypress.php b/integration/class-buddypress.php index e4ec40e..45cfc0d 100644 --- a/integration/class-buddypress.php +++ b/integration/class-buddypress.php @@ -1,7 +1,15 @@ = '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; + } +} diff --git a/integration/class-webfinger.php b/integration/class-webfinger.php new file mode 100644 index 0000000..e7e3935 --- /dev/null +++ b/integration/class-webfinger.php @@ -0,0 +1,57 @@ +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 ); + } +} diff --git a/readme.txt b/readme.txt index 3d5a9c9..7faed3d 100644 --- a/readme.txt +++ b/readme.txt @@ -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 @@ -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