2023-11-24 15:36:51 +01:00
|
|
|
<?php
|
2023-11-27 19:18:06 +01:00
|
|
|
/**
|
|
|
|
* ActivityPub Transformer for VS Event.
|
|
|
|
*
|
|
|
|
* @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
|
|
|
*/
|
|
|
|
|
|
|
|
require_once __DIR__ . '/../object/class-event.php';
|
|
|
|
|
2023-11-25 12:05:12 +01:00
|
|
|
use Activitypub\Activity\Base_Object;
|
2023-12-04 15:53:01 +01:00
|
|
|
use Place;
|
2023-11-25 12:05:12 +01:00
|
|
|
use function Activitypub\get_rest_url_by_path;
|
|
|
|
|
2023-11-24 15:36:51 +01:00
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit; // Exit if accessed directly.
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-11-27 19:18:06 +01:00
|
|
|
* ActivityPub Transformer for VS Event
|
2023-11-24 15:36:51 +01:00
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
*/
|
2023-11-25 12:05:12 +01:00
|
|
|
class VS_Event extends \Activitypub\Transformer\Base {
|
2023-11-24 15:36:51 +01:00
|
|
|
/**
|
|
|
|
* Get widget name.
|
|
|
|
*
|
|
|
|
* Retrieve oEmbed widget name.
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
* @access public
|
|
|
|
* @return string Widget name.
|
|
|
|
*/
|
|
|
|
public function get_name() {
|
|
|
|
return 'activitypub-event-transformers/vs-event';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get widget title.
|
|
|
|
*
|
|
|
|
* Retrieve Transformer title.
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
* @access public
|
|
|
|
* @return string Widget title.
|
|
|
|
*/
|
|
|
|
public function get_label() {
|
|
|
|
return 'VS Event';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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_object_type() {
|
|
|
|
return '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.
|
|
|
|
*/
|
2023-12-04 19:42:13 +01:00
|
|
|
public static function get_supported_post_types() {
|
2023-11-27 19:18:06 +01:00
|
|
|
return array( 'event' );
|
2023-11-24 15:36:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-11-27 19:18:06 +01:00
|
|
|
* Get the event location.
|
|
|
|
*
|
|
|
|
* @param int $post_id The WordPress post ID.
|
|
|
|
* @returns array The Place.
|
2023-11-24 15:36:51 +01:00
|
|
|
*/
|
2023-11-25 12:05:12 +01:00
|
|
|
public function get_event_location( $post_id ) {
|
2023-12-04 15:53:01 +01:00
|
|
|
$address = get_post_meta( $post_id, 'event-location', true );
|
2023-12-04 19:27:57 +01:00
|
|
|
return ( new Place() )
|
|
|
|
->set_type( 'Place' )
|
|
|
|
->set_name( $address )
|
|
|
|
->set_address( $address );
|
2023-11-27 19:18:06 +01:00
|
|
|
}
|
|
|
|
|
2023-11-25 12:05:12 +01:00
|
|
|
/**
|
2023-12-02 16:03:12 +01:00
|
|
|
* Get the end time from the events metadata.
|
|
|
|
*/
|
|
|
|
private function get_end_time() {
|
|
|
|
$end_time = get_post_meta( $this->wp_post->ID, 'event-date', true );
|
|
|
|
return \gmdate( 'Y-m-d\TH:i:s\Z', $end_time );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the event link from the events metadata.
|
|
|
|
*/
|
|
|
|
private function get_event_link() {
|
|
|
|
$event_link = get_post_meta( $this->wp_post->ID, 'event-link', true );
|
|
|
|
if ( $event_link ) {
|
2023-12-04 19:27:57 +01:00
|
|
|
return [
|
2023-12-02 16:03:12 +01:00
|
|
|
'type' => 'Link',
|
|
|
|
'name' => 'Website',
|
|
|
|
'href' => \esc_url( get_post_meta( $post_id, 'event-location', true ) ),
|
|
|
|
'mediaType' => 'text/html',
|
2023-12-04 19:27:57 +01:00
|
|
|
];
|
2023-12-02 16:03:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-12-04 19:27:57 +01:00
|
|
|
* Overrides/extends the get_attachments function to also add the event Link.
|
2023-12-02 16:03:12 +01:00
|
|
|
*/
|
|
|
|
protected function get_attachments() {
|
|
|
|
$attachments = parent::get_attachments();
|
2023-12-04 19:27:57 +01:00
|
|
|
$event_link = $this->get_event_link();
|
|
|
|
if ( $event_link ) {
|
|
|
|
$attachments[] = $this->get_event_link();
|
|
|
|
}
|
2023-12-02 16:03:12 +01:00
|
|
|
return $attachments;
|
|
|
|
}
|
|
|
|
|
2023-12-04 19:27:57 +01:00
|
|
|
private function get_category() {
|
|
|
|
return 'MEETING';
|
|
|
|
}
|
|
|
|
|
2023-12-02 16:03:12 +01:00
|
|
|
/**
|
|
|
|
* Transforms the VS Event WP_Post object to an ActivityPub Event Object.
|
2023-11-25 12:05:12 +01:00
|
|
|
*
|
|
|
|
* @see \Activitypub\Activity\Base_Object
|
|
|
|
*
|
2023-12-02 16:03:12 +01:00
|
|
|
* @return \Activitypub\Activity\Base_Object The ActivityPub Object.
|
2023-11-25 12:05:12 +01:00
|
|
|
*/
|
2023-12-02 16:03:12 +01:00
|
|
|
public function transform() {
|
2023-12-09 02:02:25 +01:00
|
|
|
// todo make tranform nicer
|
2023-12-03 11:21:07 +01:00
|
|
|
$context = Event::get_context();
|
2023-11-27 19:18:06 +01:00
|
|
|
$object = new Event();
|
2023-12-02 16:03:12 +01:00
|
|
|
$object
|
|
|
|
->set_id( $this->get_id() )
|
|
|
|
->set_url( $this->get_url() )
|
|
|
|
->set_type( $this->get_object_type() );
|
2023-11-25 12:05:12 +01:00
|
|
|
|
2023-12-03 11:21:07 +01:00
|
|
|
$published = \strtotime( $this->wp_post->post_date_gmt );
|
2023-11-25 12:05:12 +01:00
|
|
|
|
|
|
|
$object->set_published( \gmdate( 'Y-m-d\TH:i:s\Z', $published ) );
|
|
|
|
|
2023-12-03 11:21:07 +01:00
|
|
|
$updated = \strtotime( $this->wp_post->post_modified_gmt );
|
2023-11-25 12:05:12 +01:00
|
|
|
|
|
|
|
if ( $updated > $published ) {
|
|
|
|
$object->set_updated( \gmdate( 'Y-m-d\TH:i:s\Z', $updated ) );
|
|
|
|
}
|
|
|
|
|
2023-12-02 16:03:12 +01:00
|
|
|
$object
|
|
|
|
->set_attributed_to( $this->get_attributed_to() )
|
|
|
|
->set_content( $this->get_content() )
|
|
|
|
->set_content_map( $this->get_content_map );
|
2023-11-25 12:05:12 +01:00
|
|
|
|
2023-12-03 11:21:07 +01:00
|
|
|
$summary = get_post_meta( $this->wp_post->ID, 'event-summary', true );
|
2023-11-25 12:05:12 +01:00
|
|
|
if ( $summary ) {
|
|
|
|
$object->set_summary( $summary );
|
|
|
|
} else {
|
|
|
|
$object->set_summary( $this->content );
|
|
|
|
}
|
|
|
|
|
2023-12-03 11:21:07 +01:00
|
|
|
$start_time = get_post_meta( $this->wp_post->ID, 'event-start-date', true );
|
2023-11-25 12:05:12 +01:00
|
|
|
$object->set_start_time( \gmdate( 'Y-m-d\TH:i:s\Z', $start_time ) );
|
|
|
|
|
2023-12-03 11:21:07 +01:00
|
|
|
$hide_end_time = get_post_meta( $this->wp_post->ID, 'event-hide-end-time', true);
|
2023-11-25 12:05:12 +01:00
|
|
|
|
2023-12-03 11:21:07 +01:00
|
|
|
if ( $hide_end_time != 'yes' ) {
|
|
|
|
$object->set_end_time( $this->get_end_time() );
|
|
|
|
}
|
|
|
|
|
|
|
|
$path = sprintf( 'users/%d/followers', intval( $this->wp_post->post_author ) );
|
2023-11-25 12:05:12 +01:00
|
|
|
|
2023-12-02 16:03:12 +01:00
|
|
|
$object
|
2023-12-04 15:53:01 +01:00
|
|
|
->set_location( $this->get_event_location( $this->wp_post->ID )->to_array() )
|
2023-12-03 11:21:07 +01:00
|
|
|
->set_comments_enabled( comments_open( $this->wp_post->ID ) )
|
2023-12-02 16:03:12 +01:00
|
|
|
->set_to(
|
|
|
|
array(
|
|
|
|
'https://www.w3.org/ns/activitystreams#Public',
|
|
|
|
get_rest_url_by_path( $path ),
|
|
|
|
)
|
2023-11-25 12:05:12 +01:00
|
|
|
)
|
2023-12-02 16:03:12 +01:00
|
|
|
->set_cc( $this->get_cc() )
|
|
|
|
->set_attachment( $this->get_attachments() )
|
|
|
|
->set_tag( $this->get_tags() )
|
2023-12-03 11:21:07 +01:00
|
|
|
->set_replies_moderation_option( 'allow_all' )
|
|
|
|
->set_join_mode( 'external' )
|
2023-12-03 11:41:13 +01:00
|
|
|
->set_external_participation_url( $this->get_url() )
|
2023-12-04 19:27:57 +01:00
|
|
|
->set_status( 'CONFIRMED' )
|
|
|
|
->set_category( 'MEETING' );
|
2023-11-24 15:36:51 +01:00
|
|
|
|
2023-11-25 12:05:12 +01:00
|
|
|
return $object;
|
2023-11-24 15:36:51 +01:00
|
|
|
}
|
|
|
|
}
|