some cleanup and code linting
This commit is contained in:
parent
0999db945b
commit
6191dafe5b
8 changed files with 218 additions and 248 deletions
|
@ -32,11 +32,6 @@ Activitypub_Event_Extensions\Autoloader::register();
|
||||||
// Initialize the plugin.
|
// Initialize the plugin.
|
||||||
Activitypub_Event_Extensions\Setup::get_instance();
|
Activitypub_Event_Extensions\Setup::get_instance();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// For local development purposes: TODO. Remove everything after here.
|
// For local development purposes: TODO. Remove everything after here.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,9 +48,11 @@ add_filter( 'http_request_host_is_external', 'custom_http_request_host_is_extern
|
||||||
*
|
*
|
||||||
* TODO: Remove this for release.
|
* TODO: Remove this for release.
|
||||||
*
|
*
|
||||||
|
* @param bool $is_external Whether the request is external.
|
||||||
|
*
|
||||||
* @todo This filter is temporary code needed to do local testing.
|
* @todo This filter is temporary code needed to do local testing.
|
||||||
*/
|
*/
|
||||||
function custom_http_request_host_is_external( $is_external, $host, $url ) {
|
function custom_http_request_host_is_external( $is_external ) {
|
||||||
$is_external = true;
|
$is_external = true;
|
||||||
|
|
||||||
return $is_external;
|
return $is_external;
|
||||||
|
@ -70,6 +67,9 @@ function custom_http_request_host_is_external( $is_external, $host, $url ) {
|
||||||
*/
|
*/
|
||||||
add_filter( 'https_ssl_verify', 'dont_verify_local_dev_https', 10, 3 );
|
add_filter( 'https_ssl_verify', 'dont_verify_local_dev_https', 10, 3 );
|
||||||
|
|
||||||
function dont_verify_local_dev_https( $url ) {
|
/**
|
||||||
|
* TODO: remove it.
|
||||||
|
*/
|
||||||
|
function dont_verify_local_dev_https() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,9 +43,13 @@ class Event extends Post {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format a human readable HTML summary.
|
* Format a human readable HTML summary.
|
||||||
|
*
|
||||||
|
* @param string $summary_text The base string to be formatted.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function format_html_summary($summary_text) {
|
protected function format_html_summary( $summary_text ): string {
|
||||||
|
return $summary_text;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -127,14 +127,14 @@ class Events_Manager extends Event_Transformer {
|
||||||
/**
|
/**
|
||||||
* Get the end time from the events metadata.
|
* Get the end time from the events metadata.
|
||||||
*/
|
*/
|
||||||
protected function get_end_time() {
|
public function get_end_time() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the end time from the events metadata.
|
* Get the end time from the events metadata.
|
||||||
*/
|
*/
|
||||||
protected function get_start_time() {
|
public function get_start_time() {
|
||||||
$date_string = $this->em_event->event_start_date;
|
$date_string = $this->em_event->event_start_date;
|
||||||
$time_string = $this->em_event->event_start_time;
|
$time_string = $this->em_event->event_start_time;
|
||||||
$timezone_string = $this->em_event->event_timezone;
|
$timezone_string = $this->em_event->event_timezone;
|
||||||
|
@ -155,7 +155,7 @@ class Events_Manager extends Event_Transformer {
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
protected function get_maximum_attendee_capacity() {
|
public function get_maximum_attendee_capacity() {
|
||||||
return $this->em_event->event_spaces;
|
return $this->em_event->event_spaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ class Events_Manager extends Event_Transformer {
|
||||||
*
|
*
|
||||||
* @todo decide whether to include pending bookings or not!
|
* @todo decide whether to include pending bookings or not!
|
||||||
*/
|
*/
|
||||||
protected function get_remaining_attendee_capacity() {
|
public function get_remaining_attendee_capacity() {
|
||||||
$em_bookings = $this->em_event->get_bookings()->get_bookings();
|
$em_bookings = $this->em_event->get_bookings()->get_bookings();
|
||||||
$remaining_attendee_capacity = $this->em_event->event_spaces - count( $em_bookings->bookings );
|
$remaining_attendee_capacity = $this->em_event->event_spaces - count( $em_bookings->bookings );
|
||||||
return $remaining_attendee_capacity;
|
return $remaining_attendee_capacity;
|
||||||
|
@ -175,12 +175,15 @@ class Events_Manager extends Event_Transformer {
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
protected function get_participant_count() {
|
public function get_participant_count() {
|
||||||
$em_bookings = $this->em_event->get_bookings()->get_bookings();
|
$em_bookings = $this->em_event->get_bookings()->get_bookings();
|
||||||
return count( $em_bookings->bookings );
|
return count( $em_bookings->bookings );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function get_summary() {
|
/**
|
||||||
|
* Hardcoded function for generating a summary.
|
||||||
|
*/
|
||||||
|
public function get_summary() {
|
||||||
if ( $this->em_event->post_excerpt ) {
|
if ( $this->em_event->post_excerpt ) {
|
||||||
$excerpt = $this->em_event->post_excerpt;
|
$excerpt = $this->em_event->post_excerpt;
|
||||||
} else {
|
} else {
|
||||||
|
@ -194,17 +197,17 @@ class Events_Manager extends Event_Transformer {
|
||||||
return $summary;
|
return $summary;
|
||||||
}
|
}
|
||||||
|
|
||||||
// protected function get_join_mode() {
|
/**
|
||||||
// return 'free';
|
* Get the event link as an ActivityPub Link object, but as an associative array.
|
||||||
// }
|
*
|
||||||
|
* @return array
|
||||||
private function get_event_link_attachment() {
|
*/
|
||||||
|
private function get_event_link_attachment(): array {
|
||||||
$event_link_url = $this->em_event->event_location->data['url'];
|
$event_link_url = $this->em_event->event_location->data['url'];
|
||||||
$event_link_text = $this->em_event->event_location->data['text'];
|
$event_link_text = $this->em_event->event_location->data['text'];
|
||||||
return array(
|
return array(
|
||||||
'type' => 'Link',
|
'type' => 'Link',
|
||||||
'name' => 'Website',
|
'name' => $event_link_text ? $event_link_text : 'Website',
|
||||||
// 'name' => $event_link_text,
|
|
||||||
'href' => \esc_url( $event_link_url ),
|
'href' => \esc_url( $event_link_url ),
|
||||||
'mediaType' => 'text/html',
|
'mediaType' => 'text/html',
|
||||||
);
|
);
|
||||||
|
@ -230,54 +233,9 @@ class Events_Manager extends Event_Transformer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function tries to map VS-Event categories to Mobilizon event categories.
|
* Compose the events tags.
|
||||||
*
|
|
||||||
* @return string $category
|
|
||||||
*/
|
*/
|
||||||
protected function get_category() {
|
public function get_tag() {
|
||||||
$categories = $this->em_event->get_categories()->terms;
|
|
||||||
|
|
||||||
if ( empty( $categories ) ) {
|
|
||||||
return 'MEETING';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepare an array to store all category information for comparison.
|
|
||||||
$category_info = array();
|
|
||||||
|
|
||||||
// Extract relevant category information (name, slug, description) from the categories array.
|
|
||||||
foreach ( $categories as $category ) {
|
|
||||||
$category_info[] = strtolower( $category->name );
|
|
||||||
$category_info[] = strtolower( $category->slug );
|
|
||||||
$category_info[] = strtolower( $category->description );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert mobilizon categories to lowercase for case-insensitive comparison.
|
|
||||||
$mobilizon_categories = array_map( 'strtolower', Event::DEFAULT_EVENT_CATEGORIES );
|
|
||||||
|
|
||||||
// Initialize variables to track the best match.
|
|
||||||
$best_mobilizon_category_match = '';
|
|
||||||
$best_match_length = 0;
|
|
||||||
|
|
||||||
// Check for the best match.
|
|
||||||
foreach ( $mobilizon_categories as $mobilizon_category ) {
|
|
||||||
foreach ( $category_info as $category ) {
|
|
||||||
foreach ( explode( '_', $mobilizon_category ) as $mobilizon_category_slice ) {
|
|
||||||
if ( stripos( $category, $mobilizon_category_slice ) !== false ) {
|
|
||||||
// Check if the current match is longer than the previous best match.
|
|
||||||
$current_match_legnth = strlen( $mobilizon_category_slice );
|
|
||||||
if ( $current_match_legnth > $best_match_length ) {
|
|
||||||
$best_mobilizon_category_match = $mobilizon_category;
|
|
||||||
$best_match_length = $current_match_legnth;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ( '' != $best_mobilizon_category_match ) ? strtoupper( $best_mobilizon_category_match ) : 'MEETING';
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function get_tag() {
|
|
||||||
// The parent tag function also fetches the mentions.
|
// The parent tag function also fetches the mentions.
|
||||||
$tags = parent::get_tag();
|
$tags = parent::get_tag();
|
||||||
|
|
||||||
|
@ -296,6 +254,9 @@ class Events_Manager extends Event_Transformer {
|
||||||
return $tags;
|
return $tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the events title/name.
|
||||||
|
*/
|
||||||
protected function get_name() {
|
protected function get_name() {
|
||||||
return $this->em_event->event_name;
|
return $this->em_event->event_name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
* @license AGPL-3.0-or-later
|
* @license AGPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Activitypub\Transformer\Post;
|
use Activitypub_Event_Extensions\Activitypub\Transformer\Event;
|
||||||
use Activitypub\Model\Blog_user;
|
use Activitypub\Model\Blog;
|
||||||
use Activitypub\Activity\Extended_Object\Event as Event_Object;
|
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;
|
||||||
|
@ -23,7 +23,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
class GatherPress extends Post {
|
class GatherPress extends Event {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The target ActivityPub Event object of the transformer.
|
* The target ActivityPub Event object of the transformer.
|
||||||
|
@ -35,7 +35,7 @@ class GatherPress extends Post {
|
||||||
/**
|
/**
|
||||||
* The current GatherPress Event object.
|
* The current GatherPress Event object.
|
||||||
*
|
*
|
||||||
* @var Event
|
* @var GatherPress_Event
|
||||||
*/
|
*/
|
||||||
protected $gp_event;
|
protected $gp_event;
|
||||||
|
|
||||||
|
@ -56,7 +56,6 @@ class GatherPress extends Post {
|
||||||
* @return string Widget name.
|
* @return string Widget name.
|
||||||
*/
|
*/
|
||||||
public function get_transformer_name() {
|
public function get_transformer_name() {
|
||||||
|
|
||||||
return 'gatherpress/gp-event';
|
return 'gatherpress/gp-event';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +69,6 @@ class GatherPress extends Post {
|
||||||
* @return string Widget title.
|
* @return string Widget title.
|
||||||
*/
|
*/
|
||||||
public function get_transformer_label() {
|
public function get_transformer_label() {
|
||||||
|
|
||||||
return 'GatherPress Event';
|
return 'GatherPress Event';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +82,6 @@ class GatherPress extends Post {
|
||||||
* @return array Widget categories.
|
* @return array Widget categories.
|
||||||
*/
|
*/
|
||||||
public static function get_supported_post_types() {
|
public static function get_supported_post_types() {
|
||||||
|
|
||||||
return array( GatherPress_Event::POST_TYPE );
|
return array( GatherPress_Event::POST_TYPE );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +93,6 @@ class GatherPress extends Post {
|
||||||
* @return string The Event Object-Type.
|
* @return string The Event Object-Type.
|
||||||
*/
|
*/
|
||||||
protected function get_type() {
|
protected function get_type() {
|
||||||
|
|
||||||
return 'Event';
|
return 'Event';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +102,6 @@ class GatherPress extends Post {
|
||||||
* @return array The Place.
|
* @return array The Place.
|
||||||
*/
|
*/
|
||||||
public function get_location() {
|
public function get_location() {
|
||||||
|
|
||||||
$address = $this->gp_venue['full_address'];
|
$address = $this->gp_venue['full_address'];
|
||||||
$place = new Place();
|
$place = new Place();
|
||||||
$place->set_type( 'Place' );
|
$place->set_type( 'Place' );
|
||||||
|
@ -119,7 +114,6 @@ class GatherPress extends Post {
|
||||||
* Get the end time from the event object.
|
* Get the end time from the event object.
|
||||||
*/
|
*/
|
||||||
protected function get_end_time() {
|
protected function get_end_time() {
|
||||||
|
|
||||||
return $this->gp_event->get_datetime_end( 'Y-m-d\TH:i:s\Z' );
|
return $this->gp_event->get_datetime_end( 'Y-m-d\TH:i:s\Z' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +121,6 @@ class GatherPress extends Post {
|
||||||
* Get the end time from the event object.
|
* Get the end time from the event object.
|
||||||
*/
|
*/
|
||||||
protected function get_start_time() {
|
protected function get_start_time() {
|
||||||
|
|
||||||
return $this->gp_event->get_datetime_start( 'Y-m-d\TH:i:s\Z' );
|
return $this->gp_event->get_datetime_start( 'Y-m-d\TH:i:s\Z' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +144,6 @@ class GatherPress extends Post {
|
||||||
* Overrides/extends the get_attachments function to also add the event Link.
|
* Overrides/extends the get_attachments function to also add the event Link.
|
||||||
*/
|
*/
|
||||||
protected function get_attachment() {
|
protected function get_attachment() {
|
||||||
|
|
||||||
$attachments = parent::get_attachment();
|
$attachments = parent::get_attachment();
|
||||||
if ( count( $attachments ) ) {
|
if ( count( $attachments ) ) {
|
||||||
$attachments[0]['type'] = 'Document';
|
$attachments[0]['type'] = 'Document';
|
||||||
|
@ -164,16 +156,6 @@ class GatherPress extends Post {
|
||||||
return $attachments;
|
return $attachments;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO:
|
|
||||||
*
|
|
||||||
* @return string $category
|
|
||||||
*/
|
|
||||||
protected function get_category() {
|
|
||||||
|
|
||||||
return 'MEETING';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the User-URL of the Author of the Post.
|
* Returns the User-URL of the Author of the Post.
|
||||||
*
|
*
|
||||||
|
@ -182,8 +164,7 @@ class GatherPress extends Post {
|
||||||
* @return string The User-URL.
|
* @return string The User-URL.
|
||||||
*/
|
*/
|
||||||
protected function get_attributed_to() {
|
protected function get_attributed_to() {
|
||||||
|
$user = new Blog();
|
||||||
$user = new Blog_User();
|
|
||||||
return $user->get_url();
|
return $user->get_url();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,7 +177,6 @@ class GatherPress extends Post {
|
||||||
* @return string $summary The custom event summary.
|
* @return string $summary The custom event summary.
|
||||||
*/
|
*/
|
||||||
public function get_summary() {
|
public function get_summary() {
|
||||||
|
|
||||||
if ( $this->wp_object->excerpt ) {
|
if ( $this->wp_object->excerpt ) {
|
||||||
$excerpt = $this->wp_object->post_excerpt;
|
$excerpt = $this->wp_object->post_excerpt;
|
||||||
} elseif ( get_post_meta( $this->wp_object->ID, 'event-summary', true ) ) {
|
} elseif ( get_post_meta( $this->wp_object->ID, 'event-summary', true ) ) {
|
||||||
|
@ -219,8 +199,7 @@ class GatherPress extends Post {
|
||||||
* @return Activitypub\Activity\Event
|
* @return Activitypub\Activity\Event
|
||||||
*/
|
*/
|
||||||
public function to_object() {
|
public function to_object() {
|
||||||
|
$this->ap_object = new Event_Object();
|
||||||
$this->ap_object = new Event();
|
|
||||||
$this->gp_event = new GatherPress_Event( $this->wp_object->ID );
|
$this->gp_event = new GatherPress_Event( $this->wp_object->ID );
|
||||||
$this->gp_venue = $this->gp_event->get_venue_information();
|
$this->gp_venue = $this->gp_event->get_venue_information();
|
||||||
|
|
||||||
|
|
170
includes/activitypub/transformer/class-the-events-calendar.php
Normal file
170
includes/activitypub/transformer/class-the-events-calendar.php
Normal file
|
@ -0,0 +1,170 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* ActivityPub Tribe Transformer
|
||||||
|
*
|
||||||
|
* @package activity-event-transformers
|
||||||
|
* @license AGPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Activitypub_Event_Extensions\Activitypub\Transformer;
|
||||||
|
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
exit; // Exit if accessed directly.
|
||||||
|
}
|
||||||
|
|
||||||
|
use Activitypub_Event_Extensions\Activitypub\Transformer\Event;
|
||||||
|
use Activitypub\Activity\Extended_Object\Place;
|
||||||
|
use WP_Error;
|
||||||
|
use WP_Post;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ActivityPub Tribe Transformer
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
class The_Events_Calendar extends Event {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Tribe Event object.
|
||||||
|
*
|
||||||
|
* @var array|WP_Post|null
|
||||||
|
*/
|
||||||
|
protected $tribe_event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extend the constructor, to also set the tribe object.
|
||||||
|
*
|
||||||
|
* This is a special class object form The Events Calendar which
|
||||||
|
* has a lot of useful functions, we make use of our getter functions.
|
||||||
|
*
|
||||||
|
* @param WP_Post $wp_object The WordPress object.
|
||||||
|
*/
|
||||||
|
public function __construct( $wp_object ) {
|
||||||
|
parent::__construct( $wp_object );
|
||||||
|
$this->tribe_event = \tribe_get_event( $wp_object );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get tribe category of wp_post
|
||||||
|
*
|
||||||
|
* @return string|null tribe category if it exists
|
||||||
|
*/
|
||||||
|
public function get_tribe_category() {
|
||||||
|
// 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.
|
||||||
|
$categories = tribe_get_event_cat_slugs( $this->wp_object->ID );
|
||||||
|
|
||||||
|
if ( count( $categories ) === 0 ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $categories[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get status of the tribe event
|
||||||
|
*
|
||||||
|
* @return string status of the event
|
||||||
|
*/
|
||||||
|
public function get_tribe_status() {
|
||||||
|
|
||||||
|
if ( 'canceled' === $this->tribe_event->event_status ) {
|
||||||
|
return 'CANCELLED';
|
||||||
|
}
|
||||||
|
if ( 'postponed' === $this->tribe_event->event_status ) {
|
||||||
|
return 'CANCELLED'; // This will be reflected in the cancelled reason.
|
||||||
|
}
|
||||||
|
if ( '' === $this->tribe_event->event_status ) {
|
||||||
|
return 'CONFIRMED';
|
||||||
|
}
|
||||||
|
|
||||||
|
return new WP_Error( 'invalid event_status value', __( 'invalid event_status', 'activitypub' ), array( 'status' => 404 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract the join mode.
|
||||||
|
*
|
||||||
|
* If the ticket sale is active set it to restricted.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function get_join_mode() {
|
||||||
|
return empty( $this->tribe_event->tickets ) ? 'free' : 'restricted';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the comments are enabled for the current event.
|
||||||
|
*/
|
||||||
|
public function get_comments_enabled(): bool {
|
||||||
|
return ( 'open' === $this->tribe_event->comment_status ) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the event is an online event.
|
||||||
|
*/
|
||||||
|
public function get_is_online(): bool {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the content for the ActivityPub Item with
|
||||||
|
*
|
||||||
|
* The content will be generated based on the user settings.
|
||||||
|
*
|
||||||
|
* @return string The content.
|
||||||
|
*/
|
||||||
|
protected function get_content() {
|
||||||
|
|
||||||
|
$content = parent::get_content();
|
||||||
|
// TODO: remove link at the end of the content.
|
||||||
|
|
||||||
|
// TODO: add organizer
|
||||||
|
// $this->tribe_event->organizers[0].
|
||||||
|
|
||||||
|
// TODO: do add Cancelled reason in the content (maybe at the end).
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the event location.
|
||||||
|
*
|
||||||
|
* @return Place|array The place/venue if one is set.
|
||||||
|
*/
|
||||||
|
public function get_location(): Place|null {
|
||||||
|
if ( empty( $this->wp_object->venues ) || ! empty( $this->wp_object->venues[0] ) ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// We currently only support a single venue.
|
||||||
|
$event_venue = $this->wp_object->venues[0];
|
||||||
|
|
||||||
|
$address = array(
|
||||||
|
'addressCountry' => $event_venue->country,
|
||||||
|
'addressLocality' => $event_venue->city,
|
||||||
|
'addressRegion' => $event_venue->province,
|
||||||
|
'postalCode' => $event_venue->zip,
|
||||||
|
'streetAddress' => $event_venue->address,
|
||||||
|
'type' => 'PostalAddress',
|
||||||
|
);
|
||||||
|
|
||||||
|
$location = new Place();
|
||||||
|
$location->set_address( $address );
|
||||||
|
$location->set_id( $event_venue->permalink );
|
||||||
|
$location->set_name( $event_venue->post_name );
|
||||||
|
|
||||||
|
return $location;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extend the default event transformers to_object function.
|
||||||
|
*
|
||||||
|
* This is the heart of the ActivityPub transformer.
|
||||||
|
*
|
||||||
|
* @return Event_Object
|
||||||
|
*/
|
||||||
|
public function to_object() {
|
||||||
|
$activitypub_object = parent::to_object();
|
||||||
|
|
||||||
|
return $activitypub_object;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,136 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* ActivityPub Tribe Transformer
|
|
||||||
*
|
|
||||||
* @package activity-event-transformers
|
|
||||||
* @license AGPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Activitypub_Event_Extensions\Activitypub\Transformer;
|
|
||||||
|
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
|
||||||
exit; // Exit if accessed directly.
|
|
||||||
}
|
|
||||||
|
|
||||||
use Activitypub_Event_Extensions\Activitypub\Transformer\Event;
|
|
||||||
use Activitypub\Activity\Extended_Object\Place;
|
|
||||||
use WP_Error;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ActivityPub Tribe Transformer
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
class Tribe extends Event {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Tribe Event object.
|
|
||||||
*
|
|
||||||
* @var WP_Post
|
|
||||||
*/
|
|
||||||
protected $tribe_event;
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * resolve the tribe metadata in the setter of wp_post.
|
|
||||||
// *
|
|
||||||
// * @param WP_Post $wp_post The WP_Post object.
|
|
||||||
// * @return void
|
|
||||||
// */
|
|
||||||
// public function set_wp_post( WP_Post $wp_post ) {
|
|
||||||
// parent::set_wp_post( $wp_post );
|
|
||||||
// $this->tribe_event = tribe_get_event( $wp_post->ID );
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get tribe category of wp_post
|
|
||||||
*
|
|
||||||
* @return string|null tribe category if it exists
|
|
||||||
*/
|
|
||||||
public function get_tribe_category() {
|
|
||||||
// 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.
|
|
||||||
$categories = tribe_get_event_cat_slugs( $this->wp_object->ID );
|
|
||||||
|
|
||||||
if ( count( $categories ) === 0 ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $categories[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get status of the tribe event
|
|
||||||
*
|
|
||||||
* @return string status of the event
|
|
||||||
*/
|
|
||||||
public function get_tribe_status() {
|
|
||||||
|
|
||||||
if ( 'canceled' === $this->tribe_event->event_status ) {
|
|
||||||
return 'CANCELLED';
|
|
||||||
}
|
|
||||||
if ( 'postponed' === $this->tribe_event->event_status ) {
|
|
||||||
return 'CANCELLED'; // This will be reflected in the cancelled reason.
|
|
||||||
}
|
|
||||||
if ( '' === $this->tribe_event->event_status ) {
|
|
||||||
return 'CONFIRMED';
|
|
||||||
}
|
|
||||||
|
|
||||||
return new WP_Error( 'invalid event_status value', __( 'invalid event_status', 'activitypub' ), array( 'status' => 404 ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the content for the ActivityPub Item with
|
|
||||||
*
|
|
||||||
* The content will be generated based on the user settings.
|
|
||||||
*
|
|
||||||
* @return string The content.
|
|
||||||
*/
|
|
||||||
protected function get_content() {
|
|
||||||
|
|
||||||
$content = parent::get_content();
|
|
||||||
// TODO: remove link at the end of the content.
|
|
||||||
|
|
||||||
// TODO: add organizer
|
|
||||||
// $this->tribe_event->organizers[0].
|
|
||||||
|
|
||||||
// TODO: do add Cancelled reason in the content (maybe at the end).
|
|
||||||
|
|
||||||
return $content;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the event location.
|
|
||||||
*
|
|
||||||
* @returns array The Place.
|
|
||||||
*/
|
|
||||||
public function get_event_location() {
|
|
||||||
/*
|
|
||||||
This is how the Tribe event looks like:
|
|
||||||
TODO: Remove this comment.
|
|
||||||
'post_title' => 'testvenue',
|
|
||||||
'post_name' => 'testvenue',
|
|
||||||
'guid' => 'http://localhost/venue/testvenue/',
|
|
||||||
'post_type' => 'tribe_venue',
|
|
||||||
'address' => 'testaddr',
|
|
||||||
'country' => 'Austria',
|
|
||||||
'city' => 'testcity',
|
|
||||||
'state_province' => 'testprovince',
|
|
||||||
'state' => '',
|
|
||||||
'province' => 'testprovince',
|
|
||||||
'zip' => '8000',
|
|
||||||
'phone' => '+4312343',
|
|
||||||
'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];
|
|
||||||
return ( new Place() )
|
|
||||||
->set_type( 'Place' )
|
|
||||||
->set_name( $venue->post_name )
|
|
||||||
->set_address(
|
|
||||||
$venue->address . "\n" .
|
|
||||||
$venue->zip . ', ' . $venue->city . "\n" .
|
|
||||||
$venue->country
|
|
||||||
); // TODO: add checks that everything exists here.
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -9,7 +9,6 @@
|
||||||
namespace Activitypub_Event_Extensions\Activitypub\Transformer;
|
namespace Activitypub_Event_Extensions\Activitypub\Transformer;
|
||||||
|
|
||||||
use Activitypub_Event_Extensions\Activitypub\Transformer\Event as Event_Transformer;
|
use Activitypub_Event_Extensions\Activitypub\Transformer\Event as Event_Transformer;
|
||||||
use Activitypub\Model\Blog;
|
|
||||||
use Activitypub\Activity\Extended_Object\Event;
|
use Activitypub\Activity\Extended_Object\Event;
|
||||||
use Activitypub\Activity\Extended_Object\Place;
|
use Activitypub\Activity\Extended_Object\Place;
|
||||||
|
|
||||||
|
@ -21,14 +20,16 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ActivityPub Transformer for VS Event
|
* ActivityPub Transformer for VS Event.
|
||||||
|
*
|
||||||
|
* This transformer tries a different principle: The setters are chainable.
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
class VS_Event extends Event_Transformer {
|
class VS_Event_List extends Event_Transformer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The target transformet ActivityPub Event object.
|
* The target transformer ActivityPub Event object.
|
||||||
*
|
*
|
||||||
* @var Event
|
* @var Event
|
||||||
*/
|
*/
|
||||||
|
@ -154,15 +155,6 @@ class VS_Event extends Event_Transformer {
|
||||||
return $attachments;
|
return $attachments;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This function tries to map VS-Event categories to Mobilizon event categories.
|
|
||||||
*
|
|
||||||
* @return string $category
|
|
||||||
*/
|
|
||||||
protected function get_category() {
|
|
||||||
return 'MEETING';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a custom summary.
|
* Create a custom summary.
|
||||||
*
|
*
|
||||||
|
@ -205,7 +197,7 @@ class VS_Event extends Event_Transformer {
|
||||||
$setter_function = 'set_' . $key;
|
$setter_function = 'set_' . $key;
|
||||||
$getter_function = 'get_' . $key;
|
$getter_function = 'get_' . $key;
|
||||||
|
|
||||||
if ( in_array( $getter_function, get_class_methods( $this ) ) ) {
|
if ( in_array( $getter_function, get_class_methods( $this ), true ) ) {
|
||||||
$this->ap_object->$setter_function( $this->$getter_function() );
|
$this->ap_object->$setter_function( $this->$getter_function() );
|
||||||
} else {
|
} else {
|
||||||
$this->ap_object->$setter_function( $value );
|
$this->ap_object->$setter_function( $value );
|
||||||
|
@ -220,7 +212,7 @@ class VS_Event extends Event_Transformer {
|
||||||
* @param string $method The method name.
|
* @param string $method The method name.
|
||||||
* @param string $params The method params.
|
* @param string $params The method params.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void|this
|
||||||
*/
|
*/
|
||||||
public function __call( $method, $params ) {
|
public function __call( $method, $params ) {
|
||||||
|
|
||||||
|
@ -230,7 +222,7 @@ class VS_Event extends Event_Transformer {
|
||||||
return $this->set( $var, $params[0] );
|
return $this->set( $var, $params[0] );
|
||||||
}
|
}
|
||||||
|
|
||||||
// when do we need: call_user_func( array( $activitypub_object, $setter ), $value );
|
// TODO: When do we need: call_user_func( array( $activitypub_object, $setter ), $value ).
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
Loading…
Reference in a new issue