wip: wp event manager
All checks were successful
All checks were successful
This commit is contained in:
parent
0fba291706
commit
8069f747b4
7 changed files with 197 additions and 4 deletions
|
@ -11,7 +11,6 @@ namespace ActivityPub_Event_Bridge\Activitypub\Transformer;
|
||||||
// Exit if accessed directly.
|
// Exit if accessed directly.
|
||||||
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||||
|
|
||||||
use Activitypub\Activity\Extended_Object\Event;
|
|
||||||
use Activitypub\Activity\Extended_Object\Place;
|
use Activitypub\Activity\Extended_Object\Place;
|
||||||
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event as Event_Transformer;
|
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event as Event_Transformer;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
|
|
@ -13,7 +13,6 @@ defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||||
|
|
||||||
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 Activitypub\Model\Blog;
|
|
||||||
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event;
|
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event;
|
||||||
use GatherPress\Core\Event as GatherPress_Event;
|
use GatherPress\Core\Event as GatherPress_Event;
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ namespace ActivityPub_Event_Bridge\Activitypub\Transformer;
|
||||||
// Exit if accessed directly.
|
// Exit if accessed directly.
|
||||||
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||||
|
|
||||||
use Activitypub\Activity\Extended_Object\Event as Event_Object;
|
|
||||||
use Activitypub\Activity\Extended_Object\Place;
|
use Activitypub\Activity\Extended_Object\Place;
|
||||||
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event;
|
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event;
|
||||||
use WP_Post;
|
use WP_Post;
|
||||||
|
|
|
@ -11,7 +11,6 @@ namespace ActivityPub_Event_Bridge\Activitypub\Transformer;
|
||||||
// Exit if accessed directly.
|
// Exit if accessed directly.
|
||||||
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||||
|
|
||||||
use Activitypub\Activity\Extended_Object\Event;
|
|
||||||
use Activitypub\Activity\Extended_Object\Place;
|
use Activitypub\Activity\Extended_Object\Place;
|
||||||
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event as Event_Transformer;
|
use ActivityPub_Event_Bridge\Activitypub\Transformer\Event as Event_Transformer;
|
||||||
|
|
||||||
|
|
124
includes/activitypub/transformer/class-wp-event-manager.php
Normal file
124
includes/activitypub/transformer/class-wp-event-manager.php
Normal file
|
@ -0,0 +1,124 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* ActivityPub Transformer for the plugin Very Simple Event List.
|
||||||
|
*
|
||||||
|
* @package ActivityPub_Event_Bridge
|
||||||
|
* @license AGPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace ActivityPub_Event_Bridge\Activitypub\Transformer;
|
||||||
|
|
||||||
|
// 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 DateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ActivityPub Transformer for events from the WordPress plugin 'Events Manager'
|
||||||
|
*
|
||||||
|
* @see https://wordpress.org/plugins/events-manager/
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
final class WP_Event_Manager extends Event_Transformer {
|
||||||
|
/**
|
||||||
|
* Returns whether the even is online
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function get_is_online() {
|
||||||
|
$is_online_text = get_post_meta( $this->wp_object->ID, '_event_online', true );
|
||||||
|
$is_online = false;
|
||||||
|
// Radio buttons.
|
||||||
|
if ( 'yes' === $is_online_text ) {
|
||||||
|
$is_online = true;
|
||||||
|
}
|
||||||
|
// Checkbox.
|
||||||
|
if ( '1' === $is_online_text ) {
|
||||||
|
$is_online = true;
|
||||||
|
}
|
||||||
|
return $is_online;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the event location.
|
||||||
|
*
|
||||||
|
* @return array The Place.
|
||||||
|
*/
|
||||||
|
public function get_location(): ?Place {
|
||||||
|
$location = new Place();
|
||||||
|
$location_name = get_post_meta( $this->wp_object->ID, '_event_online', true );
|
||||||
|
$location->set_name( $location_name );
|
||||||
|
$location->set_sensitive( null );
|
||||||
|
$location->set_address( $location_name );
|
||||||
|
return $location;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the end time from the events metadata.
|
||||||
|
*/
|
||||||
|
public function get_end_time(): ?string {
|
||||||
|
$end_date = get_post_meta( $this->wp_object->ID, '_event_end_date', true );
|
||||||
|
$end_datetime = new DateTime( $end_date );
|
||||||
|
return \gmdate( 'Y-m-d\TH:i:s\Z', $end_datetime->getTimestamp() );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the end time from the events metadata.
|
||||||
|
*/
|
||||||
|
public function get_start_time(): string {
|
||||||
|
$start_date = get_post_meta( $this->wp_object->ID, '_event_start_date', true );
|
||||||
|
$start_datetime = new DateTime( $start_date );
|
||||||
|
return \gmdate( 'Y-m-d\TH:i:s\Z', $start_datetime->getTimestamp() );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the event link as an ActivityPub Link object, but as an associative array.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function get_event_link_attachment(): array {
|
||||||
|
$event_link_url = get_post_meta( $this->wp_object->ID, '_event_video_url', true );
|
||||||
|
|
||||||
|
if ( str_starts_with( $event_link_url, 'http' ) ) {
|
||||||
|
return array(
|
||||||
|
'type' => 'Link',
|
||||||
|
'name' => 'Video URL',
|
||||||
|
'href' => \esc_url( $event_link_url ),
|
||||||
|
'mediaType' => 'text/html',
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overrides/extends the get_attachments function to also add the event Link.
|
||||||
|
*/
|
||||||
|
protected function get_attachment() {
|
||||||
|
// Get attachments via parent function.
|
||||||
|
$attachments = parent::get_attachment();
|
||||||
|
|
||||||
|
// The first attachment is the featured image, make sure it is compatible with Mobilizon.
|
||||||
|
if ( count( $attachments ) ) {
|
||||||
|
$attachments[0]['type'] = 'Document';
|
||||||
|
$attachments[0]['name'] = 'Banner';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $this->get_event_link_attachment() ) {
|
||||||
|
$attachments[] = $this->get_event_link_attachment();
|
||||||
|
}
|
||||||
|
return $attachments;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the events title/name.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function get_name(): string {
|
||||||
|
return $this->wp_object->post_title;
|
||||||
|
}
|
||||||
|
}
|
|
@ -128,6 +128,7 @@ class Setup {
|
||||||
'\ActivityPub_Event_Bridge\Plugins\GatherPress',
|
'\ActivityPub_Event_Bridge\Plugins\GatherPress',
|
||||||
'\ActivityPub_Event_Bridge\Plugins\The_Events_Calendar',
|
'\ActivityPub_Event_Bridge\Plugins\The_Events_Calendar',
|
||||||
'\ActivityPub_Event_Bridge\Plugins\VS_Event_List',
|
'\ActivityPub_Event_Bridge\Plugins\VS_Event_List',
|
||||||
|
'\ActivityPub_Event_Bridge\Plugins\WP_Event_Manager',
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
72
includes/plugins/class-wp-event-manager.php
Normal file
72
includes/plugins/class-wp-event-manager.php
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* WP Event Manager.
|
||||||
|
*
|
||||||
|
* Defines all the necessary meta information for the WordPress event plugin
|
||||||
|
* "WP Event Manager"
|
||||||
|
*
|
||||||
|
* @link https://de.wordpress.org/plugins/wp-event-manager
|
||||||
|
* @package ActivityPub_Event_Bridge
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace ActivityPub_Event_Bridge\Plugins;
|
||||||
|
|
||||||
|
use ActivityPub_Event_Bridge\Plugins\Event_Plugin;
|
||||||
|
|
||||||
|
// Exit if accessed directly.
|
||||||
|
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for a supported event plugin.
|
||||||
|
*
|
||||||
|
* This interface defines which information is necessary for a supported event plugin.
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
final class WP_Event_Manager extends Event_Plugin {
|
||||||
|
/**
|
||||||
|
* Returns the full plugin file.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_plugin_file(): string {
|
||||||
|
return 'wp-event-manager/wp-event-manager.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the event post type of the plugin.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_post_type(): string {
|
||||||
|
return 'event_listing';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ID of the main settings page of the plugin.
|
||||||
|
*
|
||||||
|
* @return string The settings page url.
|
||||||
|
*/
|
||||||
|
public static function get_settings_page(): string {
|
||||||
|
return 'event-manager-settings';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ActivityPub transformer class.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_activitypub_transformer_class_name(): string {
|
||||||
|
return 'WP_Event_Manager';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the taxonomy used for the plugin's event categories.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function get_event_category_taxonomy(): string {
|
||||||
|
return 'event_listing_category';
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue