updated plugin ActivityPub
version 5.8.0
This commit is contained in:
@ -10,12 +10,14 @@ namespace Activitypub\Model;
|
||||
use WP_Query;
|
||||
use Activitypub\Signature;
|
||||
use Activitypub\Activity\Actor;
|
||||
use Activitypub\Collection\Users;
|
||||
use Activitypub\Collection\Actors;
|
||||
|
||||
use function Activitypub\get_rest_url_by_path;
|
||||
|
||||
/**
|
||||
* Application class.
|
||||
*
|
||||
* @method int get__id() Gets the internal user ID for the application (always returns APPLICATION_USER_ID).
|
||||
*/
|
||||
class Application extends Actor {
|
||||
/**
|
||||
@ -23,7 +25,7 @@ class Application extends Actor {
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_id = Users::APPLICATION_USER_ID; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
|
||||
protected $_id = Actors::APPLICATION_USER_ID; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
|
||||
|
||||
/**
|
||||
* Whether the Application is discoverable.
|
||||
@ -94,7 +96,7 @@ class Application extends Actor {
|
||||
* @return string The User-URL with @-Prefix for the username.
|
||||
*/
|
||||
public function get_alternate_url() {
|
||||
return $this->get_url();
|
||||
return $this->get_id();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -118,7 +120,7 @@ class Application extends Actor {
|
||||
/**
|
||||
* Get the User-Icon.
|
||||
*
|
||||
* @return array The User-Icon.
|
||||
* @return string[] The User-Icon.
|
||||
*/
|
||||
public function get_icon() {
|
||||
// Try site icon first.
|
||||
@ -152,7 +154,7 @@ class Application extends Actor {
|
||||
/**
|
||||
* Get the User-Header-Image.
|
||||
*
|
||||
* @return array|null The User-Header-Image.
|
||||
* @return string[]|null The User-Header-Image.
|
||||
*/
|
||||
public function get_header_image() {
|
||||
if ( \has_header_image() ) {
|
||||
@ -185,7 +187,7 @@ class Application extends Actor {
|
||||
$time = \time();
|
||||
}
|
||||
|
||||
return \gmdate( 'Y-m-d\TH:i:s\Z', $time );
|
||||
return \gmdate( ACTIVITYPUB_DATE_TIME_RFC3339, $time );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -218,13 +220,13 @@ class Application extends Actor {
|
||||
/**
|
||||
* Returns the public key.
|
||||
*
|
||||
* @return array The public key.
|
||||
* @return string[] The public key.
|
||||
*/
|
||||
public function get_public_key() {
|
||||
return array(
|
||||
'id' => $this->get_id() . '#main-key',
|
||||
'owner' => $this->get_id(),
|
||||
'publicKeyPem' => Signature::get_public_key_for( Users::APPLICATION_USER_ID ),
|
||||
'publicKeyPem' => Signature::get_public_key_for( Actors::APPLICATION_USER_ID ),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -7,20 +7,22 @@
|
||||
|
||||
namespace Activitypub\Model;
|
||||
|
||||
use WP_Query;
|
||||
|
||||
use Activitypub\Signature;
|
||||
use Activitypub\Activity\Actor;
|
||||
use Activitypub\Collection\Users;
|
||||
use Activitypub\Collection\Actors;
|
||||
use Activitypub\Collection\Extra_Fields;
|
||||
use Activitypub\Signature;
|
||||
use WP_Query;
|
||||
|
||||
use function Activitypub\esc_hashtag;
|
||||
use function Activitypub\is_single_user;
|
||||
use function Activitypub\is_blog_public;
|
||||
use function Activitypub\get_rest_url_by_path;
|
||||
use function Activitypub\get_attribution_domains;
|
||||
|
||||
/**
|
||||
* Blog class.
|
||||
*
|
||||
* @method int get__id() Gets the internal user ID for the blog (always returns BLOG_USER_ID).
|
||||
*/
|
||||
class Blog extends Actor {
|
||||
/**
|
||||
@ -51,7 +53,7 @@ class Blog extends Actor {
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_id = Users::BLOG_USER_ID; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
|
||||
protected $_id = Actors::BLOG_USER_ID; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
|
||||
|
||||
/**
|
||||
* If the User is indexable.
|
||||
@ -89,6 +91,18 @@ class Blog extends Actor {
|
||||
*/
|
||||
protected $posting_restricted_to_mods;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
/**
|
||||
* Fires when a model actor is constructed.
|
||||
*
|
||||
* @param Blog $this The Blog model.
|
||||
*/
|
||||
\do_action( 'activitypub_construct_model_actor', $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the User manually approves followers.
|
||||
*
|
||||
@ -113,13 +127,25 @@ class Blog extends Actor {
|
||||
* @return string The User ID.
|
||||
*/
|
||||
public function get_id() {
|
||||
return $this->get_url();
|
||||
$id = parent::get_id();
|
||||
|
||||
if ( $id ) {
|
||||
return $id;
|
||||
}
|
||||
|
||||
$permalink = \get_option( 'activitypub_use_permalink_as_id_for_blog', false );
|
||||
|
||||
if ( $permalink ) {
|
||||
return $this->get_url();
|
||||
}
|
||||
|
||||
return \add_query_arg( 'author', $this->_id, \trailingslashit( \home_url() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of the object.
|
||||
*
|
||||
* If the Blog is in "single user" mode, return "Person" insted of "Group".
|
||||
* If the Blog is in "single user" mode, return "Person" instead of "Group".
|
||||
*
|
||||
* @return string The type of the object.
|
||||
*/
|
||||
@ -197,7 +223,11 @@ class Blog extends Actor {
|
||||
/**
|
||||
* Filters the default blog username.
|
||||
*
|
||||
* @param string $host The default username.
|
||||
* This filter allows developers to modify the default username that is
|
||||
* generated for the blog, which by default is the site's host name
|
||||
* without the 'www.' prefix.
|
||||
*
|
||||
* @param string $host The default username (site's host name).
|
||||
*/
|
||||
return apply_filters( 'activitypub_default_blog_username', $host );
|
||||
}
|
||||
@ -220,7 +250,7 @@ class Blog extends Actor {
|
||||
/**
|
||||
* Get the User icon.
|
||||
*
|
||||
* @return array The User icon.
|
||||
* @return string[] The User icon.
|
||||
*/
|
||||
public function get_icon() {
|
||||
// Try site_logo, falling back to site_icon, first.
|
||||
@ -254,7 +284,7 @@ class Blog extends Actor {
|
||||
/**
|
||||
* Get the User-Header-Image.
|
||||
*
|
||||
* @return array|null The User-Header-Image.
|
||||
* @return string[]|null The User-Header-Image.
|
||||
*/
|
||||
public function get_image() {
|
||||
$header_image = get_option( 'activitypub_header_image' );
|
||||
@ -298,7 +328,7 @@ class Blog extends Actor {
|
||||
$time = \time();
|
||||
}
|
||||
|
||||
return \gmdate( 'Y-m-d\TH:i:s\Z', $time );
|
||||
return \gmdate( ACTIVITYPUB_DATE_TIME_RFC3339, $time );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -339,7 +369,7 @@ class Blog extends Actor {
|
||||
/**
|
||||
* Get the public key information.
|
||||
*
|
||||
* @return array The public key.
|
||||
* @return string[] The public key.
|
||||
*/
|
||||
public function get_public_key() {
|
||||
return array(
|
||||
@ -401,12 +431,12 @@ class Blog extends Actor {
|
||||
/**
|
||||
* Returns endpoints.
|
||||
*
|
||||
* @return array|null The endpoints.
|
||||
* @return string[]|null The endpoints.
|
||||
*/
|
||||
public function get_endpoints() {
|
||||
$endpoints = null;
|
||||
|
||||
if ( ACTIVITYPUB_SHARED_INBOX_FEATURE ) {
|
||||
if ( \get_option( 'activitypub_shared_inbox' ) ) {
|
||||
$endpoints = array(
|
||||
'sharedInbox' => get_rest_url_by_path( 'inbox' ),
|
||||
);
|
||||
@ -497,7 +527,7 @@ class Blog extends Actor {
|
||||
*
|
||||
* @see https://docs.joinmastodon.org/spec/activitypub/#Hashtag
|
||||
*
|
||||
* @return array The User - Hashtags.
|
||||
* @return string[] The User - Hashtags.
|
||||
*/
|
||||
public function get_tag() {
|
||||
$hashtags = array();
|
||||
@ -530,4 +560,41 @@ class Blog extends Actor {
|
||||
$extra_fields = Extra_Fields::get_actor_fields( $this->_id );
|
||||
return Extra_Fields::fields_to_attachments( $extra_fields );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the website hosts allowed to credit this blog.
|
||||
*
|
||||
* @return string[]|null The attribution domains or null if not found.
|
||||
*/
|
||||
public function get_attribution_domains() {
|
||||
return get_attribution_domains();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the alsoKnownAs.
|
||||
*
|
||||
* @return string[] The alsoKnownAs.
|
||||
*/
|
||||
public function get_also_known_as() {
|
||||
$also_known_as = array(
|
||||
\add_query_arg( 'author', $this->_id, \home_url( '/' ) ),
|
||||
$this->get_url(),
|
||||
$this->get_alternate_url(),
|
||||
);
|
||||
|
||||
$also_known_as = array_merge( $also_known_as, \get_option( 'activitypub_blog_user_also_known_as', array() ) );
|
||||
|
||||
return array_unique( $also_known_as );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the movedTo.
|
||||
*
|
||||
* @return string The movedTo.
|
||||
*/
|
||||
public function get_moved_to() {
|
||||
$moved_to = \get_option( 'activitypub_blog_user_moved_to' );
|
||||
|
||||
return $moved_to && $moved_to !== $this->get_id() ? $moved_to : null;
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,18 @@ use Activitypub\Collection\Followers;
|
||||
* @author Matthias Pfefferle
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitypub/#follow-activity-inbox
|
||||
*
|
||||
* @method int get__id() Gets the post ID of the follower record.
|
||||
* @method string[]|null get_image() Gets the follower's profile image data.
|
||||
* @method string|null get_inbox() Gets the follower's ActivityPub inbox URL.
|
||||
* @method string[]|null get_endpoints() Gets the follower's ActivityPub endpoints.
|
||||
*
|
||||
* @method Follower set__id( int $id ) Sets the post ID of the follower record.
|
||||
* @method Follower set_id( string $guid ) Sets the follower's GUID.
|
||||
* @method Follower set_name( string $name ) Sets the follower's display name.
|
||||
* @method Follower set_summary( string $summary ) Sets the follower's bio/summary.
|
||||
* @method Follower set_published( string $datetime ) Sets the follower's published datetime in ISO 8601 format.
|
||||
* @method Follower set_updated( string $datetime ) Sets the follower's last updated datetime in ISO 8601 format.
|
||||
*/
|
||||
class Follower extends Actor {
|
||||
/**
|
||||
@ -36,7 +48,7 @@ class Follower extends Actor {
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_errors() {
|
||||
return get_post_meta( $this->_id, 'activitypub_errors', false );
|
||||
return get_post_meta( $this->_id, '_activitypub_errors', false );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,7 +84,7 @@ class Follower extends Actor {
|
||||
* Reset (delete) all errors.
|
||||
*/
|
||||
public function reset_errors() {
|
||||
delete_post_meta( $this->_id, 'activitypub_errors' );
|
||||
delete_post_meta( $this->_id, '_activitypub_errors' );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -216,9 +228,9 @@ class Follower extends Actor {
|
||||
* 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'] = $this->to_json();
|
||||
$meta_input = array();
|
||||
$meta_input['_activitypub_inbox'] = $this->get_shared_inbox();
|
||||
$meta_input['_activitypub_actor_json'] = wp_slash( $this->to_json() );
|
||||
|
||||
return $meta_input;
|
||||
}
|
||||
@ -228,7 +240,7 @@ class Follower extends Actor {
|
||||
*
|
||||
* Sets a fallback to better handle API and HTML outputs.
|
||||
*
|
||||
* @return array The icon.
|
||||
* @return string[] The icon.
|
||||
*/
|
||||
public function get_icon() {
|
||||
if ( isset( $this->icon['url'] ) ) {
|
||||
@ -331,11 +343,18 @@ class Follower extends Actor {
|
||||
* Convert a Custom-Post-Type input to an Activitypub\Model\Follower.
|
||||
*
|
||||
* @param \WP_Post $post The post object.
|
||||
* @return \Activitypub\Activity\Base_Object|WP_Error
|
||||
* @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 );
|
||||
$object = self::init_from_json( $actor_json );
|
||||
$actor_json = get_post_meta( $post->ID, '_activitypub_actor_json', true );
|
||||
|
||||
/* @var Follower $object Follower object. */
|
||||
$object = self::init_from_json( $actor_json );
|
||||
|
||||
if ( is_wp_error( $object ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$object->set__id( $post->ID );
|
||||
$object->set_id( $post->guid );
|
||||
$object->set_name( $post->post_title );
|
||||
|
@ -7,17 +7,20 @@
|
||||
|
||||
namespace Activitypub\Model;
|
||||
|
||||
use WP_Error;
|
||||
use Activitypub\Signature;
|
||||
use Activitypub\Activity\Actor;
|
||||
use Activitypub\Collection\Extra_Fields;
|
||||
use Activitypub\Http;
|
||||
use Activitypub\Signature;
|
||||
|
||||
use function Activitypub\is_blog_public;
|
||||
use function Activitypub\is_user_disabled;
|
||||
use function Activitypub\get_rest_url_by_path;
|
||||
use function Activitypub\get_attribution_domains;
|
||||
use function Activitypub\user_can_activitypub;
|
||||
|
||||
/**
|
||||
* User class.
|
||||
*
|
||||
* @method int get__id() Gets the WordPress user ID.
|
||||
*/
|
||||
class User extends Actor {
|
||||
/**
|
||||
@ -68,6 +71,24 @@ class User extends Actor {
|
||||
*/
|
||||
protected $webfinger;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param int $user_id Optional. The WordPress user ID. Default null.
|
||||
*/
|
||||
public function __construct( $user_id = null ) {
|
||||
if ( $user_id ) {
|
||||
$this->_id = $user_id;
|
||||
|
||||
/**
|
||||
* Fires when a model actor is constructed.
|
||||
*
|
||||
* @param User $this The User object.
|
||||
*/
|
||||
\do_action( 'activitypub_construct_model_actor', $this );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The type of the object.
|
||||
*
|
||||
@ -82,21 +103,18 @@ class User extends Actor {
|
||||
*
|
||||
* @param int $user_id The user ID.
|
||||
*
|
||||
* @return WP_Error|User The User object or WP_Error if user not found.
|
||||
* @return \WP_Error|User The User object or \WP_Error if user not found.
|
||||
*/
|
||||
public static function from_wp_user( $user_id ) {
|
||||
if ( is_user_disabled( $user_id ) ) {
|
||||
return new WP_Error(
|
||||
if ( ! user_can_activitypub( $user_id ) ) {
|
||||
return new \WP_Error(
|
||||
'activitypub_user_not_found',
|
||||
\__( 'User not found', 'activitypub' ),
|
||||
array( 'status' => 404 )
|
||||
);
|
||||
}
|
||||
|
||||
$object = new static();
|
||||
$object->_id = $user_id;
|
||||
|
||||
return $object;
|
||||
return new static( $user_id );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -105,7 +123,19 @@ class User extends Actor {
|
||||
* @return string The user ID.
|
||||
*/
|
||||
public function get_id() {
|
||||
return $this->get_url();
|
||||
$id = parent::get_id();
|
||||
|
||||
if ( $id ) {
|
||||
return $id;
|
||||
}
|
||||
|
||||
$permalink = \get_user_option( 'activitypub_use_permalink_as_id', $this->_id );
|
||||
|
||||
if ( '1' === $permalink ) {
|
||||
return $this->get_url();
|
||||
}
|
||||
|
||||
return \add_query_arg( 'author', $this->_id, \trailingslashit( \home_url() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -114,7 +144,7 @@ class User extends Actor {
|
||||
* @return string The Username.
|
||||
*/
|
||||
public function get_name() {
|
||||
return \esc_attr( \get_the_author_meta( 'display_name', $this->_id ) );
|
||||
return \get_the_author_meta( 'display_name', $this->_id );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -154,17 +184,17 @@ class User extends Actor {
|
||||
* @return string The preferred username.
|
||||
*/
|
||||
public function get_preferred_username() {
|
||||
return \esc_attr( \get_the_author_meta( 'login', $this->_id ) );
|
||||
return \get_the_author_meta( 'login', $this->_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the User icon.
|
||||
*
|
||||
* @return array The User icon.
|
||||
* @return string[] The User icon.
|
||||
*/
|
||||
public function get_icon() {
|
||||
$icon = \get_user_option( 'activitypub_icon', $this->_id );
|
||||
if ( wp_attachment_is_image( $icon ) ) {
|
||||
if ( false !== $icon && wp_attachment_is_image( $icon ) ) {
|
||||
return array(
|
||||
'type' => 'Image',
|
||||
'url' => esc_url( wp_get_attachment_url( $icon ) ),
|
||||
@ -187,7 +217,7 @@ class User extends Actor {
|
||||
/**
|
||||
* Returns the header image.
|
||||
*
|
||||
* @return array|null The header image.
|
||||
* @return string[]|null The header image.
|
||||
*/
|
||||
public function get_image() {
|
||||
$header_image = get_user_option( 'activitypub_header_image', $this->_id );
|
||||
@ -217,13 +247,13 @@ class User extends Actor {
|
||||
* @return false|string The date the user was created.
|
||||
*/
|
||||
public function get_published() {
|
||||
return \gmdate( 'Y-m-d\TH:i:s\Z', \strtotime( \get_the_author_meta( 'registered', $this->_id ) ) );
|
||||
return \gmdate( ACTIVITYPUB_DATE_TIME_RFC3339, \strtotime( \get_the_author_meta( 'registered', $this->_id ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the public key.
|
||||
*
|
||||
* @return array The public key.
|
||||
* @return string[] The public key.
|
||||
*/
|
||||
public function get_public_key() {
|
||||
return array(
|
||||
@ -281,12 +311,12 @@ class User extends Actor {
|
||||
/**
|
||||
* Returns the endpoints.
|
||||
*
|
||||
* @return array|null The endpoints.
|
||||
* @return string[]|null The endpoints.
|
||||
*/
|
||||
public function get_endpoints() {
|
||||
$endpoints = null;
|
||||
|
||||
if ( ACTIVITYPUB_SHARED_INBOX_FEATURE ) {
|
||||
if ( \get_option( 'activitypub_shared_inbox' ) ) {
|
||||
$endpoints = array(
|
||||
'sharedInbox' => get_rest_url_by_path( 'inbox' ),
|
||||
);
|
||||
@ -358,7 +388,7 @@ class User extends Actor {
|
||||
* Update the username.
|
||||
*
|
||||
* @param string $value The new value.
|
||||
* @return int|WP_Error The updated user ID or WP_Error on failure.
|
||||
* @return int|\WP_Error The updated user ID or \WP_Error on failure.
|
||||
*/
|
||||
public function update_name( $value ) {
|
||||
$userdata = array(
|
||||
@ -403,4 +433,42 @@ class User extends Actor {
|
||||
}
|
||||
return \update_user_option( $this->_id, 'activitypub_header_image', $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the website hosts allowed to credit this blog.
|
||||
*
|
||||
* @return string[]|null The attribution domains or null if not found.
|
||||
*/
|
||||
public function get_attribution_domains() {
|
||||
return get_attribution_domains();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the alsoKnownAs.
|
||||
*
|
||||
* @return string[] The alsoKnownAs.
|
||||
*/
|
||||
public function get_also_known_as() {
|
||||
$also_known_as = array(
|
||||
\add_query_arg( 'author', $this->_id, \home_url( '/' ) ),
|
||||
$this->get_url(),
|
||||
$this->get_alternate_url(),
|
||||
);
|
||||
|
||||
// phpcs:ignore Universal.Operators.DisallowShortTernary.Found
|
||||
$also_known_as = array_merge( $also_known_as, \get_user_option( 'activitypub_also_known_as', $this->_id ) ?: array() );
|
||||
|
||||
return array_unique( $also_known_as );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the movedTo.
|
||||
*
|
||||
* @return string The movedTo.
|
||||
*/
|
||||
public function get_moved_to() {
|
||||
$moved_to = \get_user_option( 'activitypub_moved_to', $this->_id );
|
||||
|
||||
return $moved_to && $moved_to !== $this->get_id() ? $moved_to : null;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user