updated plugin ActivityPub version 9.1.0

This commit is contained in:
2026-07-28 15:03:10 +00:00
committed by Gitium
parent bf428f0e45
commit ff806e1811
217 changed files with 6098 additions and 3025 deletions

View File

@ -140,9 +140,9 @@ class User extends Actor {
* @return string The User description.
*/
public function get_summary() {
$description = get_user_option( 'activitypub_description', $this->_id );
$description = \get_user_option( 'activitypub_description', $this->_id );
if ( empty( $description ) ) {
$description = get_user_meta( $this->_id, 'description', true );
$description = \get_user_meta( $this->_id, 'description', true );
}
return \wpautop( \wp_kses( $description, 'default' ) );
}
@ -153,7 +153,7 @@ class User extends Actor {
* @return string The User url.
*/
public function get_url() {
return \esc_url( \get_author_posts_url( $this->_id ) );
return \esc_url_raw( \get_author_posts_url( $this->_id ) );
}
/**
@ -162,7 +162,7 @@ class User extends Actor {
* @return string The User URL with @-Prefix for the username.
*/
public function get_alternate_url() {
return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_preferred_username() );
return \esc_url_raw( \trailingslashit( \get_home_url() ) . '@' . $this->get_preferred_username() );
}
/**
@ -188,14 +188,14 @@ class User extends Actor {
*/
public function get_icon() {
$icon = \get_user_option( 'activitypub_icon', $this->_id );
if ( false !== $icon && 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 ) ),
'url' => \esc_url_raw( \wp_get_attachment_url( $icon ) ),
);
}
$icon = \esc_url(
$icon = \esc_url_raw(
\get_avatar_url(
$this->_id,
array( 'size' => 120 )
@ -214,7 +214,7 @@ class User extends Actor {
* @return string[]|null The header image.
*/
public function get_image() {
$header_image = get_user_option( 'activitypub_header_image', $this->_id );
$header_image = \get_user_option( 'activitypub_header_image', $this->_id );
$image_url = null;
if ( ! $header_image && \has_header_image() ) {
@ -228,7 +228,7 @@ class User extends Actor {
if ( $image_url ) {
return array(
'type' => 'Image',
'url' => esc_url( $image_url ),
'url' => \esc_url_raw( $image_url ),
);
}
@ -263,7 +263,7 @@ class User 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() ) );
}
/**
@ -272,7 +272,7 @@ class User 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() ) );
}
/**
@ -281,7 +281,7 @@ class User 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() ) );
}
/**
@ -290,7 +290,7 @@ class User 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() ) );
}
/**
@ -301,7 +301,7 @@ class User 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() ) );
}
/**
@ -310,7 +310,7 @@ class User 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() ) );
}
/**
@ -319,7 +319,7 @@ class User 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() ) );
}
/**
@ -328,7 +328,7 @@ class User 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' ),
@ -336,6 +336,16 @@ class User 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;
}
/**
@ -428,10 +438,10 @@ class User 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_user_option( $this->_id, 'activitypub_icon', $value );
return \update_user_option( $this->_id, 'activitypub_icon', $value );
}
/**
@ -441,7 +451,7 @@ class User 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_user_option( $this->_id, 'activitypub_header_image', $value );
@ -468,9 +478,9 @@ class User extends Actor {
$this->get_alternate_url(),
);
$also_known_as = array_merge( $also_known_as, \get_user_option( 'activitypub_also_known_as', $this->_id ) ?: array() );
$also_known_as = \array_merge( $also_known_as, \get_user_option( 'activitypub_also_known_as', $this->_id ) ?: array() );
return array_unique( $also_known_as );
return \array_unique( $also_known_as );
}
/**
@ -483,4 +493,50 @@ class User 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() ) );
}
}
}