wip
Some checks failed
PHP Code Checker / PHP Code Checker (pull_request) Successful in 49s
PHPUnit / PHPUnit – PHP 7.4 (pull_request) Failing after 58s
PHPUnit / PHPUnit – PHP 8.0 (pull_request) Successful in 1m5s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m7s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m6s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 1m3s
PHPUnit / PHPUnit – PHP 8.4 (pull_request) Successful in 1m3s
Some checks failed
PHP Code Checker / PHP Code Checker (pull_request) Successful in 49s
PHPUnit / PHPUnit – PHP 7.4 (pull_request) Failing after 58s
PHPUnit / PHPUnit – PHP 8.0 (pull_request) Successful in 1m5s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m7s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m6s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 1m3s
PHPUnit / PHPUnit – PHP 8.4 (pull_request) Successful in 1m3s
This commit is contained in:
parent
ef1248beed
commit
16762b2b31
5 changed files with 62 additions and 7 deletions
|
@ -22,7 +22,15 @@ class Create {
|
||||||
public static function init() {
|
public static function init() {
|
||||||
\add_action(
|
\add_action(
|
||||||
'activitypub_inbox_create',
|
'activitypub_inbox_create',
|
||||||
array( self::class, 'handle_create' )
|
array( self::class, 'handle_create' ),
|
||||||
|
15,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
\add_filter(
|
||||||
|
'activitypub_validate_object',
|
||||||
|
array( self::class, 'validate_object' ),
|
||||||
|
12,
|
||||||
|
3
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +52,7 @@ class Create {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if an object is set.
|
// Check if an object is set.
|
||||||
if ( ! isset( $activity['object']['type'] ) || 'Event' !== isset( $activity['object']['type'] ) ) {
|
if ( ! isset( $activity['object']['type'] ) || 'Event' !== $activity['object']['type'] ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,4 +65,48 @@ class Create {
|
||||||
$transmogrifier = new $transmogrifier_class( $activity['object'] );
|
$transmogrifier = new $transmogrifier_class( $activity['object'] );
|
||||||
$transmogrifier->create();
|
$transmogrifier->create();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate the object.
|
||||||
|
*
|
||||||
|
* @param bool $valid The validation state.
|
||||||
|
* @param string $param The object parameter.
|
||||||
|
* @param \WP_REST_Request $request The request object.
|
||||||
|
*
|
||||||
|
* @return bool The validation state: true if valid, false if not.
|
||||||
|
*/
|
||||||
|
public static function validate_object( $valid, $param, $request ) {
|
||||||
|
$json_params = $request->get_json_params();
|
||||||
|
|
||||||
|
if ( isset( $json_params['object']['type'] ) && 'Event' === $json_params['object']['type'] ) {
|
||||||
|
$valid = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( empty( $json_params['type'] ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
'Create' !== $json_params['type'] ||
|
||||||
|
is_wp_error( $request )
|
||||||
|
) {
|
||||||
|
return $valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
$object = $json_params['object'];
|
||||||
|
|
||||||
|
if ( ! is_array( $object ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$required = array(
|
||||||
|
'id',
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( array_intersect( $required, array_keys( $object ) ) !== $required ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $valid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ class GatherPress {
|
||||||
/**
|
/**
|
||||||
* Save the ActivityPub event object as GatherPress Event.
|
* Save the ActivityPub event object as GatherPress Event.
|
||||||
*/
|
*/
|
||||||
public function save() {
|
public function create() {
|
||||||
// Insert new GatherPress Event post.
|
// Insert new GatherPress Event post.
|
||||||
$post_id = wp_insert_post(
|
$post_id = wp_insert_post(
|
||||||
array(
|
array(
|
||||||
|
|
|
@ -144,7 +144,8 @@ class Settings {
|
||||||
$valid_options = array();
|
$valid_options = array();
|
||||||
foreach ( $active_event_plugins as $active_event_plugin ) {
|
foreach ( $active_event_plugins as $active_event_plugin ) {
|
||||||
if ( $active_event_plugin->supports_event_sources() ) {
|
if ( $active_event_plugin->supports_event_sources() ) {
|
||||||
$valid_options[] = $active_event_plugin::class;
|
$full_class = $active_event_plugin::class;
|
||||||
|
$valid_options[] = substr( $full_class, strrpos( $full_class, '\\' ) + 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( in_array( $plugin, $valid_options, true ) ) {
|
if ( in_array( $plugin, $valid_options, true ) ) {
|
||||||
|
|
|
@ -366,8 +366,10 @@ class Setup {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$active_event_plugins = $setup->get_active_event_plugins();
|
$active_event_plugins = $setup->get_active_event_plugins();
|
||||||
if ( array_key_exists( $event_plugin, $active_event_plugins ) ) {
|
foreach ( $active_event_plugins as $active_event_plugin ) {
|
||||||
return $active_event_plugins[ $event_plugin ]->get_transmogrifier_class();
|
if ( strrpos( $active_event_plugin::class, $event_plugin ) ) {
|
||||||
|
return $active_event_plugin::get_transmogrifier_class();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ abstract class Event_Plugin {
|
||||||
* Returns the class used for transmogrifying an Event (ActivityStreams to Event plugin transformation).
|
* Returns the class used for transmogrifying an Event (ActivityStreams to Event plugin transformation).
|
||||||
*/
|
*/
|
||||||
public static function get_transmogrifier_class(): ?string {
|
public static function get_transmogrifier_class(): ?string {
|
||||||
if ( ! self::supports_event_sources() ) {
|
if ( ! static::supports_event_sources() ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return str_replace( 'Integrations', 'Activitypub\Transmogrifier', static::class );
|
return str_replace( 'Integrations', 'Activitypub\Transmogrifier', static::class );
|
||||||
|
|
Loading…
Reference in a new issue