stash-2024-04-09

This commit is contained in:
André Menrath 2024-04-09 19:20:53 +02:00
parent 1859970d06
commit 4fef29a6c2
7 changed files with 367 additions and 57 deletions

View file

@ -47,6 +47,15 @@ add_filter(
return new \Events_Manager( $wp_object ); return new \Events_Manager( $wp_object );
} }
/**
* Events manager
* @see https://wordpress.org/plugins/events-manager/
*/
if ( class_exists( 'GatherPress\Core\Event' ) && $wp_object->post_type === 'gp_event' ) {
require_once __DIR__ . '/includes/activitypub/transformer/class-gatherpress.php';
return new \GatherPress( $wp_object );
}
// Return the default transformer. // Return the default transformer.
return $transformer; return $transformer;

View file

@ -1,2 +1,6 @@
<?php <?php
// Handling Event Joins /**
* Handling Event Joins.
*
* @package activitypub-event-extensions
*/

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* ActivityPub Transformer for the plugin Very Simple Event List. * ActivityPub Transformer for the plugin Very Simple Event List.
* *
@ -7,7 +8,6 @@
*/ */
use EM_Event; use EM_Event;
use Activitypub\Activity\Extended_Object\Event; use Activitypub\Activity\Extended_Object\Event;
use Activitypub\Activity\Extended_Object\Place; use Activitypub\Activity\Extended_Object\Place;
use Activitypub\Transformer\Post; use Activitypub\Transformer\Post;
@ -26,6 +26,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* @since 1.0.0 * @since 1.0.0
*/ */
class Events_Manager extends Post { class Events_Manager extends Post {
/** /**
* Holds the EM_Event object. * Holds the EM_Event object.
* *
@ -43,6 +44,7 @@ class Events_Manager extends Post {
* @return string Widget name. * @return string Widget name.
*/ */
public function get_transformer_name() { public function get_transformer_name() {
return 'activitypub-event-transformers/events-manager'; return 'activitypub-event-transformers/events-manager';
} }
@ -56,6 +58,7 @@ class Events_Manager extends Post {
* @return string Widget title. * @return string Widget title.
*/ */
public function get_transformer_label() { public function get_transformer_label() {
return 'Events Manager'; return 'Events Manager';
} }
@ -69,6 +72,7 @@ class Events_Manager extends Post {
* @return array Widget categories. * @return array Widget categories.
*/ */
public static function get_supported_post_types() { public static function get_supported_post_types() {
return array(); return array();
} }
@ -80,10 +84,12 @@ class Events_Manager extends Post {
* @return string The Event Object-Type. * @return string The Event Object-Type.
*/ */
protected function get_type() { protected function get_type() {
return 'Event'; return 'Event';
} }
protected function get_is_online() { protected function get_is_online() {
return 'url' === $this->em_event->event_location_type; return 'url' === $this->em_event->event_location_type;
} }
@ -94,6 +100,7 @@ class Events_Manager extends Post {
* @return array The Place. * @return array The Place.
*/ */
public function get_location() { public function get_location() {
if ( 'url' === $this->em_event->event_location_type ) { if ( 'url' === $this->em_event->event_location_type ) {
return null; return null;
} }
@ -121,11 +128,11 @@ class Events_Manager extends Post {
return $location; return $location;
} }
/** /**
* Get the end time from the events metadata. * Get the end time from the events metadata.
*/ */
protected function get_end_time() { protected function get_end_time() {
return null; return null;
} }
@ -133,6 +140,7 @@ class Events_Manager extends Post {
* Get the end time from the events metadata. * Get the end time from the events metadata.
*/ */
protected function get_start_time() { protected function get_start_time() {
$date_string = $this->em_event->event_start_date; $date_string = $this->em_event->event_start_date;
$time_string = $this->em_event->event_start_time; $time_string = $this->em_event->event_start_time;
$timezone_string = $this->em_event->event_timezone; $timezone_string = $this->em_event->event_timezone;
@ -149,6 +157,7 @@ class Events_Manager extends Post {
} }
protected function get_maximum_attendee_capacity() { protected function get_maximum_attendee_capacity() {
return $this->em_event->event_spaces; return $this->em_event->event_spaces;
} }
@ -156,21 +165,25 @@ class Events_Manager extends Post {
* @todo decide whether to include pending bookings or not! * @todo decide whether to include pending bookings or not!
*/ */
protected function get_remaining_attendee_capacity() { protected function get_remaining_attendee_capacity() {
$em_bookings = $this->em_event->get_bookings()->get_bookings(); $em_bookings = $this->em_event->get_bookings()->get_bookings();
$remaining_attendee_capacity = $this->em_event->event_spaces - count( $em_bookings->bookings ); $remaining_attendee_capacity = $this->em_event->event_spaces - count( $em_bookings->bookings );
return $remaining_attendee_capacity; return $remaining_attendee_capacity;
} }
protected function get_participant_count() { protected function get_participant_count() {
$em_bookings = $this->em_event->get_bookings()->get_bookings(); $em_bookings = $this->em_event->get_bookings()->get_bookings();
return count( $em_bookings->bookings ); return count( $em_bookings->bookings );
} }
protected function get_content() { protected function get_content() {
return $this->wp_object->post_content; return $this->wp_object->post_content;
} }
protected function get_summary() { protected function get_summary() {
if ( $this->em_event->post_excerpt ) { if ( $this->em_event->post_excerpt ) {
$excerpt = $this->em_event->post_excerpt; $excerpt = $this->em_event->post_excerpt;
} else { } else {
@ -189,6 +202,7 @@ class Events_Manager extends Post {
// } // }
private function get_event_link_attachment() { private function get_event_link_attachment() {
$event_link_url = $this->em_event->event_location->data['url']; $event_link_url = $this->em_event->event_location->data['url'];
$event_link_text = $this->em_event->event_location->data['text']; $event_link_text = $this->em_event->event_location->data['text'];
return array( return array(
@ -216,7 +230,8 @@ class Events_Manager extends Post {
if ( 'url' === $this->em_event->event_location_type ) { if ( 'url' === $this->em_event->event_location_type ) {
$attachments[] = $this->get_event_link_attachment(); $attachments[] = $this->get_event_link_attachment();
} }
return $attachments; } return $attachments;
}
/** /**
* This function tries to map VS-Event categories to Mobilizon event categories. * This function tries to map VS-Event categories to Mobilizon event categories.
@ -224,6 +239,7 @@ class Events_Manager extends Post {
* @return string $category * @return string $category
*/ */
protected function get_category() { protected function get_category() {
$categories = $this->em_event->get_categories()->terms; $categories = $this->em_event->get_categories()->terms;
if ( empty( $categories ) ) { if ( empty( $categories ) ) {
@ -286,6 +302,7 @@ class Events_Manager extends Post {
} }
protected function get_name() { protected function get_name() {
return $this->em_event->event_name; return $this->em_event->event_name;
} }
@ -295,6 +312,7 @@ class Events_Manager extends Post {
* @return Activitypub\Activity\Event * @return Activitypub\Activity\Event
*/ */
public function to_object() { public function to_object() {
$this->em_event = new EM_Event( $this->wp_object->ID, 'post_id' ); $this->em_event = new EM_Event( $this->wp_object->ID, 'post_id' );
$activitypub_object = new Event(); $activitypub_object = new Event();

View file

@ -0,0 +1,251 @@
<?php
/**
* ActivityPub Transformer for the plugin Very Simple Event List.
*
* @package activity-event-transformers
* @license AGPL-3.0-or-later
*/
use Activitypub\Transformer\Post;
use Activitypub\Model\Blog_user;
use Activitypub\Activity\Extended_Object\Event;
use Activitypub\Activity\Extended_Object\Place;
use GatherPress\Core\Event as GatherPress_Event;
use function Activitypub\get_rest_url_by_path;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* ActivityPub Transformer for VS Event
*
* @since 1.0.0
*/
class GatherPress extends Post {
/**
* The target transformet ActivityPub Event object.
*
* @var Event
*/
protected $ap_object;
/**
* The current GatherPress Event object.
*
* @var Event
*/
protected $gp_event;
/**
* The current GatherPress Venue object.
*
* @var Event
*/
protected $gp_venue;
/**
* Get transformer name.
*
* Retrieve the transformers name.
*
* @since 1.0.0
* @access public
* @return string Widget name.
*/
public function get_transformer_name() {
return 'gatherpress/gp-event';
}
/**
* Get transformer title.
*
* Retrieve the transformers label.
*
* @since 1.0.0
* @access public
* @return string Widget title.
*/
public function get_transformer_label() {
return 'GatherPress Event';
}
/**
* Get supported post types.
*
* Retrieve the list of supported WordPress post types this transformer widget can handle.
*
* @since 1.0.0
* @access public
* @return array Widget categories.
*/
public static function get_supported_post_types() {
return array( GatherPress_Event::POST_TYPE );
}
/**
* Returns the ActivityStreams 2.0 Object-Type for an Event.
*
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-event
* @since 1.0.0
* @return string The Event Object-Type.
*/
protected function get_type() {
return 'Event';
}
/**
* Get the event location.
*
* @return array The Place.
*/
public function get_location() {
$address = $this->gp_venue['full_address'];
$place = new Place();
$place->set_type( 'Place' );
$place->set_name( $address );
$place->set_address( $address );
return $place;
}
/**
* Get the end time from the event object.
*/
protected function get_end_time() {
return $this->gp_event->get_datetime_end( 'Y-m-d\TH:i:s\Z' );
}
/**
* Get the end time from the event object.
*/
protected function get_start_time() {
return $this->gp_event->get_datetime_start( 'Y-m-d\TH:i:s\Z' );
}
/**
* Get the event link from the events metadata.
*/
private function get_event_link() {
$event_link = get_post_meta( $this->wp_object->ID, 'event-link', true );
if ( $event_link ) {
return array(
'type' => 'Link',
'name' => 'Website',
'href' => \esc_url( $event_link ),
'mediaType' => 'text/html',
);
}
}
/**
* Overrides/extends the get_attachments function to also add the event Link.
*/
protected function get_attachment() {
$attachments = parent::get_attachment();
if ( count( $attachments ) ) {
$attachments[0]['type'] = 'Document';
$attachments[0]['name'] = 'Banner';
}
$event_link = $this->get_event_link();
if ( $event_link ) {
$attachments[] = $this->get_event_link();
}
return $attachments;
}
/**
* TODO:
*
* @return string $category
*/
protected function get_category() {
return 'MEETING';
}
/**
* Returns the User-URL of the Author of the Post.
*
* If `single_user` mode is enabled, the URL of the Blog-User is returned.
*
* @return string The User-URL.
*/
protected function get_attributed_to() {
$user = new Blog_User();
return $user->get_url();
}
/**
* Create a custom summary.
*
* It contains also the most important meta-information. The summary is often used when the
* ActivityPub object type 'Event' is not supported, e.g. in Mastodon.
*
* @return string $summary The custom event summary.
*/
public function get_summary() {
if ( $this->wp_object->excerpt ) {
$excerpt = $this->wp_object->post_excerpt;
} elseif ( get_post_meta( $this->wp_object->ID, 'event-summary', true ) ) {
$excerpt = get_post_meta( $this->wp_object->ID, 'event-summary', true );
} else {
$excerpt = $this->get_content();
}
$address = get_post_meta( $this->wp_object->ID, 'event-location', true );
$start_time = get_post_meta( $this->wp_object->ID, 'event-start-date', true );
$datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
$start_time_string = wp_date( $datetime_format, $start_time );
$summary = "📍 {$address}\n📅 {$start_time_string}\n\n{$excerpt}";
return $summary;
}
/**
* Transform the WordPress Object into an ActivityPub Object.
*
* @return Activitypub\Activity\Event
*/
public function to_object() {
$this->ap_object = new Event();
$this->gp_event = new GatherPress_Event( $this->wp_object->ID );
$this->gp_venue = $this->gp_event->get_venue_information();
$this->ap_object = parent::to_object();
$this->ap_object->set_comments_enabled( 'open' === $this->wp_object->comment_status ? true : false );
$this->ap_object->set_external_participation_url( $this->get_url() );
$online_event_link = $this->gp_event->maybe_get_online_event_link();
if ( $online_event_link ) {
$this->ap_object->set_is_online( true );
} else {
$this->ap_object->set_is_online( false );
}
$this->ap_object->set_status( 'CONFIRMED' );
$this->ap_object->set_name( get_the_title( $this->wp_object->ID ) );
$this->ap_object->set_actor( get_rest_url_by_path( 'application' ) );
$this->ap_object->set_to( array( 'https://www.w3.org/ns/activitystreams#Public' ) );
$this->ap_object->set_location();
return $this->ap_object;
}
}

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* ActivityPub Tribe Transformer * ActivityPub Tribe Transformer
* *
@ -20,6 +21,7 @@ use Activitypub\Activity\Extended_Object\Place;
* @since 1.0.0 * @since 1.0.0
*/ */
class Tribe extends Post { class Tribe extends Post {
/** /**
* The Tribe Event object. * The Tribe Event object.
* *
@ -48,6 +50,7 @@ class Tribe extends Post {
* @return string Widget name. * @return string Widget name.
*/ */
public function get_name() { public function get_name() {
return 'activitypub-event-transformers/tribe'; return 'activitypub-event-transformers/tribe';
} }
@ -61,6 +64,7 @@ class Tribe extends Post {
* @return string Widget title. * @return string Widget title.
*/ */
public function get_label() { public function get_label() {
return 'The Events Calendar'; return 'The Events Calendar';
} }
@ -72,6 +76,7 @@ class Tribe extends Post {
* @return string The Event Object-Type. * @return string The Event Object-Type.
*/ */
protected function get_object_type() { protected function get_object_type() {
return 'Event'; return 'Event';
} }
@ -85,6 +90,7 @@ class Tribe extends Post {
* @return array Widget categories. * @return array Widget categories.
*/ */
public static function get_supported_post_types() { public static function get_supported_post_types() {
return array( 'tribe_events' ); return array( 'tribe_events' );
} }
@ -112,6 +118,7 @@ class Tribe extends Post {
* @return string status of the event * @return string status of the event
*/ */
public function get_tribe_status() { public function get_tribe_status() {
if ( 'canceled' === $this->tribe_event->event_status ) { if ( 'canceled' === $this->tribe_event->event_status ) {
return 'CANCELLED'; return 'CANCELLED';
} }
@ -133,6 +140,7 @@ class Tribe extends Post {
* @return string The content. * @return string The content.
*/ */
protected function get_content() { protected function get_content() {
$content = parent::get_content(); $content = parent::get_content();
// todo remove link at the end of the content // todo remove link at the end of the content

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* ActivityPub Transformer for the plugin Very Simple Event List. * ActivityPub Transformer for the plugin Very Simple Event List.
* *
@ -23,8 +24,10 @@ if ( ! defined( 'ABSPATH' ) ) {
* @since 1.0.0 * @since 1.0.0
*/ */
class VS_Event extends Post { class VS_Event extends Post {
/** /**
* The target transformet ActivityPub Event object. * The target transformet ActivityPub Event object.
*
* @var Event * @var Event
*/ */
protected $ap_object; protected $ap_object;
@ -39,6 +42,7 @@ class VS_Event extends Post {
* @return string Widget name. * @return string Widget name.
*/ */
public function get_transformer_name() { public function get_transformer_name() {
return 'activitypub-event-transformers/vs-event'; return 'activitypub-event-transformers/vs-event';
} }
@ -52,6 +56,7 @@ class VS_Event extends Post {
* @return string Widget title. * @return string Widget title.
*/ */
public function get_transformer_label() { public function get_transformer_label() {
return 'VS Event'; return 'VS Event';
} }
@ -65,6 +70,7 @@ class VS_Event extends Post {
* @return array Widget categories. * @return array Widget categories.
*/ */
public static function get_supported_post_types() { public static function get_supported_post_types() {
return array( 'event' ); return array( 'event' );
} }
@ -76,6 +82,7 @@ class VS_Event extends Post {
* @return string The Event Object-Type. * @return string The Event Object-Type.
*/ */
protected function get_type() { protected function get_type() {
return 'Event'; return 'Event';
} }
@ -86,6 +93,7 @@ class VS_Event extends Post {
* @return array The Place. * @return array The Place.
*/ */
public function get_location() { public function get_location() {
$address = get_post_meta( $this->wp_object->ID, 'event-location', true ); $address = get_post_meta( $this->wp_object->ID, 'event-location', true );
$place = new Place(); $place = new Place();
$place->set_type( 'Place' ); $place->set_type( 'Place' );
@ -98,6 +106,7 @@ class VS_Event extends Post {
* Get the end time from the events metadata. * Get the end time from the events metadata.
*/ */
protected function get_end_time() { protected function get_end_time() {
$end_time = get_post_meta( $this->wp_object->ID, 'event-date', true ); $end_time = get_post_meta( $this->wp_object->ID, 'event-date', true );
return \gmdate( 'Y-m-d\TH:i:s\Z', $end_time ); return \gmdate( 'Y-m-d\TH:i:s\Z', $end_time );
} }
@ -106,6 +115,7 @@ class VS_Event extends Post {
* Get the end time from the events metadata. * Get the end time from the events metadata.
*/ */
protected function get_start_time() { protected function get_start_time() {
$start_time = get_post_meta( $this->wp_object->ID, 'event-start-date', true ); $start_time = get_post_meta( $this->wp_object->ID, 'event-start-date', true );
return \gmdate( 'Y-m-d\TH:i:s\Z', $start_time ); return \gmdate( 'Y-m-d\TH:i:s\Z', $start_time );
} }
@ -114,6 +124,7 @@ class VS_Event extends Post {
* Get the event link from the events metadata. * Get the event link from the events metadata.
*/ */
private function get_event_link() { private function get_event_link() {
$event_link = get_post_meta( $this->wp_object->ID, 'event-link', true ); $event_link = get_post_meta( $this->wp_object->ID, 'event-link', true );
if ( $event_link ) { if ( $event_link ) {
return array( return array(
@ -129,6 +140,7 @@ class VS_Event extends Post {
* Overrides/extends the get_attachments function to also add the event Link. * Overrides/extends the get_attachments function to also add the event Link.
*/ */
protected function get_attachment() { protected function get_attachment() {
$attachments = parent::get_attachment(); $attachments = parent::get_attachment();
if ( count( $attachments ) ) { if ( count( $attachments ) ) {
$attachments[0]['type'] = 'Document'; $attachments[0]['type'] = 'Document';
@ -147,6 +159,7 @@ class VS_Event extends Post {
* @return string $category * @return string $category
*/ */
protected function get_category() { protected function get_category() {
$post_categories = wp_get_post_terms( $this->wp_object->ID, 'event_cat' ); $post_categories = wp_get_post_terms( $this->wp_object->ID, 'event_cat' );
if ( empty( $post_categories ) ) { if ( empty( $post_categories ) ) {
@ -197,6 +210,7 @@ class VS_Event extends Post {
* @return string The User-URL. * @return string The User-URL.
*/ */
protected function get_attributed_to() { protected function get_attributed_to() {
$user = new Blog_User(); $user = new Blog_User();
return $user->get_url(); return $user->get_url();
} }
@ -210,6 +224,7 @@ class VS_Event extends Post {
* @return string $summary The custom event summary. * @return string $summary The custom event summary.
*/ */
public function get_summary() { public function get_summary() {
if ( $this->wp_object->excerpt ) { if ( $this->wp_object->excerpt ) {
$excerpt = $this->wp_object->post_excerpt; $excerpt = $this->wp_object->post_excerpt;
} elseif ( get_post_meta( $this->wp_object->ID, 'event-summary', true ) ) { } elseif ( get_post_meta( $this->wp_object->ID, 'event-summary', true ) ) {
@ -226,7 +241,6 @@ class VS_Event extends Post {
return $summary; return $summary;
} }
/** /**
* Generic setter. * Generic setter.
* *
@ -236,6 +250,7 @@ class VS_Event extends Post {
* @return mixed The value. * @return mixed The value.
*/ */
public function set( $key, $value ) { public function set( $key, $value ) {
if ( ! $this->ap_object->has( $key ) ) { if ( ! $this->ap_object->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 ) );
} }
@ -261,6 +276,7 @@ class VS_Event extends Post {
* @return void * @return void
*/ */
public function __call( $method, $params ) { public function __call( $method, $params ) {
$var = \strtolower( \substr( $method, 4 ) ); $var = \strtolower( \substr( $method, 4 ) );
if ( \strncasecmp( $method, 'set', 3 ) === 0 ) { if ( \strncasecmp( $method, 'set', 3 ) === 0 ) {
@ -278,6 +294,7 @@ class VS_Event extends Post {
* @return Activitypub\Activity\Event * @return Activitypub\Activity\Event
*/ */
public function to_object() { public function to_object() {
$this->ap_object = new Event(); $this->ap_object = new Event();
$this $this

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Mapping of WordPress Terms(Tags) to known Event Categories * Mapping of WordPress Terms(Tags) to known Event Categories
* *
@ -18,10 +19,12 @@ use Activitypub\Activity\Extended_Object\Event;
* @since 1.0.0 * @since 1.0.0
*/ */
class Category_Mapper { class Category_Mapper {
/** /**
* Static function to do the Mapping * Static function to do the Mapping
**/ **/
public static function map( $post_categories ) { public static function map( $post_categories ) {
if ( empty( $post_categories ) ) { if ( empty( $post_categories ) ) {
return 'MEETING'; return 'MEETING';
} }