2024-04-09 19:20:53 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ActivityPub Transformer for the plugin Very Simple Event List.
|
|
|
|
*
|
2024-10-02 21:54:03 +02:00
|
|
|
* @package ActivityPub_Event_Bridge
|
2024-04-09 19:20:53 +02:00
|
|
|
* @license AGPL-3.0-or-later
|
|
|
|
*/
|
|
|
|
|
2024-10-02 21:54:03 +02:00
|
|
|
namespace ActivityPub_Event_Bridge\Activitypub\Transformer;
|
2024-09-21 11:00:33 +02:00
|
|
|
|
2024-09-28 13:14:10 +02:00
|
|
|
// Exit if accessed directly.
|
|
|
|
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
|
|
|
|
2024-07-05 13:29:13 +02:00
|
|
|
use Activitypub\Activity\Extended_Object\Event as Event_Object;
|
2024-04-09 19:20:53 +02:00
|
|
|
use Activitypub\Activity\Extended_Object\Place;
|
2024-10-02 21:54:03 +02:00
|
|
|
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event;
|
2024-04-09 19:20:53 +02:00
|
|
|
use GatherPress\Core\Event as GatherPress_Event;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ActivityPub Transformer for VS Event
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
*/
|
2024-09-11 00:38:21 +02:00
|
|
|
final class GatherPress extends Event {
|
2024-04-09 19:20:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The current GatherPress Event object.
|
|
|
|
*
|
2024-08-27 21:13:37 +02:00
|
|
|
* @var GatherPress_Event
|
2024-04-09 19:20:53 +02:00
|
|
|
*/
|
|
|
|
protected $gp_event;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The current GatherPress Venue object.
|
|
|
|
*
|
|
|
|
* @var Event
|
|
|
|
*/
|
|
|
|
protected $gp_venue;
|
|
|
|
|
|
|
|
/**
|
2024-09-25 11:27:17 +02:00
|
|
|
* Extend the constructor, to also set the GatherPress objects.
|
2024-04-09 19:20:53 +02:00
|
|
|
*
|
2024-09-25 11:27:17 +02:00
|
|
|
* This is a special class object form The Events Calendar which
|
|
|
|
* has a lot of useful functions, we make use of our getter functions.
|
2024-04-09 19:20:53 +02:00
|
|
|
*
|
2024-09-25 11:27:17 +02:00
|
|
|
* @param WP_Post $wp_object The WordPress object.
|
|
|
|
* @param string $wp_taxonomy The taxonomy slug of the event post type.
|
2024-04-09 19:20:53 +02:00
|
|
|
*/
|
2024-09-25 11:27:17 +02:00
|
|
|
public function __construct( $wp_object, $wp_taxonomy ) {
|
|
|
|
parent::__construct( $wp_object, $wp_taxonomy );
|
|
|
|
$this->gp_event = new GatherPress_Event( $this->wp_object->ID );
|
|
|
|
$this->gp_venue = $this->gp_event->get_venue_information();
|
2024-04-09 19:20:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the event location.
|
|
|
|
*
|
2024-09-25 11:27:17 +02:00
|
|
|
* @return Place|null The place objector null if not place set.
|
2024-04-09 19:20:53 +02:00
|
|
|
*/
|
2024-09-25 14:30:37 +02:00
|
|
|
public function get_location(): ?Place {
|
2024-04-09 19:20:53 +02:00
|
|
|
$address = $this->gp_venue['full_address'];
|
2024-09-25 11:27:17 +02:00
|
|
|
if ( $address ) {
|
|
|
|
$place = new Place();
|
|
|
|
$place->set_type( 'Place' );
|
|
|
|
$place->set_name( $address );
|
|
|
|
$place->set_address( $address );
|
|
|
|
return $place;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2024-04-09 19:20:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the end time from the event object.
|
|
|
|
*/
|
2024-09-25 14:24:30 +02:00
|
|
|
protected function get_end_time(): ?string {
|
2024-04-09 19:20:53 +02:00
|
|
|
return $this->gp_event->get_datetime_end( 'Y-m-d\TH:i:s\Z' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the end time from the event object.
|
|
|
|
*/
|
2024-09-25 14:24:30 +02:00
|
|
|
protected function get_start_time(): string {
|
2024-04-09 19:20:53 +02:00
|
|
|
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.
|
|
|
|
*/
|
2024-09-25 11:27:17 +02:00
|
|
|
protected function get_attachment(): array {
|
2024-04-09 19:20:53 +02:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-10-02 19:15:28 +02:00
|
|
|
* Prevents gatherpress blocks from being rendered for the content.
|
2024-04-09 19:20:53 +02:00
|
|
|
*
|
2024-10-02 19:15:28 +02:00
|
|
|
* @param mixed $block_content The blocks content.
|
|
|
|
* @param mixed $block The block.
|
2024-04-09 19:20:53 +02:00
|
|
|
*/
|
2024-10-02 19:15:28 +02:00
|
|
|
public static function filter_gatherpress_blocks( $block_content, $block ) {
|
|
|
|
// Check if the block name starts with 'gatherpress'.
|
2024-10-19 16:58:54 +02:00
|
|
|
if ( isset( $block['blockName'] ) && 0 === strpos( $block['blockName'], 'gatherpress/' ) ) {
|
2024-10-02 19:15:28 +02:00
|
|
|
return ''; // Skip rendering this block.
|
2024-04-09 19:20:53 +02:00
|
|
|
}
|
|
|
|
|
2024-10-02 19:15:28 +02:00
|
|
|
return $block_content; // Return the content for other blocks.
|
2024-04-09 19:20:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-10-02 19:15:28 +02:00
|
|
|
* Apply the filter for preventing the rendering off gatherpress blocks just in time.
|
|
|
|
*
|
|
|
|
* @return Event_Object
|
2024-04-09 19:20:53 +02:00
|
|
|
*/
|
2024-10-02 19:15:28 +02:00
|
|
|
public function to_object(): Event_Object {
|
|
|
|
add_filter( 'render_block', array( self::class, 'filter_gatherpress_blocks' ), 10, 2 );
|
|
|
|
$activitypub_object = parent::to_object();
|
|
|
|
remove_filter( 'render_block', array( self::class, 'filter_gatherpress_blocks' ) );
|
|
|
|
return $activitypub_object;
|
2024-09-25 11:27:17 +02:00
|
|
|
}
|
2024-04-09 19:20:53 +02:00
|
|
|
|
2024-09-25 11:27:17 +02:00
|
|
|
/**
|
|
|
|
* Determine whether the event is online.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function get_is_online(): bool {
|
|
|
|
return $this->gp_event->maybe_get_online_event_link() ? true : false;
|
|
|
|
}
|
2024-04-09 19:20:53 +02:00
|
|
|
}
|