Compare commits
3 commits
f61ccd7a18
...
649075c424
Author | SHA1 | Date | |
---|---|---|---|
649075c424 | |||
79f00724a2 | |||
38caa8d2b0 |
2 changed files with 162 additions and 34 deletions
|
@ -16,9 +16,11 @@ require_once __DIR__ . '/class-place.php';
|
||||||
*
|
*
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-event
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-event
|
||||||
*/
|
*/
|
||||||
class Event extends \Activitypub\Activity\Base_Object { // todo maybe rename to mobilizon event?
|
class Event extends \Activitypub\Activity\Base_Object {
|
||||||
|
// todo maybe rename to mobilizon event?
|
||||||
const REPLIES_MODERATION_OPTION_TYPES = [ 'allow_all', 'closed' ];
|
const REPLIES_MODERATION_OPTION_TYPES = [ 'allow_all', 'closed' ];
|
||||||
const JOIN_MODE_TYPES = [ 'free', 'restricted', 'external' ]; // amd 'invite', but not used by mobilizon atm
|
const JOIN_MODE_TYPES = [ 'free', 'restricted', 'external' ]; // amd 'invite', but not used by mobilizon atm
|
||||||
|
const ICAL_EVENT_STATUS_TYPES = ["TENTATIVE", "CONFIRMED", "CANCELLED"];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event is an implementation of one of the
|
* Event is an implementation of one of the
|
||||||
|
@ -111,32 +113,32 @@ class Event extends \Activitypub\Activity\Base_Object { // todo maybe rename to
|
||||||
protected $maximum_attendee_capacity;
|
protected $maximum_attendee_capacity;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the context information for a property.
|
* Get the context information for a property.
|
||||||
*
|
*
|
||||||
* @param string $property
|
* @param string $property
|
||||||
*
|
*
|
||||||
* @return array|null
|
* @return array|null
|
||||||
*/
|
*/
|
||||||
private function get_property_context( string $property ) {
|
private function get_property_context( string $property ) {
|
||||||
$reflection_class = new ReflectionClass( $this );
|
$reflection_class = new ReflectionClass( $this );
|
||||||
|
|
||||||
if ( $reflection_class->hasProperty( $property ) ) {
|
if ( $reflection_class->hasProperty( $property ) ) {
|
||||||
$reflection_property = $reflection_class->getProperty( $property );
|
$reflection_property = $reflection_class->getProperty( $property );
|
||||||
$doc_omment = $reflection_property->getDocComment();
|
$doc_omment = $reflection_property->getDocComment();
|
||||||
|
|
||||||
// Extract context information from the doc comment.
|
// Extract context information from the doc comment.
|
||||||
preg_match( '/@context\s+([^\s]+)/', $doc_omment, $matches );
|
preg_match( '/@context\s+([^\s]+)/', $doc_omment, $matches );
|
||||||
|
|
||||||
if ( !empty( $matches[1] ) ) {
|
if ( ! empty( $matches[1] ) ) {
|
||||||
return $matches[1];
|
return $matches[1];
|
||||||
} else {
|
} else {
|
||||||
return 'https://www.w3.org/ns/activitystreams';
|
return 'https://www.w3.org/ns/activitystreams';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function compact_context( $key_context, $namespace, $abbreviation ) {
|
private static function compact_context( $key_context, $namespace, $abbreviation ) {
|
||||||
$abbreviation_added = false;
|
$abbreviation_added = false;
|
||||||
|
|
|
@ -16,6 +16,23 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
class Tribe extends \Activitypub\Transformer\Base {
|
class Tribe extends \Activitypub\Transformer\Base {
|
||||||
|
/**
|
||||||
|
* The Tribe Event object.
|
||||||
|
*
|
||||||
|
* @var WP_Post
|
||||||
|
*/
|
||||||
|
protected $tribe_event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* resolve the tribe metadata in the setter of wp_post.
|
||||||
|
*
|
||||||
|
* @param WP_Post $wp_post The WP_Post object.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function set_wp_post( WP_Post $wp_post ) {
|
||||||
|
parent::set_wp_post( $wp_post );
|
||||||
|
$this->tribe_event = tribe_get_event( $wp_post->ID );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get widget name.
|
* Get widget name.
|
||||||
|
@ -67,6 +84,95 @@ class Tribe extends \Activitypub\Transformer\Base {
|
||||||
return array( 'tribe_events' );
|
return array( 'tribe_events' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get tribe category of wp_post
|
||||||
|
*
|
||||||
|
* @return string|null tribe category if it exists
|
||||||
|
*/
|
||||||
|
public function get_tribe_category() {
|
||||||
|
// todo make it possible that one event can have multiple categories?
|
||||||
|
|
||||||
|
// using cat_slugs isn't 100% nice way to do this, don't know if it's a good idea
|
||||||
|
$categories = tribe_get_event_cat_slugs( $this->wp_post->ID );
|
||||||
|
|
||||||
|
if ( count( $categories ) === 0 ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $categories[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get status of the tribe event
|
||||||
|
*
|
||||||
|
* @return string status of the event
|
||||||
|
*/
|
||||||
|
public function get_tribe_status() {
|
||||||
|
if ( 'canceled' === $this->tribe_event->event_status ) {
|
||||||
|
return 'CANCELLED';
|
||||||
|
}
|
||||||
|
if ( 'postponed' === $this->tribe_event->event_status ) {
|
||||||
|
return 'CANCELLED'; // this will be reflected in the cancelled reason
|
||||||
|
}
|
||||||
|
if ( '' === $this->tribe_event->event_status ) {
|
||||||
|
return 'CONFIRMED';
|
||||||
|
}
|
||||||
|
|
||||||
|
return new WP_Error( 'invalid event_status value', __( 'invalid event_status', 'activitypub' ), array( 'status' => 404 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the content for the ActivityPub Item with
|
||||||
|
*
|
||||||
|
* The content will be generated based on the user settings.
|
||||||
|
*
|
||||||
|
* @return string The content.
|
||||||
|
*/
|
||||||
|
protected function get_content() {
|
||||||
|
$content = parent::get_content();
|
||||||
|
// todo remove link at the end of the content
|
||||||
|
|
||||||
|
// todo add organizer
|
||||||
|
// $this->tribe_event->organizers[0]
|
||||||
|
|
||||||
|
// todo add Canclled reason in the content (maybe at the end)
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the event location.
|
||||||
|
*
|
||||||
|
* @param int $post_id The WordPress post ID.
|
||||||
|
* @returns array The Place.
|
||||||
|
*/
|
||||||
|
public function get_event_location() {
|
||||||
|
/*
|
||||||
|
'post_title' => 'testvenue',
|
||||||
|
'post_name' => 'testvenue',
|
||||||
|
'guid' => 'http://localhost/venue/testvenue/',
|
||||||
|
'post_type' => 'tribe_venue',
|
||||||
|
'address' => 'testaddr',
|
||||||
|
'country' => 'Austria',
|
||||||
|
'city' => 'testcity',
|
||||||
|
'state_province' => 'testprovince',
|
||||||
|
'state' => '',
|
||||||
|
'province' => 'testprovince',
|
||||||
|
'zip' => '8000',
|
||||||
|
'phone' => '+4312343',
|
||||||
|
'permalink' => 'http://localhost/venue/testvenue/',
|
||||||
|
'directions_link' => 'https://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=testaddr+testcity+testprovince+8000+Austria',
|
||||||
|
'website' => 'https://test.at',
|
||||||
|
*/
|
||||||
|
$venue = $this->tribe_event->venues[0];
|
||||||
|
return ( new Place() )
|
||||||
|
->set_type( 'Place' )
|
||||||
|
->set_name( $venue->post_name )
|
||||||
|
->set_address( $venue->address . "\n" .
|
||||||
|
$venue->zip . ", " . $venue->city . "\n" .
|
||||||
|
$venue->country ); // todo add checks that everything exists here (lol)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms the VS Event WP_Post object to an ActivityPub Event Object.
|
* Transforms the VS Event WP_Post object to an ActivityPub Event Object.
|
||||||
*
|
*
|
||||||
|
@ -77,36 +183,56 @@ class Tribe extends \Activitypub\Transformer\Base {
|
||||||
public function transform() {
|
public function transform() {
|
||||||
$object = new Event();
|
$object = new Event();
|
||||||
|
|
||||||
|
// todo xsd:dateTime is probably nearly everywhere used, should it be default?
|
||||||
$this->set_timeformat( 'Y-m-d\TH:i:s\Z' );
|
$this->set_timeformat( 'Y-m-d\TH:i:s\Z' );
|
||||||
|
|
||||||
|
// todo this looks very duplicated
|
||||||
|
$object->set_default_language_for_maps( $this->get_locale() );
|
||||||
|
$object->set_in_language( $this->get_locale() );
|
||||||
|
|
||||||
$object
|
$object
|
||||||
|
// set metadata
|
||||||
->set_id( $this->get_id() )
|
->set_id( $this->get_id() )
|
||||||
->set_url( $this->get_url() )
|
->set_url( $this->get_url() )
|
||||||
->set_external_participation_url( $this->get_url() )
|
->set_external_participation_url( $this->get_url() )
|
||||||
|
->set_comments_enabled( $this->get_comments_open() )
|
||||||
|
->set_replies_moderation_option( 'allow_all' ) // comment_status = open todo
|
||||||
|
|
||||||
|
// set published and updated
|
||||||
->set_published( $this->get_published() )
|
->set_published( $this->get_published() )
|
||||||
->if( $this->get_updated() > $this->get_published() )
|
->if( $this->get_updated() > $this->get_published() )
|
||||||
->set_updated( $this->get_updated() )
|
->set_updated( $this->get_updated() )
|
||||||
|
|
||||||
|
// set author and location
|
||||||
->set_attributed_to( $this->get_attributed_to() )
|
->set_attributed_to( $this->get_attributed_to() )
|
||||||
->set_content( $this->get_content() )
|
->set_location( $this->get_event_location()->to_array())
|
||||||
->set_content_map( $this->get_basic_content_map() ) // todo rename to basic
|
|
||||||
|
|
||||||
->set_summary( $this->get_post_meta( 'post_excerpt', true, $this->get_content() ) ) // todo second argument is fallback / default
|
// set content
|
||||||
|
->set_name( $this->get_post_property( 'post_title' ) )
|
||||||
|
->set_content( $this->get_content() )
|
||||||
|
->set_summary( $this->get_post_meta( 'post_excerpt', true, $this->get_content() ) )
|
||||||
|
->set_attachment( $this->get_attachments() )
|
||||||
|
|
||||||
|
// set event metadata
|
||||||
->set_start_time( $this->get_post_meta_time( '_EventStartDateUTC' ) )
|
->set_start_time( $this->get_post_meta_time( '_EventStartDateUTC' ) )
|
||||||
->set_end_time( $this->get_post_meta_time( '_EventEndDateUTC' ) )
|
->set_end_time( $this->get_post_meta_time( '_EventEndDateUTC' ) )
|
||||||
->set_to( $this->get_followers_stream() )
|
// ->set_duration() // todo
|
||||||
// ->set_location( $this->get_event_location()->to_array())
|
->set_status( $this->get_tribe_status() )
|
||||||
->set_cc( $this->get_cc() )
|
|
||||||
->set_attachment( $this->get_attachments() )
|
|
||||||
->set_tag( $this->get_tags() )
|
|
||||||
|
|
||||||
->set_comments_enabled( $this->get_comments_open() )
|
|
||||||
->set_replies_moderation_option( 'allow_all' )
|
|
||||||
->set_join_mode( 'external' )
|
->set_join_mode( 'external' )
|
||||||
->set_status( 'CONFIRMED' )
|
|
||||||
->set_category( 'MEETING' );
|
->set_tag( $this->get_tags() ) // todo maybe rename to get_hashtags()?
|
||||||
|
->set_category( $this->get_tribe_category() )
|
||||||
|
|
||||||
|
// set direkt addressants (to followers and mentions)
|
||||||
|
->set_to( $this->get_followers_stream() )
|
||||||
|
->set_cc( $this->get_cc() );
|
||||||
|
|
||||||
|
// todo events that cost something?
|
||||||
|
// maybe a setting for custom tags for online mode
|
||||||
|
|
||||||
|
// todo generator maybe
|
||||||
|
|
||||||
|
$some_infos = $object->check_jsonld_completeness(); // just used for debugging
|
||||||
|
|
||||||
assert( $object->get_type() === $this->get_object_type() );
|
assert( $object->get_type() === $this->get_object_type() );
|
||||||
return $object;
|
return $object;
|
||||||
|
|
Loading…
Reference in a new issue