deleted file simple-local-avatars.php
This commit is contained in:
@ -1,66 +0,0 @@
|
||||
<?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 );
|
||||
}
|
||||
|
||||
public static function add_user_metadata( $object, $author_id ) {
|
||||
$object->url = bp_core_get_user_domain( $author_id ); //add BP member profile URL as user URL
|
||||
|
||||
// add BuddyPress' cover_image instead of WordPress' header_image
|
||||
$cover_image_url = bp_attachments_get_attachment( 'url', array( 'item_id' => $author_id ) );
|
||||
|
||||
if ( $cover_image_url ) {
|
||||
$object->image = array(
|
||||
'type' => 'Image',
|
||||
'url' => $cover_image_url,
|
||||
);
|
||||
}
|
||||
|
||||
// change profile URL to BuddyPress' profile URL
|
||||
$object->attachment['profile_url'] = array(
|
||||
'type' => 'PropertyValue',
|
||||
'name' => \__( 'Profile', 'activitypub' ),
|
||||
'value' => \html_entity_decode(
|
||||
'<a rel="me" title="' . \esc_attr( bp_core_get_user_domain( $author_id ) ) . '" target="_blank" href="' . \bp_core_get_user_domain( $author_id ) . '">' . \wp_parse_url( \bp_core_get_user_domain( $author_id ), \PHP_URL_HOST ) . '</a>',
|
||||
\ENT_QUOTES,
|
||||
'UTF-8'
|
||||
),
|
||||
);
|
||||
|
||||
// replace blog URL on multisite
|
||||
if ( is_multisite() ) {
|
||||
$user_blogs = get_blogs_of_user( $author_id ); //get sites of user to send as AP metadata
|
||||
|
||||
if ( ! empty( $user_blogs ) ) {
|
||||
unset( $object->attachment['blog_url'] );
|
||||
|
||||
foreach ( $user_blogs as $blog ) {
|
||||
if ( 1 !== $blog->userblog_id ) {
|
||||
$object->attachment[] = array(
|
||||
'type' => 'PropertyValue',
|
||||
'name' => $blog->blogname,
|
||||
'value' => \html_entity_decode(
|
||||
'<a rel="me" title="' . \esc_attr( $blog->siteurl ) . '" target="_blank" href="' . $blog->siteurl . '">' . \wp_parse_url( $blog->siteurl, \PHP_URL_HOST ) . '</a>',
|
||||
\ENT_QUOTES,
|
||||
'UTF-8'
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
}
|
@ -1,462 +0,0 @@
|
||||
<?php
|
||||
namespace Activitypub\Integration;
|
||||
|
||||
use DateTime;
|
||||
use Activitypub\Webfinger as Webfinger_Util;
|
||||
use Activitypub\Http;
|
||||
use Activitypub\Collection\Users;
|
||||
use Activitypub\Collection\Followers;
|
||||
use Activitypub\Integration\Nodeinfo;
|
||||
use Enable_Mastodon_Apps\Mastodon_API;
|
||||
use Enable_Mastodon_Apps\Entity\Account;
|
||||
use Enable_Mastodon_Apps\Entity\Status;
|
||||
use Enable_Mastodon_Apps\Entity\Media_Attachment;
|
||||
|
||||
use function Activitypub\get_remote_metadata_by_actor;
|
||||
|
||||
/**
|
||||
* Class Enable_Mastodon_Apps
|
||||
*
|
||||
* This class is used to enable Mastodon Apps to work with ActivityPub
|
||||
*
|
||||
* @see https://github.com/akirk/enable-mastodon-apps
|
||||
*/
|
||||
class Enable_Mastodon_Apps {
|
||||
/**
|
||||
* Initialize the class, registering WordPress hooks
|
||||
*/
|
||||
public static function init() {
|
||||
\add_filter( 'mastodon_api_account_followers', array( self::class, 'api_account_followers' ), 10, 2 );
|
||||
\add_filter( 'mastodon_api_account', array( self::class, 'api_account_add_followers' ), 20, 2 );
|
||||
\add_filter( 'mastodon_api_account', array( self::class, 'api_account_external' ), 15, 2 );
|
||||
\add_filter( 'mastodon_api_search', array( self::class, 'api_search' ), 40, 2 );
|
||||
\add_filter( 'mastodon_api_search', array( self::class, 'api_search_by_url' ), 40, 2 );
|
||||
\add_filter( 'mastodon_api_get_posts_query_args', array( self::class, 'api_get_posts_query_args' ) );
|
||||
\add_filter( 'mastodon_api_statuses', array( self::class, 'api_statuses_external' ), 10, 2 );
|
||||
\add_filter( 'mastodon_api_status_context', array( self::class, 'api_get_replies' ), 10, 23 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add followers to Mastodon API
|
||||
*
|
||||
* @param array $followers An array of followers
|
||||
* @param string $user_id The user id
|
||||
* @param WP_REST_Request $request The request object
|
||||
*
|
||||
* @return array The filtered followers
|
||||
*/
|
||||
public static function api_account_followers( $followers, $user_id ) {
|
||||
$activitypub_followers = Followers::get_followers( $user_id, 40 );
|
||||
$mastodon_followers = array_map(
|
||||
function ( $item ) {
|
||||
$acct = Webfinger_Util::uri_to_acct( $item->get_id() );
|
||||
|
||||
if ( $acct && ! is_wp_error( $acct ) ) {
|
||||
$acct = \str_replace( 'acct:', '', $acct );
|
||||
} else {
|
||||
$acct = $item->get_url();
|
||||
}
|
||||
|
||||
$account = new Account();
|
||||
$account->id = \strval( $item->get__id() );
|
||||
$account->username = $item->get_preferred_username();
|
||||
$account->acct = $acct;
|
||||
$account->display_name = $item->get_name();
|
||||
$account->url = $item->get_url();
|
||||
$account->uri = $item->get_id();
|
||||
$account->avatar = $item->get_icon_url();
|
||||
$account->avatar_static = $item->get_icon_url();
|
||||
$account->created_at = new DateTime( $item->get_published() );
|
||||
$account->last_status_at = new DateTime( $item->get_published() );
|
||||
$account->note = $item->get_summary();
|
||||
$account->header = $item->get_image_url();
|
||||
$account->header_static = $item->get_image_url();
|
||||
$account->followers_count = 0;
|
||||
$account->following_count = 0;
|
||||
$account->statuses_count = 0;
|
||||
$account->bot = false;
|
||||
$account->locked = false;
|
||||
$account->group = false;
|
||||
$account->discoversable = false;
|
||||
$account->indexable = false;
|
||||
$account->hide_collections = false;
|
||||
$account->noindex = false;
|
||||
$account->fields = array();
|
||||
$account->emojis = array();
|
||||
$account->roles = array();
|
||||
|
||||
return $account;
|
||||
},
|
||||
$activitypub_followers
|
||||
);
|
||||
|
||||
$followers = array_merge( $mastodon_followers, $followers );
|
||||
|
||||
return $followers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add followers count to Mastodon API
|
||||
*
|
||||
* @param Enable_Mastodon_Apps\Entity\Account $account The account
|
||||
* @param int $user_id The user id
|
||||
*
|
||||
* @return Enable_Mastodon_Apps\Entity\Account The filtered Account
|
||||
*/
|
||||
public static function api_account_add_followers( $account, $user_id ) {
|
||||
if ( ! $account instanceof Account ) {
|
||||
return $account;
|
||||
}
|
||||
|
||||
$user = Users::get_by_various( $user_id );
|
||||
|
||||
if ( ! $user || is_wp_error( $user ) ) {
|
||||
return $account;
|
||||
}
|
||||
|
||||
$header = $user->get_image();
|
||||
if ( $header ) {
|
||||
$account->header = $header['url'];
|
||||
$account->header_static = $header['url'];
|
||||
}
|
||||
|
||||
foreach ( $user->get_attachment() as $attachment ) {
|
||||
if ( 'PropertyValue' === $attachment['type'] ) {
|
||||
$account->fields[] = array(
|
||||
'name' => $attachment['name'],
|
||||
'value' => $attachment['value'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$account->acct = $user->get_preferred_username();
|
||||
$account->note = $user->get_summary();
|
||||
|
||||
$account->followers_count = Followers::count_followers( $user->get__id() );
|
||||
return $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve external accounts for Mastodon API
|
||||
*
|
||||
* @param Enable_Mastodon_Apps\Entity\Account $user_data The user data
|
||||
* @param string $user_id The user id
|
||||
*
|
||||
* @return Enable_Mastodon_Apps\Entity\Account The filtered Account
|
||||
*/
|
||||
public static function api_account_external( $user_data, $user_id ) {
|
||||
if ( $user_data || ( is_numeric( $user_id ) && $user_id ) ) {
|
||||
// Only augment.
|
||||
return $user_data;
|
||||
}
|
||||
|
||||
$uri = Webfinger_Util::resolve( $user_id );
|
||||
|
||||
if ( ! $uri || is_wp_error( $uri ) ) {
|
||||
return $user_data;
|
||||
}
|
||||
|
||||
$account = self::get_account_for_actor( $uri );
|
||||
if ( $account ) {
|
||||
return $account;
|
||||
}
|
||||
|
||||
return $user_data;
|
||||
}
|
||||
|
||||
private static function get_account_for_actor( $uri ) {
|
||||
if ( ! is_string( $uri ) ) {
|
||||
return null;
|
||||
}
|
||||
$data = get_remote_metadata_by_actor( $uri );
|
||||
|
||||
if ( ! $data || is_wp_error( $data ) ) {
|
||||
return null;
|
||||
}
|
||||
$account = new Account();
|
||||
|
||||
$acct = Webfinger_Util::uri_to_acct( $uri );
|
||||
if ( str_starts_with( $acct, 'acct:' ) ) {
|
||||
$acct = substr( $acct, 5 );
|
||||
}
|
||||
|
||||
$account->id = $acct;
|
||||
$account->username = $acct;
|
||||
$account->acct = $acct;
|
||||
$account->display_name = $data['name'];
|
||||
$account->url = $uri;
|
||||
|
||||
if ( ! empty( $data['summary'] ) ) {
|
||||
$account->note = $data['summary'];
|
||||
}
|
||||
|
||||
if (
|
||||
isset( $data['icon']['type'] ) &&
|
||||
isset( $data['icon']['url'] ) &&
|
||||
'Image' === $data['icon']['type']
|
||||
) {
|
||||
$account->avatar = $data['icon']['url'];
|
||||
$account->avatar_static = $data['icon']['url'];
|
||||
}
|
||||
|
||||
if ( isset( $data['image'] ) ) {
|
||||
$account->header = $data['image']['url'];
|
||||
$account->header_static = $data['image']['url'];
|
||||
}
|
||||
if ( ! isset( $data['published'] ) ) {
|
||||
$data['published'] = 'now';
|
||||
}
|
||||
$account->created_at = new DateTime( $data['published'] );
|
||||
|
||||
return $account;
|
||||
}
|
||||
|
||||
public static function api_search_by_url( $search_data, $request ) {
|
||||
$p = \wp_parse_url( $request->get_param( 'q' ) );
|
||||
if ( ! $p || ! isset( $p['host'] ) ) {
|
||||
return $search_data;
|
||||
}
|
||||
|
||||
$object = Http::get_remote_object( $request->get_param( 'q' ), true );
|
||||
if ( is_wp_error( $object ) || ! isset( $object['attributedTo'] ) ) {
|
||||
return $search_data;
|
||||
}
|
||||
|
||||
$account = self::get_account_for_actor( $object['attributedTo'] );
|
||||
if ( ! $account ) {
|
||||
return $search_data;
|
||||
}
|
||||
|
||||
$status = self::activity_to_status( $object, $account );
|
||||
if ( $status ) {
|
||||
$search_data['statuses'][] = $status;
|
||||
}
|
||||
|
||||
return $search_data;
|
||||
}
|
||||
|
||||
public static function api_search( $search_data, $request ) {
|
||||
$user_id = \get_current_user_id();
|
||||
if ( ! $user_id ) {
|
||||
return $search_data;
|
||||
}
|
||||
|
||||
$q = $request->get_param( 'q' );
|
||||
if ( ! $q ) {
|
||||
return $search_data;
|
||||
}
|
||||
$q = sanitize_text_field( wp_unslash( $q ) );
|
||||
|
||||
$followers = Followers::get_followers( $user_id, 40, null, array( 's' => $q ) );
|
||||
if ( ! $followers ) {
|
||||
return $search_data;
|
||||
}
|
||||
|
||||
foreach ( $followers as $follower ) {
|
||||
$acct = Webfinger_Util::uri_to_acct( $follower->get_id() );
|
||||
|
||||
if ( $acct && ! is_wp_error( $acct ) ) {
|
||||
$acct = \str_replace( 'acct:', '', $acct );
|
||||
} else {
|
||||
$acct = $follower->get_url();
|
||||
}
|
||||
|
||||
$account = new Account();
|
||||
$account->id = \strval( $follower->get__id() );
|
||||
$account->username = $follower->get_preferred_username();
|
||||
$account->acct = $acct;
|
||||
$account->display_name = $follower->get_name();
|
||||
$account->url = $follower->get_url();
|
||||
$account->uri = $follower->get_id();
|
||||
$account->avatar = $follower->get_icon_url();
|
||||
$account->avatar_static = $follower->get_icon_url();
|
||||
$account->created_at = new DateTime( $follower->get_published() );
|
||||
$account->last_status_at = new DateTime( $follower->get_published() );
|
||||
$account->note = $follower->get_summary();
|
||||
$account->header = $follower->get_image_url();
|
||||
$account->header_static = $follower->get_image_url();
|
||||
|
||||
$search_data['accounts'][] = $account;
|
||||
}
|
||||
|
||||
return $search_data;
|
||||
}
|
||||
|
||||
public static function api_get_posts_query_args( $args ) {
|
||||
if ( isset( $args['author'] ) && is_string( $args['author'] ) ) {
|
||||
$uri = Webfinger_Util::resolve( $args['author'] );
|
||||
if ( $uri && ! is_wp_error( $uri ) ) {
|
||||
$args['activitypub'] = $uri;
|
||||
unset( $args['author'] );
|
||||
}
|
||||
}
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
private static function activity_to_status( $item, $account ) {
|
||||
if ( isset( $item['object'] ) ) {
|
||||
$object = $item['object'];
|
||||
} else {
|
||||
$object = $item;
|
||||
}
|
||||
|
||||
if ( ! isset( $object['type'] ) || 'Note' !== $object['type'] ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$status = new Status();
|
||||
$status->id = $object['id'];
|
||||
$status->created_at = new DateTime( $object['published'] );
|
||||
$status->content = $object['content'];
|
||||
$status->account = $account;
|
||||
|
||||
if ( ! empty( $object['inReplyTo'] ) ) {
|
||||
$status->in_reply_to_id = $object['inReplyTo'];
|
||||
}
|
||||
|
||||
if ( ! empty( $object['visibility'] ) ) {
|
||||
$status->visibility = $object['visibility'];
|
||||
}
|
||||
if ( ! empty( $object['url'] ) ) {
|
||||
$status->url = $object['url'];
|
||||
$status->uri = $object['url'];
|
||||
} else {
|
||||
$status->uri = $object['id'];
|
||||
}
|
||||
|
||||
if ( ! empty( $object['attachment'] ) ) {
|
||||
$status->media_attachments = array_map(
|
||||
function ( $attachment ) {
|
||||
$default_attachment = array(
|
||||
'url' => null,
|
||||
'mediaType' => null,
|
||||
'name' => null,
|
||||
'width' => 0,
|
||||
'height' => 0,
|
||||
'blurhash' => null,
|
||||
);
|
||||
|
||||
$attachment = array_merge( $default_attachment, $attachment );
|
||||
|
||||
$media_attachment = new Media_Attachment();
|
||||
$media_attachment->id = $attachment['url'];
|
||||
$media_attachment->type = strtok( $attachment['mediaType'], '/' );
|
||||
$media_attachment->url = $attachment['url'];
|
||||
$media_attachment->preview_url = $attachment['url'];
|
||||
$media_attachment->description = $attachment['name'];
|
||||
if ( $attachment['blurhash'] ) {
|
||||
$media_attachment->blurhash = $attachment['blurhash'];
|
||||
}
|
||||
if ( $attachment['width'] > 0 && $attachment['height'] > 0 ) {
|
||||
$media_attachment->meta = array(
|
||||
'original' => array(
|
||||
'width' => $attachment['width'],
|
||||
'height' => $attachment['height'],
|
||||
'size' => $attachment['width'] . 'x' . $attachment['height'],
|
||||
'aspect' => $attachment['width'] / $attachment['height'],
|
||||
),
|
||||
);}
|
||||
return $media_attachment;
|
||||
},
|
||||
$object['attachment']
|
||||
);
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
public static function api_statuses_external( $statuses, $args ) {
|
||||
if ( ! isset( $args['activitypub'] ) ) {
|
||||
return $statuses;
|
||||
}
|
||||
|
||||
$data = get_remote_metadata_by_actor( $args['activitypub'] );
|
||||
|
||||
if ( ! $data || is_wp_error( $data ) || ! isset( $data['outbox'] ) ) {
|
||||
return $statuses;
|
||||
}
|
||||
|
||||
$outbox = Http::get_remote_object( $data['outbox'], true );
|
||||
if ( is_wp_error( $outbox ) || ! isset( $outbox['first'] ) ) {
|
||||
return $statuses;
|
||||
}
|
||||
|
||||
$account = self::get_account_for_actor( $args['activitypub'] );
|
||||
if ( ! $account ) {
|
||||
return $statuses;
|
||||
}
|
||||
$limit = 10;
|
||||
if ( isset( $args['posts_per_page'] ) ) {
|
||||
$limit = $args['posts_per_page'];
|
||||
}
|
||||
if ( $limit > 40 ) {
|
||||
$limit = 40;
|
||||
}
|
||||
$activitypub_statuses = array();
|
||||
$url = $outbox['first'];
|
||||
$tries = 0;
|
||||
while ( $url ) {
|
||||
if ( ++$tries > 3 ) {
|
||||
break;
|
||||
}
|
||||
|
||||
$posts = Http::get_remote_object( $url, true );
|
||||
if ( is_wp_error( $posts ) ) {
|
||||
return $statuses;
|
||||
}
|
||||
|
||||
$new_statuses = array_map(
|
||||
function ( $item ) use ( $account, $args ) {
|
||||
if ( $args['exclude_replies'] ) {
|
||||
if ( isset( $item['object']['inReplyTo'] ) && $item['object']['inReplyTo'] ) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return self::activity_to_status( $item, $account );
|
||||
},
|
||||
$posts['orderedItems']
|
||||
);
|
||||
$activitypub_statuses = array_merge( $activitypub_statuses, array_filter( $new_statuses ) );
|
||||
$url = $posts['next'];
|
||||
|
||||
if ( count( $activitypub_statuses ) >= $limit ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return array_slice( $activitypub_statuses, 0, $limit );
|
||||
}
|
||||
|
||||
public static function api_get_replies( $context, $post_id, $url ) {
|
||||
$meta = Http::get_remote_object( $url, true );
|
||||
if ( is_wp_error( $meta ) || ! isset( $meta['replies']['first']['next'] ) ) {
|
||||
return $context;
|
||||
}
|
||||
|
||||
$replies_url = $meta['replies']['first']['next'];
|
||||
$replies = Http::get_remote_object( $replies_url, true );
|
||||
if ( is_wp_error( $replies ) || ! isset( $replies['items'] ) ) {
|
||||
return $context;
|
||||
}
|
||||
|
||||
foreach ( $replies['items'] as $url ) {
|
||||
$response = Http::get( $url, true );
|
||||
if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) {
|
||||
continue;
|
||||
}
|
||||
$status = json_decode( wp_remote_retrieve_body( $response ), true );
|
||||
if ( ! $status || is_wp_error( $status ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$account = self::get_account_for_actor( $status['attributedTo'] );
|
||||
$status = self::activity_to_status( $status, $account );
|
||||
if ( $status ) {
|
||||
$context['descendants'][ $status->id ] = $status;
|
||||
}
|
||||
}
|
||||
|
||||
return $context;
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
<?php
|
||||
namespace Activitypub\Integration;
|
||||
|
||||
class Jetpack {
|
||||
|
||||
public static function init() {
|
||||
\add_filter( 'jetpack_sync_post_meta_whitelist', [ __CLASS__, 'add_sync_meta' ] );
|
||||
}
|
||||
|
||||
public static function add_sync_meta( $whitelist ) {
|
||||
if ( ! is_array( $whitelist ) ) {
|
||||
return $whitelist;
|
||||
}
|
||||
$activitypub_meta_keys = [
|
||||
'activitypub_user_id',
|
||||
'activitypub_inbox',
|
||||
'activitypub_actor_json',
|
||||
];
|
||||
return \array_merge( $whitelist, $activitypub_meta_keys );
|
||||
}
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
<?php
|
||||
namespace Activitypub\Integration;
|
||||
|
||||
use function Activitypub\get_total_users;
|
||||
use function Activitypub\get_active_users;
|
||||
use function Activitypub\get_rest_url_by_path;
|
||||
|
||||
/**
|
||||
* 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_data' ), 10, 2 );
|
||||
\add_filter( 'nodeinfo2_data', array( self::class, 'add_nodeinfo2_data' ), 10 );
|
||||
|
||||
\add_filter( 'wellknown_nodeinfo_data', array( self::class, 'add_wellknown_nodeinfo_data' ), 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend NodeInfo data
|
||||
*
|
||||
* @param array $nodeinfo NodeInfo data
|
||||
* @param string The NodeInfo Version
|
||||
*
|
||||
* @return array The extended array
|
||||
*/
|
||||
public static function add_nodeinfo_data( $nodeinfo, $version ) {
|
||||
if ( $version >= '2.0' ) {
|
||||
$nodeinfo['protocols'][] = 'activitypub';
|
||||
} else {
|
||||
$nodeinfo['protocols']['inbound'][] = 'activitypub';
|
||||
$nodeinfo['protocols']['outbound'][] = 'activitypub';
|
||||
}
|
||||
|
||||
$nodeinfo['usage']['users'] = array(
|
||||
'total' => get_total_users(),
|
||||
'activeMonth' => get_active_users( '1 month ago' ),
|
||||
'activeHalfyear' => get_active_users( '6 month ago' ),
|
||||
);
|
||||
|
||||
return $nodeinfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend NodeInfo2 data
|
||||
*
|
||||
* @param array $nodeinfo NodeInfo2 data
|
||||
*
|
||||
* @return array The extended array
|
||||
*/
|
||||
public static function add_nodeinfo2_data( $nodeinfo ) {
|
||||
$nodeinfo['protocols'][] = 'activitypub';
|
||||
|
||||
$nodeinfo['usage']['users'] = array(
|
||||
'total' => get_total_users(),
|
||||
'activeMonth' => get_active_users( '1 month ago' ),
|
||||
'activeHalfyear' => get_active_users( '6 month ago' ),
|
||||
);
|
||||
|
||||
return $nodeinfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend the well-known nodeinfo data
|
||||
*
|
||||
* @param array $data The well-known nodeinfo data
|
||||
*
|
||||
* @return array The extended array
|
||||
*/
|
||||
public static function add_wellknown_nodeinfo_data( $data ) {
|
||||
$data['links'][] = array(
|
||||
'rel' => 'https://www.w3.org/ns/activitystreams#Application',
|
||||
'href' => get_rest_url_by_path( 'application' ),
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
<?php
|
||||
namespace Activitypub\Integration;
|
||||
|
||||
use Activitypub\Rest\Webfinger as Webfinger_Rest;
|
||||
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' ), 1, 3 );
|
||||
\add_filter( 'webfinger_data', array( self::class, 'add_pseudo_user_discovery' ), 1, 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 );
|
||||
|
||||
if ( ! $user || is_wp_error( $user ) ) {
|
||||
return $array;
|
||||
}
|
||||
|
||||
$array['subject'] = sprintf( 'acct:%s', $user->get_webfinger() );
|
||||
|
||||
$array['aliases'][] = $user->get_url();
|
||||
$array['aliases'][] = $user->get_alternate_url();
|
||||
|
||||
$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 ) {
|
||||
$user = Webfinger_Rest::get_profile( $resource );
|
||||
|
||||
if ( ! $user || is_wp_error( $user ) ) {
|
||||
return $array;
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user