Compare commits

..

4 commits

Author SHA1 Message Date
62a355d328 Merge branch 'main' into join_ignore
All checks were successful
PHP Code Checker / PHP Code Checker (pull_request) Successful in 46s
PHPUnit / PHPUnit – PHP 7.4 (pull_request) Successful in 1m3s
PHPUnit / PHPUnit – PHP 8.0 (pull_request) Successful in 1m1s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m2s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m6s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 1m7s
PHPUnit / PHPUnit – PHP 8.4 (pull_request) Successful in 1m8s
2025-01-04 09:38:35 +01:00
a0fa94847e phpcs 2025-01-04 09:36:49 +01:00
b4a216fd78 Merge branch 'main' into join_ignore
Some checks failed
PHP Code Checker / PHP Code Checker (pull_request) Failing after 50s
PHPUnit / PHPUnit – PHP 7.4 (pull_request) Successful in 1m4s
PHPUnit / PHPUnit – PHP 8.0 (pull_request) Successful in 1m1s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m3s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 1m3s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 1m8s
PHPUnit / PHPUnit – PHP 8.4 (pull_request) Successful in 1m2s
2024-12-31 14:45:27 +01:00
08f136d52f first draft of join handler
Some checks failed
PHP Code Checker / PHP Code Checker (pull_request) Failing after 50s
PHPUnit / PHPUnit – PHP 7.4 (pull_request) Successful in 1m0s
PHPUnit / PHPUnit – PHP 8.0 (pull_request) Successful in 1m1s
PHPUnit / PHPUnit – PHP 8.1 (pull_request) Successful in 1m0s
PHPUnit / PHPUnit – PHP 8.2 (pull_request) Successful in 58s
PHPUnit / PHPUnit – PHP 8.3 (pull_request) Successful in 57s
2024-11-19 11:41:32 +01:00
4 changed files with 155 additions and 0 deletions

View file

@ -3,7 +3,11 @@
**Tags:** events, fediverse, activitypub, calendar
**Requires at least:** 6.5
**Tested up to:** 6.7
<<<<<<< HEAD
**Stable tag:** 0.3.4
=======
**Stable tag:** 0.3.5
>>>>>>> 4dd1d56daa487caa56755e874dd7e74995f0340a
**Requires PHP:** 7.4
**License:** AGPL-3.0-or-later
**License URI:** https://www.gnu.org/licenses/agpl-3.0.html
@ -101,7 +105,13 @@ We're always interested in your feedback. Feel free to reach out to us via [E-Ma
## Acknowledgement
<<<<<<< HEAD
### [0.3.4] 2024-12-21 ###
* Initial release on https://wordpress.org/
=======
[<img src="./assets/img/acknowledgement-NLnet.svg" alt="NLnet foundation logo" width="20%" style="margin: 10px 5% 10px 5%;"/>](https://nlnet.nl)
[<img src="./assets/img/acknowledgement-NGI0Entrust.svg" alt="NGI Zero Logo" width="20%" style="margin: 10px 5% 10px 5%;"/>](https://nlnet.nl/entrust)
The development of this WordPress plugin was funded through the [NGI0 Entrust](https://NLnet.nl/entrust) Fund, a fund established by [NLnet](https://nlnet.nl) with financial support from the European Commission's [Next Generation Internet](https://ngi.eu) programme, under the aegis of [Communications Networks, Content and Technology](https://commission.europa.eu/about-european-commission/departments-and-executive-agencies/communications-networks-content-and-technology_en) under grant agreement number 101069594.
>>>>>>> 4dd1d56daa487caa56755e874dd7e74995f0340a

View file

@ -0,0 +1,137 @@
<?php
/**
* Join handler file.
*
* @package Event_Bridge_For_ActivityPub
* @license AGPL-3.0-or-later
*/
namespace Event_Bridge_For_ActivityPub\Activitypub\Handler;
use Activitypub\Activity\Activity;
use Activitypub\Collection\Actors;
use Activitypub\Http;
use Activitypub\Transformer\Factory;
use Event_Bridge_For_ActivityPub\Activitypub\Transformer\Event as Event_Transformer;
use function Activitypub\is_same_domain;
use function Activitypub\object_to_uri;
/**
* Handle Join requests.
*/
class Join {
/**
* Initialize the class, registering WordPress hooks.
*/
public static function init() {
\add_action(
'activitypub_inbox_join',
array( self::class, 'handle_join' )
);
\add_action(
'event_bridge_for_activitypub_ignore_join',
array( self::class, 'send_ignore_response' ),
10,
4
);
}
/**
* Handle ActivityPub "Join" requests.
*
* @param array $activity The activity object.
*/
public static function handle_follow( $activity ) {
$actor = Actors::get_by_resource( $activity['actor'] );
if ( ! $actor || is_wp_error( $actor ) ) {
// If we can not find a user, we can not proceed the join process.
return;
}
if ( ! array_key_exists( 'object', $activity ) ) {
// If the object is not set, we can not proceed the join process.
return;
}
$object_id = object_to_uri( $activity['object'] );
if ( ! is_same_domain( $object_id ) ) {
// If the "Join" object is not owned by this WordPress site, abort.
return;
}
$post_id = url_to_postid( $object_id );
if ( ! $post_id ) {
// No post is found for this URL/ID.
return;
}
$transformer = Factory::get_transformer( get_post( $post_id ) );
if ( ! $transformer instanceof Event_Transformer ) {
// The target post is not an event post.
return;
}
// Pass over to Event plugin specific handler if implemented here.
// Until then just send an ignore.
do_action(
'event_bridge_for_activitypub_ignore_join',
$transformer->get_actor_object()->get_id(),
$activity,
);
}
/**
* Send "Ignore" response.
*
* @param string $actor The actors ActivityPub ID which sends the response.
* @param array $activity_object The Activity object that gets ignored.
* @param string $to The target actor.
*/
public static function send_ignore_response( $actor, $activity_object, $to = null ) {
if ( ! $to && array_key_exists( 'actor', $activity_object ) ) {
$to = object_to_uri( $activity_object['actor'] );
}
if ( ! $to ) {
return;
}
// Only send minimal data.
$activity_object = array_intersect_key(
$activity_object,
array_flip(
array(
'id',
'type',
'actor',
'object',
)
)
);
$to = Actors::get_by_resource( $to );
$actor = Actors::get_by_resource( $actor );
// Get inbox.
$inbox = $to->get_shared_inbox();
// Send "Ignore" activity.
$activity = new Activity();
$activity->set_type( 'Ignore' );
$activity->set_object( $activity_object );
$activity->set_actor( $actor->get_id() );
$activity->set_to( $to );
$activity->set_id( $actor->get_id() . '#ignore-' . \preg_replace( '~^https?://~', '', $activity_object['id'] ) );
$activity = $activity->to_json();
Http::post( $inbox, $activity, $actor->get__id() );
}
}

View file

@ -215,6 +215,10 @@ class Setup {
return;
}
// Register the handler for incoming ActivityPub "Join" activities.
add_action( 'init', array( \Event_Bridge_For_ActivityPub\ActivityPub\Handler\Join::class, 'init' ) );
// Register the custom ActivityPub transformers.
add_filter( 'activitypub_transformer', array( $this, 'register_activitypub_event_transformer' ), 10, 3 );
}

View file

@ -3,7 +3,11 @@ Contributors: andremenrath
Tags: events, fediverse, activitypub, calendar
Requires at least: 6.5
Tested up to: 6.7
<<<<<<< HEAD
Stable tag: 0.3.4
=======
Stable tag: 0.3.5
>>>>>>> 4dd1d56daa487caa56755e874dd7e74995f0340a
Requires PHP: 7.4
License: AGPL-3.0-or-later
License URI: https://www.gnu.org/licenses/agpl-3.0.html