updated plugin ActivityPub version 9.1.0
This commit is contained in:
@ -38,8 +38,10 @@ class Activity extends Base_Object {
|
||||
const JSON_LD_CONTEXT = array(
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
array(
|
||||
'toot' => 'http://joinmastodon.org/ns#',
|
||||
'QuoteRequest' => 'toot:QuoteRequest',
|
||||
'toot' => 'http://joinmastodon.org/ns#',
|
||||
'QuoteRequest' => 'toot:QuoteRequest',
|
||||
'blurhash' => 'toot:blurhash',
|
||||
'FeatureRequest' => 'https://w3id.org/fep/7aa9#FeatureRequest',
|
||||
),
|
||||
);
|
||||
|
||||
@ -70,6 +72,7 @@ class Activity extends Base_Object {
|
||||
'Move',
|
||||
'Offer',
|
||||
'QuoteRequest', // @see https://codeberg.org/fediverse/fep/src/branch/main/fep/044f/fep-044f.md
|
||||
'FeatureRequest', // @see https://w3id.org/fep/7aa9 (FEP-7aa9 draft)
|
||||
'Read',
|
||||
'Reject',
|
||||
'Remove',
|
||||
@ -188,9 +191,9 @@ class Activity extends Base_Object {
|
||||
$object = $data;
|
||||
|
||||
// Convert array to appropriate object type.
|
||||
if ( is_array( $data ) ) {
|
||||
if ( array_is_list( $data ) ) {
|
||||
$object = array_map( array( $this, 'maybe_convert_to_object' ), $data );
|
||||
if ( \is_array( $data ) ) {
|
||||
if ( \array_is_list( $data ) ) {
|
||||
$object = \array_map( array( $this, 'maybe_convert_to_object' ), $data );
|
||||
} else {
|
||||
$object = $this->maybe_convert_to_object( $data );
|
||||
}
|
||||
@ -207,14 +210,14 @@ class Activity extends Base_Object {
|
||||
$object = $this->get_object();
|
||||
|
||||
// Check if `$object` is a URL and use it to generate an ID then.
|
||||
if ( is_string( $object ) && filter_var( $object, FILTER_VALIDATE_URL ) && ! $this->get_id() ) {
|
||||
$this->set( 'id', $object . '#activity-' . strtolower( $this->get_type() ) . '-' . time() );
|
||||
if ( \is_string( $object ) && \filter_var( $object, FILTER_VALIDATE_URL ) && ! $this->get_id() ) {
|
||||
$this->set( 'id', $object . '#activity-' . \strtolower( $this->get_type() ) . '-' . \time() );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if `$object` is an object and copy some properties otherwise do nothing.
|
||||
if ( ! is_object( $object ) ) {
|
||||
if ( ! \is_object( $object ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -246,15 +249,15 @@ class Activity extends Base_Object {
|
||||
}
|
||||
|
||||
if ( $object->get_id() && ! $this->get_id() ) {
|
||||
$id = strtok( $object->get_id(), '#' );
|
||||
$id = \strtok( $object->get_id(), '#' );
|
||||
if ( $object->get_updated() ) {
|
||||
$updated = $object->get_updated();
|
||||
} elseif ( $object->get_published() ) {
|
||||
$updated = $object->get_published();
|
||||
} else {
|
||||
$updated = time();
|
||||
$updated = \time();
|
||||
}
|
||||
$this->set( 'id', $id . '#activity-' . strtolower( $this->get_type() ) . '-' . $updated );
|
||||
$this->set( 'id', $id . '#activity-' . \strtolower( $this->get_type() ) . '-' . $updated );
|
||||
}
|
||||
}
|
||||
|
||||
@ -265,7 +268,7 @@ class Activity extends Base_Object {
|
||||
*/
|
||||
public function get_json_ld_context() {
|
||||
if ( \is_object( $this->object ) ) {
|
||||
$class = get_class( $this->object );
|
||||
$class = \get_class( $this->object );
|
||||
if ( $class && $class::JSON_LD_CONTEXT ) {
|
||||
// Without php 5.6 support this could be just: 'return $this->object::JSON_LD_CONTEXT;'.
|
||||
return $class::JSON_LD_CONTEXT;
|
||||
@ -283,17 +286,17 @@ class Activity extends Base_Object {
|
||||
* @return Activity|Actor|Base_Object|Generic_Object|string|\WP_Error|null The converted object or original data.
|
||||
*/
|
||||
private function maybe_convert_to_object( $data ) {
|
||||
if ( ! is_array( $data ) ) {
|
||||
if ( ! \is_array( $data ) ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$type = $data['type'] ?? null;
|
||||
|
||||
if ( in_array( $type, self::TYPES, true ) ) {
|
||||
if ( \in_array( $type, self::TYPES, true ) ) {
|
||||
$object = self::init_from_array( $data );
|
||||
} elseif ( in_array( $type, Actor::TYPES, true ) ) {
|
||||
} elseif ( \in_array( $type, Actor::TYPES, true ) ) {
|
||||
$object = Actor::init_from_array( $data );
|
||||
} elseif ( in_array( $type, Base_Object::TYPES, true ) ) {
|
||||
} elseif ( \in_array( $type, Base_Object::TYPES, true ) ) {
|
||||
switch ( $type ) {
|
||||
case 'Event':
|
||||
$object = Event::init_from_array( $data );
|
||||
|
||||
@ -74,6 +74,7 @@ class Actor extends Base_Object {
|
||||
'toot' => 'http://joinmastodon.org/ns#',
|
||||
'lemmy' => 'https://join-lemmy.org/ns#',
|
||||
'litepub' => 'http://litepub.social/ns#',
|
||||
'gts' => 'https://gotosocial.org/ns#',
|
||||
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
|
||||
'PropertyValue' => 'schema:PropertyValue',
|
||||
'value' => 'schema:value',
|
||||
@ -107,6 +108,18 @@ class Actor extends Base_Object {
|
||||
'@type' => '@id',
|
||||
'@container' => '@list',
|
||||
),
|
||||
'interactionPolicy' => array(
|
||||
'@id' => 'gts:interactionPolicy',
|
||||
'@type' => '@id',
|
||||
),
|
||||
'canFeature' => array(
|
||||
'@id' => 'https://w3id.org/fep/7aa9#canFeature',
|
||||
'@type' => '@id',
|
||||
),
|
||||
'automaticApproval' => array(
|
||||
'@id' => 'gts:automaticApproval',
|
||||
'@type' => '@id',
|
||||
),
|
||||
'postingRestrictedToMods' => 'lemmy:postingRestrictedToMods',
|
||||
'discoverable' => 'toot:discoverable',
|
||||
'indexable' => 'toot:indexable',
|
||||
|
||||
@ -162,6 +162,8 @@ class Base_Object extends Generic_Object {
|
||||
'@id' => 'gts:always',
|
||||
'@type' => '@id',
|
||||
),
|
||||
'toot' => 'http://joinmastodon.org/ns#',
|
||||
'blurhash' => 'toot:blurhash',
|
||||
),
|
||||
);
|
||||
|
||||
@ -634,7 +636,7 @@ class Base_Object extends Generic_Object {
|
||||
*/
|
||||
public function get( $key ) {
|
||||
if ( ! $this->has( $key ) ) {
|
||||
return new \WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
|
||||
return new \WP_Error( 'invalid_key', \__( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
|
||||
}
|
||||
|
||||
return parent::get( $key );
|
||||
@ -650,7 +652,7 @@ class Base_Object extends Generic_Object {
|
||||
*/
|
||||
public function set( $key, $value ) {
|
||||
if ( ! $this->has( $key ) ) {
|
||||
return new \WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
|
||||
return new \WP_Error( 'invalid_key', \__( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
|
||||
}
|
||||
|
||||
return parent::set( $key, $value );
|
||||
@ -666,7 +668,7 @@ class Base_Object extends Generic_Object {
|
||||
*/
|
||||
public function add( $key, $value ) {
|
||||
if ( ! $this->has( $key ) ) {
|
||||
return new \WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
|
||||
return new \WP_Error( 'invalid_key', \__( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
|
||||
}
|
||||
|
||||
return parent::add( $key, $value );
|
||||
|
||||
@ -99,7 +99,7 @@ class Generic_Object {
|
||||
* @return mixed The value.
|
||||
*/
|
||||
public function get( $key ) {
|
||||
return call_user_func( array( $this, 'get_' . $key ) );
|
||||
return \call_user_func( array( $this, 'get_' . $key ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -133,19 +133,19 @@ class Generic_Object {
|
||||
$this->$key = array();
|
||||
}
|
||||
|
||||
if ( is_string( $this->$key ) ) {
|
||||
if ( \is_string( $this->$key ) ) {
|
||||
$this->$key = array( $this->$key );
|
||||
}
|
||||
|
||||
$attributes = $this->$key;
|
||||
|
||||
if ( is_array( $value ) ) {
|
||||
$attributes = array_merge( $attributes, $value );
|
||||
if ( \is_array( $value ) ) {
|
||||
$attributes = \array_merge( $attributes, $value );
|
||||
} else {
|
||||
$attributes[] = $value;
|
||||
}
|
||||
|
||||
$this->$key = array_unique( $attributes );
|
||||
$this->$key = \array_unique( $attributes );
|
||||
|
||||
return $this->$key;
|
||||
}
|
||||
@ -158,7 +158,7 @@ class Generic_Object {
|
||||
* @return boolean True if the object has the key.
|
||||
*/
|
||||
public function has( $key ) {
|
||||
return property_exists( $this, $key );
|
||||
return \property_exists( $this, $key );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -171,8 +171,8 @@ class Generic_Object {
|
||||
public static function init_from_json( $json ) {
|
||||
$array = \json_decode( $json, true );
|
||||
|
||||
if ( ! is_array( $array ) ) {
|
||||
return new \WP_Error( 'invalid_json', __( 'Invalid JSON', 'activitypub' ), array( 'status' => 400 ) );
|
||||
if ( ! \is_array( $array ) ) {
|
||||
return new \WP_Error( 'invalid_json', \__( 'Invalid JSON', 'activitypub' ), array( 'status' => 400 ) );
|
||||
}
|
||||
|
||||
return self::init_from_array( $array );
|
||||
@ -186,8 +186,8 @@ class Generic_Object {
|
||||
* @return static|\WP_Error An Object built from the input array or WP_Error when it's not an array.
|
||||
*/
|
||||
public static function init_from_array( $data ) {
|
||||
if ( ! is_array( $data ) ) {
|
||||
return new \WP_Error( 'invalid_array', __( 'Invalid array', 'activitypub' ), array( 'status' => 400 ) );
|
||||
if ( ! \is_array( $data ) ) {
|
||||
return new \WP_Error( 'invalid_array', \__( 'Invalid array', 'activitypub' ), array( 'status' => 400 ) );
|
||||
}
|
||||
|
||||
$object = new static();
|
||||
@ -209,7 +209,7 @@ class Generic_Object {
|
||||
$key = camel_to_snake_case( $key );
|
||||
}
|
||||
|
||||
call_user_func( array( $this, 'set_' . $key ), $value );
|
||||
\call_user_func( array( $this, 'set_' . $key ), $value );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -244,7 +244,7 @@ class Generic_Object {
|
||||
*/
|
||||
public function to_array( $include_json_ld_context = true, $include_blind_audience = false ) {
|
||||
$array = array();
|
||||
$vars = get_object_vars( $this );
|
||||
$vars = \get_object_vars( $this );
|
||||
|
||||
foreach ( $vars as $key => $value ) {
|
||||
if ( \is_wp_error( $value ) ) {
|
||||
@ -252,20 +252,20 @@ class Generic_Object {
|
||||
}
|
||||
|
||||
// Ignore all _prefixed keys.
|
||||
if ( '_' === substr( $key, 0, 1 ) ) {
|
||||
if ( '_' === \substr( $key, 0, 1 ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If value is empty, try to get it from a getter.
|
||||
if ( ! $value ) {
|
||||
$value = call_user_func( array( $this, 'get_' . $key ) );
|
||||
$value = \call_user_func( array( $this, 'get_' . $key ) );
|
||||
}
|
||||
|
||||
if ( is_object( $value ) ) {
|
||||
if ( \is_object( $value ) ) {
|
||||
$value = $value->to_array( false, $include_blind_audience );
|
||||
}
|
||||
|
||||
if ( is_array( $value ) && $this->is_namespaced( $key ) ) {
|
||||
if ( \is_array( $value ) && $this->is_namespaced( $key ) ) {
|
||||
foreach ( $value as $sub_key => $sub_value ) {
|
||||
$array[ snake_to_camel_case( $key ) . ':' . snake_to_camel_case( $sub_key ) ] = $sub_value;
|
||||
}
|
||||
@ -276,11 +276,11 @@ class Generic_Object {
|
||||
|
||||
if ( $include_json_ld_context ) {
|
||||
// Get JsonLD context and move it to '@context' at the top.
|
||||
$array = array_merge( array( '@context' => $this->get_json_ld_context() ), $array );
|
||||
$array = \array_merge( array( '@context' => $this->get_json_ld_context() ), $array );
|
||||
}
|
||||
|
||||
$class = new \ReflectionClass( $this );
|
||||
$class = strtolower( $class->getShortName() );
|
||||
$class = \strtolower( $class->getShortName() );
|
||||
|
||||
/**
|
||||
* Filter the array of the ActivityPub object.
|
||||
@ -371,7 +371,7 @@ class Generic_Object {
|
||||
$namespaces = array();
|
||||
|
||||
foreach ( static::JSON_LD_CONTEXT as $context ) {
|
||||
if ( is_array( $context ) ) {
|
||||
if ( \is_array( $context ) ) {
|
||||
$namespaces = \array_merge( $namespaces, $context );
|
||||
}
|
||||
}
|
||||
|
||||
@ -301,10 +301,10 @@ class Event extends Base_Object {
|
||||
* @return Event
|
||||
*/
|
||||
public function set_timezone( $timezone ) {
|
||||
if ( in_array( $timezone, timezone_identifiers_list(), true ) ) {
|
||||
if ( \in_array( $timezone, \timezone_identifiers_list(), true ) ) {
|
||||
$this->timezone = $timezone;
|
||||
} else {
|
||||
$this->timezone = wp_timezone_string();
|
||||
$this->timezone = \wp_timezone_string();
|
||||
}
|
||||
|
||||
return $this;
|
||||
@ -318,11 +318,11 @@ class Event extends Base_Object {
|
||||
* @return Event
|
||||
*/
|
||||
public function set_replies_moderation_option( $type ) {
|
||||
if ( in_array( $type, self::REPLIES_MODERATION_OPTION_TYPES, true ) ) {
|
||||
if ( \in_array( $type, self::REPLIES_MODERATION_OPTION_TYPES, true ) ) {
|
||||
$this->replies_moderation_option = $type;
|
||||
$this->comments_enabled = ( 'allow_all' === $type ) ? true : false;
|
||||
} else {
|
||||
_doing_it_wrong(
|
||||
\_doing_it_wrong(
|
||||
__METHOD__,
|
||||
'The replies moderation option must be either allow_all or closed.',
|
||||
'<version_placeholder>'
|
||||
@ -340,11 +340,11 @@ class Event extends Base_Object {
|
||||
* @return Event
|
||||
*/
|
||||
public function set_comments_enabled( $comments_enabled ) {
|
||||
if ( is_bool( $comments_enabled ) ) {
|
||||
if ( \is_bool( $comments_enabled ) ) {
|
||||
$this->comments_enabled = $comments_enabled;
|
||||
$this->replies_moderation_option = $comments_enabled ? 'allow_all' : 'closed';
|
||||
} else {
|
||||
_doing_it_wrong(
|
||||
\_doing_it_wrong(
|
||||
__METHOD__,
|
||||
'The commentsEnabled must be boolean.',
|
||||
'<version_placeholder>'
|
||||
@ -362,10 +362,10 @@ class Event extends Base_Object {
|
||||
* @return Event
|
||||
*/
|
||||
public function set_status( $status ) {
|
||||
if ( in_array( $status, self::ICAL_EVENT_STATUS_TYPES, true ) ) {
|
||||
if ( \in_array( $status, self::ICAL_EVENT_STATUS_TYPES, true ) ) {
|
||||
$this->status = $status;
|
||||
} else {
|
||||
_doing_it_wrong(
|
||||
\_doing_it_wrong(
|
||||
__METHOD__,
|
||||
'The status of the event must be a VEVENT iCal status.',
|
||||
'<version_placeholder>'
|
||||
@ -387,7 +387,7 @@ class Event extends Base_Object {
|
||||
*/
|
||||
public function set_category( $category, $mobilizon_compatibility = true ) {
|
||||
if ( $mobilizon_compatibility ) {
|
||||
$this->category = in_array( $category, self::DEFAULT_EVENT_CATEGORIES, true ) ? $category : 'MEETING';
|
||||
$this->category = \in_array( $category, self::DEFAULT_EVENT_CATEGORIES, true ) ? $category : 'MEETING';
|
||||
} else {
|
||||
$this->category = $category;
|
||||
}
|
||||
@ -405,7 +405,7 @@ class Event extends Base_Object {
|
||||
* @return Event
|
||||
*/
|
||||
public function set_external_participation_url( $url ) {
|
||||
if ( preg_match( '/^https?:\/\/.*/i', $url ) ) {
|
||||
if ( \preg_match( '/^https?:\/\/.*/i', $url ) ) {
|
||||
$this->external_participation_url = $url;
|
||||
$this->join_mode = 'external';
|
||||
}
|
||||
|
||||
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* Feature_Authorization is an implementation of the FeatureAuthorization activity type,
|
||||
* as defined in FEP-7aa9 (https://w3id.org/fep/7aa9).
|
||||
*
|
||||
* This class represents a FeatureAuthorization activity for ActivityPub implementations.
|
||||
*
|
||||
* @package Activitypub
|
||||
*/
|
||||
|
||||
namespace Activitypub\Activity\Extended_Object;
|
||||
|
||||
use Activitypub\Activity\Base_Object;
|
||||
|
||||
/**
|
||||
* Class representing a FeatureAuthorization activity.
|
||||
*
|
||||
* @see https://w3id.org/fep/7aa9
|
||||
*
|
||||
* @since 9.0.0
|
||||
*
|
||||
* @method Base_Object|string|array|null get_interacting_object() Gets the interacting object property of the object.
|
||||
* @method Base_Object|string|array|null get_interaction_target() Gets the interaction target property of the object.
|
||||
*
|
||||
* @method Feature_Authorization set_interacting_object( string|array|Base_Object|null $data ) Sets the interacting object property of the object.
|
||||
* @method Feature_Authorization set_interaction_target( string|array|Base_Object|null $data ) Sets the interaction target property of the object.
|
||||
*/
|
||||
class Feature_Authorization extends Base_Object {
|
||||
/**
|
||||
* The JSON-LD context for the object.
|
||||
*
|
||||
* Intentionally minimal: stamps are always served standalone at their own
|
||||
* URL, so we ship only the vocabulary the stamp document itself uses.
|
||||
* Mirrors the Quote_Authorization (FEP-044f) approach.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
const JSON_LD_CONTEXT = array(
|
||||
'https://www.w3.org/ns/activitystreams',
|
||||
array(
|
||||
'FeatureAuthorization' => 'https://w3id.org/fep/7aa9#FeatureAuthorization',
|
||||
'gts' => 'https://gotosocial.org/ns#',
|
||||
'interactingObject' => array(
|
||||
'@id' => 'gts:interactingObject',
|
||||
'@type' => '@id',
|
||||
),
|
||||
'interactionTarget' => array(
|
||||
'@id' => 'gts:interactionTarget',
|
||||
'@type' => '@id',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* The type of the object.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $type = 'FeatureAuthorization';
|
||||
|
||||
/**
|
||||
* The object that is being interacted with.
|
||||
*
|
||||
* @var Base_Object|string|array|null
|
||||
*/
|
||||
protected $interacting_object;
|
||||
|
||||
/**
|
||||
* The target of the interaction.
|
||||
*
|
||||
* @var Base_Object|string|array|null
|
||||
*/
|
||||
protected $interaction_target;
|
||||
}
|
||||
@ -106,10 +106,10 @@ class Place extends Base_Object {
|
||||
* @param array|string $address The address of the place.
|
||||
*/
|
||||
public function set_address( $address ) {
|
||||
if ( is_string( $address ) || is_array( $address ) ) {
|
||||
if ( \is_string( $address ) || \is_array( $address ) ) {
|
||||
$this->address = $address;
|
||||
} else {
|
||||
_doing_it_wrong(
|
||||
\_doing_it_wrong(
|
||||
__METHOD__,
|
||||
'The address must be either a string or an array like schema.org/PostalAddress.',
|
||||
'<version_placeholder>'
|
||||
|
||||
Reference in New Issue
Block a user