2023-11-19 19:56:03 +01:00
|
|
|
<?php
|
2024-04-09 19:20:53 +02:00
|
|
|
|
2023-11-27 19:18:06 +01:00
|
|
|
/**
|
|
|
|
* ActivityPub Tribe Transformer
|
|
|
|
*
|
|
|
|
* @package activity-event-transformers
|
2023-12-04 19:27:57 +01:00
|
|
|
* @license AGPL-3.0-or-later
|
2023-11-27 19:18:06 +01:00
|
|
|
*/
|
|
|
|
|
2023-11-19 19:56:03 +01:00
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit; // Exit if accessed directly.
|
|
|
|
}
|
|
|
|
|
2024-06-30 14:17:59 +02:00
|
|
|
use Activitypub_Event_Extensions\Activitypub\Transformer\Event as Event_Transformer;
|
2024-01-18 15:27:16 +01:00
|
|
|
use Activitypub\Activity\Extended_Object\Event;
|
|
|
|
use Activitypub\Activity\Extended_Object\Place;
|
2023-12-22 19:07:59 +01:00
|
|
|
|
2023-11-19 19:56:03 +01:00
|
|
|
/**
|
|
|
|
* ActivityPub Tribe Transformer
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
*/
|
2024-06-30 14:17:59 +02:00
|
|
|
class Tribe extends Event_Transformer {
|
2024-04-09 19:20:53 +02:00
|
|
|
|
2023-12-11 23:24:13 +01:00
|
|
|
/**
|
|
|
|
* The Tribe Event object.
|
|
|
|
*
|
|
|
|
* @var WP_Post
|
|
|
|
*/
|
|
|
|
protected $tribe_event;
|
|
|
|
|
2023-12-22 19:07:59 +01:00
|
|
|
// /**
|
2024-04-09 19:20:53 +02:00
|
|
|
// * resolve the tribe metadata in the setter of wp_post.
|
|
|
|
// *
|
|
|
|
// * @param WP_Post $wp_post The WP_Post object.
|
|
|
|
// * @return void
|
|
|
|
// */
|
2023-12-22 19:07:59 +01:00
|
|
|
// public function set_wp_post( WP_Post $wp_post ) {
|
2024-04-09 19:20:53 +02:00
|
|
|
// parent::set_wp_post( $wp_post );
|
|
|
|
// $this->tribe_event = tribe_get_event( $wp_post->ID );
|
2023-12-22 19:07:59 +01:00
|
|
|
// }
|
2023-11-19 19:56:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get widget name.
|
|
|
|
*
|
|
|
|
* Retrieve oEmbed widget name.
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
* @access public
|
|
|
|
* @return string Widget name.
|
|
|
|
*/
|
|
|
|
public function get_name() {
|
2024-04-09 19:20:53 +02:00
|
|
|
|
2023-11-25 12:05:12 +01:00
|
|
|
return 'activitypub-event-transformers/tribe';
|
2023-11-19 19:56:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get widget title.
|
|
|
|
*
|
|
|
|
* Retrieve Transformer title.
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
* @access public
|
|
|
|
* @return string Widget title.
|
|
|
|
*/
|
|
|
|
public function get_label() {
|
2024-04-09 19:20:53 +02:00
|
|
|
|
2023-11-19 19:56:03 +01:00
|
|
|
return 'The Events Calendar';
|
|
|
|
}
|
|
|
|
|
2023-11-20 18:06:20 +01:00
|
|
|
/**
|
|
|
|
* Returns the ActivityStreams 2.0 Object-Type for an Event.
|
|
|
|
*
|
|
|
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-event
|
|
|
|
*
|
|
|
|
* @return string The Event Object-Type.
|
|
|
|
*/
|
|
|
|
protected function get_object_type() {
|
2024-04-09 19:20:53 +02:00
|
|
|
|
2023-11-20 18:06:20 +01:00
|
|
|
return 'Event';
|
|
|
|
}
|
2023-11-22 14:59:51 +01:00
|
|
|
|
2023-11-19 19:56:03 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2023-12-04 19:42:13 +01:00
|
|
|
public static function get_supported_post_types() {
|
2024-04-09 19:20:53 +02:00
|
|
|
|
2023-11-27 19:18:06 +01:00
|
|
|
return array( 'tribe_events' );
|
2023-11-19 19:56:03 +01:00
|
|
|
}
|
2023-12-09 02:02:25 +01:00
|
|
|
|
2023-12-11 23:24:13 +01:00
|
|
|
/**
|
|
|
|
* Get tribe category of wp_post
|
|
|
|
*
|
|
|
|
* @return string|null tribe category if it exists
|
|
|
|
*/
|
|
|
|
public function get_tribe_category() {
|
|
|
|
// todo make it possible that one event can have multiple categories?
|
|
|
|
|
|
|
|
// using cat_slugs isn't 100% nice way to do this, don't know if it's a good idea
|
2024-01-04 14:50:29 +01:00
|
|
|
$categories = tribe_get_event_cat_slugs( $this->wp_object->ID );
|
2023-12-11 23:24:13 +01:00
|
|
|
|
|
|
|
if ( count( $categories ) === 0 ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $categories[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get status of the tribe event
|
|
|
|
*
|
|
|
|
* @return string status of the event
|
|
|
|
*/
|
|
|
|
public function get_tribe_status() {
|
2024-04-09 19:20:53 +02:00
|
|
|
|
2023-12-11 23:24:13 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
if ( '' === $this->tribe_event->event_status ) {
|
|
|
|
return 'CONFIRMED';
|
|
|
|
}
|
|
|
|
|
|
|
|
return new WP_Error( 'invalid event_status value', __( 'invalid event_status', 'activitypub' ), array( 'status' => 404 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-04-09 19:20:53 +02:00
|
|
|
|
2023-12-11 23:24:13 +01:00
|
|
|
$content = parent::get_content();
|
|
|
|
// todo remove link at the end of the content
|
|
|
|
|
|
|
|
// todo add organizer
|
|
|
|
// $this->tribe_event->organizers[0]
|
|
|
|
|
|
|
|
// todo add Canclled reason in the content (maybe at the end)
|
|
|
|
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the event location.
|
|
|
|
*
|
|
|
|
* @param int $post_id The WordPress post ID.
|
|
|
|
* @returns array The Place.
|
|
|
|
*/
|
|
|
|
public function get_event_location() {
|
|
|
|
/*
|
2024-01-05 21:18:34 +01:00
|
|
|
'post_title' => 'testvenue',
|
|
|
|
'post_name' => 'testvenue',
|
|
|
|
'guid' => 'http://localhost/venue/testvenue/',
|
|
|
|
'post_type' => 'tribe_venue',
|
|
|
|
'address' => 'testaddr',
|
|
|
|
'country' => 'Austria',
|
|
|
|
'city' => 'testcity',
|
|
|
|
'state_province' => 'testprovince',
|
|
|
|
'state' => '',
|
|
|
|
'province' => 'testprovince',
|
|
|
|
'zip' => '8000',
|
|
|
|
'phone' => '+4312343',
|
|
|
|
'permalink' => 'http://localhost/venue/testvenue/',
|
|
|
|
'directions_link' => 'https://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=testaddr+testcity+testprovince+8000+Austria',
|
|
|
|
'website' => 'https://test.at',
|
2023-12-11 23:24:13 +01:00
|
|
|
*/
|
|
|
|
$venue = $this->tribe_event->venues[0];
|
|
|
|
return ( new Place() )
|
|
|
|
->set_type( 'Place' )
|
|
|
|
->set_name( $venue->post_name )
|
2023-12-12 17:27:43 +01:00
|
|
|
->set_address(
|
|
|
|
$venue->address . "\n" .
|
2024-01-05 21:18:34 +01:00
|
|
|
$venue->zip . ', ' . $venue->city . "\n" .
|
|
|
|
$venue->country
|
2023-12-12 17:27:43 +01:00
|
|
|
); // todo add checks that everything exists here (lol)
|
2023-12-11 23:24:13 +01:00
|
|
|
}
|
2023-11-19 19:56:03 +01:00
|
|
|
}
|