updated plugin ActivityPub version 8.3.0
This commit is contained in:
@ -7,8 +7,12 @@
|
||||
|
||||
namespace Activitypub\Rest;
|
||||
|
||||
use Activitypub\Activity\Activity;
|
||||
use Activitypub\Collection\Actors;
|
||||
use Activitypub\Http;
|
||||
|
||||
use function Activitypub\user_can_activitypub;
|
||||
|
||||
/**
|
||||
* Interaction Controller.
|
||||
*/
|
||||
@ -40,11 +44,16 @@ class Interaction_Controller extends \WP_REST_Controller {
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => '__return_true',
|
||||
'args' => array(
|
||||
'uri' => array(
|
||||
'description' => 'The URI of the object to interact with.',
|
||||
'uri' => array(
|
||||
'description' => 'The URI or webfinger ID of the object to interact with.',
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
'sanitize_callback' => array( $this, 'sanitize_uri' ),
|
||||
),
|
||||
'intent' => array(
|
||||
'description' => 'The intent of the interaction, e.g., follow, reply, import.',
|
||||
'type' => 'string',
|
||||
'format' => 'uri',
|
||||
'required' => true,
|
||||
'enum' => array_map( 'Activitypub\camel_to_snake_case', Activity::TYPES ),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -52,6 +61,29 @@ class Interaction_Controller extends \WP_REST_Controller {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize the URI parameter.
|
||||
*
|
||||
* @param string $uri The URI or webfinger ID of the object to interact with.
|
||||
*
|
||||
* @return string Sanitized URI.
|
||||
*/
|
||||
public function sanitize_uri( $uri ) {
|
||||
// Remove "acct:" prefix if present.
|
||||
if ( str_starts_with( $uri, 'acct:' ) ) {
|
||||
$uri = \substr( $uri, 5 );
|
||||
}
|
||||
|
||||
// Remove "@" prefix if present.
|
||||
$uri = \ltrim( $uri, '@' );
|
||||
|
||||
if ( is_email( $uri ) ) {
|
||||
return \sanitize_text_field( $uri );
|
||||
}
|
||||
|
||||
return \sanitize_url( $uri );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the interaction URL for a given URI.
|
||||
*
|
||||
@ -61,6 +93,7 @@ class Interaction_Controller extends \WP_REST_Controller {
|
||||
*/
|
||||
public function get_item( $request ) {
|
||||
$uri = $request->get_param( 'uri' );
|
||||
$intent = $request->get_param( 'intent' );
|
||||
$redirect_url = '';
|
||||
$object = Http::get_remote_object( $uri );
|
||||
|
||||
@ -76,27 +109,58 @@ class Interaction_Controller extends \WP_REST_Controller {
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $object['url'] ) ) {
|
||||
$uri = \esc_url( $object['url'] );
|
||||
if ( ! empty( $object['id'] ) ) {
|
||||
$uri = \esc_url( $object['id'] );
|
||||
}
|
||||
|
||||
// Prepare URL parameter.
|
||||
$url_param = \rawurlencode( $uri );
|
||||
|
||||
switch ( $object['type'] ) {
|
||||
case 'Group':
|
||||
case 'Person':
|
||||
case 'Service':
|
||||
case 'Application':
|
||||
case 'Organization':
|
||||
if ( \get_option( 'activitypub_following_ui', '0' ) ) {
|
||||
if ( user_can_activitypub( \get_current_user_id() ) ) {
|
||||
$redirect_url = \admin_url( 'users.php?page=activitypub-following-list&resource=' . $url_param );
|
||||
} elseif ( user_can_activitypub( Actors::BLOG_USER_ID ) ) {
|
||||
$redirect_url = \admin_url( 'options-general.php?page=activitypub&tab=following&resource=' . $url_param );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the URL used for following an ActivityPub actor.
|
||||
*
|
||||
* @param string $redirect_url The URL to redirect to.
|
||||
* @param string $uri The URI of the actor to follow.
|
||||
* @param array $object The full actor object data.
|
||||
* @param string $intent The intent of the interaction.
|
||||
*/
|
||||
$redirect_url = \apply_filters( 'activitypub_interactions_follow_url', $redirect_url, $uri, $object );
|
||||
$redirect_url = \apply_filters( 'activitypub_interactions_follow_url', $redirect_url, $uri, $object, $intent );
|
||||
break;
|
||||
case 'Collection':
|
||||
case 'CollectionPage':
|
||||
case 'OrderedCollection':
|
||||
case 'OrderedCollectionPage':
|
||||
if ( \get_option( 'activitypub_following_ui', '0' ) ) {
|
||||
$redirect_url = \admin_url( 'admin.php?import=starter-kit&url=' . $url_param );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the URL used for importing a Starter Kit collection.
|
||||
*
|
||||
* @param string $redirect_url The URL to redirect to.
|
||||
* @param string $uri The URI of the collection to import.
|
||||
* @param array $object The full collection object data.
|
||||
* @param string $intent The intent of the interaction.
|
||||
*/
|
||||
$redirect_url = \apply_filters( 'activitypub_interactions_starter_kit_url', $redirect_url, $uri, $object, $intent );
|
||||
break;
|
||||
default:
|
||||
$redirect_url = \admin_url( 'post-new.php?in_reply_to=' . $uri );
|
||||
$redirect_url = \admin_url( 'post-new.php?in_reply_to=' . $url_param );
|
||||
|
||||
/**
|
||||
* Filters the URL used for replying to an ActivityPub object.
|
||||
*
|
||||
@ -105,8 +169,9 @@ class Interaction_Controller extends \WP_REST_Controller {
|
||||
* @param string $redirect_url The URL to redirect to.
|
||||
* @param string $uri The URI of the object to reply to.
|
||||
* @param array $object The full object data being replied to.
|
||||
* @param string $intent The intent of the interaction.
|
||||
*/
|
||||
$redirect_url = \apply_filters( 'activitypub_interactions_reply_url', $redirect_url, $uri, $object );
|
||||
$redirect_url = \apply_filters( 'activitypub_interactions_reply_url', $redirect_url, $uri, $object, $intent );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -118,8 +183,9 @@ class Interaction_Controller extends \WP_REST_Controller {
|
||||
* @param string $redirect_url The URL to redirect to.
|
||||
* @param string $uri The URI of the object.
|
||||
* @param array $object The object being interacted with.
|
||||
* @param string $intent The intent of the interaction.
|
||||
*/
|
||||
$redirect_url = \apply_filters( 'activitypub_interactions_url', $redirect_url, $uri, $object );
|
||||
$redirect_url = \apply_filters( 'activitypub_interactions_url', $redirect_url, $uri, $object, $intent );
|
||||
|
||||
// Check if hook is implemented.
|
||||
if ( ! $redirect_url ) {
|
||||
@ -134,6 +200,6 @@ class Interaction_Controller extends \WP_REST_Controller {
|
||||
);
|
||||
}
|
||||
|
||||
return new \WP_REST_Response( null, 302, array( 'Location' => \esc_url( $redirect_url ) ) );
|
||||
return new \WP_REST_Response( null, 302, array( 'Location' => $redirect_url ) );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user