add dummy handlers for incoming event source related activities
Some checks failed
PHP Code Checker / PHP Code Checker (pull_request) Failing after 48s
PHPUnit / PHPUnit – PHP 7.4 (pull_request) Successful in 1m7s
PHPUnit / PHPUnit – PHP 8.0 (pull_request) Failing after 56s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Failing after 55s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Failing after 55s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Failing after 55s
PHPUnit / PHPUnit – PHP 8.4 (pull_request) Failing after 54s
Some checks failed
PHP Code Checker / PHP Code Checker (pull_request) Failing after 48s
PHPUnit / PHPUnit – PHP 7.4 (pull_request) Successful in 1m7s
PHPUnit / PHPUnit – PHP 8.0 (pull_request) Failing after 56s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Failing after 55s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Failing after 55s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Failing after 55s
PHPUnit / PHPUnit – PHP 8.4 (pull_request) Failing after 54s
and phpcs
This commit is contained in:
parent
d77cdf1430
commit
970f3e7754
13 changed files with 320 additions and 29 deletions
36
includes/activitypub/class-handler.php
Normal file
36
includes/activitypub/class-handler.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
/**
|
||||
* Class responsible for registering handlers for incoming activities to the ActivityPub plugin.
|
||||
*
|
||||
* @package Event_Bridge_For_ActivityPub
|
||||
* @since 1.0.0
|
||||
* @license AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace Event_Bridge_For_ActivityPub\ActivityPub;
|
||||
|
||||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||
|
||||
use Event_Bridge_For_ActivityPub\ActivityPub\Handler\Accept;
|
||||
use Event_Bridge_For_ActivityPub\ActivityPub\Handler\Announce;
|
||||
use Event_Bridge_For_ActivityPub\ActivityPub\Handler\Update;
|
||||
use Event_Bridge_For_ActivityPub\ActivityPub\Handler\Create;
|
||||
use Event_Bridge_For_ActivityPub\ActivityPub\Handler\Delete;
|
||||
|
||||
/**
|
||||
* Class responsible for registering handlers for incoming activities to the ActivityPub plugin.
|
||||
*/
|
||||
class Handler {
|
||||
/**
|
||||
* Register all ActivityPub handlers.
|
||||
*/
|
||||
public static function register_handlers() {
|
||||
|
||||
Accept::init();
|
||||
Announce::init();
|
||||
Update::init();
|
||||
Create::init();
|
||||
Delete::init();
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@
|
|||
* Event sources collection file.
|
||||
*
|
||||
* @package Event_Bridge_For_ActivityPub
|
||||
* @since 1.0.0
|
||||
* @license AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
|
@ -87,8 +88,8 @@ class Event_Sources {
|
|||
self::POST_TYPE,
|
||||
'event_source_active',
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'single' => true,
|
||||
'type' => 'bool',
|
||||
'single' => true,
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -294,7 +295,7 @@ class Event_Sources {
|
|||
|
||||
$actor = Event_Source::init_from_cpt( get_post( $post_id ) );
|
||||
|
||||
if ( is_wp_error( $actor ) ) {
|
||||
if ( ! $actor instanceof Event_Source ) {
|
||||
return $actor;
|
||||
}
|
||||
|
||||
|
@ -309,7 +310,7 @@ class Event_Sources {
|
|||
$activity->set_cc( null );
|
||||
$activity->set_actor( $application->get_id() );
|
||||
$activity->set_object( $to );
|
||||
$activity->set_id( $actor . '#follow-' . \preg_replace( '~^https?://~', '', $to ) );
|
||||
$activity->set_id( $application->get_id() . '#follow-' . \preg_replace( '~^https?://~', '', $to ) );
|
||||
$activity = $activity->to_json();
|
||||
\Activitypub\safe_remote_post( $inbox, $activity, \Activitypub\Collection\Actors::APPLICATION_USER_ID );
|
||||
}
|
||||
|
@ -345,7 +346,7 @@ class Event_Sources {
|
|||
|
||||
$actor = Event_Source::init_from_cpt( get_post( $post_id ) );
|
||||
|
||||
if ( is_wp_error( $actor ) ) {
|
||||
if ( ! $actor instanceof Event_Source ) {
|
||||
return $actor;
|
||||
}
|
||||
|
||||
|
|
50
includes/activitypub/handler/class-accept.php
Normal file
50
includes/activitypub/handler/class-accept.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
/**
|
||||
* Accept handler file.
|
||||
*
|
||||
* @package Event_Bridge_For_ActivityPub
|
||||
* @since 1.0.0
|
||||
* @license AGPL-3.0-or-later */
|
||||
|
||||
namespace Event_Bridge_For_ActivityPub\ActivityPub\Handler;
|
||||
|
||||
use Activitypub\Notification;
|
||||
use Activitypub\Collection\Actors;
|
||||
|
||||
/**
|
||||
* Handle Accept requests.
|
||||
*/
|
||||
class Accept {
|
||||
/**
|
||||
* Initialize the class, registering WordPress hooks.
|
||||
*/
|
||||
public static function init() {
|
||||
\add_action(
|
||||
'activitypub_inbox_accept',
|
||||
array( self::class, 'handle_accept' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle "Follow" requests.
|
||||
*
|
||||
* @param array $activity The activity object.
|
||||
*/
|
||||
public static function handle_accept( $activity ) {
|
||||
if ( ! isset( $activity['object'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$object = Actors::get_by_resource( $activity['object'] );
|
||||
|
||||
if ( ! $object || is_wp_error( $object ) ) {
|
||||
// If we can not find a actor, we handle the `Accept` activity.
|
||||
return;
|
||||
}
|
||||
|
||||
// We only expect `Accept` activities being answers to follow requests by the application actor.
|
||||
if ( Actors::APPLICATION_USER_ID !== $object->get__id() ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
49
includes/activitypub/handler/class-announce.php
Normal file
49
includes/activitypub/handler/class-announce.php
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
/**
|
||||
* Accept handler file.
|
||||
*
|
||||
* @package Event_Bridge_For_ActivityPub
|
||||
*/
|
||||
|
||||
namespace Event_Bridge_For_ActivityPub\ActivityPub\Handler;
|
||||
|
||||
use Activitypub\Notification;
|
||||
use Activitypub\Collection\Actors;
|
||||
|
||||
/**
|
||||
* Handle Accept requests.
|
||||
*/
|
||||
class Announce {
|
||||
/**
|
||||
* Initialize the class, registering WordPress hooks.
|
||||
*/
|
||||
public static function init() {
|
||||
\add_action(
|
||||
'activitypub_inbox_announce',
|
||||
array( self::class, 'handle_announce' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle "Announce" requests.
|
||||
*
|
||||
* @param array $activity The activity object.
|
||||
*/
|
||||
public static function handle_announce( $activity ) {
|
||||
if ( ! isset( $activity['object'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$object = Actors::get_by_resource( $activity['object'] );
|
||||
|
||||
if ( ! $object || is_wp_error( $object ) ) {
|
||||
// If we can not find a actor, we handle the `Accept` activity.
|
||||
return;
|
||||
}
|
||||
|
||||
// We only expect `Accept` activities being answers to follow requests by the application actor.
|
||||
if ( Actors::APPLICATION_USER_ID !== $object->get__id() ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
49
includes/activitypub/handler/class-create.php
Normal file
49
includes/activitypub/handler/class-create.php
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
/**
|
||||
* Create handler file.
|
||||
*
|
||||
* @package Event_Bridge_For_ActivityPub
|
||||
*/
|
||||
|
||||
namespace Event_Bridge_For_ActivityPub\ActivityPub\Handler;
|
||||
|
||||
use Activitypub\Notification;
|
||||
use Activitypub\Collection\Actors;
|
||||
|
||||
/**
|
||||
* Handle Create requests.
|
||||
*/
|
||||
class Create {
|
||||
/**
|
||||
* Initialize the class, registering WordPress hooks.
|
||||
*/
|
||||
public static function init() {
|
||||
\add_action(
|
||||
'activitypub_inbox_create',
|
||||
array( self::class, 'handle_create' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle "Create" requests.
|
||||
*
|
||||
* @param array $activity The activity object.
|
||||
*/
|
||||
public static function handle_create( $activity ) {
|
||||
if ( ! isset( $activity['object'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$object = Actors::get_by_resource( $activity['object'] );
|
||||
|
||||
if ( ! $object || is_wp_error( $object ) ) {
|
||||
// If we can not find a actor, we handle the `create` activity.
|
||||
return;
|
||||
}
|
||||
|
||||
// We only expect `create` activities being answers to follow requests by the application actor.
|
||||
if ( Actors::APPLICATION_USER_ID !== $object->get__id() ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
49
includes/activitypub/handler/class-delete.php
Normal file
49
includes/activitypub/handler/class-delete.php
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
/**
|
||||
* Delete handler file.
|
||||
*
|
||||
* @package Event_Bridge_For_ActivityPub
|
||||
*/
|
||||
|
||||
namespace Event_Bridge_For_ActivityPub\ActivityPub\Handler;
|
||||
|
||||
use Activitypub\Notification;
|
||||
use Activitypub\Collection\Actors;
|
||||
|
||||
/**
|
||||
* Handle Delete requests.
|
||||
*/
|
||||
class Delete {
|
||||
/**
|
||||
* Initialize the class, registering WordPress hooks.
|
||||
*/
|
||||
public static function init() {
|
||||
\add_action(
|
||||
'activitypub_inbox_delete',
|
||||
array( self::class, 'handle_delete' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle "Follow" requests.
|
||||
*
|
||||
* @param array $activity The activity object.
|
||||
*/
|
||||
public static function handle_delete( $activity ) {
|
||||
if ( ! isset( $activity['object'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$object = Actors::get_by_resource( $activity['object'] );
|
||||
|
||||
if ( ! $object || is_wp_error( $object ) ) {
|
||||
// If we can not find a actor, we handle the `Delete` activity.
|
||||
return;
|
||||
}
|
||||
|
||||
// We only expect `Delete` activities being answers to follow requests by the application actor.
|
||||
if ( Actors::APPLICATION_USER_ID !== $object->get__id() ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
49
includes/activitypub/handler/class-update.php
Normal file
49
includes/activitypub/handler/class-update.php
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
/**
|
||||
* Update handler file.
|
||||
*
|
||||
* @package Event_Bridge_For_ActivityPub
|
||||
*/
|
||||
|
||||
namespace Event_Bridge_For_ActivityPub\ActivityPub\Handler;
|
||||
|
||||
use Activitypub\Notification;
|
||||
use Activitypub\Collection\Actors;
|
||||
|
||||
/**
|
||||
* Handle Update requests.
|
||||
*/
|
||||
class Update {
|
||||
/**
|
||||
* Initialize the class, registering WordPress hooks.
|
||||
*/
|
||||
public static function init() {
|
||||
\add_action(
|
||||
'activitypub_inbox_update',
|
||||
array( self::class, 'handle_update' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle "Follow" requests.
|
||||
*
|
||||
* @param array $activity The activity object.
|
||||
*/
|
||||
public static function handle_update( $activity ) {
|
||||
if ( ! isset( $activity['object'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$object = Actors::get_by_resource( $activity['object'] );
|
||||
|
||||
if ( ! $object || is_wp_error( $object ) ) {
|
||||
// If we can not find a actor, we handle the `Update` activity.
|
||||
return;
|
||||
}
|
||||
|
||||
// We only expect `Update` activities being answers to follow requests by the application actor.
|
||||
if ( Actors::APPLICATION_USER_ID !== $object->get__id() ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -77,19 +77,17 @@ class Settings_Page {
|
|||
|
||||
if ( isset( $url['path'] ) && isset( $url['host'] ) && isset( $url['scheme'] ) ) {
|
||||
$actor_url = $event_source;
|
||||
} elseif ( preg_match( '/^@?' . Event_Source::ACTIVITYPUB_USER_HANDLE_REGEXP . '$/i', $event_source ) ) {
|
||||
$actor_url = Webfinger::resolve( $event_source );
|
||||
if ( is_wp_error( $actor_url ) ) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if ( preg_match( '/^@?' . Event_Source::ACTIVITYPUB_USER_HANDLE_REGEXP . '$/i', $event_source ) ) {
|
||||
$actor_url = Webfinger::resolve( $event_source );
|
||||
if ( is_wp_error( $actor_url ) ) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if ( ! isset( $url['path'] ) && isset( $url['host'] ) ) {
|
||||
$actor_url = Event_Sources::get_application_actor( $url['host'] );
|
||||
}
|
||||
if ( self::is_domain( $event_source ) ) {
|
||||
$actor_url = Event_Sources::get_application_actor( $event_source );
|
||||
}
|
||||
if ( ! isset( $url['path'] ) && isset( $url['host'] ) ) {
|
||||
$actor_url = Event_Sources::get_application_actor( $url['host'] );
|
||||
}
|
||||
if ( self::is_domain( $event_source ) ) {
|
||||
$actor_url = Event_Sources::get_application_actor( $event_source );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
* Class for handling and saving the ActivityPub event sources (i.e. follows).
|
||||
*
|
||||
* @package Event_Bridge_For_ActivityPub
|
||||
* @since 1.0.0
|
||||
* @license AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace Event_Bridge_For_ActivityPub;
|
||||
|
|
|
@ -15,12 +15,13 @@ namespace Event_Bridge_For_ActivityPub;
|
|||
// Exit if accessed directly.
|
||||
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
|
||||
|
||||
use Event_Bridge_For_ActivityPub\ActivityPub\Collection\Event_Sources as Event_Sources_Collection;
|
||||
use Event_Bridge_For_ActivityPub\ActivityPub\Handler;
|
||||
use Event_Bridge_For_ActivityPub\Admin\Event_Plugin_Admin_Notices;
|
||||
use Event_Bridge_For_ActivityPub\Admin\General_Admin_Notices;
|
||||
use Event_Bridge_For_ActivityPub\Admin\Health_Check;
|
||||
use Event_Bridge_For_ActivityPub\Admin\Settings_Page;
|
||||
use Event_Bridge_For_ActivityPub\Integrations\Event_Plugin;
|
||||
use Event_Bridge_For_ActivityPub\ActivityPub\Collection\Event_Sources as Event_Sources_Collection;
|
||||
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
|
||||
|
@ -178,6 +179,8 @@ class Setup {
|
|||
array( Settings_Page::class, 'settings_link' )
|
||||
);
|
||||
|
||||
add_action( 'activitypub_register_handlers', array( Handler::class, 'register_activitypub_handlers' ) ) ;
|
||||
|
||||
// If we don't have any active event plugins, or the ActivityPub plugin is not enabled, abort here.
|
||||
if ( empty( $this->active_event_plugins ) || ! $this->activitypub_plugin_is_active ) {
|
||||
return;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*
|
||||
* @package Event_Bridge_For_ActivityPub
|
||||
* @since 1.0.0
|
||||
* @license AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace Event_Bridge_For_ActivityPub\Integrations;
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
* Event Sources Table-Class file.
|
||||
*
|
||||
* @package Event_Bridge_For_ActivityPub
|
||||
* @since 1.0.0
|
||||
* @license AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace Event_Bridge_For_ActivityPub\Table;
|
||||
|
@ -40,13 +42,13 @@ class Event_Sources extends WP_List_Table {
|
|||
*/
|
||||
public function get_columns() {
|
||||
return array(
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'icon' => \__( 'Icon', 'event-bridge-for-activitypub' ),
|
||||
'name' => \__( 'Name', 'event-bridge-for-activitypub' ),
|
||||
'active' => \__( 'Active', 'event-bridge-for-activitypub' ),
|
||||
'url' => \__( 'URL', 'event-bridge-for-activitypub' ),
|
||||
'published' => \__( 'Followed', 'event-bridge-for-activitypub' ),
|
||||
'modified' => \__( 'Last updated', 'event-bridge-for-activitypub' ),
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'icon' => \__( 'Icon', 'event-bridge-for-activitypub' ),
|
||||
'name' => \__( 'Name', 'event-bridge-for-activitypub' ),
|
||||
'active' => \__( 'Active', 'event-bridge-for-activitypub' ),
|
||||
'url' => \__( 'URL', 'event-bridge-for-activitypub' ),
|
||||
'published' => \__( 'Followed', 'event-bridge-for-activitypub' ),
|
||||
'modified' => \__( 'Last updated', 'event-bridge-for-activitypub' ),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -57,9 +59,9 @@ class Event_Sources extends WP_List_Table {
|
|||
*/
|
||||
public function get_sortable_columns() {
|
||||
return array(
|
||||
'name' => array( 'name', true ),
|
||||
'modified' => array( 'modified', false ),
|
||||
'published' => array( 'published', false ),
|
||||
'name' => array( 'name', true ),
|
||||
'modified' => array( 'modified', false ),
|
||||
'published' => array( 'published', false ),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -113,7 +115,7 @@ class Event_Sources extends WP_List_Table {
|
|||
'icon' => esc_attr( $actor->get_icon_url() ),
|
||||
'name' => esc_attr( $actor->get_name() ),
|
||||
'url' => esc_attr( object_to_uri( $actor->get_id() ) ),
|
||||
'active' => esc_attr( get_post_meta( $actor->get__id(), 'event_source_active', true) ),
|
||||
'active' => esc_attr( get_post_meta( $actor->get__id(), 'event_source_active', true ) ),
|
||||
'identifier' => esc_attr( $actor->get_id() ),
|
||||
'published' => esc_attr( $actor->get_published() ),
|
||||
'modified' => esc_attr( $actor->get_updated() ),
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
* Event Sources management page for the ActivityPub Event Bridge.
|
||||
*
|
||||
* @package Event_Bridge_For_ActivityPub
|
||||
* @since 1.0.0
|
||||
* @license AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
// Exit if accessed directly.
|
||||
|
|
Loading…
Reference in a new issue