diff --git a/composer.json b/composer.json
index 06122c9..2c96db8 100644
--- a/composer.json
+++ b/composer.json
@@ -61,7 +61,7 @@
],
"test-debug": [
"@prepare-test",
- "@test-gatherpress"
+ "@test-vs-event-list"
],
"test-vs-event-list": "phpunit --filter=vs_event_list",
"test-the-events-calendar": "phpunit --filter=the_events_calendar",
diff --git a/includes/activitypub/collection/class-event-sources.php b/includes/activitypub/collection/class-event-sources.php
index 3dc412e..208fb81 100644
--- a/includes/activitypub/collection/class-event-sources.php
+++ b/includes/activitypub/collection/class-event-sources.php
@@ -53,7 +53,6 @@ class Event_Sources {
*/
public static function init() {
self::register_post_type();
- \add_filter( 'allowed_redirect_hosts', array( self::class, 'add_event_sources_hosts_to_allowed_redirect_hosts' ) );
\add_action( 'event_bridge_for_activitypub_follow', array( self::class, 'activitypub_follow_actor' ), 10, 1 );
\add_action( 'event_bridge_for_activitypub_unfollow', array( self::class, 'activitypub_unfollow_actor' ), 10, 1 );
}
diff --git a/includes/activitypub/model/class-event-source.php b/includes/activitypub/model/class-event-source.php
index df9d882..7344be9 100644
--- a/includes/activitypub/model/class-event-source.php
+++ b/includes/activitypub/model/class-event-source.php
@@ -54,6 +54,13 @@ class Event_Source extends Actor {
return $icon;
}
+ /**
+ * Return the Post-IDs of all events cached by this event source.
+ */
+ public static function get_cached_events(): array {
+ return array();
+ }
+
/**
* Get the WordPress post which stores the Event Source by the ActivityPub actor id of the event source.
*
diff --git a/includes/activitypub/transmogrifier/class-gatherpress.php b/includes/activitypub/transmogrifier/class-gatherpress.php
index 7567373..7da7305 100644
--- a/includes/activitypub/transmogrifier/class-gatherpress.php
+++ b/includes/activitypub/transmogrifier/class-gatherpress.php
@@ -12,6 +12,7 @@
namespace Event_Bridge_For_ActivityPub\ActivityPub\Transmogrifier;
use DateTime;
+use Event_Bridge_For_ActivityPub\Integrations\GatherPress as IntegrationsGatherPress;
use function Activitypub\sanitize_url;
@@ -51,7 +52,7 @@ class GatherPress extends Base {
// Add the tags as terms to the post.
if ( ! empty( $tag_names ) ) {
- wp_set_object_terms( $post_id, $tag_names, 'gatherpress_topic', true );
+ wp_set_object_terms( $post_id, $tag_names, IntegrationsGatherPress::get_event_category_taxonomy(), true );
}
return true;
diff --git a/includes/activitypub/transmogrifier/class-vs-event-list.php b/includes/activitypub/transmogrifier/class-vs-event-list.php
index f1731d5..e34c2e1 100644
--- a/includes/activitypub/transmogrifier/class-vs-event-list.php
+++ b/includes/activitypub/transmogrifier/class-vs-event-list.php
@@ -12,6 +12,8 @@
namespace Event_Bridge_For_ActivityPub\ActivityPub\Transmogrifier;
+use Event_Bridge_For_ActivityPub\Integrations\VS_Event_List as IntegrationsVS_Event_List;
+
use function Activitypub\sanitize_url;
// Exit if accessed directly.
@@ -27,94 +29,67 @@ defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
*/
class VS_Event_List extends Base {
/**
- * Get a list of Post IDs of events that have ended.
+ * Extract location and address as string.
*
- * @param int $cache_retention_period Additional time buffer in seconds.
- * @return ?array
+ * @param ?array $location The ActivitySTreams location as an associative array.
+ * @return string The location and address formatted as a single string.
*/
- public static function get_past_events( $cache_retention_period = 0 ): ?array {
- unset( $cache_retention_period );
+ private function get_location_as_string( $location ): string {
+ $location_string = '';
- $results = array();
+ // Return empty string when location is not an associative array.
+ if ( is_null( $location ) || ! is_array( $location ) ) {
+ return $location_string;
+ }
- return $results;
+ if ( ! isset( $location['type'] ) || 'Place' !== $location['type'] ) {
+ return $location_string;
+ }
+
+ // Add name of the location.
+ if ( isset( $location['name'] ) ) {
+ $location_string .= $location['name'];
+ }
+
+ // Add delimiter between name and address if both are set.
+ if ( isset( $location['name'] ) && isset( $location['address'] ) ) {
+ $location_string .= ' – ';
+ }
+
+ // Add address.
+ if ( isset( $location['address'] ) ) {
+ $location_string .= $this->address_to_string( $location['address'] );
+ }
+ return $location_string;
}
/**
- * Map an ActivityStreams Place to the Events Calendar venue.
+ * Add tags to post.
*
- * @param array $location An ActivityPub location as an associative array.
- * @link https://www.w3.org/TR/activitystreams-vocabulary/#dfn-place
- * @return array
+ * @param int $post_id The post ID.
*/
- private function get_venue_args( $location ) {
- $args = array(
- 'venue' => $location['name'],
- 'status' => 'publish',
- );
+ private function add_tags_to_post( $post_id ) {
+ $tags_array = $this->activitypub_event->get_tag();
- if ( is_array( $location['address'] ) && isset( $location['address']['type'] ) && 'PostalAddress' === $location['address']['type'] ) {
- $mapping = array(
- 'streetAddress' => 'address',
- 'postalCode' => 'zip',
- 'addressLocality' => 'city',
- 'addressState' => 'state',
- 'addressCountry' => 'country',
- 'url' => 'website',
- );
-
- foreach ( $mapping as $postal_address_key => $venue_key ) {
- if ( isset( $location['address'][ $postal_address_key ] ) ) {
- $args[ $venue_key ] = $location['address'][ $postal_address_key ];
- }
- }
- } elseif ( is_string( $location['address'] ) ) {
- // Use the address field for a solely text address.
- $args['address'] = $location['address'];
+ // Ensure the input is valid.
+ if ( empty( $tags_array ) || ! is_array( $tags_array ) || ! $post_id ) {
+ return false;
}
- return $args;
- }
-
- /**
- * Add venue.
- *
- * @return int|bool $post_id The venues post ID.
- */
- private function add_venue() {
- $location = $this->activitypub_event->get_location();
-
- if ( ! $location ) {
- return;
- }
-
- if ( ! isset( $location['name'] ) ) {
- return;
- }
-
- // Fallback for Gancio instances.
- if ( 'online' === $location['name'] ) {
- return;
- }
-
- $post_ids = tribe_events()->search( $location['name'] )->all();
-
- $post_id = false;
-
- if ( count( $post_ids ) ) {
- $post_id = reset( $post_ids );
- }
-
- if ( $post_id && get_post_meta( $post_id, '_event_bridge_for_activitypub_is_remote_cached', true ) ) {
- tribe_venues()->where( 'id', $post_id )->set_args( $this->get_venue_args( $location ) )->save()[0];
- } else {
- $post = tribe_venues()->set_args( $this->get_venue_args( $location ) )->create();
- if ( $post ) {
- $post_id = $post->ID;
+ // Extract and process tag names.
+ $tag_names = array();
+ foreach ( $tags_array as $tag ) {
+ if ( isset( $tag['name'] ) && 'Hashtag' === $tag['type'] ) {
+ $tag_names[] = ltrim( $tag['name'], '#' ); // Remove the '#' from the name.
}
}
- return $post_id;
+ // Add the tags as terms to the post.
+ if ( ! empty( $tag_names ) ) {
+ wp_set_object_terms( $post_id, $tag_names, IntegrationsVS_Event_List::get_event_category_taxonomy(), true );
+ }
+
+ return true;
}
/**
@@ -124,59 +99,62 @@ class VS_Event_List extends Base {
*/
public function save_event() {
// Limit this as a safety measure.
- add_filter( 'wp_revisions_to_keep', array( self::class, 'revisions_to_keep' ) );
+ \add_filter( 'wp_revisions_to_keep', array( self::class, 'revisions_to_keep' ) );
$post_id = $this->get_post_id_from_activitypub_id();
- $duration = $this->get_duration();
-
- $venue_id = $this->add_venue();
-
$args = array(
- 'title' => sanitize_text_field( $this->activitypub_event->get_name() ),
- 'content' => wp_kses_post( $this->activitypub_event->get_content() ),
- 'start_date' => gmdate( 'Y-m-d H:i:s', strtotime( $this->activitypub_event->get_start_time() ) ),
- 'duration' => $duration,
- 'status' => 'publish',
- 'guid' => sanitize_url( $this->activitypub_event->get_id() ),
+ 'post_title' => \sanitize_text_field( $this->activitypub_event->get_name() ),
+ 'post_type' => \Event_Bridge_For_ActivityPub\Integrations\VS_Event_List::get_post_type(),
+ 'post_content' => \wp_kses_post( $this->activitypub_event->get_content() ?? '' ),
+ 'post_excerpt' => \wp_kses_post( $this->activitypub_event->get_summary() ?? '' ),
+ 'post_status' => 'publish',
+ 'guid' => \sanitize_url( $this->activitypub_event->get_id() ),
+ 'meta_input' => array(
+ 'event-start-date' => \strtotime( $this->activitypub_event->get_start_time() ),
+ 'event-link' => \sanitize_url( $this->activitypub_event->get_url() ),
+ 'event-link-label' => \sanitize_text_field( __( 'Original Website', 'event-bridge-for-activitypub' ) ),
+ 'event-link-target' => 'yes', // Open in new window.
+ 'event-link-title' => 'no', // Whether to redirect event title to original source.
+ 'event-link-image' => 'no', // Whether to redirect events featured image to original source.
+ ),
);
- if ( $venue_id ) {
- $args['venue'] = $venue_id;
- $args['VenueID'] = $venue_id;
+ // Add end time.
+ $end_time = $this->activitypub_event->get_end_time();
+ if ( $end_time ) {
+ $args['meta_input']['event-date'] = \strtotime( $end_time );
}
- $tribe_event = new The_Events_Calendar_Event_Repository();
+ // Maybe add location.
+ $location = $this->get_location_as_string( $this->activitypub_event->get_location() );
+ if ( $location ) {
+ $args['meta_input']['event-location'] = $location;
+ }
if ( $post_id ) {
- $args['post_title'] = $args['title'];
- $args['post_content'] = $args['content'];
- // Update existing GatherPress event post.
- $post = \Tribe__Events__API::updateEvent( $post_id, $args );
+ // Update existing event post.
+ $args['ID'] = $post_id;
+ $post_id = \wp_update_post( $args );
} else {
- $post = $tribe_event->set_args( $args )->create();
+ // Insert new event post.
+ $post_id = \wp_insert_post( $args );
}
- if ( ! $post ) {
+ if ( ! $post_id || \is_wp_error( $post_id ) ) {
return false;
}
+ // Insert featured image.
+ $image = $this->get_featured_image();
+ self::set_featured_image_with_alt( $post_id, $image['url'], $image['alt'] );
+
+ // Add hashtags.
+ $this->add_tags_to_post( $post_id );
+
// Limit this as a safety measure.
- remove_filter( 'wp_revisions_to_keep', array( self::class, 'revisions_to_keep' ) );
+ \remove_filter( 'wp_revisions_to_keep', array( self::class, 'revisions_to_keep' ) );
- return $post->ID;
- }
-
- /**
- * Get the events duration in seconds.
- *
- * @return int
- */
- private function get_duration() {
- $end_time = $this->activitypub_event->get_end_time();
- if ( ! $end_time ) {
- return 2 * HOUR_IN_SECONDS;
- }
- return abs( strtotime( $end_time ) - strtotime( $this->activitypub_event->get_start_time() ) );
+ return $post_id;
}
}
diff --git a/includes/class-event-sources.php b/includes/class-event-sources.php
index 06e5165..4d16531 100644
--- a/includes/class-event-sources.php
+++ b/includes/class-event-sources.php
@@ -36,6 +36,9 @@ class Event_Sources {
// Register the Event Sources Collection which takes care of managing the event sources.
\add_action( 'init', array( Event_Sources_Collection::class, 'init' ) );
+ // Allow wp_safe_redirect to all followed event sources hosts.
+ \add_filter( 'allowed_redirect_hosts', array( self::class, 'add_event_sources_hosts_to_allowed_redirect_hosts' ) );
+
// Register handlers for incoming activities to the ActivityPub plugin, e.g. incoming `Event` objects.
\add_action( 'activitypub_register_handlers', array( Handler::class, 'register_handlers' ) );
diff --git a/includes/class-settings.php b/includes/class-settings.php
index a9a91f8..224dac8 100644
--- a/includes/class-settings.php
+++ b/includes/class-settings.php
@@ -122,7 +122,7 @@ class Settings {
'event-bridge-for-activitypub',
'event_bridge_for_activitypub_integration_used_for_event_sources_feature',
array(
- 'type' => 'array',
+ 'type' => 'string',
'description' => \__( 'Define which plugin/integration is used for the event sources feature', 'event-bridge-for-activitypub' ),
'default' => array(),
'sanitize_callback' => array( self::class, 'sanitize_event_plugin_integration_used_for_event_sources' ),
diff --git a/includes/integrations/class-vs-event-list.php b/includes/integrations/class-vs-event-list.php
index beb56b4..f00b54c 100644
--- a/includes/integrations/class-vs-event-list.php
+++ b/includes/integrations/class-vs-event-list.php
@@ -13,6 +13,8 @@
namespace Event_Bridge_For_ActivityPub\Integrations;
use Event_Bridge_For_ActivityPub\ActivityPub\Transformer\VS_Event_List as VS_Event_List_Transformer;
+use Event_Bridge_For_ActivityPub\ActivityPub\Transmogrifier\VS_Event_List as VS_Event_List_Transmogrifier;
+use WP_Query;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
@@ -25,7 +27,7 @@ defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
*
* @since 1.0.0
*/
-final class VS_Event_List extends Event_Plugin_Integration {
+final class VS_Event_List extends Event_Plugin_Integration implements Feature_Event_Sources {
/**
* Returns the full plugin file.
*
@@ -71,4 +73,45 @@ final class VS_Event_List extends Event_Plugin_Integration {
public static function get_activitypub_event_transformer( $post ): VS_Event_List_Transformer {
return new VS_Event_List_Transformer( $post, self::get_event_category_taxonomy() );
}
+
+ /**
+ * Returns the Transmogrifier for The_Events_Calendar.
+ */
+ public static function get_transmogrifier(): VS_Event_List_Transmogrifier {
+ return new VS_Event_List_Transmogrifier();
+ }
+
+ /**
+ * Get a list of Post IDs of events that have ended.
+ *
+ * @param int $ends_before_time Filter to only get events that ended before that datetime as unix-time.
+ *
+ * @return array
⚠' . \wp_kses( $notice, General_Admin_Notices::ALLOWED_HTML ) . '
'; } - echo '⚠' . \wp_kses( $notice, General_Admin_Notices::ALLOWED_HTML ) . '
'; ?>