updated plugin ActivityPub version 9.1.0
This commit is contained in:
@ -16,6 +16,7 @@ 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;
|
||||
use function Activitypub\site_icon;
|
||||
|
||||
/**
|
||||
* Blog class.
|
||||
@ -93,7 +94,7 @@ class Blog extends Actor {
|
||||
$permalink = \get_option( 'activitypub_use_permalink_as_id_for_blog', false );
|
||||
|
||||
if ( $permalink ) {
|
||||
return \esc_url( \home_url( '/@' . $this->get_preferred_username() ) );
|
||||
return \esc_url_raw( \home_url( '/@' . $this->get_preferred_username() ) );
|
||||
}
|
||||
|
||||
return \add_query_arg( 'author', $this->_id, \home_url( '/' ) );
|
||||
@ -169,7 +170,7 @@ class Blog extends Actor {
|
||||
* @return string The User-Url.
|
||||
*/
|
||||
public function get_alternate_url() {
|
||||
return \esc_url( \trailingslashit( get_home_url() ) );
|
||||
return \esc_url_raw( \trailingslashit( \get_home_url() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -191,7 +192,7 @@ class Blog extends Actor {
|
||||
*
|
||||
* @param string $host The default username (site's host name).
|
||||
*/
|
||||
return apply_filters( 'activitypub_default_blog_username', $host );
|
||||
return \apply_filters( 'activitypub_default_blog_username', $host );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -215,32 +216,7 @@ class Blog extends Actor {
|
||||
* @return string[] The User icon.
|
||||
*/
|
||||
public function get_icon() {
|
||||
// Try site_logo, falling back to site_icon, first.
|
||||
$icon_id = get_option( 'site_icon' );
|
||||
|
||||
// Try custom logo second.
|
||||
if ( ! $icon_id ) {
|
||||
$icon_id = get_theme_mod( 'custom_logo' );
|
||||
}
|
||||
|
||||
$icon_url = false;
|
||||
|
||||
if ( $icon_id ) {
|
||||
$icon = wp_get_attachment_image_src( $icon_id, 'full' );
|
||||
if ( $icon ) {
|
||||
$icon_url = $icon[0];
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $icon_url ) {
|
||||
// Fallback to default icon.
|
||||
$icon_url = plugins_url( '/assets/img/wp-logo.png', ACTIVITYPUB_PLUGIN_FILE );
|
||||
}
|
||||
|
||||
return array(
|
||||
'type' => 'Image',
|
||||
'url' => esc_url( $icon_url ),
|
||||
);
|
||||
return site_icon();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -249,7 +225,7 @@ class Blog extends Actor {
|
||||
* @return string[]|null The User-Header-Image.
|
||||
*/
|
||||
public function get_image() {
|
||||
$header_image = get_option( 'activitypub_header_image' );
|
||||
$header_image = \get_option( 'activitypub_header_image' );
|
||||
$image_url = null;
|
||||
|
||||
if ( $header_image ) {
|
||||
@ -263,7 +239,7 @@ class Blog extends Actor {
|
||||
if ( $image_url ) {
|
||||
return array(
|
||||
'type' => 'Image',
|
||||
'url' => esc_url( $image_url ),
|
||||
'url' => \esc_url_raw( $image_url ),
|
||||
);
|
||||
}
|
||||
|
||||
@ -383,7 +359,7 @@ class Blog extends Actor {
|
||||
* @return string The Inbox-Endpoint.
|
||||
*/
|
||||
public function get_inbox() {
|
||||
return get_rest_url_by_path( sprintf( 'actors/%d/inbox', $this->get__id() ) );
|
||||
return get_rest_url_by_path( \sprintf( 'actors/%d/inbox', $this->get__id() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -392,7 +368,7 @@ class Blog extends Actor {
|
||||
* @return string The Outbox-Endpoint.
|
||||
*/
|
||||
public function get_outbox() {
|
||||
return get_rest_url_by_path( sprintf( 'actors/%d/outbox', $this->get__id() ) );
|
||||
return get_rest_url_by_path( \sprintf( 'actors/%d/outbox', $this->get__id() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -401,7 +377,7 @@ class Blog extends Actor {
|
||||
* @return string The Followers-Endpoint.
|
||||
*/
|
||||
public function get_followers() {
|
||||
return get_rest_url_by_path( sprintf( 'actors/%d/followers', $this->get__id() ) );
|
||||
return get_rest_url_by_path( \sprintf( 'actors/%d/followers', $this->get__id() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -410,7 +386,7 @@ class Blog extends Actor {
|
||||
* @return string The Following-Endpoint.
|
||||
*/
|
||||
public function get_following() {
|
||||
return get_rest_url_by_path( sprintf( 'actors/%d/following', $this->get__id() ) );
|
||||
return get_rest_url_by_path( \sprintf( 'actors/%d/following', $this->get__id() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -419,7 +395,7 @@ class Blog extends Actor {
|
||||
* @return string[]|null The endpoints.
|
||||
*/
|
||||
public function get_endpoints() {
|
||||
return array(
|
||||
$endpoints = array(
|
||||
'sharedInbox' => get_rest_url_by_path( 'inbox' ),
|
||||
'oauthAuthorizationEndpoint' => get_rest_url_by_path( 'oauth/authorize' ),
|
||||
'oauthTokenEndpoint' => get_rest_url_by_path( 'oauth/token' ),
|
||||
@ -427,6 +403,16 @@ class Blog extends Actor {
|
||||
'proxyUrl' => get_rest_url_by_path( 'proxy' ),
|
||||
'proxyEventStream' => get_rest_url_by_path( 'proxy/stream' ),
|
||||
);
|
||||
|
||||
if ( \get_option( 'activitypub_api', false ) ) {
|
||||
/*
|
||||
* RFC 6570 template. add_query_arg() picks the ?/& separator (plain permalinks already
|
||||
* carry a query string) and does not encode values, so the {q} placeholder stays intact.
|
||||
*/
|
||||
$endpoints['actorAutocomplete'] = \add_query_arg( 'q', '{q}', get_rest_url_by_path( 'actors/autocomplete' ) );
|
||||
}
|
||||
|
||||
return $endpoints;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -446,7 +432,7 @@ class Blog extends Actor {
|
||||
* @return string The Liked endpoint.
|
||||
*/
|
||||
public function get_liked() {
|
||||
return get_rest_url_by_path( sprintf( 'actors/%d/liked', $this->get__id() ) );
|
||||
return get_rest_url_by_path( \sprintf( 'actors/%d/liked', $this->get__id() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -455,7 +441,7 @@ class Blog extends Actor {
|
||||
* @return string The Featured-Endpoint.
|
||||
*/
|
||||
public function get_featured() {
|
||||
return get_rest_url_by_path( sprintf( 'actors/%d/collections/featured', $this->get__id() ) );
|
||||
return get_rest_url_by_path( \sprintf( 'actors/%d/collections/featured', $this->get__id() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -464,7 +450,7 @@ class Blog extends Actor {
|
||||
* @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() ) );
|
||||
return get_rest_url_by_path( \sprintf( 'actors/%d/collections/tags', $this->get__id() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -507,7 +493,7 @@ class Blog extends Actor {
|
||||
* @return bool True if the attribute was updated, false otherwise.
|
||||
*/
|
||||
public function update_icon( $value ) {
|
||||
if ( ! wp_attachment_is_image( $value ) ) {
|
||||
if ( ! \wp_attachment_is_image( $value ) ) {
|
||||
return false;
|
||||
}
|
||||
return \update_option( 'site_icon', $value );
|
||||
@ -520,7 +506,7 @@ class Blog extends Actor {
|
||||
* @return bool True if the attribute was updated, false otherwise.
|
||||
*/
|
||||
public function update_header( $value ) {
|
||||
if ( ! wp_attachment_is_image( $value ) ) {
|
||||
if ( ! \wp_attachment_is_image( $value ) ) {
|
||||
return false;
|
||||
}
|
||||
return \update_option( 'activitypub_header_image', $value );
|
||||
@ -542,7 +528,7 @@ class Blog extends Actor {
|
||||
'number' => 10,
|
||||
);
|
||||
|
||||
$tags = get_tags( $args );
|
||||
$tags = \get_tags( $args );
|
||||
|
||||
foreach ( $tags as $tag ) {
|
||||
$hashtags[] = array(
|
||||
@ -586,9 +572,9 @@ class Blog extends Actor {
|
||||
$this->get_alternate_url(),
|
||||
);
|
||||
|
||||
$also_known_as = array_merge( $also_known_as, \get_option( 'activitypub_blog_user_also_known_as', array() ) );
|
||||
$also_known_as = \array_merge( $also_known_as, \get_option( 'activitypub_blog_user_also_known_as', array() ) );
|
||||
|
||||
return array_unique( $also_known_as );
|
||||
return \array_unique( $also_known_as );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -601,4 +587,50 @@ class Blog extends Actor {
|
||||
|
||||
return $moved_to && $moved_to !== $this->get_id() ? $moved_to : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the actor-level interaction policy.
|
||||
*
|
||||
* Overrides the magic property accessor on Base_Object so that we always
|
||||
* compute the policy from the current site setting rather than returning a
|
||||
* cached property value. Currently only emits `canFeature` (FEP-7aa9).
|
||||
* Driven by the site option `activitypub_default_feature_policy` and
|
||||
* defaults to denying all featured-collection requests, in line with
|
||||
* FEP-7aa9's "absence of policy = no consent" rule.
|
||||
*
|
||||
* @see https://w3id.org/fep/7aa9
|
||||
*
|
||||
* @since 9.0.0
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_interaction_policy() {
|
||||
$policy = array( 'canFeature' => $this->build_can_feature_policy() );
|
||||
|
||||
// Merge with an explicitly set interaction policy, if any.
|
||||
if ( $this->interaction_policy ) {
|
||||
$policy = \array_merge( (array) $this->interaction_policy, $policy );
|
||||
}
|
||||
|
||||
return $policy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the `canFeature` policy array from the site option.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function build_can_feature_policy() {
|
||||
$policy = \get_option( 'activitypub_default_feature_policy', ACTIVITYPUB_INTERACTION_POLICY_ME );
|
||||
|
||||
switch ( $policy ) {
|
||||
case ACTIVITYPUB_INTERACTION_POLICY_ANYONE:
|
||||
return array( 'automaticApproval' => array( 'https://www.w3.org/ns/activitystreams#Public' ) );
|
||||
case ACTIVITYPUB_INTERACTION_POLICY_FOLLOWERS:
|
||||
return array( 'automaticApproval' => array( $this->get_followers() ) );
|
||||
case ACTIVITYPUB_INTERACTION_POLICY_ME:
|
||||
default:
|
||||
return array( 'automaticApproval' => array( $this->get_id() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user