2024-08-27 21:13:37 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* ActivityPub Tribe Transformer
|
|
|
|
*
|
2024-09-18 21:26:53 +02:00
|
|
|
* @package Activitypub_Event_Extensions
|
2024-08-27 21:13:37 +02:00
|
|
|
* @license AGPL-3.0-or-later
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Activitypub_Event_Extensions\Activitypub\Transformer;
|
|
|
|
|
2024-09-28 13:14:10 +02:00
|
|
|
// Exit if accessed directly.
|
|
|
|
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
2024-08-27 21:13:37 +02:00
|
|
|
|
2024-09-27 23:20:30 +02:00
|
|
|
use Activitypub\Activity\Extended_Object\Event as Event_Object;
|
|
|
|
use Activitypub\Activity\Extended_Object\Place;
|
|
|
|
use Activitypub_Event_Extensions\Activitypub\Transformer\Event;
|
2024-08-27 21:13:37 +02:00
|
|
|
use WP_Post;
|
2024-09-27 23:20:30 +02:00
|
|
|
|
|
|
|
use function Activitypub\esc_hashtag;
|
|
|
|
|
2024-08-27 21:13:37 +02:00
|
|
|
/**
|
|
|
|
* ActivityPub Tribe Transformer
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
*/
|
2024-09-11 00:38:21 +02:00
|
|
|
final class The_Events_Calendar extends Event {
|
2024-08-27 21:13:37 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Tribe Event object.
|
|
|
|
*
|
|
|
|
* @var array|WP_Post|null
|
|
|
|
*/
|
|
|
|
protected $tribe_event;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extend the constructor, to also set the tribe object.
|
|
|
|
*
|
|
|
|
* 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.
|
2024-09-11 00:38:21 +02:00
|
|
|
* @param string $wp_taxonomy The taxonomy slug of the event post type.
|
2024-08-27 21:13:37 +02:00
|
|
|
*/
|
2024-09-11 00:38:21 +02:00
|
|
|
public function __construct( $wp_object, $wp_taxonomy ) {
|
|
|
|
parent::__construct( $wp_object, $wp_taxonomy );
|
2024-08-27 21:13:37 +02:00
|
|
|
$this->tribe_event = \tribe_get_event( $wp_object );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-09-27 23:20:30 +02:00
|
|
|
* Get the tags, including also the set categories from The Events Calendar.
|
2024-08-27 21:13:37 +02:00
|
|
|
*
|
2024-09-27 23:20:30 +02:00
|
|
|
* @return ?array The array if tags,
|
2024-08-27 21:13:37 +02:00
|
|
|
*/
|
2024-09-27 23:20:30 +02:00
|
|
|
public function get_tag(): ?array {
|
|
|
|
$tags = array();
|
|
|
|
$category_ids = tribe_get_event_cat_ids();
|
|
|
|
if ( $category_ids ) {
|
|
|
|
foreach ( $category_ids as $category_id ) {
|
|
|
|
$term = \get_term( $category_id );
|
|
|
|
$tag = array(
|
|
|
|
'type' => 'Hashtag',
|
|
|
|
'href' => \esc_url( \get_term_link( $term ) ),
|
|
|
|
'name' => esc_hashtag( $term->name ),
|
|
|
|
);
|
|
|
|
$tags[] = $tag;
|
|
|
|
}
|
2024-08-27 21:13:37 +02:00
|
|
|
}
|
2024-09-27 23:20:30 +02:00
|
|
|
$tags[] = parent::get_tag();
|
2024-08-27 21:13:37 +02:00
|
|
|
|
2024-09-27 23:20:30 +02:00
|
|
|
return $tags;
|
2024-08-27 21:13:37 +02:00
|
|
|
}
|
|
|
|
|
2024-09-18 21:26: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 {
|
|
|
|
if ( empty( $this->tribe_event->end_date ) ) {
|
|
|
|
return null;
|
|
|
|
}
|
2024-09-18 21:26:53 +02:00
|
|
|
$date = date_create( $this->tribe_event->end_date, wp_timezone() );
|
|
|
|
return \gmdate( 'Y-m-d\TH:i:s\Z', $date->getTimestamp() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the end time from the event object.
|
|
|
|
*/
|
2024-09-25 14:24:30 +02:00
|
|
|
protected function get_start_time(): string {
|
2024-09-18 21:26:53 +02:00
|
|
|
$date = date_create( $this->tribe_event->start_date, wp_timezone() );
|
|
|
|
return \gmdate( 'Y-m-d\TH:i:s\Z', $date->getTimestamp() );
|
|
|
|
}
|
|
|
|
|
2024-08-27 21:13:37 +02:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
}
|
2024-09-27 23:20:30 +02:00
|
|
|
return 'CONFIRMED';
|
2024-08-27 21:13:37 +02:00
|
|
|
}
|
|
|
|
|
2024-09-27 23:20:30 +02:00
|
|
|
|
2024-08-27 21:13:37 +02:00
|
|
|
/**
|
|
|
|
* Check if the comments are enabled for the current event.
|
|
|
|
*/
|
|
|
|
public function get_comments_enabled(): bool {
|
|
|
|
return ( 'open' === $this->tribe_event->comment_status ) ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the event is an online event.
|
|
|
|
*/
|
|
|
|
public function get_is_online(): bool {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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() {
|
2024-09-21 11:00:33 +02:00
|
|
|
// /BeforeFirstRelease:
|
2024-09-29 15:45:53 +02:00
|
|
|
// * [X] remove link at the end of the content.
|
|
|
|
// * [ ] add organizer.
|
|
|
|
// * [ ] do add Cancelled reason in the content.
|
|
|
|
|
|
|
|
// Add Organizer:
|
|
|
|
// $this->wp_object->post_content .= organizer_string;
|
|
|
|
// rest will be handled by parent::get_content().
|
2024-08-27 21:13:37 +02:00
|
|
|
|
2024-09-29 15:45:53 +02:00
|
|
|
$content = parent::get_content();
|
2024-08-27 21:13:37 +02:00
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the event location.
|
|
|
|
*
|
|
|
|
* @return Place|array The place/venue if one is set.
|
|
|
|
*/
|
|
|
|
public function get_location(): Place|null {
|
2024-09-24 16:24:31 +02:00
|
|
|
// Get short handle for the venues.
|
2024-09-27 18:04:29 +02:00
|
|
|
$venues = $this->tribe_event->venues;
|
2024-09-24 16:24:31 +02:00
|
|
|
|
|
|
|
// Get first venue. We currently only support a single venue.
|
|
|
|
if ( $venues instanceof \Tribe\Events\Collections\Lazy_Post_Collection ) {
|
|
|
|
$venue = $venues->first();
|
|
|
|
} elseif ( empty( $this->wp_object->venues ) || ! empty( $this->wp_object->venues[0] ) ) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
$venue = $venues[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! $venue ) {
|
2024-08-27 21:13:37 +02:00
|
|
|
return null;
|
|
|
|
}
|
2024-09-24 16:24:31 +02:00
|
|
|
|
|
|
|
// Set the address.
|
|
|
|
$address = array();
|
|
|
|
|
|
|
|
if ( ! empty( $venue->country ) ) {
|
|
|
|
$address['addressCountry'] = $venue->country;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! empty( $venue->city ) ) {
|
|
|
|
$address['addressLocality'] = $venue->city;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! empty( $venue->province ) ) {
|
|
|
|
$address['addressRegion'] = $venue->province;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! empty( $venue->zip ) ) {
|
|
|
|
$address['postalCode'] = $venue->zip;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! empty( $venue->address ) ) {
|
|
|
|
$address['streetAddress'] = $venue->address;
|
|
|
|
}
|
2024-09-24 17:14:39 +02:00
|
|
|
if ( ! empty( $venue->post_title ) ) {
|
|
|
|
$address['name'] = $venue->post_title;
|
|
|
|
}
|
2024-09-24 16:24:31 +02:00
|
|
|
$address['type'] = 'PostalAddress';
|
2024-08-27 21:13:37 +02:00
|
|
|
|
|
|
|
$location = new Place();
|
2024-09-24 16:24:31 +02:00
|
|
|
if ( count( $address ) > 1 ) {
|
|
|
|
$location->set_address( $address );
|
2024-09-27 18:04:29 +02:00
|
|
|
} else {
|
|
|
|
$location->set_address( $venue->post_title );
|
2024-09-24 16:24:31 +02:00
|
|
|
}
|
|
|
|
$location->set_id( $venue->permalink );
|
|
|
|
$location->set_name( $venue->post_title );
|
2024-08-27 21:13:37 +02:00
|
|
|
|
|
|
|
return $location;
|
|
|
|
}
|
|
|
|
}
|