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,18 +1,22 @@
<?php
/**
* ActivityPub Actors REST-Class
*
* @package Activitypub
*/
namespace Activitypub\Rest;
use WP_Error;
use WP_REST_Server;
use WP_REST_Request;
use WP_REST_Response;
use Activitypub\Webfinger;
use Activitypub\Activity\Activity;
use Activitypub\Collection\Users as User_Collection;
use function Activitypub\is_activitypub_request;
/**
* ActivityPub Actors REST-Class
* ActivityPub Actors REST-Class.
*
* @author Matthias Pfefferle
*
@ -20,14 +24,14 @@ use function Activitypub\is_activitypub_request;
*/
class Actors {
/**
* Initialize the class, registering WordPress hooks
* Initialize the class, registering WordPress hooks.
*/
public static function init() {
self::register_routes();
}
/**
* Register routes
* Register routes.
*/
public static function register_routes() {
\register_rest_route(
@ -65,9 +69,9 @@ class Actors {
/**
* Handle GET request
*
* @param WP_REST_Request $request
* @param \WP_REST_Request $request The request object.
*
* @return WP_REST_Response
* @return WP_REST_Response|\WP_Error The response object or WP_Error.
*/
public static function get( $request ) {
$user_id = $request->get_param( 'user_id' );
@ -77,14 +81,17 @@ class Actors {
return $user;
}
// redirect to canonical URL if it is not an ActivityPub request
$link_header = sprintf( '<%1$s>; rel="alternate"; type="application/activity+json"', $user->get_id() );
// Redirect to canonical URL if it is not an ActivityPub request.
if ( ! is_activitypub_request() ) {
header( 'Link: ' . $link_header );
header( 'Location: ' . $user->get_canonical_url(), true, 301 );
exit;
}
/*
* Action triggerd prior to the ActivityPub profile being created and sent to the client
/**
* Action triggered prior to the ActivityPub profile being created and sent to the client.
*/
\do_action( 'activitypub_rest_users_pre' );
@ -92,17 +99,18 @@ class Actors {
$rest_response = new WP_REST_Response( $json, 200 );
$rest_response->header( 'Content-Type', 'application/activity+json; charset=' . get_option( 'blog_charset' ) );
$rest_response->header( 'Link', $link_header );
return $rest_response;
}
/**
* Endpoint for remote follow UI/Block
* Endpoint for remote follow UI/Block.
*
* @param WP_REST_Request $request The request object.
*
* @return void|string The URL to the remote follow page
* @return WP_REST_Response|\WP_Error The response object or WP_Error.
*/
public static function remote_follow_get( WP_REST_Request $request ) {
$resource = $request->get_param( 'resource' );
@ -123,15 +131,18 @@ class Actors {
$url = str_replace( '{uri}', $resource, $template );
return new WP_REST_Response(
array( 'url' => $url, 'template' => $template ),
array(
'url' => $url,
'template' => $template,
),
200
);
}
/**
* The supported parameters
* The supported parameters.
*
* @return array list of parameters
* @return array List of parameters,
*/
public static function request_parameters() {
$params = array();