updated plugin ActivityPub version 8.3.0
This commit is contained in:
@ -7,9 +7,11 @@
|
||||
|
||||
namespace Activitypub\Model;
|
||||
|
||||
use WP_Error;
|
||||
use Activitypub\Activity\Actor;
|
||||
use Activitypub\Collection\Followers;
|
||||
use Activitypub\Collection\Remote_Actors;
|
||||
|
||||
use function Activitypub\extract_name_from_uri;
|
||||
|
||||
/**
|
||||
* ActivityPub Follower Class.
|
||||
@ -20,6 +22,7 @@ use Activitypub\Collection\Followers;
|
||||
* @author Matt Wiebe
|
||||
* @author Matthias Pfefferle
|
||||
*
|
||||
* @deprecated 7.0.0
|
||||
* @see https://www.w3.org/TR/activitypub/#follow-activity-inbox
|
||||
*
|
||||
* @method int get__id() Gets the post ID of the follower record.
|
||||
@ -42,13 +45,31 @@ class Follower extends Actor {
|
||||
*/
|
||||
protected $_id; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @deprecated Use Actor instead.
|
||||
*/
|
||||
public function __construct() {
|
||||
\_deprecated_class( __CLASS__, '7.0.0', Actor::class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the errors.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_errors() {
|
||||
return get_post_meta( $this->_id, '_activitypub_errors', false );
|
||||
return Remote_Actors::get_errors( $this->_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the errors for the current Follower.
|
||||
*
|
||||
* @return bool True on success, false on failure.
|
||||
*/
|
||||
public function clear_errors() {
|
||||
return Remote_Actors::clear_errors( $this->_id );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,9 +103,11 @@ class Follower extends Actor {
|
||||
|
||||
/**
|
||||
* Reset (delete) all errors.
|
||||
*
|
||||
* @return bool True on success, false on failure.
|
||||
*/
|
||||
public function reset_errors() {
|
||||
delete_post_meta( $this->_id, '_activitypub_errors' );
|
||||
return Remote_Actors::clear_errors( $this->_id );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -93,13 +116,7 @@ class Follower extends Actor {
|
||||
* @return int The number of errors.
|
||||
*/
|
||||
public function count_errors() {
|
||||
$errors = $this->get_errors();
|
||||
|
||||
if ( is_array( $errors ) && ! empty( $errors ) ) {
|
||||
return count( $errors );
|
||||
}
|
||||
|
||||
return 0;
|
||||
return Remote_Actors::count_errors( $this->_id );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -110,8 +127,8 @@ class Follower extends Actor {
|
||||
public function get_latest_error_message() {
|
||||
$errors = $this->get_errors();
|
||||
|
||||
if ( is_array( $errors ) && ! empty( $errors ) ) {
|
||||
return reset( $errors );
|
||||
if ( \is_array( $errors ) && ! empty( $errors ) ) {
|
||||
return \reset( $errors );
|
||||
}
|
||||
|
||||
return '';
|
||||
@ -151,61 +168,26 @@ class Follower extends Actor {
|
||||
/**
|
||||
* Save the current Follower object.
|
||||
*
|
||||
* @return int|WP_Error The post ID or an WP_Error.
|
||||
* @return int|\WP_Error The post ID or an WP_Error.
|
||||
*/
|
||||
public function save() {
|
||||
if ( ! $this->is_valid() ) {
|
||||
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 ) );
|
||||
}
|
||||
|
||||
if ( ! $this->get__id() ) {
|
||||
global $wpdb;
|
||||
|
||||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery
|
||||
$post_id = $wpdb->get_var(
|
||||
$wpdb->prepare(
|
||||
"SELECT ID FROM $wpdb->posts WHERE guid=%s",
|
||||
esc_sql( $this->get_id() )
|
||||
)
|
||||
);
|
||||
|
||||
if ( $post_id ) {
|
||||
$post = get_post( $post_id );
|
||||
$this->set__id( $post->ID );
|
||||
}
|
||||
$id = Remote_Actors::upsert( $this );
|
||||
if ( \is_wp_error( $id ) ) {
|
||||
return $id;
|
||||
}
|
||||
|
||||
$post_id = $this->get__id();
|
||||
|
||||
$args = array(
|
||||
'ID' => $post_id,
|
||||
'guid' => esc_url_raw( $this->get_id() ),
|
||||
'post_title' => wp_strip_all_tags( sanitize_text_field( $this->get_name() ) ),
|
||||
'post_author' => 0,
|
||||
'post_type' => Followers::POST_TYPE,
|
||||
'post_name' => esc_url_raw( $this->get_id() ),
|
||||
'post_excerpt' => sanitize_text_field( wp_kses( $this->get_summary(), 'user_description' ) ),
|
||||
'post_status' => 'publish',
|
||||
'meta_input' => $this->get_post_meta_input(),
|
||||
);
|
||||
|
||||
if ( ! empty( $post_id ) ) {
|
||||
// If this is an update, prevent the "followed" date from being overwritten by the current date.
|
||||
$post = get_post( $post_id );
|
||||
$args['post_date'] = $post->post_date;
|
||||
$args['post_date_gmt'] = $post->post_date_gmt;
|
||||
}
|
||||
|
||||
$post_id = wp_insert_post( $args );
|
||||
$this->_id = $post_id;
|
||||
|
||||
return $post_id;
|
||||
$this->set__id( $id );
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upsert the current Follower object.
|
||||
*
|
||||
* @return int|WP_Error The post ID or an WP_Error.
|
||||
* @return int|\WP_Error The post ID or an WP_Error.
|
||||
*/
|
||||
public function upsert() {
|
||||
return $this->save();
|
||||
@ -221,18 +203,7 @@ class Follower extends Actor {
|
||||
* @see \Activitypub\Rest\Followers::remove_follower()
|
||||
*/
|
||||
public function delete() {
|
||||
wp_delete_post( $this->_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the post meta.
|
||||
*/
|
||||
protected function get_post_meta_input() {
|
||||
$meta_input = array();
|
||||
$meta_input['_activitypub_inbox'] = $this->get_shared_inbox();
|
||||
$meta_input['_activitypub_actor_json'] = wp_slash( $this->to_json() );
|
||||
|
||||
return $meta_input;
|
||||
Followers::remove_follower( $this->_id, $this->get_id() );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -298,7 +269,7 @@ class Follower extends Actor {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( is_array( $icon ) ) {
|
||||
if ( \is_array( $icon ) ) {
|
||||
return $icon['url'];
|
||||
}
|
||||
|
||||
@ -317,7 +288,7 @@ class Follower extends Actor {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( is_array( $image ) ) {
|
||||
if ( \is_array( $image ) ) {
|
||||
return $image['url'];
|
||||
}
|
||||
|
||||
@ -346,12 +317,16 @@ class Follower extends Actor {
|
||||
* @return Follower|false The Follower object or false on failure.
|
||||
*/
|
||||
public static function init_from_cpt( $post ) {
|
||||
$actor_json = get_post_meta( $post->ID, '_activitypub_actor_json', true );
|
||||
if ( empty( $post->post_content ) ) {
|
||||
$json = \get_post_meta( $post->ID, '_activitypub_actor_json', true );
|
||||
} else {
|
||||
$json = $post->post_content;
|
||||
}
|
||||
|
||||
/* @var Follower $object Follower object. */
|
||||
$object = self::init_from_json( $actor_json );
|
||||
$object = self::init_from_json( $json );
|
||||
|
||||
if ( is_wp_error( $object ) ) {
|
||||
if ( \is_wp_error( $object ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -374,37 +349,11 @@ class Follower extends Actor {
|
||||
protected function extract_name_from_uri() {
|
||||
// prefer the URL, but fall back to the ID.
|
||||
if ( $this->url ) {
|
||||
$name = $this->url;
|
||||
$uri = $this->url;
|
||||
} else {
|
||||
$name = $this->id;
|
||||
$uri = $this->id;
|
||||
}
|
||||
|
||||
if ( \filter_var( $name, FILTER_VALIDATE_URL ) ) {
|
||||
$name = \rtrim( $name, '/' );
|
||||
$path = \wp_parse_url( $name, PHP_URL_PATH );
|
||||
|
||||
if ( $path ) {
|
||||
if ( \strpos( $name, '@' ) !== false ) {
|
||||
// Expected: https://example.com/@user (default URL pattern).
|
||||
$name = \preg_replace( '|^/@?|', '', $path );
|
||||
} else {
|
||||
// Expected: https://example.com/users/user (default ID pattern).
|
||||
$parts = \explode( '/', $path );
|
||||
$name = \array_pop( $parts );
|
||||
}
|
||||
}
|
||||
} elseif (
|
||||
\is_email( $name ) ||
|
||||
\strpos( $name, 'acct' ) === 0 ||
|
||||
\strpos( $name, '@' ) === 0
|
||||
) {
|
||||
// Expected: user@example.com or acct:user@example (WebFinger).
|
||||
$name = \ltrim( $name, '@' );
|
||||
$name = \ltrim( $name, 'acct:' );
|
||||
$parts = \explode( '@', $name );
|
||||
$name = $parts[0];
|
||||
}
|
||||
|
||||
return $name;
|
||||
return extract_name_from_uri( $uri );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user