-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix compatibility with WebFinger and NodeInfo plugin
- Loading branch information
Showing
8 changed files
with
131 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters