phpcs
Some checks failed
PHP Code Checker / PHP Code Checker (pull_request) Failing after 43s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 56s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 55s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 56s

This commit is contained in:
André Menrath 2024-10-26 16:56:00 +02:00
parent 0ac8c8c413
commit cdcfbb25ad

View file

@ -1,6 +1,8 @@
<?php <?php
/** /**
* ActivityPub Transformer for the plugin My Calendar. * ActivityPub Transformer for the WordPress plugin "My Calendar Accessible Event Manager".
*
* @see https://wordpress.org/plugins/my-calendar/
* *
* @package Activitypub_Event_Extensions * @package Activitypub_Event_Extensions
* @license AGPL-3.0-or-later * @license AGPL-3.0-or-later
@ -11,17 +13,13 @@ namespace ActivityPub_Event_Bridge\Activitypub\Transformer;
// Exit if accessed directly. // Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
use Activitypub\Activity\Extended_Object\Event;
use Activitypub\Activity\Extended_Object\Place; use Activitypub\Activity\Extended_Object\Place;
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event as Event_Transformer; use ActivityPub_Event_Bridge\Activitypub\Transformer\Event as Event_Transformer;
use DateTime; use DateTime;
use DateTimeZone; use DateTimeZone;
use EM_Event;
use function Activitypub\esc_hashtag;
/** /**
* ActivityPub Transformer for events from the WordPress plugin 'My Calendar' * ActivityPub Transformer for events from the WordPress plugin "My Calendar Accessible Event Manager".
* *
* @see https://wordpress.org/plugins/my-calendar/ * @see https://wordpress.org/plugins/my-calendar/
* *
@ -29,33 +27,42 @@ use function Activitypub\esc_hashtag;
*/ */
final class My_Calendar extends Event_Transformer { final class My_Calendar extends Event_Transformer {
/** /**
* Holds the mycalendar post object. * Holds the My Calendar post object.
* *
* @var array * @var object $event Event object.
*/ */
protected $mc_event; protected $mc_event;
/**
* Holds the My Calendar Schema object.
*
* @var array JSON/LD Schema for event.
*/
protected $mc_event_schema; protected $mc_event_schema;
/** /**
* Extend the constructor, to also set the Eventsmanager objects. * Extend the constructor, to also set the Event plugins API objects.
* *
* This is a special class object form The Events Calendar which * This is a special class object form The Events Calendar which
* has a lot of useful functions, we make use of our getter functions. * has a lot of useful functions, we make use of our getter functions.
* *
* @param WP_Post $wp_object The WordPress object. * @param WP_Post $wp_object The WordPress object.
* @param string $wp_taxonomy The taxonomy slug of the event post type. * @param string $wp_taxonomy The taxonomy slug of the event post type.
*/ */
public function __construct( $wp_object, $wp_taxonomy ) { public function __construct( $wp_object, $wp_taxonomy ) {
parent::__construct( $wp_object, $wp_taxonomy ); parent::__construct( $wp_object, $wp_taxonomy );
$mc_event_id = get_post_meta( $this->wp_object->ID, '_mc_event_id', true ); $mc_event_id = get_post_meta( $this->wp_object->ID, '_mc_event_id', true );
$this->mc_event = mc_get_event( $mc_event_id ); $this->mc_event = mc_get_event( $mc_event_id );
$this->mc_event_schema = mc_event_schema( $this->mc_event ); $this->mc_event_schema = mc_event_schema( $this->mc_event );
} }
/** /**
* Formats time from the plugin to the activitypub standard * Formats time from the plugin to the activitypub standard.
*
* @param string $date_string The plugins string representation for a date without time.
* @param string $time_string The plugins string representation for a time.
*
* @return string
*/ */
private function convert_time( $date_string, $time_string ): string { private function convert_time( $date_string, $time_string ): string {
// Create a DateTime object with the given date, time, and timezone. // Create a DateTime object with the given date, time, and timezone.
@ -70,6 +77,8 @@ final class My_Calendar extends Event_Transformer {
} }
/** /**
* Get the start time from the events metadata. * Get the start time from the events metadata.
*
* @return string The events start date-time.
*/ */
public function get_start_time(): string { public function get_start_time(): string {
return $this->convert_time( $this->mc_event->event_begin, $this->mc_event->event_time); return $this->convert_time( $this->mc_event->event_begin, $this->mc_event->event_time);
@ -77,6 +86,8 @@ final class My_Calendar extends Event_Transformer {
/** /**
* Get the end time from the events metadata. * Get the end time from the events metadata.
*
* @return string The events start end-time.
*/ */
public function get_end_time(): ?string { public function get_end_time(): ?string {
return $this->convert_time( $this->mc_event->event_end, $this->mc_event->event_endtime); return $this->convert_time( $this->mc_event->event_end, $this->mc_event->event_endtime);
@ -88,7 +99,7 @@ final class My_Calendar extends Event_Transformer {
* @return Place|null The place/venue if one is set. * @return Place|null The place/venue if one is set.
*/ */
public function get_location(): ?Place { public function get_location(): ?Place {
if ( array_key_exists('location', $this->mc_event_schema ) && $this->mc_event_schema['location']['@type'] == 'Place' ) { if ( array_key_exists( 'location', $this->mc_event_schema, true ) && 'Place' === $this->mc_event_schema['location']['@type'] ) {
$mc_place = $this->mc_event_schema['location']; $mc_place = $this->mc_event_schema['location'];
$place = new Place(); $place = new Place();
@ -111,13 +122,6 @@ final class My_Calendar extends Event_Transformer {
* @return string status of the event * @return string status of the event
*/ */
public function get_status(): ?string { public function get_status(): ?string {
return 'CONFIRMED'; # my-calender doesn't implement canceled events. return 'CONFIRMED'; // My Calendar doesn't implement canceled events.
}
public function to_object(): Event {
$activitypub_object = parent::to_object();
return $activitypub_object;
} }
} }