diff --git a/includes/activitypub/class-handler.php b/includes/activitypub/class-handler.php new file mode 100644 index 0000000..b9961d2 --- /dev/null +++ b/includes/activitypub/class-handler.php @@ -0,0 +1,36 @@ + '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; } diff --git a/includes/activitypub/handler/class-accept.php b/includes/activitypub/handler/class-accept.php new file mode 100644 index 0000000..4a86ae5 --- /dev/null +++ b/includes/activitypub/handler/class-accept.php @@ -0,0 +1,50 @@ +get__id() ) { + return; + } + } +} diff --git a/includes/activitypub/handler/class-announce.php b/includes/activitypub/handler/class-announce.php new file mode 100644 index 0000000..f79b3e7 --- /dev/null +++ b/includes/activitypub/handler/class-announce.php @@ -0,0 +1,49 @@ +get__id() ) { + return; + } + } +} diff --git a/includes/activitypub/handler/class-create.php b/includes/activitypub/handler/class-create.php new file mode 100644 index 0000000..854a084 --- /dev/null +++ b/includes/activitypub/handler/class-create.php @@ -0,0 +1,49 @@ +get__id() ) { + return; + } + } +} diff --git a/includes/activitypub/handler/class-delete.php b/includes/activitypub/handler/class-delete.php new file mode 100644 index 0000000..ff4cede --- /dev/null +++ b/includes/activitypub/handler/class-delete.php @@ -0,0 +1,49 @@ +get__id() ) { + return; + } + } +} diff --git a/includes/activitypub/handler/class-update.php b/includes/activitypub/handler/class-update.php new file mode 100644 index 0000000..16b7559 --- /dev/null +++ b/includes/activitypub/handler/class-update.php @@ -0,0 +1,49 @@ +get__id() ) { + return; + } + } +} diff --git a/includes/admin/class-settings-page.php b/includes/admin/class-settings-page.php index a81252f..c49602b 100644 --- a/includes/admin/class-settings-page.php +++ b/includes/admin/class-settings-page.php @@ -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 ); } } diff --git a/includes/class-event-sources.php b/includes/class-event-sources.php index b636569..f2701fa 100644 --- a/includes/class-event-sources.php +++ b/includes/class-event-sources.php @@ -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; diff --git a/includes/class-setup.php b/includes/class-setup.php index df9970a..e18e468 100644 --- a/includes/class-setup.php +++ b/includes/class-setup.php @@ -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; diff --git a/includes/integrations/class-event-plugin.php b/includes/integrations/class-event-plugin.php index 56d020a..aba3d22 100644 --- a/includes/integrations/class-event-plugin.php +++ b/includes/integrations/class-event-plugin.php @@ -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; diff --git a/includes/table/class-event-sources.php b/includes/table/class-event-sources.php index 2969483..9dcbf03 100644 --- a/includes/table/class-event-sources.php +++ b/includes/table/class-event-sources.php @@ -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' => '', - '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' => '', + '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() ), diff --git a/templates/event-sources.php b/templates/event-sources.php index b2a4b20..47e2f22 100644 --- a/templates/event-sources.php +++ b/templates/event-sources.php @@ -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.