updated plugin ActivityPub version 5.8.0

This commit is contained in:
2025-04-29 21:19:06 +00:00
committed by Gitium
parent 19dfd317cc
commit fdfbf76539
166 changed files with 14119 additions and 7163 deletions

View File

@ -8,7 +8,7 @@
namespace Activitypub;
use WP_Error;
use Activitypub\Collection\Users;
use Activitypub\Collection\Actors;
/**
* ActivityPub HTTP Class
@ -26,6 +26,13 @@ class Http {
* @return array|WP_Error The POST Response or an WP_Error.
*/
public static function post( $url, $body, $user_id ) {
/**
* Fires before an HTTP POST request is made.
*
* @param string $url The URL endpoint.
* @param string $body The POST body.
* @param int $user_id The WordPress User ID.
*/
\do_action( 'activitypub_pre_http_post', $url, $body, $user_id );
$date = \gmdate( 'D, d M Y H:i:s T' );
@ -35,7 +42,7 @@ class Http {
$wp_version = get_masked_wp_version();
/**
* Filter the HTTP headers user agent.
* Filters the HTTP headers user agent string.
*
* @param string $user_agent The user agent string.
*/
@ -59,7 +66,14 @@ class Http {
$code = \wp_remote_retrieve_response_code( $response );
if ( $code >= 400 ) {
$response = new WP_Error( $code, __( 'Failed HTTP Request', 'activitypub' ), array( 'status' => $code ) );
$response = new WP_Error(
$code,
__( 'Failed HTTP Request', 'activitypub' ),
array(
'status' => $code,
'response' => $response,
)
);
}
/**
@ -84,6 +98,11 @@ class Http {
* @return array|WP_Error The GET Response or a WP_Error.
*/
public static function get( $url, $cached = false ) {
/**
* Fires before an HTTP GET request is made.
*
* @param string $url The URL endpoint.
*/
\do_action( 'activitypub_pre_http_get', $url );
if ( $cached ) {
@ -105,19 +124,29 @@ class Http {
}
$date = \gmdate( 'D, d M Y H:i:s T' );
$signature = Signature::generate_signature( Users::APPLICATION_USER_ID, 'get', $url, $date );
$signature = Signature::generate_signature( Actors::APPLICATION_USER_ID, 'get', $url, $date );
$wp_version = get_masked_wp_version();
/**
* Filter the HTTP headers user agent.
* Filters the HTTP headers user agent string.
*
* This filter allows developers to modify the user agent string that is
* sent with HTTP requests.
*
* @param string $user_agent The user agent string.
*/
$user_agent = \apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . \get_bloginfo( 'url' ) );
/**
* Filters the timeout duration for remote GET requests in ActivityPub.
*
* @param int $timeout The timeout value in seconds. Default 100 seconds.
*/
$timeout = \apply_filters( 'activitypub_remote_get_timeout', 100 );
$args = array(
'timeout' => apply_filters( 'activitypub_remote_get_timeout', 100 ),
'timeout' => $timeout,
'limit_response_size' => 1048576,
'redirection' => 3,
'user-agent' => "$user_agent; ActivityPub",
@ -164,19 +193,25 @@ class Http {
*/
public static function is_tombstone( $url ) {
/**
* Action before checking if the URL is a tombstone.
* Fires before checking if the URL is a tombstone.
*
* @param string $url The URL to check.
*/
\do_action( 'activitypub_pre_http_is_tombstone', $url );
$response = \wp_safe_remote_get( $url );
$response = \wp_safe_remote_get( $url, array( 'headers' => array( 'Accept' => 'application/activity+json' ) ) );
$code = \wp_remote_retrieve_response_code( $response );
if ( in_array( (int) $code, array( 404, 410 ), true ) ) {
return true;
}
$data = \wp_remote_retrieve_body( $response );
$data = \json_decode( $data, true );
if ( $data && isset( $data['type'] ) && 'Tombstone' === $data['type'] ) {
return true;
}
return false;
}
@ -200,24 +235,7 @@ class Http {
* @return array|WP_Error The Object data as array or WP_Error on failure.
*/
public static function get_remote_object( $url_or_object, $cached = true ) {
if ( is_array( $url_or_object ) ) {
if ( array_key_exists( 'id', $url_or_object ) ) {
$url = $url_or_object['id'];
} elseif ( array_key_exists( 'url', $url_or_object ) ) {
$url = $url_or_object['url'];
} else {
return new WP_Error(
'activitypub_no_valid_actor_identifier',
\__( 'The "actor" identifier is not valid', 'activitypub' ),
array(
'status' => 404,
'object' => $url_or_object,
)
);
}
} else {
$url = $url_or_object;
}
$url = object_to_uri( $url_or_object );
if ( preg_match( '/^@?' . ACTIVITYPUB_USERNAME_REGEXP . '$/i', $url ) ) {
$url = Webfinger::resolve( $url );