updated plugin ActivityPub version 8.3.0
This commit is contained in:
@ -10,14 +10,12 @@ namespace Activitypub\Model;
|
||||
use Activitypub\Activity\Actor;
|
||||
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;
|
||||
use function Activitypub\get_rest_url_by_path;
|
||||
use function Activitypub\is_blog_public;
|
||||
use function Activitypub\is_single_user;
|
||||
|
||||
/**
|
||||
* Blog class.
|
||||
@ -25,29 +23,6 @@ use function Activitypub\get_attribution_domains;
|
||||
* @method int get__id() Gets the internal user ID for the blog (always returns BLOG_USER_ID).
|
||||
*/
|
||||
class Blog extends Actor {
|
||||
/**
|
||||
* The Featured-Posts.
|
||||
*
|
||||
* @see https://docs.joinmastodon.org/spec/activitypub/#featured
|
||||
*
|
||||
* @context {
|
||||
* "@id": "http://joinmastodon.org/ns#featured",
|
||||
* "@type": "@id"
|
||||
* }
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $featured;
|
||||
|
||||
/**
|
||||
* Moderators endpoint.
|
||||
*
|
||||
* @see https://join-lemmy.org/docs/contributors/05-federation.html
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $moderators;
|
||||
|
||||
/**
|
||||
* The User-ID
|
||||
*
|
||||
@ -56,40 +31,22 @@ class Blog extends Actor {
|
||||
protected $_id = Actors::BLOG_USER_ID; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore
|
||||
|
||||
/**
|
||||
* If the User is indexable.
|
||||
* The generator of the object.
|
||||
*
|
||||
* @context http://joinmastodon.org/ns#indexable
|
||||
* @see https://www.w3.org/TR/activitypub/#generator
|
||||
* @see https://codeberg.org/fediverse/fep/src/branch/main/fep/844e/fep-844e.md#discovery-through-an-actor
|
||||
*
|
||||
* @var boolean
|
||||
* @var array
|
||||
*/
|
||||
protected $indexable;
|
||||
|
||||
/**
|
||||
* The WebFinger Resource.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $webfinger;
|
||||
|
||||
/**
|
||||
* Whether the User is discoverable.
|
||||
*
|
||||
* @see https://docs.joinmastodon.org/spec/activitypub/#discoverable
|
||||
*
|
||||
* @context http://joinmastodon.org/ns#discoverable
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $discoverable;
|
||||
|
||||
/**
|
||||
* Restrict posting to mods.
|
||||
*
|
||||
* @see https://join-lemmy.org/docs/contributors/05-federation.html
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $posting_restricted_to_mods;
|
||||
protected $generator = array(
|
||||
'type' => 'Application',
|
||||
'implements' => array(
|
||||
array(
|
||||
'href' => 'https://datatracker.ietf.org/doc/html/rfc9421',
|
||||
'name' => 'RFC-9421: HTTP Message Signatures',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@ -136,20 +93,25 @@ class Blog extends Actor {
|
||||
$permalink = \get_option( 'activitypub_use_permalink_as_id_for_blog', false );
|
||||
|
||||
if ( $permalink ) {
|
||||
return $this->get_url();
|
||||
return \esc_url( \home_url( '/@' . $this->get_preferred_username() ) );
|
||||
}
|
||||
|
||||
return \add_query_arg( 'author', $this->_id, \trailingslashit( \home_url() ) );
|
||||
return \add_query_arg( 'author', $this->_id, \home_url( '/' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of the object.
|
||||
*
|
||||
* If relay mode is enabled, return "Service".
|
||||
* If the Blog is in "single user" mode, return "Person" instead of "Group".
|
||||
*
|
||||
* @return string The type of the object.
|
||||
*/
|
||||
public function get_type() {
|
||||
if ( \get_option( 'activitypub_relay_mode', false ) ) {
|
||||
return 'Service';
|
||||
}
|
||||
|
||||
if ( is_single_user() ) {
|
||||
return 'Person';
|
||||
} else {
|
||||
@ -198,7 +160,7 @@ class Blog extends Actor {
|
||||
* @return string The User url.
|
||||
*/
|
||||
public function get_url() {
|
||||
return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_preferred_username() );
|
||||
return \get_bloginfo( 'url' );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -314,21 +276,44 @@ class Blog extends Actor {
|
||||
* @return string The published date.
|
||||
*/
|
||||
public function get_published() {
|
||||
$first_post = new WP_Query(
|
||||
$published = \get_option( 'activitypub_blog_published' );
|
||||
|
||||
if ( $published ) {
|
||||
return $published;
|
||||
}
|
||||
|
||||
// Backfill from the first federated post.
|
||||
$first_federated = new \WP_Query(
|
||||
array(
|
||||
'orderby' => 'date',
|
||||
'order' => 'ASC',
|
||||
'number' => 1,
|
||||
'orderby' => 'date',
|
||||
'order' => 'ASC',
|
||||
'posts_per_page' => 1,
|
||||
'post_status' => 'publish',
|
||||
'no_found_rows' => true,
|
||||
'ignore_sticky_posts' => true,
|
||||
'update_post_meta_cache' => false,
|
||||
'update_post_term_cache' => false,
|
||||
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => 'activitypub_status',
|
||||
'compare' => 'EXISTS',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
if ( ! empty( $first_post->posts[0] ) ) {
|
||||
$time = \strtotime( $first_post->posts[0]->post_date_gmt );
|
||||
if ( ! empty( $first_federated->posts[0] ) ) {
|
||||
$time = \strtotime( $first_federated->posts[0]->post_date_gmt );
|
||||
} else {
|
||||
$time = \time();
|
||||
}
|
||||
|
||||
return \gmdate( ACTIVITYPUB_DATE_TIME_RFC3339, $time );
|
||||
$published = \gmdate( ACTIVITYPUB_DATE_TIME_RFC3339, $time );
|
||||
|
||||
\update_option( 'activitypub_blog_published', $published, false );
|
||||
|
||||
return $published;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -375,7 +360,7 @@ class Blog extends Actor {
|
||||
return array(
|
||||
'id' => $this->get_id() . '#main-key',
|
||||
'owner' => $this->get_id(),
|
||||
'publicKeyPem' => Signature::get_public_key_for( $this->get__id() ),
|
||||
'publicKeyPem' => Actors::get_public_key( $this->get__id() ),
|
||||
);
|
||||
}
|
||||
|
||||
@ -434,15 +419,14 @@ class Blog extends Actor {
|
||||
* @return string[]|null The endpoints.
|
||||
*/
|
||||
public function get_endpoints() {
|
||||
$endpoints = null;
|
||||
|
||||
if ( \get_option( 'activitypub_shared_inbox' ) ) {
|
||||
$endpoints = array(
|
||||
'sharedInbox' => get_rest_url_by_path( 'inbox' ),
|
||||
);
|
||||
}
|
||||
|
||||
return $endpoints;
|
||||
return array(
|
||||
'sharedInbox' => get_rest_url_by_path( 'inbox' ),
|
||||
'oauthAuthorizationEndpoint' => get_rest_url_by_path( 'oauth/authorize' ),
|
||||
'oauthTokenEndpoint' => get_rest_url_by_path( 'oauth/token' ),
|
||||
'oauthRegistrationEndpoint' => get_rest_url_by_path( 'oauth/clients' ),
|
||||
'proxyUrl' => get_rest_url_by_path( 'proxy' ),
|
||||
'proxyEventStream' => get_rest_url_by_path( 'proxy/stream' ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -454,6 +438,17 @@ class Blog extends Actor {
|
||||
return $this->get_preferred_username() . '@' . \wp_parse_url( \home_url(), \PHP_URL_HOST );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Liked API endpoint.
|
||||
*
|
||||
* @since 8.1.0
|
||||
*
|
||||
* @return string The Liked endpoint.
|
||||
*/
|
||||
public function get_liked() {
|
||||
return get_rest_url_by_path( sprintf( 'actors/%d/liked', $this->get__id() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Featured-API-Endpoint.
|
||||
*
|
||||
@ -463,6 +458,15 @@ class Blog extends Actor {
|
||||
return get_rest_url_by_path( sprintf( 'actors/%d/collections/featured', $this->get__id() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Featured-Tags-API-Endpoint.
|
||||
*
|
||||
* @return string The Featured-Tags-Endpoint.
|
||||
*/
|
||||
public function get_featured_tags() {
|
||||
return get_rest_url_by_path( sprintf( 'actors/%d/collections/tags', $this->get__id() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the site is indexable.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user