stash-2024-04-09
This commit is contained in:
parent
1859970d06
commit
4fef29a6c2
7 changed files with 367 additions and 57 deletions
|
@ -47,6 +47,15 @@ add_filter(
|
|||
return new \Events_Manager( $wp_object );
|
||||
}
|
||||
|
||||
/**
|
||||
* Events manager
|
||||
* @see https://wordpress.org/plugins/events-manager/
|
||||
*/
|
||||
if ( class_exists( 'GatherPress\Core\Event' ) && $wp_object->post_type === 'gp_event' ) {
|
||||
require_once __DIR__ . '/includes/activitypub/transformer/class-gatherpress.php';
|
||||
return new \GatherPress( $wp_object );
|
||||
}
|
||||
|
||||
// Return the default transformer.
|
||||
|
||||
return $transformer;
|
||||
|
|
|
@ -1,2 +1,6 @@
|
|||
<?php
|
||||
// Handling Event Joins
|
||||
/**
|
||||
* Handling Event Joins.
|
||||
*
|
||||
* @package activitypub-event-extensions
|
||||
*/
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* ActivityPub Transformer for the plugin Very Simple Event List.
|
||||
*
|
||||
|
@ -7,7 +8,6 @@
|
|||
*/
|
||||
|
||||
use EM_Event;
|
||||
|
||||
use Activitypub\Activity\Extended_Object\Event;
|
||||
use Activitypub\Activity\Extended_Object\Place;
|
||||
use Activitypub\Transformer\Post;
|
||||
|
@ -26,6 +26,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
* @since 1.0.0
|
||||
*/
|
||||
class Events_Manager extends Post {
|
||||
|
||||
/**
|
||||
* Holds the EM_Event object.
|
||||
*
|
||||
|
@ -43,6 +44,7 @@ class Events_Manager extends Post {
|
|||
* @return string Widget name.
|
||||
*/
|
||||
public function get_transformer_name() {
|
||||
|
||||
return 'activitypub-event-transformers/events-manager';
|
||||
}
|
||||
|
||||
|
@ -56,6 +58,7 @@ class Events_Manager extends Post {
|
|||
* @return string Widget title.
|
||||
*/
|
||||
public function get_transformer_label() {
|
||||
|
||||
return 'Events Manager';
|
||||
}
|
||||
|
||||
|
@ -69,6 +72,7 @@ class Events_Manager extends Post {
|
|||
* @return array Widget categories.
|
||||
*/
|
||||
public static function get_supported_post_types() {
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
|
@ -80,10 +84,12 @@ class Events_Manager extends Post {
|
|||
* @return string The Event Object-Type.
|
||||
*/
|
||||
protected function get_type() {
|
||||
|
||||
return 'Event';
|
||||
}
|
||||
|
||||
protected function get_is_online() {
|
||||
|
||||
return 'url' === $this->em_event->event_location_type;
|
||||
}
|
||||
|
||||
|
@ -94,21 +100,22 @@ class Events_Manager extends Post {
|
|||
* @return array The Place.
|
||||
*/
|
||||
public function get_location() {
|
||||
|
||||
if ( 'url' === $this->em_event->event_location_type ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$location = new Place();
|
||||
$location = new Place();
|
||||
$em_location = $this->em_event->get_location();
|
||||
|
||||
$location->set_name( $em_location->location_name );
|
||||
|
||||
$address = array(
|
||||
'type' => 'PostalAddress',
|
||||
'addressCountry' => $em_location->location_country,
|
||||
'type' => 'PostalAddress',
|
||||
'addressCountry' => $em_location->location_country,
|
||||
'addressLocality' => $em_location->location_town,
|
||||
'streetAddress' => $em_location->location_address,
|
||||
'name' => $em_location->location_name,
|
||||
'streetAddress' => $em_location->location_address,
|
||||
'name' => $em_location->location_name,
|
||||
);
|
||||
if ( $em_location->location_state ) {
|
||||
$address['addressRegion'] = $em_location->location_state;
|
||||
|
@ -121,11 +128,11 @@ class Events_Manager extends Post {
|
|||
return $location;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the end time from the events metadata.
|
||||
*/
|
||||
protected function get_end_time() {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -133,8 +140,9 @@ class Events_Manager extends Post {
|
|||
* Get the end time from the events metadata.
|
||||
*/
|
||||
protected function get_start_time() {
|
||||
$date_string = $this->em_event->event_start_date;
|
||||
$time_string = $this->em_event->event_start_time;
|
||||
|
||||
$date_string = $this->em_event->event_start_date;
|
||||
$time_string = $this->em_event->event_start_time;
|
||||
$timezone_string = $this->em_event->event_timezone;
|
||||
|
||||
// Create a DateTime object with the given date, time, and timezone
|
||||
|
@ -149,6 +157,7 @@ class Events_Manager extends Post {
|
|||
}
|
||||
|
||||
protected function get_maximum_attendee_capacity() {
|
||||
|
||||
return $this->em_event->event_spaces;
|
||||
}
|
||||
|
||||
|
@ -156,46 +165,51 @@ class Events_Manager extends Post {
|
|||
* @todo decide whether to include pending bookings or not!
|
||||
*/
|
||||
protected 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 );
|
||||
return $remaining_attendee_capacity;
|
||||
}
|
||||
|
||||
protected function get_participant_count() {
|
||||
|
||||
$em_bookings = $this->em_event->get_bookings()->get_bookings();
|
||||
return count( $em_bookings->bookings );
|
||||
}
|
||||
|
||||
protected function get_content() {
|
||||
|
||||
return $this->wp_object->post_content;
|
||||
}
|
||||
|
||||
protected function get_summary() {
|
||||
|
||||
if ( $this->em_event->post_excerpt ) {
|
||||
$excerpt = $this->em_event->post_excerpt;
|
||||
} else {
|
||||
$excerpt = $this->get_content();
|
||||
}
|
||||
$address = $this->em_event->get_location()->location_name;
|
||||
$start_time = strtotime( $this->get_start_time() );
|
||||
$datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
|
||||
$address = $this->em_event->get_location()->location_name;
|
||||
$start_time = strtotime( $this->get_start_time() );
|
||||
$datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
|
||||
$start_time_string = wp_date( $datetime_format, $start_time );
|
||||
$summary = "📍 {$address}\n📅 {$start_time_string}\n\n{$excerpt}";
|
||||
$summary = "📍 {$address}\n📅 {$start_time_string}\n\n{$excerpt}";
|
||||
return $summary;
|
||||
}
|
||||
|
||||
// protected function get_join_mode() {
|
||||
// return 'free';
|
||||
// return 'free';
|
||||
// }
|
||||
|
||||
private function get_event_link_attachment() {
|
||||
$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'];
|
||||
return array(
|
||||
'type' => 'Link',
|
||||
'name' => 'Website',
|
||||
'type' => 'Link',
|
||||
'name' => 'Website',
|
||||
// 'name' => $event_link_text,
|
||||
'href' => \esc_url( $event_link_url ),
|
||||
'href' => \esc_url( $event_link_url ),
|
||||
'mediaType' => 'text/html',
|
||||
);
|
||||
}
|
||||
|
@ -216,7 +230,8 @@ class Events_Manager extends Post {
|
|||
if ( 'url' === $this->em_event->event_location_type ) {
|
||||
$attachments[] = $this->get_event_link_attachment();
|
||||
}
|
||||
return $attachments; }
|
||||
return $attachments;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function tries to map VS-Event categories to Mobilizon event categories.
|
||||
|
@ -224,6 +239,7 @@ class Events_Manager extends Post {
|
|||
* @return string $category
|
||||
*/
|
||||
protected function get_category() {
|
||||
|
||||
$categories = $this->em_event->get_categories()->terms;
|
||||
|
||||
if ( empty( $categories ) ) {
|
||||
|
@ -245,7 +261,7 @@ class Events_Manager extends Post {
|
|||
|
||||
// Initialize variables to track the best match.
|
||||
$best_mobilizon_category_match = '';
|
||||
$best_match_length = 0;
|
||||
$best_match_length = 0;
|
||||
|
||||
// Check for the best match.
|
||||
foreach ( $mobilizon_categories as $mobilizon_category ) {
|
||||
|
@ -256,7 +272,7 @@ class Events_Manager extends Post {
|
|||
$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;
|
||||
$best_match_length = $current_match_legnth;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -274,7 +290,7 @@ class Events_Manager extends Post {
|
|||
|
||||
if ( $post_tags ) {
|
||||
foreach ( $post_tags as $post_tag ) {
|
||||
$tag = array(
|
||||
$tag = array(
|
||||
'type' => 'Hashtag',
|
||||
'href' => \esc_url( \get_tag_link( $post_tag->term_id ) ),
|
||||
'name' => esc_hashtag( $post_tag->name ),
|
||||
|
@ -286,6 +302,7 @@ class Events_Manager extends Post {
|
|||
}
|
||||
|
||||
protected function get_name() {
|
||||
|
||||
return $this->em_event->event_name;
|
||||
}
|
||||
|
||||
|
@ -295,7 +312,8 @@ class Events_Manager extends Post {
|
|||
* @return Activitypub\Activity\Event
|
||||
*/
|
||||
public function to_object() {
|
||||
$this->em_event = new EM_Event( $this->wp_object->ID, 'post_id' );
|
||||
|
||||
$this->em_event = new EM_Event( $this->wp_object->ID, 'post_id' );
|
||||
$activitypub_object = new Event();
|
||||
|
||||
$activitypub_object = $this->transform_object_properties( $activitypub_object );
|
||||
|
|
251
includes/activitypub/transformer/class-gatherpress.php
Normal file
251
includes/activitypub/transformer/class-gatherpress.php
Normal file
|
@ -0,0 +1,251 @@
|
|||
<?php
|
||||
/**
|
||||
* ActivityPub Transformer for the plugin Very Simple Event List.
|
||||
*
|
||||
* @package activity-event-transformers
|
||||
* @license AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
use Activitypub\Transformer\Post;
|
||||
use Activitypub\Model\Blog_user;
|
||||
use Activitypub\Activity\Extended_Object\Event;
|
||||
use Activitypub\Activity\Extended_Object\Place;
|
||||
use GatherPress\Core\Event as GatherPress_Event;
|
||||
|
||||
use function Activitypub\get_rest_url_by_path;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* ActivityPub Transformer for VS Event
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class GatherPress extends Post {
|
||||
|
||||
/**
|
||||
* The target transformet ActivityPub Event object.
|
||||
*
|
||||
* @var Event
|
||||
*/
|
||||
protected $ap_object;
|
||||
|
||||
/**
|
||||
* The current GatherPress Event object.
|
||||
*
|
||||
* @var Event
|
||||
*/
|
||||
protected $gp_event;
|
||||
|
||||
/**
|
||||
* The current GatherPress Venue object.
|
||||
*
|
||||
* @var Event
|
||||
*/
|
||||
protected $gp_venue;
|
||||
|
||||
/**
|
||||
* Get transformer name.
|
||||
*
|
||||
* Retrieve the transformers name.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
* @return string Widget name.
|
||||
*/
|
||||
public function get_transformer_name() {
|
||||
|
||||
return 'gatherpress/gp-event';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get transformer title.
|
||||
*
|
||||
* Retrieve the transformers label.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access public
|
||||
* @return string Widget title.
|
||||
*/
|
||||
public function get_transformer_label() {
|
||||
|
||||
return 'GatherPress 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( GatherPress_Event::POST_TYPE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ActivityStreams 2.0 Object-Type for an Event.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-event
|
||||
* @since 1.0.0
|
||||
* @return string The Event Object-Type.
|
||||
*/
|
||||
protected function get_type() {
|
||||
|
||||
return 'Event';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the event location.
|
||||
*
|
||||
* @return array The Place.
|
||||
*/
|
||||
public function get_location() {
|
||||
|
||||
$address = $this->gp_venue['full_address'];
|
||||
$place = new Place();
|
||||
$place->set_type( 'Place' );
|
||||
$place->set_name( $address );
|
||||
$place->set_address( $address );
|
||||
return $place;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the end time from the event object.
|
||||
*/
|
||||
protected function get_end_time() {
|
||||
|
||||
return $this->gp_event->get_datetime_end( 'Y-m-d\TH:i:s\Z' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the end time from the event object.
|
||||
*/
|
||||
protected function get_start_time() {
|
||||
|
||||
return $this->gp_event->get_datetime_start( 'Y-m-d\TH:i:s\Z' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the event link from the events metadata.
|
||||
*/
|
||||
private function get_event_link() {
|
||||
|
||||
$event_link = get_post_meta( $this->wp_object->ID, 'event-link', true );
|
||||
if ( $event_link ) {
|
||||
return array(
|
||||
'type' => 'Link',
|
||||
'name' => 'Website',
|
||||
'href' => \esc_url( $event_link ),
|
||||
'mediaType' => 'text/html',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides/extends the get_attachments function to also add the event Link.
|
||||
*/
|
||||
protected function get_attachment() {
|
||||
|
||||
$attachments = parent::get_attachment();
|
||||
if ( count( $attachments ) ) {
|
||||
$attachments[0]['type'] = 'Document';
|
||||
$attachments[0]['name'] = 'Banner';
|
||||
}
|
||||
$event_link = $this->get_event_link();
|
||||
if ( $event_link ) {
|
||||
$attachments[] = $this->get_event_link();
|
||||
}
|
||||
return $attachments;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO:
|
||||
*
|
||||
* @return string $category
|
||||
*/
|
||||
protected function get_category() {
|
||||
|
||||
return 'MEETING';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the User-URL of the Author of the Post.
|
||||
*
|
||||
* If `single_user` mode is enabled, the URL of the Blog-User is returned.
|
||||
*
|
||||
* @return string The User-URL.
|
||||
*/
|
||||
protected function get_attributed_to() {
|
||||
|
||||
$user = new Blog_User();
|
||||
return $user->get_url();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a custom summary.
|
||||
*
|
||||
* It contains also the most important meta-information. The summary is often used when the
|
||||
* ActivityPub object type 'Event' is not supported, e.g. in Mastodon.
|
||||
*
|
||||
* @return string $summary The custom event summary.
|
||||
*/
|
||||
public function get_summary() {
|
||||
|
||||
if ( $this->wp_object->excerpt ) {
|
||||
$excerpt = $this->wp_object->post_excerpt;
|
||||
} elseif ( get_post_meta( $this->wp_object->ID, 'event-summary', true ) ) {
|
||||
$excerpt = get_post_meta( $this->wp_object->ID, 'event-summary', true );
|
||||
} else {
|
||||
$excerpt = $this->get_content();
|
||||
}
|
||||
|
||||
$address = get_post_meta( $this->wp_object->ID, 'event-location', true );
|
||||
$start_time = get_post_meta( $this->wp_object->ID, 'event-start-date', true );
|
||||
$datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
|
||||
$start_time_string = wp_date( $datetime_format, $start_time );
|
||||
$summary = "📍 {$address}\n📅 {$start_time_string}\n\n{$excerpt}";
|
||||
return $summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform the WordPress Object into an ActivityPub Object.
|
||||
*
|
||||
* @return Activitypub\Activity\Event
|
||||
*/
|
||||
public function to_object() {
|
||||
|
||||
$this->ap_object = new Event();
|
||||
$this->gp_event = new GatherPress_Event( $this->wp_object->ID );
|
||||
$this->gp_venue = $this->gp_event->get_venue_information();
|
||||
|
||||
$this->ap_object = parent::to_object();
|
||||
|
||||
$this->ap_object->set_comments_enabled( 'open' === $this->wp_object->comment_status ? true : false );
|
||||
|
||||
$this->ap_object->set_external_participation_url( $this->get_url() );
|
||||
|
||||
$online_event_link = $this->gp_event->maybe_get_online_event_link();
|
||||
|
||||
if ( $online_event_link ) {
|
||||
$this->ap_object->set_is_online( true );
|
||||
} else {
|
||||
$this->ap_object->set_is_online( false );
|
||||
}
|
||||
|
||||
$this->ap_object->set_status( 'CONFIRMED' );
|
||||
|
||||
$this->ap_object->set_name( get_the_title( $this->wp_object->ID ) );
|
||||
|
||||
$this->ap_object->set_actor( get_rest_url_by_path( 'application' ) );
|
||||
$this->ap_object->set_to( array( 'https://www.w3.org/ns/activitystreams#Public' ) );
|
||||
|
||||
$this->ap_object->set_location();
|
||||
return $this->ap_object;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* ActivityPub Tribe Transformer
|
||||
*
|
||||
|
@ -20,6 +21,7 @@ use Activitypub\Activity\Extended_Object\Place;
|
|||
* @since 1.0.0
|
||||
*/
|
||||
class Tribe extends Post {
|
||||
|
||||
/**
|
||||
* The Tribe Event object.
|
||||
*
|
||||
|
@ -28,14 +30,14 @@ class Tribe extends 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
|
||||
// */
|
||||
// * 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 );
|
||||
// parent::set_wp_post( $wp_post );
|
||||
// $this->tribe_event = tribe_get_event( $wp_post->ID );
|
||||
// }
|
||||
|
||||
/**
|
||||
|
@ -48,6 +50,7 @@ class Tribe extends Post {
|
|||
* @return string Widget name.
|
||||
*/
|
||||
public function get_name() {
|
||||
|
||||
return 'activitypub-event-transformers/tribe';
|
||||
}
|
||||
|
||||
|
@ -61,6 +64,7 @@ class Tribe extends Post {
|
|||
* @return string Widget title.
|
||||
*/
|
||||
public function get_label() {
|
||||
|
||||
return 'The Events Calendar';
|
||||
}
|
||||
|
||||
|
@ -72,6 +76,7 @@ class Tribe extends Post {
|
|||
* @return string The Event Object-Type.
|
||||
*/
|
||||
protected function get_object_type() {
|
||||
|
||||
return 'Event';
|
||||
}
|
||||
|
||||
|
@ -85,6 +90,7 @@ class Tribe extends Post {
|
|||
* @return array Widget categories.
|
||||
*/
|
||||
public static function get_supported_post_types() {
|
||||
|
||||
return array( 'tribe_events' );
|
||||
}
|
||||
|
||||
|
@ -112,6 +118,7 @@ class Tribe extends Post {
|
|||
* @return string status of the event
|
||||
*/
|
||||
public function get_tribe_status() {
|
||||
|
||||
if ( 'canceled' === $this->tribe_event->event_status ) {
|
||||
return 'CANCELLED';
|
||||
}
|
||||
|
@ -133,6 +140,7 @@ class Tribe extends Post {
|
|||
* @return string The content.
|
||||
*/
|
||||
protected function get_content() {
|
||||
|
||||
$content = parent::get_content();
|
||||
// todo remove link at the end of the content
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* ActivityPub Transformer for the plugin Very Simple Event List.
|
||||
*
|
||||
|
@ -23,8 +24,10 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
* @since 1.0.0
|
||||
*/
|
||||
class VS_Event extends Post {
|
||||
|
||||
/**
|
||||
* The target transformet ActivityPub Event object.
|
||||
*
|
||||
* @var Event
|
||||
*/
|
||||
protected $ap_object;
|
||||
|
@ -39,6 +42,7 @@ class VS_Event extends Post {
|
|||
* @return string Widget name.
|
||||
*/
|
||||
public function get_transformer_name() {
|
||||
|
||||
return 'activitypub-event-transformers/vs-event';
|
||||
}
|
||||
|
||||
|
@ -52,6 +56,7 @@ class VS_Event extends Post {
|
|||
* @return string Widget title.
|
||||
*/
|
||||
public function get_transformer_label() {
|
||||
|
||||
return 'VS Event';
|
||||
}
|
||||
|
||||
|
@ -65,6 +70,7 @@ class VS_Event extends Post {
|
|||
* @return array Widget categories.
|
||||
*/
|
||||
public static function get_supported_post_types() {
|
||||
|
||||
return array( 'event' );
|
||||
}
|
||||
|
||||
|
@ -76,6 +82,7 @@ class VS_Event extends Post {
|
|||
* @return string The Event Object-Type.
|
||||
*/
|
||||
protected function get_type() {
|
||||
|
||||
return 'Event';
|
||||
}
|
||||
|
||||
|
@ -86,8 +93,9 @@ class VS_Event extends Post {
|
|||
* @return array The Place.
|
||||
*/
|
||||
public function get_location() {
|
||||
|
||||
$address = get_post_meta( $this->wp_object->ID, 'event-location', true );
|
||||
$place = new Place();
|
||||
$place = new Place();
|
||||
$place->set_type( 'Place' );
|
||||
$place->set_name( $address );
|
||||
$place->set_address( $address );
|
||||
|
@ -98,6 +106,7 @@ class VS_Event extends Post {
|
|||
* Get the end time from the events metadata.
|
||||
*/
|
||||
protected function get_end_time() {
|
||||
|
||||
$end_time = get_post_meta( $this->wp_object->ID, 'event-date', true );
|
||||
return \gmdate( 'Y-m-d\TH:i:s\Z', $end_time );
|
||||
}
|
||||
|
@ -106,6 +115,7 @@ class VS_Event extends Post {
|
|||
* Get the end time from the events metadata.
|
||||
*/
|
||||
protected function get_start_time() {
|
||||
|
||||
$start_time = get_post_meta( $this->wp_object->ID, 'event-start-date', true );
|
||||
return \gmdate( 'Y-m-d\TH:i:s\Z', $start_time );
|
||||
}
|
||||
|
@ -114,12 +124,13 @@ class VS_Event extends Post {
|
|||
* Get the event link from the events metadata.
|
||||
*/
|
||||
private function get_event_link() {
|
||||
|
||||
$event_link = get_post_meta( $this->wp_object->ID, 'event-link', true );
|
||||
if ( $event_link ) {
|
||||
return array(
|
||||
'type' => 'Link',
|
||||
'name' => 'Website',
|
||||
'href' => \esc_url( $event_link ),
|
||||
'type' => 'Link',
|
||||
'name' => 'Website',
|
||||
'href' => \esc_url( $event_link ),
|
||||
'mediaType' => 'text/html',
|
||||
);
|
||||
}
|
||||
|
@ -129,6 +140,7 @@ class VS_Event extends Post {
|
|||
* Overrides/extends the get_attachments function to also add the event Link.
|
||||
*/
|
||||
protected function get_attachment() {
|
||||
|
||||
$attachments = parent::get_attachment();
|
||||
if ( count( $attachments ) ) {
|
||||
$attachments[0]['type'] = 'Document';
|
||||
|
@ -147,6 +159,7 @@ class VS_Event extends Post {
|
|||
* @return string $category
|
||||
*/
|
||||
protected function get_category() {
|
||||
|
||||
$post_categories = wp_get_post_terms( $this->wp_object->ID, 'event_cat' );
|
||||
|
||||
if ( empty( $post_categories ) ) {
|
||||
|
@ -168,7 +181,7 @@ class VS_Event extends Post {
|
|||
|
||||
// Initialize variables to track the best match.
|
||||
$best_mobilizon_category_match = '';
|
||||
$best_match_length = 0;
|
||||
$best_match_length = 0;
|
||||
|
||||
// Check for the best match.
|
||||
foreach ( $mobilizon_categories as $mobilizon_category ) {
|
||||
|
@ -179,7 +192,7 @@ class VS_Event extends Post {
|
|||
$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;
|
||||
$best_match_length = $current_match_legnth;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -191,12 +204,13 @@ class VS_Event extends Post {
|
|||
|
||||
/**
|
||||
* Returns the User-URL of the Author of the Post.
|
||||
*
|
||||
* If `single_user` mode is enabled, the URL of the Blog-User is returned.
|
||||
*
|
||||
* If `single_user` mode is enabled, the URL of the Blog-User is returned.
|
||||
*
|
||||
* @return string The User-URL.
|
||||
*/
|
||||
protected function get_attributed_to() {
|
||||
|
||||
$user = new Blog_User();
|
||||
return $user->get_url();
|
||||
}
|
||||
|
@ -210,6 +224,7 @@ class VS_Event extends Post {
|
|||
* @return string $summary The custom event summary.
|
||||
*/
|
||||
public function get_summary() {
|
||||
|
||||
if ( $this->wp_object->excerpt ) {
|
||||
$excerpt = $this->wp_object->post_excerpt;
|
||||
} elseif ( get_post_meta( $this->wp_object->ID, 'event-summary', true ) ) {
|
||||
|
@ -218,15 +233,14 @@ class VS_Event extends Post {
|
|||
$excerpt = $this->get_content();
|
||||
}
|
||||
|
||||
$address = get_post_meta( $this->wp_object->ID, 'event-location', true );
|
||||
$start_time = get_post_meta( $this->wp_object->ID, 'event-start-date', true );
|
||||
$datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
|
||||
$address = get_post_meta( $this->wp_object->ID, 'event-location', true );
|
||||
$start_time = get_post_meta( $this->wp_object->ID, 'event-start-date', true );
|
||||
$datetime_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
|
||||
$start_time_string = wp_date( $datetime_format, $start_time );
|
||||
$summary = "📍 {$address}\n📅 {$start_time_string}\n\n{$excerpt}";
|
||||
$summary = "📍 {$address}\n📅 {$start_time_string}\n\n{$excerpt}";
|
||||
return $summary;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generic setter.
|
||||
*
|
||||
|
@ -236,6 +250,7 @@ class VS_Event extends Post {
|
|||
* @return mixed The value.
|
||||
*/
|
||||
public function set( $key, $value ) {
|
||||
|
||||
if ( ! $this->ap_object->has( $key ) ) {
|
||||
return new WP_Error( 'invalid_key', __( 'Invalid key', 'activitypub' ), array( 'status' => 404 ) );
|
||||
}
|
||||
|
@ -261,6 +276,7 @@ class VS_Event extends Post {
|
|||
* @return void
|
||||
*/
|
||||
public function __call( $method, $params ) {
|
||||
|
||||
$var = \strtolower( \substr( $method, 4 ) );
|
||||
|
||||
if ( \strncasecmp( $method, 'set', 3 ) === 0 ) {
|
||||
|
@ -278,10 +294,11 @@ class VS_Event extends Post {
|
|||
* @return Activitypub\Activity\Event
|
||||
*/
|
||||
public function to_object() {
|
||||
|
||||
$this->ap_object = new Event();
|
||||
|
||||
$this
|
||||
->set_content()
|
||||
->set_content()
|
||||
->set_content_map()
|
||||
->set_attributed_to()
|
||||
->set_published()
|
||||
|
@ -289,10 +306,10 @@ class VS_Event extends Post {
|
|||
->set_end_time()
|
||||
->set_type()
|
||||
->set_category()
|
||||
->set_attachment()
|
||||
->set_comments_enabled( true )
|
||||
->set_attachment()
|
||||
->set_comments_enabled( true )
|
||||
->set_external_participation_url( $this->get_url() )
|
||||
->set_status( 'CONFIRMED' )
|
||||
->set_status( 'CONFIRMED' )
|
||||
->set_name( get_the_title( $this->wp_object->ID ) )
|
||||
->set_is_online( false )
|
||||
->set_in_language( $this->get_locale() )
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Mapping of WordPress Terms(Tags) to known Event Categories
|
||||
*
|
||||
|
@ -18,10 +19,12 @@ use Activitypub\Activity\Extended_Object\Event;
|
|||
* @since 1.0.0
|
||||
*/
|
||||
class Category_Mapper {
|
||||
|
||||
/**
|
||||
* Static function to do the Mapping
|
||||
**/
|
||||
public static function map( $post_categories ) {
|
||||
* Static function to do the Mapping
|
||||
**/
|
||||
public static function map( $post_categories ) {
|
||||
|
||||
if ( empty( $post_categories ) ) {
|
||||
return 'MEETING';
|
||||
}
|
||||
|
@ -41,7 +44,7 @@ class Category_Mapper {
|
|||
|
||||
// Initialize variables to track the best match.
|
||||
$best_mobilizon_category_match = '';
|
||||
$best_match_length = 0;
|
||||
$best_match_length = 0;
|
||||
|
||||
// Check for the best match.
|
||||
foreach ( $mobilizon_categories as $mobilizon_category ) {
|
||||
|
@ -52,7 +55,7 @@ class Category_Mapper {
|
|||
$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;
|
||||
$best_match_length = $current_match_legnth;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -60,5 +63,5 @@ class Category_Mapper {
|
|||
}
|
||||
|
||||
return ( '' != $best_mobilizon_category_match ) ? strtoupper( $best_mobilizon_category_match ) : 'MEETING';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue