updated plugin ActivityPub version 3.3.3

This commit is contained in:
2024-10-09 12:44:17 +00:00
committed by Gitium
parent fb4b27bbc6
commit c54fa007bd
106 changed files with 7070 additions and 2918 deletions

View File

@ -1,4 +1,10 @@
<?php
/**
* Follow handler file.
*
* @package Activitypub
*/
namespace Activitypub\Handler;
use Activitypub\Http;
@ -8,11 +14,11 @@ use Activitypub\Collection\Users;
use Activitypub\Collection\Followers;
/**
* Handle Follow requests
* Handle Follow requests.
*/
class Follow {
/**
* Initialize the class, registering WordPress hooks
* Initialize the class, registering WordPress hooks.
*/
public static function init() {
\add_action(
@ -29,23 +35,21 @@ class Follow {
}
/**
* Handle "Follow" requests
* Handle "Follow" requests.
*
* @param array $activity The activity object
* @param int $user_id The user ID
* @param array $activity The activity object.
*/
public static function handle_follow( $activity ) {
$user = Users::get_by_resource( $activity['object'] );
if ( ! $user || is_wp_error( $user ) ) {
// If we can not find a user,
// we can not initiate a follow process
// If we can not find a user, we can not initiate a follow process.
return;
}
$user_id = $user->get__id();
// save follower
// Save follower.
$follower = Followers::add_follower(
$user_id,
$activity['actor']
@ -59,7 +63,7 @@ class Follow {
$follower
);
// send notification
// Send notification.
$notification = new Notification(
'follow',
$activity['actor'],
@ -70,25 +74,22 @@ class Follow {
}
/**
* Send Accept response
* Send Accept response.
*
* @param string $actor The Actor URL
* @param array $object The Activity object
* @param int $user_id The ID of the WordPress User
* @param Activitypub\Model\Follower $follower The Follower object
*
* @return void
* @param string $actor The Actor URL.
* @param array $activity_object The Activity object.
* @param int $user_id The ID of the WordPress User.
* @param \Activitypub\Model\Follower $follower The Follower object.
*/
public static function send_follow_response( $actor, $object, $user_id, $follower ) {
public static function send_follow_response( $actor, $activity_object, $user_id, $follower ) {
if ( \is_wp_error( $follower ) ) {
// it is not even possible to send a "Reject" because
// we can not get the Remote-Inbox
// Impossible to send a "Reject" because we can not get the Remote-Inbox.
return;
}
// only send minimal data
$object = array_intersect_key(
$object,
// Only send minimal data.
$activity_object = array_intersect_key(
$activity_object,
array_flip(
array(
'id',
@ -101,13 +102,13 @@ class Follow {
$user = Users::get_by_id( $user_id );
// get inbox
// Get inbox.
$inbox = $follower->get_shared_inbox();
// send "Accept" activity
// Send "Accept" activity.
$activity = new Activity();
$activity->set_type( 'Accept' );
$activity->set_object( $object );
$activity->set_object( $activity_object );
$activity->set_actor( $user->get_id() );
$activity->set_to( $actor );
$activity->set_id( $user->get_id() . '#follow-' . \preg_replace( '~^https?://~', '', $actor ) . '-' . \time() );