add testing snippets and merging the latest versions
Some checks failed
Deploy to https://wordpress-test.event-federation.eu/ / deploy (push) Failing after 7s

This commit is contained in:
André Menrath 2023-12-12 17:27:43 +01:00
parent 649075c424
commit 014b2e1171
6 changed files with 123 additions and 63 deletions

View file

@ -37,3 +37,30 @@ function register_event_transformers( $transformers_manager ) {
} }
add_action( 'activitypub_transformers_register', 'register_event_transformers' ); add_action( 'activitypub_transformers_register', 'register_event_transformers' );
// TODO Below here is temporary code needed to do local testing atm.
// Add a filter for http_request_host_is_external
add_filter( 'http_request_host_is_external', 'custom_http_request_host_is_external', 10, 3 );
// Your custom callback function
function custom_http_request_host_is_external( $is_external, $host, $url ) {
$is_external = true;
return $is_external;
}
// add_filter( 'rest_request_before_callbacks', 'change_relay_actor_to_blog_actor', 10, 3 );
// function change_relay_actor_to_blog_actor( $response, $handler, $request ) {
// }
// add_filters( 'https_ssl_verify', 'dont_verify_local_dev_https', 10, 3);
// function dont_verify_local_dev_https($url) {
// return false;
// }

View file

@ -18,9 +18,9 @@ require_once __DIR__ . '/class-place.php';
*/ */
class Event extends \Activitypub\Activity\Base_Object { class Event extends \Activitypub\Activity\Base_Object {
// todo maybe rename to mobilizon event? // todo maybe rename to mobilizon event?
const REPLIES_MODERATION_OPTION_TYPES = [ 'allow_all', 'closed' ]; const REPLIES_MODERATION_OPTION_TYPES = array( 'allow_all', 'closed' );
const JOIN_MODE_TYPES = [ 'free', 'restricted', 'external' ]; // amd 'invite', but not used by mobilizon atm const JOIN_MODE_TYPES = array( 'free', 'restricted', 'external' ); // amd 'invite', but not used by mobilizon atm
const ICAL_EVENT_STATUS_TYPES = ["TENTATIVE", "CONFIRMED", "CANCELLED"]; const ICAL_EVENT_STATUS_TYPES = array( 'TENTATIVE', 'CONFIRMED', 'CANCELLED' );
/** /**
* Event is an implementation of one of the * Event is an implementation of one of the
@ -30,6 +30,10 @@ class Event extends \Activitypub\Activity\Base_Object {
*/ */
protected $type = 'Event'; protected $type = 'Event';
protected $name;
protected $contacts;
/** /**
* Extension invented by PeerTube whether comments/replies are <enabled> * Extension invented by PeerTube whether comments/replies are <enabled>
* Mobilizon also implemented this as a fallback to their own * Mobilizon also implemented this as a fallback to their own
@ -81,7 +85,7 @@ class Event extends \Activitypub\Activity\Base_Object {
protected $is_online; protected $is_online;
/** /**
* @context http://www.w3.org/2002/12/cal/ical#status * @context https://www.w3.org/2002/12/cal/ical#status
* @var enum * @var enum
*/ */
protected $status; protected $status;
@ -112,6 +116,13 @@ class Event extends \Activitypub\Activity\Base_Object {
*/ */
protected $maximum_attendee_capacity; protected $maximum_attendee_capacity;
/**
* @context https://schema.org/remainingAttendeeCapacity
* @see https://docs.joinmobilizon.org/contribute/activity_pub/#remainignattendeecapacity
* @var int
*/
protected $remaining_attendee_capacity;
/** /**
* Get the context information for a property. * Get the context information for a property.
@ -150,7 +161,7 @@ class Event extends \Activitypub\Activity\Base_Object {
// Add abbreviation element for the namespace only once // Add abbreviation element for the namespace only once
if ( ! $abbreviation_added ) { if ( ! $abbreviation_added ) {
$key_context = [ $abbreviation => $namespace ] + $key_context; $key_context = array( $abbreviation => $namespace ) + $key_context;
$abbreviation_added = true; $abbreviation_added = true;
} }
} }
@ -163,7 +174,7 @@ class Event extends \Activitypub\Activity\Base_Object {
$transient = "activitypub_json_context_object_{$class}"; $transient = "activitypub_json_context_object_{$class}";
$context = get_transient( $transient ); $context = get_transient( $transient );
// if ( $context ) { // if ( $context ) {
// return $context; // return $context;
// } // }
$reflection_class = new ReflectionClass( self::class ); $reflection_class = new ReflectionClass( self::class );
$context = array( $context = array(
@ -171,7 +182,7 @@ class Event extends \Activitypub\Activity\Base_Object {
'https://w3id.org/security/v1', 'https://w3id.org/security/v1',
); );
$key_context = []; $key_context = array();
foreach ( $reflection_class->getProperties() as $property ) { foreach ( $reflection_class->getProperties() as $property ) {
$doc_omment = $property->getDocComment(); $doc_omment = $property->getDocComment();
@ -188,7 +199,7 @@ class Event extends \Activitypub\Activity\Base_Object {
'https://joinpeertube.org/ns#' => 'pt', 'https://joinpeertube.org/ns#' => 'pt',
'https://joinmobilizon.org/ns#' => 'mz', 'https://joinmobilizon.org/ns#' => 'mz',
'https://schema.org/' => 'sc', 'https://schema.org/' => 'sc',
'http://www.w3.org/2002/12/cal/ical#' => 'ical', 'https://www.w3.org/2002/12/cal/ical#' => 'ical',
); );
foreach ( $namespace_abbreviations as $namespace => $abbreviation ) { foreach ( $namespace_abbreviations as $namespace => $abbreviation ) {

View file

@ -26,26 +26,36 @@ class Place extends \Activitypub\Activity\Base_Object {
protected $type = 'Place'; protected $type = 'Place';
/** /**
* Indicates the accuracy of position coordinates on a Place objects.
* Expressed in properties of percentage. e.g. "94.0" means "94.0% accurate".
*
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-accuracy * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-accuracy
* @var float * @var float xsd:float [>= 0.0f, <= 100.0f]
*/ */
protected $accuracy; protected $accuracy;
/** /**
* Indicates the altitude of a place. The measurement units is indicated using the units property.
* If units is not specified, the default is assumed to be "m" indicating meters.
*
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-altitude * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-altitude
* @var float * @var float xsd:float
*/ */
protected $altitude; protected $altitude;
/** /**
* The latitude of a place.
*
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-latitude * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-latitude
* @var float * @var float xsd:float
*/ */
protected $latitude; protected $latitude;
/** /**
* The longitude of a place.
*
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-longitude * @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-longitude
* @var float * @var float xsd:float
*/ */
protected $longitude; protected $longitude;
@ -73,8 +83,8 @@ class Place extends \Activitypub\Activity\Base_Object {
*/ */
protected $comments_enabled; protected $comments_enabled;
/** /**
* @var Postal_Address|string * @var Postal_Address|string
*/ */
protected $address; protected $address;
} }

View file

@ -19,40 +19,40 @@ class Postal_Address extends \Activitypub\Activity\Base_Object {
*/ */
protected $type = 'PostalAddress'; protected $type = 'PostalAddress';
/** /**
* The country. For example, USA. You can also provide the two-letter ISO 3166-1 alpha-2 country code. * 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 * @see http://en.wikipedia.org/wiki/ISO_3166-1
* @var string * @var string
*/ */
protected $address_country; protected $address_country;
/** /**
* The locality in which the street address is, and which is in the region. For example, Mountain View. * The locality in which the street address is, and which is in the region. For example, Mountain View.
* *
* @var string * @var string
*/ */
protected $address_locality; protected $address_locality;
/** /**
* The region in which the locality is, and which is in the country. * The region in which the locality is, and which is in the country.
* For example, California or another appropriate first-level Administrative division. * For example, California or another appropriate first-level Administrative division.
* *
* @var string * @var string
*/ */
protected $address_region; protected $address_region;
/** /**
* The postal code. For example, 94043. * The postal code. For example, 94043.
* *
* @var string * @var string
*/ */
protected $postal_code; protected $postal_code;
/** /**
* The street address. For example, 1600 Amphitheatre Pkwy. * The street address. For example, 1600 Amphitheatre Pkwy.
* *
* @var string * @var string
*/ */
protected $street_address; protected $street_address;
} }

View file

@ -168,9 +168,11 @@ class Tribe extends \Activitypub\Transformer\Base {
return ( new Place() ) return ( new Place() )
->set_type( 'Place' ) ->set_type( 'Place' )
->set_name( $venue->post_name ) ->set_name( $venue->post_name )
->set_address( $venue->address . "\n" . ->set_address(
$venue->zip . ", " . $venue->city . "\n" . $venue->address . "\n" .
$venue->country ); // todo add checks that everything exists here (lol) $venue->zip . ', ' . $venue->city . "\n" .
$venue->country
); // todo add checks that everything exists here (lol)
} }
/** /**
@ -205,7 +207,7 @@ class Tribe extends \Activitypub\Transformer\Base {
// set author and location // set author and location
->set_attributed_to( $this->get_attributed_to() ) ->set_attributed_to( $this->get_attributed_to() )
->set_location( $this->get_event_location()->to_array()) ->set_location( $this->get_event_location()->to_array() )
// set content // set content
->set_name( $this->get_post_property( 'post_title' ) ) ->set_name( $this->get_post_property( 'post_title' ) )

View file

@ -100,12 +100,12 @@ class VS_Event extends \Activitypub\Transformer\Base {
private function get_event_link() { private function get_event_link() {
$event_link = get_post_meta( $this->wp_post->ID, 'event-link', true ); $event_link = get_post_meta( $this->wp_post->ID, 'event-link', true );
if ( $event_link ) { if ( $event_link ) {
return [ return array(
'type' => 'Link', 'type' => 'Link',
'name' => 'Website', 'name' => 'Website',
'href' => \esc_url( get_post_meta( $post_id, 'event-location', true ) ), 'href' => \esc_url( $event_link ),
'mediaType' => 'text/html', 'mediaType' => 'text/html',
]; );
} }
} }
@ -114,6 +114,8 @@ class VS_Event extends \Activitypub\Transformer\Base {
*/ */
protected function get_attachments() { protected function get_attachments() {
$attachments = parent::get_attachments(); $attachments = parent::get_attachments();
$attachments[0]['type'] = 'Document';
$attachments[0]['name'] = 'Banner';
$event_link = $this->get_event_link(); $event_link = $this->get_event_link();
if ( $event_link ) { if ( $event_link ) {
$attachments[] = $this->get_event_link(); $attachments[] = $this->get_event_link();
@ -121,10 +123,6 @@ class VS_Event extends \Activitypub\Transformer\Base {
return $attachments; return $attachments;
} }
private function get_category() {
return 'MEETING';
}
/** /**
* Transforms the VS Event WP_Post object to an ActivityPub Event Object. * Transforms the VS Event WP_Post object to an ActivityPub Event Object.
* *
@ -160,13 +158,13 @@ class VS_Event extends \Activitypub\Transformer\Base {
if ( $summary ) { if ( $summary ) {
$object->set_summary( $summary ); $object->set_summary( $summary );
} else { } else {
$object->set_summary( $this->content ); $object->set_summary( $this->get_content() );
} }
$start_time = get_post_meta( $this->wp_post->ID, 'event-start-date', true ); $start_time = get_post_meta( $this->wp_post->ID, 'event-start-date', true );
$object->set_start_time( \gmdate( 'Y-m-d\TH:i:s\Z', $start_time ) ); $object->set_start_time( \gmdate( 'Y-m-d\TH:i:s\Z', $start_time ) );
$hide_end_time = get_post_meta( $this->wp_post->ID, 'event-hide-end-time', true); $hide_end_time = get_post_meta( $this->wp_post->ID, 'event-hide-end-time', true );
if ( $hide_end_time != 'yes' ) { if ( $hide_end_time != 'yes' ) {
$object->set_end_time( $this->get_end_time() ); $object->set_end_time( $this->get_end_time() );
@ -183,14 +181,26 @@ class VS_Event extends \Activitypub\Transformer\Base {
get_rest_url_by_path( $path ), get_rest_url_by_path( $path ),
) )
) )
->set_cc( $this->get_cc() ) ->set_cc( array( get_rest_url_by_path( $path ) ) )
->set_attachment( $this->get_attachments() ) ->set_attachment( $this->get_attachments() )
->set_tag( $this->get_tags() ) ->set_tag( $this->get_tags() )
->set_replies_moderation_option( 'allow_all' ) ->set_replies_moderation_option( 'allow_all' )
->set_join_mode( 'external' ) ->set_join_mode( 'external' )
->set_external_participation_url( $this->get_url() ) ->set_external_participation_url( $this->get_url() )
->set_status( 'CONFIRMED' ) ->set_status( 'CONFIRMED' )
->set_category( 'MEETING' ); ->set_category( 'MEETING' )
->set_contacts( array() )
->set_name( get_the_title( $this->wp_post->ID ) )
->set_timezone( 'Europe/Vienna' )
->set_is_online( false )
->set_in_language( 'de ' )
->set_actor( $this->get_attributed_to() );
$object->set_remaining_attendee_capacity( null )
->set_anonymous_participation_enabled( null )
->set_draft( false );
$object->set_participant_count( 2 );
$object->set_uuid( '1de96701-bceb-4a78-bc18-6c417f52b314' );
return $object; return $object;
} }