updated plugin ActivityPub version 8.3.0
This commit is contained in:
@ -7,7 +7,7 @@
|
||||
|
||||
namespace Activitypub;
|
||||
|
||||
use WP_Error;
|
||||
use Activitypub\Collection\Remote_Actors;
|
||||
|
||||
/**
|
||||
* ActivityPub Mention Class.
|
||||
@ -19,9 +19,9 @@ class Mention {
|
||||
* Initialize the class, registering WordPress hooks.
|
||||
*/
|
||||
public static function init() {
|
||||
\add_filter( 'the_content', array( self::class, 'the_content' ), 99, 1 );
|
||||
\add_filter( 'comment_text', array( self::class, 'the_content' ), 10, 1 );
|
||||
\add_filter( 'activitypub_extra_field_content', array( self::class, 'the_content' ), 10, 1 );
|
||||
\add_filter( 'the_content', array( self::class, 'the_content' ), 99 );
|
||||
\add_filter( 'comment_text', array( self::class, 'the_content' ) );
|
||||
\add_filter( 'activitypub_extra_field_content', array( self::class, 'the_content' ) );
|
||||
\add_filter( 'activitypub_extract_mentions', array( self::class, 'extract_mentions' ), 99, 2 );
|
||||
\add_filter( 'activitypub_activity_object_array', array( self::class, 'filter_activity_object' ), 99 );
|
||||
}
|
||||
@ -65,27 +65,22 @@ class Mention {
|
||||
* @return string The final string.
|
||||
*/
|
||||
public static function replace_with_links( $result ) {
|
||||
$metadata = get_remote_metadata_by_actor( $result[0] );
|
||||
$post = Remote_Actors::fetch_by_acct( $result[0] );
|
||||
|
||||
if (
|
||||
! empty( $metadata ) &&
|
||||
! is_wp_error( $metadata ) &&
|
||||
( ! empty( $metadata['id'] ) || ! empty( $metadata['url'] ) )
|
||||
) {
|
||||
$username = ltrim( $result[0], '@' );
|
||||
if ( ! empty( $metadata['name'] ) ) {
|
||||
$username = $metadata['name'];
|
||||
}
|
||||
if ( ! empty( $metadata['preferredUsername'] ) ) {
|
||||
$username = $metadata['preferredUsername'];
|
||||
}
|
||||
|
||||
$url = isset( $metadata['url'] ) ? object_to_uri( $metadata['url'] ) : object_to_uri( $metadata['id'] );
|
||||
|
||||
return \sprintf( '<a rel="mention" class="u-url mention" href="%1$s">@%2$s</a>', esc_url( $url ), esc_html( $username ) );
|
||||
if ( \is_wp_error( $post ) ) {
|
||||
return $result[0];
|
||||
}
|
||||
|
||||
return $result[0];
|
||||
$actor = Remote_Actors::get_actor( $post );
|
||||
|
||||
if ( \is_wp_error( $actor ) ) {
|
||||
return $result[0];
|
||||
}
|
||||
|
||||
$username = $actor->get_preferred_username() ?: $actor->get_name() ?: Sanitize::webfinger( $result[0] );
|
||||
$url = object_to_uri( $actor->get_url() ?: $actor->get_id() );
|
||||
|
||||
return \sprintf( '<a rel="mention" class="u-url mention" href="%1$s">@%2$s</a>', esc_url( $url ), esc_html( $username ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -114,7 +109,7 @@ class Mention {
|
||||
*
|
||||
* @param string $actor The Actor URL.
|
||||
*
|
||||
* @return string|WP_Error The Inbox-URL or WP_Error if not found.
|
||||
* @return string|\WP_Error The Inbox-URL or WP_Error if not found.
|
||||
*/
|
||||
public static function get_inbox_by_mentioned_actor( $actor ) {
|
||||
$metadata = get_remote_metadata_by_actor( $actor );
|
||||
@ -131,7 +126,7 @@ class Mention {
|
||||
return $metadata['inbox'];
|
||||
}
|
||||
|
||||
return new WP_Error( 'activitypub_no_inbox', \__( 'No "Inbox" found', 'activitypub' ), $metadata );
|
||||
return new \WP_Error( 'activitypub_no_inbox', \__( 'No "Inbox" found', 'activitypub' ), $metadata );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user