2023-11-27 19:18:06 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2023-12-04 15:53:01 +01:00
|
|
|
* ActivityPub Object of type Event.
|
2023-11-27 19:18:06 +01:00
|
|
|
*
|
|
|
|
* @package activity-event-transformers
|
2023-12-04 19:27:57 +01:00
|
|
|
* @license AGPL-3.0-or-later
|
2023-11-27 19:18:06 +01:00
|
|
|
*/
|
|
|
|
|
2023-12-03 11:21:07 +01:00
|
|
|
use function Activitypub\snake_to_camel_case;
|
2023-12-04 15:53:01 +01:00
|
|
|
require_once __DIR__ . '/class-place.php';
|
2023-12-03 11:21:07 +01:00
|
|
|
|
2023-11-27 19:18:06 +01:00
|
|
|
/**
|
2023-12-04 15:53:01 +01:00
|
|
|
* Event is an implementation of one of the Activity Streams Event object type.
|
2023-11-27 19:18:06 +01:00
|
|
|
*
|
2023-12-04 15:53:01 +01:00
|
|
|
* This class contains extra keys as used by Mobilizon to ensure compatibility.
|
2023-11-27 19:18:06 +01:00
|
|
|
*
|
|
|
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-event
|
|
|
|
*/
|
2023-12-11 19:47:24 +01:00
|
|
|
class Event extends \Activitypub\Activity\Base_Object {
|
|
|
|
// todo maybe rename to mobilizon event?
|
2023-12-12 17:27:43 +01:00
|
|
|
const REPLIES_MODERATION_OPTION_TYPES = array( 'allow_all', 'closed' );
|
|
|
|
const JOIN_MODE_TYPES = array( 'free', 'restricted', 'external' ); // amd 'invite', but not used by mobilizon atm
|
|
|
|
const ICAL_EVENT_STATUS_TYPES = array( 'TENTATIVE', 'CONFIRMED', 'CANCELLED' );
|
2023-12-03 11:21:07 +01:00
|
|
|
|
2023-11-27 19:18:06 +01:00
|
|
|
/**
|
|
|
|
* Event is an implementation of one of the
|
|
|
|
* Activity Streams
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $type = 'Event';
|
|
|
|
|
2023-12-12 17:27:43 +01:00
|
|
|
protected $name;
|
|
|
|
|
|
|
|
protected $contacts;
|
|
|
|
|
2023-11-27 19:18:06 +01:00
|
|
|
/**
|
|
|
|
* Extension invented by PeerTube whether comments/replies are <enabled>
|
|
|
|
* Mobilizon also implemented this as a fallback to their own
|
|
|
|
* repliesModerationOption.
|
|
|
|
*
|
2023-12-04 15:53:01 +01:00
|
|
|
* @context https://joinpeertube.org/ns#commentsEnabled
|
2023-11-27 19:18:06 +01:00
|
|
|
* @see https://docs.joinpeertube.org/api/activitypub#video
|
|
|
|
* @see https://docs.joinmobilizon.org/contribute/activity_pub/
|
2023-12-04 15:53:01 +01:00
|
|
|
* @var bool|null
|
2023-11-27 19:18:06 +01:00
|
|
|
*/
|
|
|
|
protected $comments_enabled;
|
2023-12-02 16:03:12 +01:00
|
|
|
|
|
|
|
/**
|
2023-12-04 15:53:01 +01:00
|
|
|
* @context https://joinmobilizon.org/ns#timezone
|
2023-12-02 16:03:12 +01:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $timezone;
|
|
|
|
|
|
|
|
/**
|
2023-12-04 15:53:01 +01:00
|
|
|
* @context https://joinmobilizon.org/ns#repliesModerationOption
|
2023-12-03 11:21:07 +01:00
|
|
|
* @see https://docs.joinmobilizon.org/contribute/activity_pub/#repliesmoderation
|
|
|
|
* @var string
|
2023-12-02 16:03:12 +01:00
|
|
|
*/
|
|
|
|
protected $replies_moderation_option;
|
|
|
|
|
|
|
|
/**
|
2023-12-04 15:53:01 +01:00
|
|
|
* @context https://joinmobilizon.org/ns#anonymousParticipationEnabled
|
2023-12-11 19:42:30 +01:00
|
|
|
* @see https://docs.joinmobilizon.org/contribute/activity_pub/#anonymousparticipationenabled
|
2023-12-02 16:03:12 +01:00
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $anonymous_participation_enabled;
|
|
|
|
|
|
|
|
/**
|
2023-12-03 11:21:07 +01:00
|
|
|
* @context https://schema.org/category
|
2023-12-02 16:03:12 +01:00
|
|
|
* @var enum
|
|
|
|
*/
|
|
|
|
protected $category;
|
|
|
|
|
|
|
|
/**
|
2023-12-03 11:21:07 +01:00
|
|
|
* @context https://schema.org/inLanguage
|
2023-12-02 16:03:12 +01:00
|
|
|
* @var
|
|
|
|
*/
|
|
|
|
protected $in_language;
|
|
|
|
|
|
|
|
/**
|
2023-12-04 15:53:01 +01:00
|
|
|
* @context https://joinmobilizon.org/ns#isOnline
|
2023-12-02 16:03:12 +01:00
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
protected $is_online;
|
|
|
|
|
|
|
|
/**
|
2023-12-12 17:27:43 +01:00
|
|
|
* @context https://www.w3.org/2002/12/cal/ical#status
|
2023-12-02 16:03:12 +01:00
|
|
|
* @var enum
|
|
|
|
*/
|
2023-12-04 15:53:01 +01:00
|
|
|
protected $status;
|
2023-12-02 16:03:12 +01:00
|
|
|
|
|
|
|
/**
|
2023-12-04 15:53:01 +01:00
|
|
|
* @context https://joinmobilizon.org/ns#externalParticipationUrl
|
2023-12-02 16:03:12 +01:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $external_participation_url;
|
|
|
|
|
|
|
|
/**
|
2023-12-04 15:53:01 +01:00
|
|
|
* @context https://joinmobilizon.org/ns#joinMode
|
2023-12-03 11:21:07 +01:00
|
|
|
* @see https://docs.joinmobilizon.org/contribute/activity_pub/#joinmode
|
|
|
|
* @var
|
2023-12-02 16:03:12 +01:00
|
|
|
*/
|
|
|
|
protected $join_mode;
|
|
|
|
|
|
|
|
/**
|
2023-12-04 15:53:01 +01:00
|
|
|
* @context https://joinmobilizon.org/ns#participantCount
|
2023-12-02 16:03:12 +01:00
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $participant_count;
|
|
|
|
|
|
|
|
/**
|
2023-12-03 11:21:07 +01:00
|
|
|
* @context https://schema.org/maximumAttendeeCapacity
|
|
|
|
* @see https://docs.joinmobilizon.org/contribute/activity_pub/#maximumattendeecapacity
|
2023-12-02 16:03:12 +01:00
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $maximum_attendee_capacity;
|
|
|
|
|
2023-12-12 17:27:43 +01:00
|
|
|
/**
|
|
|
|
* @context https://schema.org/remainingAttendeeCapacity
|
|
|
|
* @see https://docs.joinmobilizon.org/contribute/activity_pub/#remainignattendeecapacity
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $remaining_attendee_capacity;
|
|
|
|
|
2023-12-02 16:03:12 +01:00
|
|
|
|
2023-12-11 19:47:24 +01:00
|
|
|
/**
|
|
|
|
* Get the context information for a property.
|
|
|
|
*
|
|
|
|
* @param string $property
|
|
|
|
*
|
|
|
|
* @return array|null
|
|
|
|
*/
|
|
|
|
private function get_property_context( string $property ) {
|
|
|
|
$reflection_class = new ReflectionClass( $this );
|
2023-12-02 16:03:12 +01:00
|
|
|
|
2023-12-11 19:47:24 +01:00
|
|
|
if ( $reflection_class->hasProperty( $property ) ) {
|
|
|
|
$reflection_property = $reflection_class->getProperty( $property );
|
|
|
|
$doc_omment = $reflection_property->getDocComment();
|
2023-12-02 16:03:12 +01:00
|
|
|
|
2023-12-11 19:47:24 +01:00
|
|
|
// Extract context information from the doc comment.
|
|
|
|
preg_match( '/@context\s+([^\s]+)/', $doc_omment, $matches );
|
2023-12-02 16:03:12 +01:00
|
|
|
|
2023-12-11 19:47:24 +01:00
|
|
|
if ( ! empty( $matches[1] ) ) {
|
|
|
|
return $matches[1];
|
|
|
|
} else {
|
2023-12-02 16:03:12 +01:00
|
|
|
return 'https://www.w3.org/ns/activitystreams';
|
|
|
|
}
|
2023-12-11 19:47:24 +01:00
|
|
|
}
|
2023-12-02 16:03:12 +01:00
|
|
|
|
2023-12-11 19:47:24 +01:00
|
|
|
return null;
|
|
|
|
}
|
2023-12-02 16:03:12 +01:00
|
|
|
|
2023-12-03 11:21:07 +01:00
|
|
|
private static function compact_context( $key_context, $namespace, $abbreviation ) {
|
|
|
|
$abbreviation_added = false;
|
|
|
|
foreach ( $key_context as $key => $value ) {
|
2023-12-03 11:41:13 +01:00
|
|
|
// Check if the key starts with the namespace
|
2023-12-03 11:21:07 +01:00
|
|
|
if ( strpos( $value, $namespace ) === 0 ) {
|
|
|
|
// Replace the key
|
2023-12-03 11:41:13 +01:00
|
|
|
$key_context[ $key ] = $abbreviation . ':' . substr( $value, strlen( $namespace ) );
|
2023-12-03 11:21:07 +01:00
|
|
|
|
2023-12-03 11:41:13 +01:00
|
|
|
// Add abbreviation element for the namespace only once
|
2023-12-03 11:21:07 +01:00
|
|
|
if ( ! $abbreviation_added ) {
|
2023-12-12 17:27:43 +01:00
|
|
|
$key_context = array( $abbreviation => $namespace ) + $key_context;
|
2023-12-03 11:21:07 +01:00
|
|
|
$abbreviation_added = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $key_context;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function get_context() {
|
|
|
|
$class = self::class;
|
2023-12-04 15:53:01 +01:00
|
|
|
$transient = "activitypub_json_context_object_{$class}";
|
2023-12-11 19:42:30 +01:00
|
|
|
$context = get_transient( $transient );
|
2023-12-03 11:41:13 +01:00
|
|
|
// if ( $context ) {
|
2023-12-12 17:27:43 +01:00
|
|
|
// return $context;
|
2023-12-03 11:41:13 +01:00
|
|
|
// }
|
2023-12-03 11:21:07 +01:00
|
|
|
$reflection_class = new ReflectionClass( self::class );
|
|
|
|
$context = array(
|
|
|
|
'https://www.w3.org/ns/activitystreams',
|
|
|
|
'https://w3id.org/security/v1',
|
|
|
|
);
|
|
|
|
|
2023-12-12 17:27:43 +01:00
|
|
|
$key_context = array();
|
2023-12-03 11:21:07 +01:00
|
|
|
|
|
|
|
foreach ( $reflection_class->getProperties() as $property ) {
|
|
|
|
$doc_omment = $property->getDocComment();
|
|
|
|
|
|
|
|
// Extract context information from the doc comment.
|
|
|
|
preg_match( '/@context\s+([^\s]+)/', $doc_omment, $matches );
|
|
|
|
|
2023-12-11 19:42:30 +01:00
|
|
|
if ( ! empty( $matches[1] ) ) {
|
2023-12-03 11:21:07 +01:00
|
|
|
$key_context[ snake_to_camel_case( $property->name ) ] = $matches[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$namespace_abbreviations = array(
|
2023-12-04 15:53:01 +01:00
|
|
|
'https://joinpeertube.org/ns#' => 'pt',
|
|
|
|
'https://joinmobilizon.org/ns#' => 'mz',
|
|
|
|
'https://schema.org/' => 'sc',
|
2023-12-12 17:27:43 +01:00
|
|
|
'https://www.w3.org/2002/12/cal/ical#' => 'ical',
|
2023-12-03 11:21:07 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
foreach ( $namespace_abbreviations as $namespace => $abbreviation ) {
|
|
|
|
$key_context = self::compact_context( $key_context, $namespace, $abbreviation );
|
|
|
|
}
|
|
|
|
|
|
|
|
$context[] = $key_context;
|
|
|
|
|
|
|
|
set_transient( $transient, $context );
|
2023-12-11 19:42:30 +01:00
|
|
|
return $context;
|
2023-12-03 11:21:07 +01:00
|
|
|
}
|
|
|
|
|
2023-12-02 16:03:12 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* When using this class we need to add some filters.
|
|
|
|
*/
|
|
|
|
public function __construct() {
|
2023-12-04 15:53:01 +01:00
|
|
|
// $class = strtolower( get_class( $this ) );
|
|
|
|
// add_filter( "activitypub_activity_{$class}_object_array", [ $this, 'filter_object_array' ] );
|
|
|
|
// add_filter( 'activitypub_json_context', [ $this, 'filter_json_context' ] );
|
2023-12-02 16:03:12 +01:00
|
|
|
}
|
2023-11-27 19:18:06 +01:00
|
|
|
}
|