prefix files with class
Some checks failed
Deploy to https://wordpress-test.event-federation.eu/ / deploy (push) Failing after 6s
Some checks failed
Deploy to https://wordpress-test.event-federation.eu/ / deploy (push) Failing after 6s
add new activitypub event object
This commit is contained in:
parent
dcfb4462f1
commit
8db7742ee8
4 changed files with 93 additions and 20 deletions
|
@ -9,6 +9,8 @@
|
|||
* Text Domain: activitypub-event-transformers
|
||||
*
|
||||
* ActivityPub tested up to: 1.2.0
|
||||
*
|
||||
* @package activitypub-event-transformer
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
|
@ -25,19 +27,24 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
* @return void
|
||||
*/
|
||||
function register_event_transformers( $transformers_manager ) {
|
||||
// if ( ! function_exists( 'is_plugin_active' ) ) {
|
||||
// require_once __DIR__ . '/wp-admin/includes/plugin.php';
|
||||
// }
|
||||
require_once __DIR__ . '/activitypub/transformer/class-tribe.php';
|
||||
$transformers_manager->register( new \Tribe() );
|
||||
|
||||
// if ( is_plugin_active( 'the-events-calendar/the-events-calendar.php' ) ) {
|
||||
// require_once __DIR__ . '/activitypub/transformer/tribe.php';
|
||||
// $transformers_manager->register( new \Tribe() );
|
||||
// }
|
||||
|
||||
// if ( is_plugin_active( 'vsel/vsel.php' ) ) {
|
||||
require_once __DIR__ . '/activitypub/transformer/vs-event.php';
|
||||
$transformers_manager->register( new \VS_Event() );
|
||||
// }
|
||||
require_once __DIR__ . '/activitypub/transformer/class-vs-event.php';
|
||||
$transformers_manager->register( new \VS_Event() );
|
||||
}
|
||||
|
||||
add_filter(
|
||||
'activitypub_json_context',
|
||||
function ( $context ) {
|
||||
$context[2]['commentsEnabled'] = array(
|
||||
'@id' => 'pt:commentsEnabled',
|
||||
'@type' => 'sc:Boolean',
|
||||
);
|
||||
return $context;
|
||||
},
|
||||
10,
|
||||
2
|
||||
);
|
||||
|
||||
add_action( 'activitypub_transformers_register', 'register_event_transformers' );
|
||||
|
|
38
activitypub/object/class-event.php
Normal file
38
activitypub/object/class-event.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
/**
|
||||
* Event is an implementation of one of the
|
||||
* Activity Streams Event object type
|
||||
*
|
||||
* @package activity-event-transformers
|
||||
*/
|
||||
|
||||
/**
|
||||
* Event is an implementation of one of the
|
||||
* Activity Streams Event object type
|
||||
*
|
||||
* The Object is the primary base type for the Activity Streams
|
||||
* vocabulary.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-event
|
||||
*/
|
||||
class Event extends \Activitypub\Activity\Base_Object {
|
||||
/**
|
||||
* Event is an implementation of one of the
|
||||
* Activity Streams
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $type = 'Event';
|
||||
|
||||
/**
|
||||
* Extension invented by PeerTube whether comments/replies are <enabled>
|
||||
* Mobilizon also implemented this as a fallback to their own
|
||||
* repliesModerationOption.
|
||||
*
|
||||
* @see https://docs.joinpeertube.org/api/activitypub#video
|
||||
* @see https://docs.joinmobilizon.org/contribute/activity_pub/
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $comments_enabled;
|
||||
}
|
|
@ -1,4 +1,10 @@
|
|||
<?php
|
||||
/**
|
||||
* ActivityPub Tribe Transformer
|
||||
*
|
||||
* @package activity-event-transformers
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
@ -57,7 +63,6 @@ class Tribe extends \Activitypub\Transformer\Base {
|
|||
* @return array Widget categories.
|
||||
*/
|
||||
public function get_supported_post_types() {
|
||||
return [ 'tribe_events' ];
|
||||
return array( 'tribe_events' );
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,12 @@
|
|||
<?php
|
||||
/**
|
||||
* ActivityPub Transformer for VS Event.
|
||||
*
|
||||
* @package activity-event-transformers
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../object/class-event.php';
|
||||
|
||||
use Activitypub\Activity\Base_Object;
|
||||
use function Activitypub\get_rest_url_by_path;
|
||||
|
||||
|
@ -7,12 +15,11 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
}
|
||||
|
||||
/**
|
||||
* ActivityPub Tribe Transformer
|
||||
* ActivityPub Transformer for VS Event
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class VS_Event extends \Activitypub\Transformer\Base {
|
||||
|
||||
/**
|
||||
* Get widget name.
|
||||
*
|
||||
|
@ -60,11 +67,14 @@ class VS_Event extends \Activitypub\Transformer\Base {
|
|||
* @return array Widget categories.
|
||||
*/
|
||||
public function get_supported_post_types() {
|
||||
return [ 'event' ];
|
||||
return array( 'event' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the event location
|
||||
* Get the event location.
|
||||
*
|
||||
* @param int $post_id The WordPress post ID.
|
||||
* @returns array The Place.
|
||||
*/
|
||||
public function get_event_location( $post_id ) {
|
||||
$object = new Base_Object();
|
||||
|
@ -74,6 +84,17 @@ class VS_Event extends \Activitypub\Transformer\Base {
|
|||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test
|
||||
*
|
||||
* @param string $context context.
|
||||
* @return string $context context.
|
||||
*/
|
||||
private function add_pt_comments_enabled_context( $context ) {
|
||||
$test = $context;
|
||||
return $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the VS Event WP_Post object to an ActivityPub Event Object
|
||||
*
|
||||
|
@ -83,7 +104,7 @@ class VS_Event extends \Activitypub\Transformer\Base {
|
|||
*/
|
||||
public function to_object() {
|
||||
$wp_post = $this->wp_post;
|
||||
$object = new Base_Object();
|
||||
$object = new Event();
|
||||
|
||||
$object->set_id( $this->get_id() );
|
||||
$object->set_url( $this->get_url() );
|
||||
|
@ -121,6 +142,9 @@ class VS_Event extends \Activitypub\Transformer\Base {
|
|||
$location = get_post_meta( $wp_post->ID, 'event-link', true );
|
||||
$object->set_location( $this->get_event_location( $wp_post->ID ) );
|
||||
|
||||
$is_open_for_comments = comments_open( $wp_post->ID );
|
||||
$object->set_comments_enabled( $is_open_for_comments );
|
||||
|
||||
$object->set_to(
|
||||
array(
|
||||
'https://www.w3.org/ns/activitystreams#Public',
|
||||
|
@ -136,5 +160,4 @@ class VS_Event extends \Activitypub\Transformer\Base {
|
|||
|
||||
return $object;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue