wordpress-activitypub-event.../activitypub/transformer/class-vs-event.php

180 lines
3.9 KiB
PHP
Raw Normal View History

2023-11-24 15:36:51 +01:00
<?php
/**
* ActivityPub Transformer for VS Event.
*
* @package activity-event-transformers
2023-12-04 19:27:57 +01:00
* @license AGPL-3.0-or-later
*/
2023-12-22 19:07:59 +01:00
use Activitypub\Activity\Event;
use Activitypub\Activity\Place;
use Activitypub\Transformer\Post;
2023-11-25 12:05:12 +01:00
2023-11-24 15:36:51 +01:00
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* ActivityPub Transformer for VS Event
2023-11-24 15:36:51 +01:00
*
* @since 1.0.0
*/
2023-12-22 19:07:59 +01:00
class VS_Event extends Post {
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.
*/
public static function get_supported_post_types() {
return array( 'event' );
2023-11-24 15:36:51 +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 ) {
$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-25 12:05:12 +01:00
/**
* Get the end time from the events metadata.
*/
2023-12-22 19:07:59 +01:00
protected function get_end_time() {
$end_time = get_post_meta( $this->object->ID, 'event-date', true );
return \gmdate( 'Y-m-d\TH:i:s\Z', $end_time );
}
/**
* Get the end time from the events metadata.
*/
protected function get_start_time() {
$end_time = get_post_meta( $this->object->ID, 'event-start-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() {
2023-12-22 19:07:59 +01:00
$event_link = get_post_meta( $this->object->ID, 'event-link', true );
if ( $event_link ) {
return array(
'type' => 'Link',
'name' => 'Website',
'href' => \esc_url( $event_link ),
'mediaType' => 'text/html',
);
}
}
/**
2023-12-04 19:27:57 +01:00
* Overrides/extends the get_attachments function to also add the event Link.
*/
2023-12-22 19:07:59 +01:00
protected function get_attachment() {
$attachments = parent::get_attachment();
$attachments[0]['type'] = 'Document';
$attachments[0]['name'] = 'Banner';
2023-12-04 19:27:57 +01:00
$event_link = $this->get_event_link();
if ( $event_link ) {
$attachments[] = $this->get_event_link();
}
return $attachments;
}
2023-12-22 19:07:59 +01:00
protected function get_replies_moderation_option() {
return 'allow_all';
}
protected function get_status() {
return 'CONFIRMED';
}
/**
2023-12-22 19:07:59 +01:00
* Transform the WordPress Object into an ActivityPub Object.
2023-11-25 12:05:12 +01:00
*
2023-12-22 19:07:59 +01:00
* @return Activitypub\Activity\Event
2023-11-25 12:05:12 +01:00
*/
2023-12-22 19:07:59 +01:00
public function to_object() {
$object = new Event();
2023-11-25 12:05:12 +01:00
2023-12-22 19:07:59 +01:00
$vars = $object->get_object_var_keys();
2023-11-25 12:05:12 +01:00
2023-12-22 19:07:59 +01:00
foreach ( $vars as $var ) {
$getter = 'get_' . $var;
2023-11-25 12:05:12 +01:00
2023-12-22 19:07:59 +01:00
if ( method_exists( $this, $getter ) ) {
$value = call_user_func( array( $this, $getter ) );
2023-11-25 12:05:12 +01:00
2023-12-22 19:07:59 +01:00
if ( isset( $value ) ) {
$setter = 'set_' . $var;
2023-11-25 12:05:12 +01:00
2023-12-22 19:07:59 +01:00
call_user_func( array( $object, $setter ), $value );
}
}
}
2023-12-22 19:07:59 +01:00
return $object
->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-12-22 19:07:59 +01:00
->set_name( get_the_title( $this->object->ID ) )
->set_timezone( 'Europe/Vienna' )
->set_is_online( false )
->set_in_language( 'de ' )
2023-12-22 19:07:59 +01:00
->set_actor ('http://wp.lan/@blog')
->set_to ( [
"https://www.w3.org/ns/activitystreams#Public"
]);
2023-11-24 15:36:51 +01:00
}
}