André Menrath
579f0e5f57
Some checks failed
PHP Code Checker / PHP Code Checker (pull_request) Successful in 48s
PHPUnit / PHPUnit – PHP 7.4 (pull_request) Failing after 56s
PHPUnit / PHPUnit – PHP 8.0 (pull_request) Successful in 58s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 57s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m2s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 1m2s
Use own transformers for `Place`
125 lines
2.9 KiB
PHP
125 lines
2.9 KiB
PHP
<?php
|
|
/**
|
|
* ActivityPub Tribe Transformer
|
|
*
|
|
* @package ActivityPub_Event_Bridge
|
|
* @license AGPL-3.0-or-later
|
|
*/
|
|
|
|
namespace ActivityPub_Event_Bridge\Activitypub\Transformer\Location;
|
|
|
|
// Exit if accessed directly.
|
|
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
|
|
|
use Activitypub\Activity\Extended_Object\Place;
|
|
use Activitypub\Transformer\Post;
|
|
use WP_Post;
|
|
|
|
/**
|
|
* ActivityPub Tribe Transformer
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
final class The_Events_Calendar extends Post {
|
|
/**
|
|
* Set the type of the object.
|
|
*/
|
|
public function get_type(): string {
|
|
return 'Place';
|
|
}
|
|
|
|
/**
|
|
* Set the type of the object.
|
|
*/
|
|
public function get_replies() {
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Set the type of the object.
|
|
*/
|
|
public function get_sensitive() {
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Get the event location.
|
|
*
|
|
* @return array|string|null The place/venue if one is set.
|
|
*/
|
|
public function get_address(): mixed {
|
|
$address = array();
|
|
|
|
if ( ! empty( $this->wp_object->country ) ) {
|
|
$address['addressCountry'] = $this->wp_object->country;
|
|
}
|
|
|
|
if ( ! empty( $this->wp_object->city ) ) {
|
|
$address['addressLocality'] = $this->wp_object->city;
|
|
}
|
|
|
|
if ( ! empty( $this->wp_object->province ) ) {
|
|
$address['addressRegion'] = $this->wp_object->province;
|
|
}
|
|
|
|
if ( ! empty( $this->wp_object->zip ) ) {
|
|
$address['postalCode'] = $this->wp_object->zip;
|
|
}
|
|
|
|
if ( ! empty( $this->wp_object->address ) ) {
|
|
$address['streetAddress'] = $this->wp_object->address;
|
|
}
|
|
if ( ! empty( $this->wp_object->post_title ) ) {
|
|
$address['name'] = $this->wp_object->post_title;
|
|
}
|
|
$address['type'] = 'PostalAddress';
|
|
|
|
if ( count( $address ) > 1 ) {
|
|
return $address;
|
|
} else {
|
|
return $this->get_name();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Generic function that converts an WP-Event object to an ActivityPub-Event object.
|
|
*
|
|
* @param bool $full_object bool Return an object with all properties set, or a minimal one as used within an `as:Event`s location.
|
|
* @return Event_Object
|
|
*/
|
|
public function to_object( $full_object = true ): Place {
|
|
$activitypub_object = new Place();
|
|
$activitypub_object = $this->transform_object_properties( $activitypub_object );
|
|
|
|
if ( ! empty( $activitypub_object->content ) ) {
|
|
$activitypub_object->set_content_map(
|
|
array(
|
|
$this->get_locale() => $this->get_content(),
|
|
)
|
|
);
|
|
}
|
|
|
|
if ( $full_object ) {
|
|
$published = \strtotime( $this->wp_object->post_date_gmt );
|
|
|
|
$activitypub_object->set_published( \gmdate( 'Y-m-d\TH:i:s\Z', $published ) );
|
|
|
|
$updated = \strtotime( $this->wp_object->post_modified_gmt );
|
|
|
|
if ( $updated > $published ) {
|
|
$activitypub_object->set_updated( \gmdate( 'Y-m-d\TH:i:s\Z', $updated ) );
|
|
}
|
|
|
|
$activitypub_object->set_to(
|
|
array(
|
|
'https://www.w3.org/ns/activitystreams#Public',
|
|
$this->get_actor_object()->get_followers(),
|
|
)
|
|
);
|
|
}
|
|
|
|
$activitypub_object->set_address( $this->get_address() );
|
|
|
|
return $activitypub_object;
|
|
}
|
|
}
|