Prepare ActivityPub resolveable locations
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
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`
This commit is contained in:
parent
7f23ed17c0
commit
579f0e5f57
18 changed files with 155 additions and 76 deletions
|
@ -58,7 +58,7 @@
|
|||
],
|
||||
"test-debug": [
|
||||
"@prepare-test",
|
||||
"@test-gatherpress"
|
||||
"@test-the-events-calendar"
|
||||
],
|
||||
"test-vs-event-list": "phpunit --filter=vs_event_list",
|
||||
"test-the-events-calendar": "phpunit --filter=the_events_calendar",
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* @license AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace ActivityPub_Event_Bridge\Activitypub\Transformer;
|
||||
namespace ActivityPub_Event_Bridge\Activitypub\Transformer\Event;
|
||||
|
||||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||
|
@ -64,17 +64,6 @@ abstract class Event extends Post {
|
|||
return '[ap_content]';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the title of the event.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-name
|
||||
*
|
||||
* @return string The name.
|
||||
*/
|
||||
protected function get_name(): string {
|
||||
return $this->wp_object->post_title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend the construction of the Post Transformer to also set the according taxonomy of the event post type.
|
||||
*
|
||||
|
@ -213,7 +202,7 @@ abstract class Event extends Post {
|
|||
return '';
|
||||
}
|
||||
$address = $location->get_address();
|
||||
if ( ! $address ) {
|
||||
if ( ! $address && is_string( $location->get_name() ) ) {
|
||||
return $location->get_name();
|
||||
}
|
||||
if ( is_string( $address ) ) {
|
||||
|
@ -370,7 +359,7 @@ abstract class Event extends Post {
|
|||
$activitypub_object->set_to(
|
||||
array(
|
||||
'https://www.w3.org/ns/activitystreams#Public',
|
||||
$this->get_actor_object()->get_followers(), // this fails on my machine.
|
||||
$this->get_actor_object()->get_followers(),
|
||||
)
|
||||
);
|
||||
|
|
@ -8,15 +8,13 @@
|
|||
* @license AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace ActivityPub_Event_Bridge\Activitypub\Transformer;
|
||||
namespace ActivityPub_Event_Bridge\Activitypub\Transformer\Event;
|
||||
|
||||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||
|
||||
use Activitypub\Activity\Extended_Object\Place;
|
||||
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event;
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event\Event;
|
||||
use Etn\Core\Event\Event_Model;
|
||||
|
||||
use function Activitypub\esc_hashtag;
|
|
@ -6,13 +6,13 @@
|
|||
* @license AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace ActivityPub_Event_Bridge\Activitypub\Transformer;
|
||||
namespace ActivityPub_Event_Bridge\Activitypub\Transformer\Event;
|
||||
|
||||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||
|
||||
use Activitypub\Activity\Extended_Object\Place;
|
||||
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event as Event_Transformer;
|
||||
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event\Event as Event_Transformer;
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use EM_Event;
|
|
@ -6,14 +6,14 @@
|
|||
* @license AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace ActivityPub_Event_Bridge\Activitypub\Transformer;
|
||||
namespace ActivityPub_Event_Bridge\Activitypub\Transformer\Event;
|
||||
|
||||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||
|
||||
use Activitypub\Activity\Extended_Object\Event as Event_Object;
|
||||
use Activitypub\Activity\Extended_Object\Place;
|
||||
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event;
|
||||
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event\Event;
|
||||
use GatherPress\Core\Event as GatherPress_Event;
|
||||
|
||||
/**
|
|
@ -6,14 +6,13 @@
|
|||
* @license AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace ActivityPub_Event_Bridge\Activitypub\Transformer;
|
||||
namespace ActivityPub_Event_Bridge\Activitypub\Transformer\Event;
|
||||
|
||||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||
|
||||
use Activitypub\Activity\Extended_Object\Place;
|
||||
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event;
|
||||
|
||||
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event\Event;
|
||||
use MEC;
|
||||
use MEC\Events\Event as MEC_Event;
|
||||
use MEC_main;
|
|
@ -6,13 +6,14 @@
|
|||
* @license AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace ActivityPub_Event_Bridge\Activitypub\Transformer;
|
||||
namespace ActivityPub_Event_Bridge\Activitypub\Transformer\Event;
|
||||
|
||||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||
|
||||
use Activitypub\Activity\Extended_Object\Place;
|
||||
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event;
|
||||
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event\Event;
|
||||
use ActivityPub_Event_Bridge\Activitypub\Transformer\Location\The_Events_Calendar as The_Events_Calendar_Location;
|
||||
use WP_Post;
|
||||
|
||||
use function Activitypub\esc_hashtag;
|
||||
|
@ -140,42 +141,9 @@ final class The_Events_Calendar extends Event {
|
|||
return null;
|
||||
}
|
||||
|
||||
// Set the address.
|
||||
$address = array();
|
||||
|
||||
if ( ! empty( $venue->country ) ) {
|
||||
$address['addressCountry'] = $venue->country;
|
||||
}
|
||||
|
||||
if ( ! empty( $venue->city ) ) {
|
||||
$address['addressLocality'] = $venue->city;
|
||||
}
|
||||
|
||||
if ( ! empty( $venue->province ) ) {
|
||||
$address['addressRegion'] = $venue->province;
|
||||
}
|
||||
|
||||
if ( ! empty( $venue->zip ) ) {
|
||||
$address['postalCode'] = $venue->zip;
|
||||
}
|
||||
|
||||
if ( ! empty( $venue->address ) ) {
|
||||
$address['streetAddress'] = $venue->address;
|
||||
}
|
||||
if ( ! empty( $venue->post_title ) ) {
|
||||
$address['name'] = $venue->post_title;
|
||||
}
|
||||
$address['type'] = 'PostalAddress';
|
||||
|
||||
$location = new Place();
|
||||
if ( count( $address ) > 1 ) {
|
||||
$location->set_address( $address );
|
||||
} else {
|
||||
$location->set_address( $venue->post_title );
|
||||
}
|
||||
$location->set_id( $venue->ID );
|
||||
$location->set_name( $venue->post_title );
|
||||
|
||||
$location_transformer = new The_Events_Calendar_Location( $venue );
|
||||
$full_location_object = false;
|
||||
$location = $location_transformer->to_object( $full_location_object );
|
||||
return $location;
|
||||
}
|
||||
|
|
@ -6,13 +6,13 @@
|
|||
* @license AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace ActivityPub_Event_Bridge\Activitypub\Transformer;
|
||||
namespace ActivityPub_Event_Bridge\Activitypub\Transformer\Event;
|
||||
|
||||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||
|
||||
use Activitypub\Activity\Extended_Object\Place;
|
||||
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event as Event_Transformer;
|
||||
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event\Event as Event_Transformer;
|
||||
|
||||
/**
|
||||
* ActivityPub Transformer for VS Event.
|
|
@ -6,13 +6,13 @@
|
|||
* @license AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace ActivityPub_Event_Bridge\Activitypub\Transformer;
|
||||
namespace ActivityPub_Event_Bridge\Activitypub\Transformer\Event;
|
||||
|
||||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||
|
||||
use Activitypub\Activity\Extended_Object\Place;
|
||||
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event as Event_Transformer;
|
||||
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event\Event as Event_Transformer;
|
||||
use DateTime;
|
||||
|
||||
/**
|
|
@ -0,0 +1,125 @@
|
|||
<?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;
|
||||
}
|
||||
}
|
|
@ -83,6 +83,6 @@ abstract class Event_Plugin {
|
|||
* Returns the Activitypub transformer for the event plugins event post type.
|
||||
*/
|
||||
public static function get_activitypub_event_transformer_class(): string {
|
||||
return str_replace( 'Plugins', 'Activitypub\Transformer', static::class );
|
||||
return str_replace( 'Plugins', 'Activitypub\Transformer\Event', static::class );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ class Test_Eventin extends WP_UnitTestCase {
|
|||
$transformer = \Activitypub\Transformer\Factory::get_transformer( get_post( $event->id ) );
|
||||
|
||||
// Check that we got the right transformer.
|
||||
$this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\Eventin::class, $transformer );
|
||||
$this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\Event\Eventin::class, $transformer );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -61,7 +61,7 @@ class Test_Events_Manager extends WP_UnitTestCase {
|
|||
$transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object );
|
||||
|
||||
// Check that we got the right transformer.
|
||||
$this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\Events_Manager::class, $transformer );
|
||||
$this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\Event\Events_Manager::class, $transformer );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -65,7 +65,7 @@ class Test_GatherPress extends WP_UnitTestCase {
|
|||
$transformer = \Activitypub\Transformer\Factory::get_transformer( $event->event );
|
||||
|
||||
// Check that we got the right transformer.
|
||||
$this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\GatherPress::class, $transformer );
|
||||
$this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\Event\GatherPress::class, $transformer );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -74,7 +74,7 @@ class Test_Modern_Events_Calendar_Lite extends WP_UnitTestCase {
|
|||
$transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object );
|
||||
|
||||
// Check that we got the right transformer.
|
||||
$this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\Modern_Events_Calendar_Lite::class, $transformer );
|
||||
$this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\Event\Modern_Events_Calendar_Lite::class, $transformer );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -91,7 +91,7 @@ class Test_The_Events_Calendar extends WP_UnitTestCase {
|
|||
$transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object );
|
||||
|
||||
// Check that we got the right transformer.
|
||||
$this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\The_Events_Calendar::class, $transformer );
|
||||
$this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\Event\The_Events_Calendar::class, $transformer );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -58,7 +58,7 @@ class Test_VS_Event_List extends WP_UnitTestCase {
|
|||
$transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object );
|
||||
|
||||
// Check that we got the right transformer.
|
||||
$this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\VS_Event_List::class, $transformer );
|
||||
$this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\Event\VS_Event_List::class, $transformer );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -58,7 +58,7 @@ class Test_WP_Event_Manager extends WP_UnitTestCase {
|
|||
$transformer = \Activitypub\Transformer\Factory::get_transformer( $wp_object );
|
||||
|
||||
// Check that we got the right transformer.
|
||||
$this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\WP_Event_Manager::class, $transformer );
|
||||
$this->assertInstanceOf( \ActivityPub_Event_Bridge\Activitypub\Transformer\Event\WP_Event_Manager::class, $transformer );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue