wip: add event boilerplate with third party context
Some checks failed
Deploy to https://wordpress-test.event-federation.eu/ / deploy (push) Failing after 5s
Some checks failed
Deploy to https://wordpress-test.event-federation.eu/ / deploy (push) Failing after 5s
This commit is contained in:
parent
8db7742ee8
commit
cb86454d94
5 changed files with 323 additions and 37 deletions
|
@ -23,12 +23,12 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
* Include fransformer file and register transformer class.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @param \Activitypub\Transformer\Transformers_Manager $transformers_manager ActivtiyPub transformers manager.
|
||||
* @param \Activitypub\Transformer\Transformer_Factory $transformers_manager ActivtiyPub transformers manager.
|
||||
* @return void
|
||||
*/
|
||||
function register_event_transformers( $transformers_manager ) {
|
||||
require_once __DIR__ . '/activitypub/transformer/class-tribe.php';
|
||||
$transformers_manager->register( new \Tribe() );
|
||||
// require_once __DIR__ . '/activitypub/transformer/class-tribe.php';
|
||||
// $transformers_manager->register( new \Tribe() );
|
||||
|
||||
require_once __DIR__ . '/activitypub/transformer/class-vs-event.php';
|
||||
$transformers_manager->register( new \VS_Event() );
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
/**
|
||||
* Event is an implementation of one of the
|
||||
* Activity Streams Event object type
|
||||
* ActivityPub Transformer for VS Event.
|
||||
*
|
||||
* This is a file doc comments.
|
||||
*
|
||||
* @package activity-event-transformers
|
||||
*/
|
||||
|
@ -35,4 +36,128 @@ class Event extends \Activitypub\Activity\Base_Object {
|
|||
* @var bool
|
||||
*/
|
||||
protected $comments_enabled;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $timezone;
|
||||
|
||||
/**
|
||||
* @context https://joinmobilizon/repliesModerationOption
|
||||
* @var enum
|
||||
*/
|
||||
protected $replies_moderation_option;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $anonymous_participation_enabled;
|
||||
|
||||
/**
|
||||
* @var enum
|
||||
*/
|
||||
protected $category;
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected $in_language;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $is_online;
|
||||
|
||||
/**
|
||||
* @var enum
|
||||
*/
|
||||
protected $ical_status;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $external_participation_url;
|
||||
|
||||
/**
|
||||
* @var enum
|
||||
*/
|
||||
protected $join_mode;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $draft;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $participant_count;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $maximum_attendee_capacity;
|
||||
|
||||
/**
|
||||
* @param array $array The array version of an object of this class.
|
||||
*/
|
||||
private function rename_ical_status_key( $array ) {
|
||||
$array[ 'ical:status' ] = $array[ 'icalStatus' ];
|
||||
unset( $array[ 'icalStatus' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array The array version of an object of this class.
|
||||
*/
|
||||
public function rename_array_keys( $array ) {
|
||||
if ( isset( $array[ 'icalStatus' ] ) ) {
|
||||
$array = rename_ical_status_key( $array );
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 );
|
||||
|
||||
if ( $reflection_class->hasProperty( $property ) ) {
|
||||
$reflection_property = $reflection_class->getProperty( $property );
|
||||
$doc_omment = $reflection_property->getDocComment();
|
||||
|
||||
// Extract context information from the doc comment.
|
||||
preg_match( '/@context\s+([^\s]+)/', $doc_omment, $matches );
|
||||
|
||||
if ( !empty( $matches[1] ) ) {
|
||||
return $matches[1];
|
||||
} else {
|
||||
return 'https://www.w3.org/ns/activitystreams';
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function filter_context( $context ) {
|
||||
if ( isset( $this->replies_moderation_option ) ) {
|
||||
$replies_moderation_option_context = $this->get_property_context( 'replies_moderation_option' );
|
||||
}
|
||||
return $context;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* When using this class we need to add some filters.
|
||||
*/
|
||||
public function __construct() {
|
||||
$class = get_class( $this );
|
||||
$class = 'event';
|
||||
add_filter( "activitypub_activity_{$class}_object_array", [ $this, 'rename_array_keys' ] );
|
||||
add_filter( 'activitypub_json_context', [ $this, 'filter_context' ] );
|
||||
}
|
||||
}
|
||||
|
|
79
activitypub/object/class-place.php
Normal file
79
activitypub/object/class-place.php
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
/**
|
||||
* Event is an implementation of one of the
|
||||
* Activity Streams Event object type
|
||||
*
|
||||
* @package activity-event-transformers
|
||||
*/
|
||||
|
||||
/**
|
||||
* Event is an implementation of one of the
|
||||
* Activity Streams Event object type
|
||||
*
|
||||
* The Object is the primary base type for the Activity Streams
|
||||
* vocabulary.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-event
|
||||
*/
|
||||
class Place extends \Activitypub\Activity\Base_Object {
|
||||
/**
|
||||
* Place is an implementation of one of the
|
||||
* Activity Streams
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $type = 'Place';
|
||||
|
||||
/**
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-accuracy
|
||||
* @var float
|
||||
*/
|
||||
protected $accuracy;
|
||||
|
||||
/**
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-altitude
|
||||
* @var float
|
||||
*/
|
||||
protected $altitude;
|
||||
|
||||
/**
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-latitude
|
||||
* @var float
|
||||
*/
|
||||
protected $latitude;
|
||||
|
||||
/**
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-longitude
|
||||
* @var float
|
||||
*/
|
||||
protected $longitude;
|
||||
|
||||
/**
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-radius
|
||||
* @var float
|
||||
*/
|
||||
protected $radius;
|
||||
|
||||
/**
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-units
|
||||
* @var string
|
||||
*/
|
||||
protected $units;
|
||||
|
||||
/**
|
||||
* Extension invented by PeerTube whether comments/replies are <enabled>
|
||||
* Mobilizon also implemented this as a fallback to their own
|
||||
* repliesModerationOption.
|
||||
*
|
||||
* @see https://docs.joinpeertube.org/api/activitypub#video
|
||||
* @see https://docs.joinmobilizon.org/contribute/activity_pub/
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $comments_enabled;
|
||||
|
||||
/**
|
||||
* @var Postal_Address|string
|
||||
*/
|
||||
protected $address;
|
||||
}
|
57
activitypub/object/class-postal-address.php
Normal file
57
activitypub/object/class-postal-address.php
Normal file
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
/**
|
||||
* PostalAddress is a custom ActivityPub object firstly used by Mobilizon
|
||||
* derived from https://schema.org/PostalAddress.
|
||||
*
|
||||
* @package activity-event-transformers
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-event
|
||||
*/
|
||||
class Postal_Address extends \Activitypub\Activity\Base_Object {
|
||||
/**
|
||||
* Place is an implementation of one of the
|
||||
* Activity Streams
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $type = 'PostalAddress';
|
||||
|
||||
/**
|
||||
* The country. For example, USA. You can also provide the two-letter ISO 3166-1 alpha-2 country code.
|
||||
*
|
||||
* @see http://en.wikipedia.org/wiki/ISO_3166-1
|
||||
* @var string
|
||||
*/
|
||||
protected $address_country;
|
||||
|
||||
/**
|
||||
* The locality in which the street address is, and which is in the region. For example, Mountain View.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $address_locality;
|
||||
|
||||
/**
|
||||
* The region in which the locality is, and which is in the country.
|
||||
* For example, California or another appropriate first-level Administrative division.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $address_region;
|
||||
|
||||
/**
|
||||
* The postal code. For example, 94043.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $postal_code;
|
||||
|
||||
/**
|
||||
* The street address. For example, 1600 Amphitheatre Pkwy.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $street_address;
|
||||
}
|
|
@ -80,8 +80,7 @@ class VS_Event extends \Activitypub\Transformer\Base {
|
|||
$object = new Base_Object();
|
||||
$object->set_type( 'Place' );
|
||||
$object->set_name( get_post_meta( $post_id, 'event-location', true ) );
|
||||
$array = $object->to_array();
|
||||
return $array;
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -96,19 +95,50 @@ class VS_Event extends \Activitypub\Transformer\Base {
|
|||
}
|
||||
|
||||
/**
|
||||
* Transforms the VS Event WP_Post object to an ActivityPub Event Object
|
||||
* Get the end time from the events metadata.
|
||||
*/
|
||||
private function get_end_time() {
|
||||
$end_time = get_post_meta( $this->wp_post->ID, 'event-date', true );
|
||||
return \gmdate( 'Y-m-d\TH:i:s\Z', $end_time );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the event link from the events metadata.
|
||||
*/
|
||||
private function get_event_link() {
|
||||
$event_link = get_post_meta( $this->wp_post->ID, 'event-link', true );
|
||||
if ( $event_link ) {
|
||||
return array(
|
||||
'type' => 'Link',
|
||||
'name' => 'Website',
|
||||
'href' => \esc_url( get_post_meta( $post_id, 'event-location', true ) ),
|
||||
'mediaType' => 'text/html',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extends the get_attachments function to also add the event Link.
|
||||
*/
|
||||
protected function get_attachments() {
|
||||
$attachments = parent::get_attachments();
|
||||
$attachments[] = $this->get_event_link();
|
||||
return $attachments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the VS Event WP_Post object to an ActivityPub Event Object.
|
||||
*
|
||||
* @see \Activitypub\Activity\Base_Object
|
||||
*
|
||||
* @return \Activitypub\Activity\Base_Object The ActivityPub Object
|
||||
* @return \Activitypub\Activity\Base_Object The ActivityPub Object.
|
||||
*/
|
||||
public function to_object() {
|
||||
$wp_post = $this->wp_post;
|
||||
public function transform() {
|
||||
$object = new Event();
|
||||
|
||||
$object->set_id( $this->get_id() );
|
||||
$object->set_url( $this->get_url() );
|
||||
$object->set_type( $this->get_object_type() );
|
||||
$object
|
||||
->set_id( $this->get_id() )
|
||||
->set_url( $this->get_url() )
|
||||
->set_type( $this->get_object_type() );
|
||||
|
||||
$published = \strtotime( $wp_post->post_date_gmt );
|
||||
|
||||
|
@ -120,9 +150,10 @@ class VS_Event extends \Activitypub\Transformer\Base {
|
|||
$object->set_updated( \gmdate( 'Y-m-d\TH:i:s\Z', $updated ) );
|
||||
}
|
||||
|
||||
$object->set_attributed_to( $this->get_attributed_to() );
|
||||
$object->set_content( $this->get_content() );
|
||||
$object->set_content_map( $this->get_content_map );
|
||||
$object
|
||||
->set_attributed_to( $this->get_attributed_to() )
|
||||
->set_content( $this->get_content() )
|
||||
->set_content_map( $this->get_content_map );
|
||||
|
||||
$summary = get_post_meta( $wp_post->ID, 'event-summary', true );
|
||||
if ( $summary ) {
|
||||
|
@ -134,29 +165,23 @@ class VS_Event extends \Activitypub\Transformer\Base {
|
|||
$start_time = get_post_meta( $wp_post->ID, 'event-start-date', true );
|
||||
$object->set_start_time( \gmdate( 'Y-m-d\TH:i:s\Z', $start_time ) );
|
||||
|
||||
$end_time = get_post_meta( $wp_post->ID, 'event-date', true );
|
||||
$object->set_end_time( \gmdate( 'Y-m-d\TH:i:s\Z', $end_time ) );
|
||||
$object->set_end_time( $this->get_end_time() );
|
||||
|
||||
$path = sprintf( 'users/%d/followers', intval( $wp_post->post_author ) );
|
||||
|
||||
$location = get_post_meta( $wp_post->ID, 'event-link', true );
|
||||
$object->set_location( $this->get_event_location( $wp_post->ID ) );
|
||||
|
||||
$is_open_for_comments = comments_open( $wp_post->ID );
|
||||
$object->set_comments_enabled( $is_open_for_comments );
|
||||
|
||||
$object->set_to(
|
||||
$object
|
||||
->set_location( $this->get_event_location( $wp_post->ID ) )
|
||||
->set_comments_enabled( comments_open( $wp_post->ID ) )
|
||||
->set_to(
|
||||
array(
|
||||
'https://www.w3.org/ns/activitystreams#Public',
|
||||
get_rest_url_by_path( $path ),
|
||||
)
|
||||
);
|
||||
$object->set_cc( $this->get_cc() );
|
||||
|
||||
$attachments = $this->get_attachments();
|
||||
|
||||
$object->set_attachment( $this->get_attachments() );
|
||||
$object->set_tag( $this->get_tags() );
|
||||
)
|
||||
->set_cc( $this->get_cc() )
|
||||
->set_attachment( $this->get_attachments() )
|
||||
->set_tag( $this->get_tags() )
|
||||
->set_replies_moderation_option( 'allow_all' );
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue