WIP on transformers
This commit is contained in:
parent
9eebf588ab
commit
4b9dbbef06
5 changed files with 83 additions and 86 deletions
|
@ -8,9 +8,12 @@
|
||||||
|
|
||||||
namespace Activitypub_Event_Extensions\Activitypub\Transformer;
|
namespace Activitypub_Event_Extensions\Activitypub\Transformer;
|
||||||
|
|
||||||
|
use Activitypub\Activity\Extended_Object\Event as Event_Object;
|
||||||
use Activitypub\Model\Blog;
|
use Activitypub\Model\Blog;
|
||||||
use Activitypub\Transformer\Post;
|
use Activitypub\Transformer\Post;
|
||||||
|
|
||||||
|
use function Activitypub\get_rest_url_by_path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base transformer for WordPress event post types to ActivityPub events.
|
* Base transformer for WordPress event post types to ActivityPub events.
|
||||||
*/
|
*/
|
||||||
|
@ -26,4 +29,51 @@ class Event extends Post {
|
||||||
$blog = new Blog();
|
$blog = new Blog();
|
||||||
return $blog->get_id();
|
return $blog->get_id();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ActivityStreams 2.0 Object-Type for an Event.
|
||||||
|
*
|
||||||
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-event
|
||||||
|
*
|
||||||
|
* @return string The Event Object-Type.
|
||||||
|
*/
|
||||||
|
protected function get_object_type() {
|
||||||
|
return 'Event';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic function that converts an WP-Event object to an ActivityPub-Event object.
|
||||||
|
*
|
||||||
|
* @return Event_Object
|
||||||
|
*/
|
||||||
|
public function to_object() {
|
||||||
|
$activitypub_object = new Event_Object();
|
||||||
|
$activitypub_object = $this->transform_object_properties( $activitypub_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_content_map(
|
||||||
|
array(
|
||||||
|
$this->get_locale() => $this->get_content(),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$path = sprintf( 'actors/%d/followers', intval( $this->wp_object->post_author ) );
|
||||||
|
|
||||||
|
$activitypub_object->set_to(
|
||||||
|
array(
|
||||||
|
'https://www.w3.org/ns/activitystreams#Public',
|
||||||
|
get_rest_url_by_path( $path ),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return $activitypub_object;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
use Activitypub\Transformer\Post;
|
use Activitypub\Transformer\Post;
|
||||||
use Activitypub\Model\Blog_user;
|
use Activitypub\Model\Blog_user;
|
||||||
use Activitypub\Activity\Extended_Object\Event;
|
use Activitypub\Activity\Extended_Object\Event as Event_Object;
|
||||||
use Activitypub\Activity\Extended_Object\Place;
|
use Activitypub\Activity\Extended_Object\Place;
|
||||||
use GatherPress\Core\Event as GatherPress_Event;
|
use GatherPress\Core\Event as GatherPress_Event;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub Tribe Transformer
|
* ActivityPub Tribe Transformer
|
||||||
*
|
*
|
||||||
|
@ -7,20 +6,22 @@
|
||||||
* @license AGPL-3.0-or-later
|
* @license AGPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Activitypub_Event_Extensions\Activitypub\Transformer;
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
exit; // Exit if accessed directly.
|
exit; // Exit if accessed directly.
|
||||||
}
|
}
|
||||||
|
|
||||||
use Activitypub_Event_Extensions\Activitypub\Transformer\Event as Event_Transformer;
|
use Activitypub_Event_Extensions\Activitypub\Transformer\Event;
|
||||||
use Activitypub\Activity\Extended_Object\Event;
|
|
||||||
use Activitypub\Activity\Extended_Object\Place;
|
use Activitypub\Activity\Extended_Object\Place;
|
||||||
|
use WP_Error;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub Tribe Transformer
|
* ActivityPub Tribe Transformer
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
class Tribe extends Event_Transformer {
|
class Tribe extends Event {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Tribe Event object.
|
* The Tribe Event object.
|
||||||
|
@ -40,69 +41,14 @@ class Tribe extends Event_Transformer {
|
||||||
// $this->tribe_event = tribe_get_event( $wp_post->ID );
|
// $this->tribe_event = tribe_get_event( $wp_post->ID );
|
||||||
// }
|
// }
|
||||||
|
|
||||||
/**
|
|
||||||
* 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/tribe';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get widget title.
|
|
||||||
*
|
|
||||||
* Retrieve Transformer title.
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
* @access public
|
|
||||||
* @return string Widget title.
|
|
||||||
*/
|
|
||||||
public function get_label() {
|
|
||||||
|
|
||||||
return 'The Events Calendar';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the ActivityStreams 2.0 Object-Type for an Event.
|
|
||||||
*
|
|
||||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-event
|
|
||||||
*
|
|
||||||
* @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( 'tribe_events' );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get tribe category of wp_post
|
* Get tribe category of wp_post
|
||||||
*
|
*
|
||||||
* @return string|null tribe category if it exists
|
* @return string|null tribe category if it exists
|
||||||
*/
|
*/
|
||||||
public function get_tribe_category() {
|
public function get_tribe_category() {
|
||||||
// todo make it possible that one event can have multiple categories?
|
// TODO: make it possible that one event can have multiple categories?
|
||||||
|
// Using cat_slugs isn't the best way to do this, don't know if it's a good idea.
|
||||||
// using cat_slugs isn't 100% nice way to do this, don't know if it's a good idea
|
|
||||||
$categories = tribe_get_event_cat_slugs( $this->wp_object->ID );
|
$categories = tribe_get_event_cat_slugs( $this->wp_object->ID );
|
||||||
|
|
||||||
if ( count( $categories ) === 0 ) {
|
if ( count( $categories ) === 0 ) {
|
||||||
|
@ -123,7 +69,7 @@ class Tribe extends Event_Transformer {
|
||||||
return 'CANCELLED';
|
return 'CANCELLED';
|
||||||
}
|
}
|
||||||
if ( 'postponed' === $this->tribe_event->event_status ) {
|
if ( 'postponed' === $this->tribe_event->event_status ) {
|
||||||
return 'CANCELLED'; // this will be reflected in the cancelled reason
|
return 'CANCELLED'; // This will be reflected in the cancelled reason.
|
||||||
}
|
}
|
||||||
if ( '' === $this->tribe_event->event_status ) {
|
if ( '' === $this->tribe_event->event_status ) {
|
||||||
return 'CONFIRMED';
|
return 'CONFIRMED';
|
||||||
|
@ -142,12 +88,12 @@ class Tribe extends Event_Transformer {
|
||||||
protected function get_content() {
|
protected function get_content() {
|
||||||
|
|
||||||
$content = parent::get_content();
|
$content = parent::get_content();
|
||||||
// todo remove link at the end of the content
|
// TODO: remove link at the end of the content.
|
||||||
|
|
||||||
// todo add organizer
|
// TODO: add organizer
|
||||||
// $this->tribe_event->organizers[0]
|
// $this->tribe_event->organizers[0].
|
||||||
|
|
||||||
// todo add Canclled reason in the content (maybe at the end)
|
// TODO: do add Cancelled reason in the content (maybe at the end).
|
||||||
|
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
@ -155,26 +101,27 @@ class Tribe extends Event_Transformer {
|
||||||
/**
|
/**
|
||||||
* Get the event location.
|
* Get the event location.
|
||||||
*
|
*
|
||||||
* @param int $post_id The WordPress post ID.
|
|
||||||
* @returns array The Place.
|
* @returns array The Place.
|
||||||
*/
|
*/
|
||||||
public function get_event_location() {
|
public function get_event_location() {
|
||||||
/*
|
/*
|
||||||
'post_title' => 'testvenue',
|
This is how the Tribe event looks like:
|
||||||
'post_name' => 'testvenue',
|
TODO: Remove this comment.
|
||||||
'guid' => 'http://localhost/venue/testvenue/',
|
'post_title' => 'testvenue',
|
||||||
'post_type' => 'tribe_venue',
|
'post_name' => 'testvenue',
|
||||||
'address' => 'testaddr',
|
'guid' => 'http://localhost/venue/testvenue/',
|
||||||
'country' => 'Austria',
|
'post_type' => 'tribe_venue',
|
||||||
'city' => 'testcity',
|
'address' => 'testaddr',
|
||||||
'state_province' => 'testprovince',
|
'country' => 'Austria',
|
||||||
'state' => '',
|
'city' => 'testcity',
|
||||||
'province' => 'testprovince',
|
'state_province' => 'testprovince',
|
||||||
'zip' => '8000',
|
'state' => '',
|
||||||
'phone' => '+4312343',
|
'province' => 'testprovince',
|
||||||
'permalink' => 'http://localhost/venue/testvenue/',
|
'zip' => '8000',
|
||||||
'directions_link' => 'https://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=testaddr+testcity+testprovince+8000+Austria',
|
'phone' => '+4312343',
|
||||||
'website' => 'https://test.at',
|
'permalink' => 'http://localhost/venue/testvenue/',
|
||||||
|
'directions_link' => 'https://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=testaddr+testcity+testprovince+8000+Austria',
|
||||||
|
'website' => 'https://test.at',
|
||||||
*/
|
*/
|
||||||
$venue = $this->tribe_event->venues[0];
|
$venue = $this->tribe_event->venues[0];
|
||||||
return ( new Place() )
|
return ( new Place() )
|
||||||
|
@ -184,6 +131,6 @@ class Tribe extends Event_Transformer {
|
||||||
$venue->address . "\n" .
|
$venue->address . "\n" .
|
||||||
$venue->zip . ', ' . $venue->city . "\n" .
|
$venue->zip . ', ' . $venue->city . "\n" .
|
||||||
$venue->country
|
$venue->country
|
||||||
); // todo add checks that everything exists here (lol)
|
); // TODO: add checks that everything exists here.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ class Admin_Notices {
|
||||||
// Get the current page.
|
// Get the current page.
|
||||||
$screen = get_current_screen();
|
$screen = get_current_screen();
|
||||||
// Check if we are on a edit page for the event, or on the settings page of the event plugin.
|
// Check if we are on a edit page for the event, or on the settings page of the event plugin.
|
||||||
$is_event_plugins_edit_page = 'edit' === $screen->base && $this->event_plugin['post_type'] === $screen->event_post_type;
|
$is_event_plugins_edit_page = 'edit' === $screen->base && $this->event_plugin['post_type'] === $screen->post_type;
|
||||||
$is_event_plugins_settings_page = $this->event_plugin['settings_page_id'] === $screen->id;
|
$is_event_plugins_settings_page = $this->event_plugin['settings_page_id'] === $screen->id;
|
||||||
|
|
||||||
if ( $is_event_plugins_edit_page || $is_event_plugins_settings_page ) {
|
if ( $is_event_plugins_edit_page || $is_event_plugins_settings_page ) {
|
||||||
|
|
|
@ -40,7 +40,7 @@ class Setup {
|
||||||
'the_events_calendar' => array(
|
'the_events_calendar' => array(
|
||||||
'plugin_file' => 'the-events-calendar/the-events-calendar.php',
|
'plugin_file' => 'the-events-calendar/the-events-calendar.php',
|
||||||
'post_type' => 'tribe_events',
|
'post_type' => 'tribe_events',
|
||||||
'transformer_class' => 'Tribe_Events',
|
'transformer_class' => 'Tribe',
|
||||||
'settings_page_id' => 'tribe_general',
|
'settings_page_id' => 'tribe_general',
|
||||||
),
|
),
|
||||||
'vsel' => array(
|
'vsel' => array(
|
||||||
|
|
Loading…
Reference in a new issue