2024-10-12 10:34:21 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ActivityPub Transformer for Events managed with Eventin.
|
|
|
|
*
|
|
|
|
* @link https://support.themewinter.com/docs/plugins/docs-category/eventin/
|
|
|
|
*
|
|
|
|
* @package ActivityPub_Event_Bridge
|
|
|
|
* @license AGPL-3.0-or-later
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace ActivityPub_Event_Bridge\Activitypub\Transformer;
|
|
|
|
|
|
|
|
// Exit if accessed directly.
|
|
|
|
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
|
|
|
|
|
|
|
use Activitypub\Activity\Extended_Object\Place;
|
|
|
|
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event;
|
2024-10-12 13:52:06 +02:00
|
|
|
use DateTime;
|
|
|
|
use DateTimeZone;
|
2024-10-12 10:34:21 +02:00
|
|
|
use Etn\Core\Event\Event_Model;
|
|
|
|
|
2024-10-12 13:52:06 +02:00
|
|
|
use function Activitypub\esc_hashtag;
|
|
|
|
|
2024-10-12 10:34:21 +02:00
|
|
|
/**
|
|
|
|
* ActivityPub Transformer for Events managed with Eventin.
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
*/
|
|
|
|
final class Eventin extends Event {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Holds the EM_Event object.
|
|
|
|
*
|
|
|
|
* @var Event_Model
|
|
|
|
*/
|
|
|
|
protected $event_model;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extend the constructor, to also set the Event Model.
|
|
|
|
*
|
|
|
|
* This is a special class object form The Events Calendar which
|
|
|
|
* has a lot of useful functions, we make use of our getter functions.
|
|
|
|
*
|
|
|
|
* @param WP_Post $wp_object The WordPress object.
|
|
|
|
* @param string $wp_taxonomy The taxonomy slug of the event post type.
|
|
|
|
*/
|
|
|
|
public function __construct( $wp_object, $wp_taxonomy ) {
|
|
|
|
parent::__construct( $wp_object, $wp_taxonomy );
|
|
|
|
$this->event_model = new Event_Model( $this->wp_object->ID );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the end time from the event object.
|
|
|
|
*/
|
2024-10-12 13:52:06 +02:00
|
|
|
public function get_start_time(): string {
|
|
|
|
$datetime = new DateTime( $this->event_model->get_start_datetime(), new DateTimeZone( $this->event_model->get_timezone() ) );
|
|
|
|
return \gmdate( 'Y-m-d\TH:i:s\Z', $datetime->getTimestamp() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the end time from the event object.
|
|
|
|
*/
|
|
|
|
public function get_end_time(): string {
|
|
|
|
$datetime = new DateTime( $this->event_model->get_end_datetime(), new DateTimeZone( $this->event_model->get_timezone() ) );
|
|
|
|
return \gmdate( 'Y-m-d\TH:i:s\Z', $datetime->getTimestamp() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the timezone of the event.
|
|
|
|
*/
|
|
|
|
public function get_timezone(): string {
|
|
|
|
return $this->event_model->get_timezone();
|
2024-10-12 10:34:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-10-12 13:52:06 +02:00
|
|
|
* Get whether the event is online.
|
2024-10-12 10:34:21 +02:00
|
|
|
*
|
2024-10-12 13:52:06 +02:00
|
|
|
* @return bool
|
2024-10-12 10:34:21 +02:00
|
|
|
*/
|
2024-10-12 13:52:06 +02:00
|
|
|
public function get_is_online(): bool {
|
|
|
|
return 'online' === $this->event_model->__get( 'event_type' ) ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maybe add online link to attachments.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get_attachment(): array {
|
|
|
|
$attachment = parent::get_attachment();
|
|
|
|
|
|
|
|
$location = (array) $this->event_model->__get( 'location' );
|
|
|
|
if ( array_key_exists( 'integration', $location ) && array_key_exists( $location['integration'], $location ) ) {
|
|
|
|
$online_link = array(
|
|
|
|
'type' => 'Link',
|
|
|
|
'mediaType' => 'text/html',
|
|
|
|
'name' => $location[ $location['integration'] ],
|
|
|
|
'href' => $location[ $location['integration'] ],
|
|
|
|
);
|
|
|
|
$attachment[] = $online_link;
|
|
|
|
}
|
|
|
|
return $attachment;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compose the events tags.
|
|
|
|
*/
|
|
|
|
public function get_tag() {
|
|
|
|
// The parent tag function also fetches the mentions.
|
|
|
|
$tags = parent::get_tag();
|
|
|
|
|
|
|
|
$post_tags = \wp_get_post_terms( $this->wp_object->ID, 'etn_tags' );
|
|
|
|
$post_categories = \wp_get_post_terms( $this->wp_object->ID, 'etn_category' );
|
|
|
|
|
|
|
|
if ( ! is_wp_error( $post_tags ) && $post_tags ) {
|
|
|
|
foreach ( $post_tags as $term ) {
|
|
|
|
$tag = array(
|
|
|
|
'type' => 'Hashtag',
|
|
|
|
'href' => \esc_url( \get_tag_link( $term->term_id ) ),
|
|
|
|
'name' => esc_hashtag( $term->name ),
|
|
|
|
);
|
|
|
|
$tags[] = $tag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! is_wp_error( $post_categories ) && $post_categories ) {
|
|
|
|
foreach ( $post_categories as $term ) {
|
|
|
|
$tag = array(
|
|
|
|
'type' => 'Hashtag',
|
|
|
|
'href' => \esc_url( \get_tag_link( $term->term_id ) ),
|
|
|
|
'name' => esc_hashtag( $term->name ),
|
|
|
|
);
|
|
|
|
$tags[] = $tag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( empty( $tags ) ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $tags;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the location.
|
|
|
|
*
|
|
|
|
* @return ?Place
|
|
|
|
*/
|
|
|
|
public function get_location(): ?Place {
|
|
|
|
$location = (array) $this->event_model->__get( 'location' );
|
|
|
|
|
|
|
|
if ( ! array_key_exists( 'address', $location ) ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$place = new Place();
|
|
|
|
|
|
|
|
$address = $location['address'];
|
|
|
|
|
|
|
|
$place->set_name( $address );
|
|
|
|
$place->set_address( $address );
|
2024-10-12 13:59:50 +02:00
|
|
|
$place->set_sensitive( null );
|
2024-10-12 13:52:06 +02:00
|
|
|
|
|
|
|
return $place;
|
2024-10-12 10:34:21 +02:00
|
|
|
}
|
|
|
|
}
|