updated plugin ActivityPub version 9.1.0
This commit is contained in:
@ -12,6 +12,8 @@ use Activitypub\Tombstone;
|
||||
|
||||
use function Activitypub\get_remote_metadata_by_actor;
|
||||
use function Activitypub\get_rest_url_by_path;
|
||||
use function Activitypub\is_same_host;
|
||||
use function Activitypub\object_to_uri;
|
||||
|
||||
/**
|
||||
* ActivityPub Followers Collection.
|
||||
@ -50,7 +52,20 @@ class Followers {
|
||||
}
|
||||
|
||||
if ( empty( $meta ) || ! \is_array( $meta ) || \is_wp_error( $meta ) ) {
|
||||
return new \WP_Error( 'activitypub_invalid_follower', __( 'Invalid Follower', 'activitypub' ), array( 'status' => 400 ) );
|
||||
return new \WP_Error( 'activitypub_invalid_follower', \__( 'Invalid Follower', 'activitypub' ), array( 'status' => 400 ) );
|
||||
}
|
||||
|
||||
/*
|
||||
* The signed sender ($actor) must be the actor we actually resolved. A document that
|
||||
* declares an id on a different host than the one that sent the Follow would
|
||||
* otherwise record a third party, who never sent the Follow, as a follower.
|
||||
*/
|
||||
if ( ! is_same_host( $actor, object_to_uri( $meta ) ) ) {
|
||||
return new \WP_Error(
|
||||
'activitypub_follower_host_mismatch',
|
||||
\__( 'The follower does not match the actor that sent the request.', 'activitypub' ),
|
||||
array( 'status' => 403 )
|
||||
);
|
||||
}
|
||||
|
||||
$post_id = Remote_Actors::upsert( $meta );
|
||||
@ -114,28 +129,6 @@ class Followers {
|
||||
return \delete_post_meta( $post->ID, self::FOLLOWER_META_KEY, $user_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a Follower.
|
||||
*
|
||||
* @deprecated 7.1.0 Use {@see Followers::remove()}.
|
||||
*
|
||||
* @param int $user_id The ID of the WordPress User.
|
||||
* @param string $actor The Actor URL.
|
||||
*
|
||||
* @return bool True on success, false on failure.
|
||||
*/
|
||||
public static function remove_follower( $user_id, $actor ) {
|
||||
\_deprecated_function( __METHOD__, '7.1.0', 'Activitypub\Collection\Followers::remove' );
|
||||
|
||||
$remote_actor = self::get_by_uri( $user_id, $actor );
|
||||
|
||||
if ( \is_wp_error( $remote_actor ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return self::remove( $remote_actor->ID, $user_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Follower by URI.
|
||||
*
|
||||
@ -182,25 +175,10 @@ class Followers {
|
||||
* @return \WP_Post|\WP_Error The Follower object or WP_Error on failure.
|
||||
*/
|
||||
public static function get_follower( $user_id, $actor ) {
|
||||
_deprecated_function( __METHOD__, '7.6.0', 'Activitypub\Collection\Followers::get_by_uri' );
|
||||
\_deprecated_function( __METHOD__, '7.6.0', 'Activitypub\Collection\Followers::get_by_uri' );
|
||||
return self::get_by_uri( $user_id, $actor );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Follower by Actor independent of the User.
|
||||
*
|
||||
* @deprecated 7.4.0 Use {@see Remote_Actors::get_by_uri()}.
|
||||
*
|
||||
* @param string $actor The Actor URL.
|
||||
*
|
||||
* @return \WP_Post|\WP_Error The Follower object or WP_Error on failure.
|
||||
*/
|
||||
public static function get_follower_by_actor( $actor ) {
|
||||
\_deprecated_function( __METHOD__, '7.4.0', 'Activitypub\Collection\Remote_Actors::get_by_uri' );
|
||||
|
||||
return Remote_Actors::get_by_uri( $actor );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get many followers.
|
||||
*
|
||||
@ -230,7 +208,7 @@ class Followers {
|
||||
* @return \WP_Post[] List of `Follower` objects.
|
||||
*/
|
||||
public static function get_followers( $user_id, $number = -1, $page = null, $args = array() ) {
|
||||
_deprecated_function( __METHOD__, '7.6.0', 'Activitypub\Collection\Followers::get_many' );
|
||||
\_deprecated_function( __METHOD__, '7.6.0', 'Activitypub\Collection\Followers::get_many' );
|
||||
return self::get_many( $user_id, $number, $page, $args );
|
||||
}
|
||||
|
||||
@ -441,126 +419,6 @@ class Followers {
|
||||
return \array_slice( $inboxes, $offset, $batch_size );
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe add Inboxes of the Blog User.
|
||||
*
|
||||
* @deprecated 7.3.0
|
||||
*
|
||||
* @param string $json The ActivityPub Activity JSON.
|
||||
* @param int $actor_id The WordPress Actor ID.
|
||||
*
|
||||
* @return bool True if the Inboxes of the Blog User should be added, false otherwise.
|
||||
*/
|
||||
public static function maybe_add_inboxes_of_blog_user( $json, $actor_id ) {
|
||||
\_deprecated_function( __METHOD__, '7.3.0' );
|
||||
|
||||
// Only if we're in both Blog and User modes.
|
||||
if ( ACTIVITYPUB_ACTOR_AND_BLOG_MODE !== \get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE ) ) {
|
||||
return false;
|
||||
}
|
||||
// Only if this isn't the Blog Actor.
|
||||
if ( Actors::BLOG_USER_ID === $actor_id ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$activity = \json_decode( $json, true );
|
||||
// Only if this is an Update or Delete. Create handles its own "Announce" in dual user mode.
|
||||
if ( ! \in_array( $activity['type'] ?? null, array( 'Update', 'Delete' ), true ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Followers.
|
||||
*
|
||||
* @deprecated 7.1.0 Use {@see Actors::get_all()}.
|
||||
*
|
||||
* @return \WP_Post[] The list of Followers.
|
||||
*/
|
||||
public static function get_all_followers() {
|
||||
_deprecated_function( __METHOD__, '7.1.0', 'Activitypub\Collection\Actors::get_all' );
|
||||
|
||||
$args = array(
|
||||
'nopaging' => true,
|
||||
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
|
||||
'meta_query' => array(
|
||||
'relation' => 'AND',
|
||||
array(
|
||||
'key' => '_activitypub_inbox',
|
||||
'compare' => 'EXISTS',
|
||||
),
|
||||
),
|
||||
);
|
||||
return self::get_many( null, null, null, $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Followers that have not been updated for a given time.
|
||||
*
|
||||
* @deprecated 7.0.0 Use {@see Remote_Actors::get_outdated()}.
|
||||
*
|
||||
* @param int $number Optional. Limits the result. Default 50.
|
||||
* @param int $older_than Optional. The time in seconds. Default 86400 (1 day).
|
||||
*
|
||||
* @return \WP_Post[] The list of Actors.
|
||||
*/
|
||||
public static function get_outdated_followers( $number = 50, $older_than = 86400 ) {
|
||||
_deprecated_function( __METHOD__, '7.0.0', 'Activitypub\Collection\Remote_Actors::get_outdated' );
|
||||
|
||||
return Remote_Actors::get_outdated( $number, $older_than );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Followers that had errors.
|
||||
*
|
||||
* @deprecated 7.0.0 Use {@see Remote_Actors::get_faulty()}.
|
||||
*
|
||||
* @param int $number Optional. The number of Followers to return. Default 20.
|
||||
*
|
||||
* @return \WP_Post[] The list of Actors.
|
||||
*/
|
||||
public static function get_faulty_followers( $number = 20 ) {
|
||||
_deprecated_function( __METHOD__, '7.0.0', 'Activitypub\Collection\Remote_Actors::get_faulty' );
|
||||
|
||||
return Remote_Actors::get_faulty( $number );
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is used to store errors that occur when
|
||||
* sending an ActivityPub message to a Follower.
|
||||
*
|
||||
* The error will be stored in post meta.
|
||||
*
|
||||
* @deprecated 7.0.0 Use {@see Remote_Actors::add_error()}.
|
||||
*
|
||||
* @param int $post_id The ID of the WordPress Custom-Post-Type.
|
||||
* @param mixed $error The error message. Can be a string or a WP_Error.
|
||||
*
|
||||
* @return int|false The meta ID on success, false on failure.
|
||||
*/
|
||||
public static function add_error( $post_id, $error ) {
|
||||
\_deprecated_function( __METHOD__, '7.0.0', 'Activitypub\Collection\Remote_Actors::add_error' );
|
||||
|
||||
return Remote_Actors::add_error( $post_id, $error );
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the errors for a Follower.
|
||||
*
|
||||
* @deprecated 7.0.0 Use {@see Remote_Actors::clear_errors()}.
|
||||
*
|
||||
* @param int $post_id The ID of the WordPress Custom-Post-Type.
|
||||
*
|
||||
* @return bool True on success, false on failure.
|
||||
*/
|
||||
public static function clear_errors( $post_id ) {
|
||||
\_deprecated_function( __METHOD__, '7.0.0', 'Activitypub\Collection\Remote_Actors::clear_errors' );
|
||||
|
||||
return Remote_Actors::clear_errors( $post_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the status of a given following.
|
||||
*
|
||||
@ -682,19 +540,19 @@ class Followers {
|
||||
}
|
||||
|
||||
// Build the collection ID (followers collection URL).
|
||||
$collection_id = get_rest_url_by_path( sprintf( 'actors/%d/followers', $user_id ) );
|
||||
$collection_id = get_rest_url_by_path( \sprintf( 'actors/%d/followers', $user_id ) );
|
||||
|
||||
// Build the partial followers URL.
|
||||
$url = get_rest_url_by_path(
|
||||
sprintf(
|
||||
\sprintf(
|
||||
'actors/%d/followers/sync?authority=%s',
|
||||
$user_id,
|
||||
rawurlencode( $authority )
|
||||
\rawurlencode( $authority )
|
||||
)
|
||||
);
|
||||
|
||||
// Format as per FEP-8fcf (similar to HTTP Signatures format).
|
||||
return sprintf(
|
||||
return \sprintf(
|
||||
'collectionId="%s", url="%s", digest="%s"',
|
||||
$collection_id,
|
||||
$url,
|
||||
|
||||
Reference in New Issue
Block a user